parameters: (combo, new_vals)
docstring: Update the contents of a combo box with a set of new values.
  
      If the previously selected element is still present in the new values, it
      will remain as active selection, even if its index has changed. This will
      not trigger any signal.
  
      If the previously selected element is no longer present in the new values,
      the combo will unset its selection. This will trigger signals for changed
      element.
docstring_summary: Update the contents of a combo box with a set of new values.
docstring_tokens: Update the contents of a combo box with a set of new values .
function: def update_combo(combo, new_vals):
      """
      Update the contents of a combo box with a set of new values.
  
      If the previously selected element is still present in the new values, it
      will remain as active selection, even if its index has changed. This will
      not trigger any signal.
  
      If the previously selected element is no longer present in the new values,
      the combo will unset its selection. This will trigger signals for changed
      element.
      """
      selected_val = combo.currentText()
      old_vals = [combo.itemText(i) for i in range(combo.count())]
  
      # Check if combo items changed
      if not _is_permutation(old_vals, new_vals):
          # Determine if selected value is in the new list
          selected_id = -1
          try:
              selected_id = new_vals.index(selected_val)
          except (ValueError):
              combo.setCurrentIndex(-1)
  
          # Re-populate items
          combo.blockSignals(True)  # No need to notify these changes
          combo.clear()
          combo.insertItems(0, new_vals)
          combo.setCurrentIndex(selected_id)  # Restore selection
          combo.blockSignals(False)
function_tokens: def update_combo ( combo , new_vals ) : selected_val = combo . currentText ( ) old_vals = [ combo . itemText ( i ) for i in range ( combo . count ( ) ) ] # Check if combo items changed if not _is_permutation ( old_vals , new_vals ) : # Determine if selected value is in the new list selected_id = - 1 try : selected_id = new_vals . index ( selected_val ) except ( ValueError ) : combo . setCurrentIndex ( - 1 ) # Re-populate items combo . blockSignals ( True ) # No need to notify these changes combo . clear ( ) combo . insertItems ( 0 , new_vals ) combo . setCurrentIndex ( selected_id ) # Restore selection combo . blockSignals ( False )