class GroupSelectParameterWidget(GenericParameterWidget): """Widget class for Group Select Parameter.""" def __init__(self, parameter, parent=None): """Constructor. :param parameter: A GroupSelectParameter object. :type parameter: GroupSelectParameter """ QWidget.__init__(self, parent) self._parameter = parameter # Store spin box self.spin_boxes = {} # Create elements # Label (name) self.label = QLabel(self._parameter.name) # Layouts self.main_layout = QVBoxLayout() self.input_layout = QVBoxLayout() # _inner_input_layout must be filled with widget in the child class self.inner_input_layout = QVBoxLayout() self.radio_button_layout = QGridLayout() # Create radio button group self.input_button_group = QButtonGroup() # List widget self.list_widget = QListWidget() self.list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection) self.list_widget.setDragDropMode(QAbstractItemView.DragDrop) self.list_widget.setDefaultDropAction(Qt.MoveAction) self.list_widget.setEnabled(False) self.list_widget.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding) for i, key in enumerate(self._parameter.options): value = self._parameter.options[key] radio_button = QRadioButton(value.get('label')) self.radio_button_layout.addWidget(radio_button, i, 0) if value.get('type') == SINGLE_DYNAMIC: double_spin_box = QDoubleSpinBox() self.radio_button_layout.addWidget(double_spin_box, i, 1) double_spin_box.setValue(value.get('value', 0)) double_spin_box.setMinimum( value.get('constraint', {}).get('min', 0)) double_spin_box.setMaximum( value.get('constraint', {}).get('max', 1)) double_spin_box.setSingleStep( value.get('constraint', {}).get('step', 0.01)) step = double_spin_box.singleStep() if step > 1: precision = 0 else: precision = len(str(step).split('.')[1]) if precision > 3: precision = 3 double_spin_box.setDecimals(precision) self.spin_boxes[key] = double_spin_box # Enable spin box depends on the selected option if self._parameter.selected == key: double_spin_box.setEnabled(True) else: double_spin_box.setEnabled(False) elif value.get('type') == STATIC: static_value = value.get('value', 0) if static_value is not None: self.radio_button_layout.addWidget( QLabel(str(static_value)), i, 1) elif value.get('type') == MULTIPLE_DYNAMIC: selected_fields = value.get('value', []) if self._parameter.selected == key: self.list_widget.setEnabled(True) else: self.list_widget.setEnabled(False) self.input_button_group.addButton(radio_button, i) if self._parameter.selected == key: radio_button.setChecked(True) # Help text self.help_label = QLabel(self._parameter.help_text) self.help_label.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding) self.help_label.setWordWrap(True) self.help_label.setAlignment(Qt.AlignTop) self.inner_input_layout.addLayout(self.radio_button_layout) self.inner_input_layout.addWidget(self.list_widget) # Put elements into layouts self.input_layout.addWidget(self.label) self.input_layout.addLayout(self.inner_input_layout) self.help_layout = QVBoxLayout() self.help_layout.addWidget(self.help_label) self.main_layout.addLayout(self.input_layout) self.main_layout.addLayout(self.help_layout) self.setLayout(self.main_layout) self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding) # Update list widget self.update_list_widget() # Connect signal self.input_button_group.buttonClicked.connect( self.radio_buttons_clicked) def get_parameter(self): """Obtain list parameter object from the current widget state. :returns: A DefaultValueParameter from the current state of widget :rtype: DefaultValueParameter """ # Set value for each key for key, value in self._parameter.options.items(): if value.get('type') == STATIC: continue elif value.get('type') == SINGLE_DYNAMIC: new_value = self.spin_boxes.get(key).value() self._parameter.set_value_for_key(key, new_value) elif value.get('type') == MULTIPLE_DYNAMIC: # Need to iterate through all items items = [] for index in xrange(self.list_widget.count()): items.append(self.list_widget.item(index)) new_value = [i.text() for i in items] self._parameter.set_value_for_key(key, new_value) # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() # No radio button checked, then default value = None if radio_button_checked_id == -1: self._parameter.selected = None else: self._parameter.selected = self._parameter.options.keys( )[radio_button_checked_id] return self._parameter def update_list_widget(self): """Update list widget when radio button is clicked.""" # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() # No radio button checked, then default value = None if radio_button_checked_id > -1: selected_dict = self._parameter.options.values( )[radio_button_checked_id] if selected_dict.get('type') == MULTIPLE_DYNAMIC: for field in selected_dict.get('value'): # Update list widget field_item = QListWidgetItem(self.list_widget) field_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) field_item.setData(Qt.UserRole, field) field_item.setText(field) self.list_widget.addItem(field_item) def radio_buttons_clicked(self): """Handler when selected radio button changed.""" # Disable all spin boxes for spin_box in self.spin_boxes.values(): spin_box.setEnabled(False) # Disable list widget self.list_widget.setEnabled(False) # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() if radio_button_checked_id > -1: selected_value = self._parameter.options.values( )[radio_button_checked_id] if selected_value.get('type') == MULTIPLE_DYNAMIC: # Enable list widget self.list_widget.setEnabled(True) elif selected_value.get('type') == SINGLE_DYNAMIC: selected_key = self._parameter.options.keys( )[radio_button_checked_id] self.spin_boxes[selected_key].setEnabled(True) def select_radio_button(self, key): """Helper to select a radio button with key. :param key: The key of the radio button. :type key: str """ key_index = self._parameter.options.keys().index(key) radio_button = self.input_button_group.button(key_index) radio_button.click()
class GroupSelectParameterWidget(GenericParameterWidget): """Widget class for Group Select Parameter.""" def __init__(self, parameter, parent=None): """Constructor. :param parameter: A GroupSelectParameter object. :type parameter: GroupSelectParameter """ QWidget.__init__(self, parent) self._parameter = parameter # Store spin box self.spin_boxes = {} # Create elements # Label (name) self.label = QLabel(self._parameter.name) # Layouts self.main_layout = QVBoxLayout() self.input_layout = QVBoxLayout() # _inner_input_layout must be filled with widget in the child class self.inner_input_layout = QVBoxLayout() self.radio_button_layout = QGridLayout() # Create radio button group self.input_button_group = QButtonGroup() # List widget self.list_widget = QListWidget() self.list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection) self.list_widget.setDragDropMode(QAbstractItemView.DragDrop) self.list_widget.setDefaultDropAction(Qt.MoveAction) self.list_widget.setEnabled(False) self.list_widget.setSizePolicy( QSizePolicy.Maximum, QSizePolicy.Expanding) for i, key in enumerate(self._parameter.options): value = self._parameter.options[key] radio_button = QRadioButton(value.get('label')) self.radio_button_layout.addWidget(radio_button, i, 0) if value.get('type') == SINGLE_DYNAMIC: double_spin_box = QDoubleSpinBox() self.radio_button_layout.addWidget(double_spin_box, i, 1) double_spin_box.setValue(value.get('value', 0)) double_spin_box.setMinimum( value.get('constraint', {}).get('min', 0)) double_spin_box.setMaximum(value.get( 'constraint', {}).get('max', 1)) double_spin_box.setSingleStep( value.get('constraint', {}).get('step', 0.01)) step = double_spin_box.singleStep() if step > 1: precision = 0 else: precision = len(str(step).split('.')[1]) if precision > 3: precision = 3 double_spin_box.setDecimals(precision) self.spin_boxes[key] = double_spin_box # Enable spin box depends on the selected option if self._parameter.selected == key: double_spin_box.setEnabled(True) else: double_spin_box.setEnabled(False) elif value.get('type') == STATIC: static_value = value.get('value', 0) if static_value is not None: self.radio_button_layout.addWidget( QLabel(str(static_value)), i, 1) elif value.get('type') == MULTIPLE_DYNAMIC: selected_fields = value.get('value', []) if self._parameter.selected == key: self.list_widget.setEnabled(True) else: self.list_widget.setEnabled(False) self.input_button_group.addButton(radio_button, i) if self._parameter.selected == key: radio_button.setChecked(True) # Help text self.help_label = QLabel(self._parameter.help_text) self.help_label.setSizePolicy( QSizePolicy.Maximum, QSizePolicy.Expanding) self.help_label.setWordWrap(True) self.help_label.setAlignment(Qt.AlignTop) self.inner_input_layout.addLayout(self.radio_button_layout) self.inner_input_layout.addWidget(self.list_widget) # Put elements into layouts self.input_layout.addWidget(self.label) self.input_layout.addLayout(self.inner_input_layout) self.help_layout = QVBoxLayout() self.help_layout.addWidget(self.help_label) self.main_layout.addLayout(self.input_layout) self.main_layout.addLayout(self.help_layout) self.setLayout(self.main_layout) self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding) # Update list widget self.update_list_widget() # Connect signal self.input_button_group.buttonClicked.connect( self.radio_buttons_clicked) def get_parameter(self): """Obtain list parameter object from the current widget state. :returns: A DefaultValueParameter from the current state of widget :rtype: DefaultValueParameter """ # Set value for each key for key, value in self._parameter.options.items(): if value.get('type') == STATIC: continue elif value.get('type') == SINGLE_DYNAMIC: new_value = self.spin_boxes.get(key).value() self._parameter.set_value_for_key(key, new_value) elif value.get('type') == MULTIPLE_DYNAMIC: # Need to iterate through all items items = [] for index in xrange(self.list_widget.count()): items.append(self.list_widget.item(index)) new_value = [i.text() for i in items] self._parameter.set_value_for_key(key, new_value) # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() # No radio button checked, then default value = None if radio_button_checked_id == -1: self._parameter.selected = None else: self._parameter.selected = self._parameter.options.keys()[ radio_button_checked_id] return self._parameter def update_list_widget(self): """Update list widget when radio button is clicked.""" # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() # No radio button checked, then default value = None if radio_button_checked_id > -1: selected_dict = self._parameter.options.values()[ radio_button_checked_id] if selected_dict.get('type') == MULTIPLE_DYNAMIC: for field in selected_dict.get('value'): # Update list widget field_item = QListWidgetItem(self.list_widget) field_item.setFlags( Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) field_item.setData(Qt.UserRole, field) field_item.setText(field) self.list_widget.addItem(field_item) def radio_buttons_clicked(self): """Handler when selected radio button changed.""" # Disable all spin boxes for spin_box in self.spin_boxes.values(): spin_box.setEnabled(False) # Disable list widget self.list_widget.setEnabled(False) # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() if radio_button_checked_id > -1: selected_value = self._parameter.options.values()[ radio_button_checked_id] if selected_value.get('type') == MULTIPLE_DYNAMIC: # Enable list widget self.list_widget.setEnabled(True) elif selected_value.get('type') == SINGLE_DYNAMIC: selected_key = self._parameter.options.keys()[ radio_button_checked_id] self.spin_boxes[selected_key].setEnabled(True) def select_radio_button(self, key): """Helper to select a radio button with key. :param key: The key of the radio button. :type key: str """ key_index = self._parameter.options.keys().index(key) radio_button = self.input_button_group.button(key_index) radio_button.click()
class ListBox(QWidget): def __init__(self, parent): QWidget.__init__(self, parent) while not isinstance(parent, QDialog): parent = parent.parent() self.setObjectName("ListBox" + str(len(parent.findChildren(ListBox)))) self.hLayoutBoxPanel = QHBoxLayout(self) self.hLayoutBoxPanel.setSpacing(0) self.hLayoutBoxPanel.setContentsMargins(3, 3, 3, 3) self.hLayoutBoxPanel.setObjectName(("hLayoutBoxPanel")) self.frameBoxPanel = QFrame(self) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.frameBoxPanel.sizePolicy().hasHeightForWidth()) self.frameBoxPanel.setSizePolicy(sizePolicy) self.frameBoxPanel.setFrameShape(QFrame.NoFrame) self.frameBoxPanel.setFrameShadow(QFrame.Raised) self.frameBoxPanel.setObjectName(("frameBoxPanel")) self.hLayoutframeBoxPanel = QHBoxLayout(self.frameBoxPanel) self.hLayoutframeBoxPanel.setSpacing(0) self.hLayoutframeBoxPanel.setMargin(0) self.hLayoutframeBoxPanel.setObjectName(("hLayoutframeBoxPanel")) self.captionLabel = QLabel(self.frameBoxPanel) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.captionLabel.sizePolicy().hasHeightForWidth()) self.captionLabel.setSizePolicy(sizePolicy) self.captionLabel.setMinimumSize(QSize(200, 0)) self.captionLabel.setMaximumSize(QSize(200, 16777215)) font = QFont() font.setBold(False) font.setWeight(50) self.captionLabel.setFont(font) self.captionLabel.setObjectName(("captionLabel")) self.hLayoutframeBoxPanel.addWidget(self.captionLabel) self.listBox = QListWidget(self.frameBoxPanel) self.listBox.setEnabled(True) font = QFont() font.setBold(False) font.setWeight(50) self.listBox.setFont(font) self.listBox.setObjectName(("listBox")) # self.listBox.setText("0.0") self.hLayoutframeBoxPanel.addWidget(self.listBox) self.imageButton = QToolButton(self.frameBoxPanel) self.imageButton.setText(("")) icon = QIcon() icon.addPixmap(QPixmap(("Resource/convex_hull.png")), QIcon.Normal, QIcon.Off) self.imageButton.setIcon(icon) self.imageButton.setObjectName(("imageButton")) self.imageButton.setVisible(False) self.hLayoutframeBoxPanel.addWidget(self.imageButton) self.hLayoutBoxPanel.addWidget(self.frameBoxPanel) self.listBox.currentRowChanged.connect(self.listBoxChanged) self.imageButton.clicked.connect(self.imageButtonClicked) self.captionUnits = "" self.hasObject = False self.objectList = [] self.captionLabel.setVisible(False) def get_Count(self): return self.listBox.count() Count = property(get_Count, None, None, None) def method_3(self, string_0): return self.listBox.row(self.listBox.findItems(string_0)[0]) def method_11(self, string_0): if (self.IsEmpty): return "%s%s\t" % (string_0, self.Caption) return "%s%s\t%s %s" % (string_0, self.Caption, self.Value, self.CaptionUnits) def listBoxChanged(self, index): i = index self.emit(SIGNAL("Event_0"), self) def IndexOf(self, item): if isinstance(item, str): return self.listBox.row(self.listBox.findItems(item)[0]) else: return self.listBox.row( self.listBox.findItems(item.ToString())[0]) def Contains(self, item): compStr = None if isinstance(item, str): compStr = item elif isinstance(item, float) or isinstance(item, int): compStr = str(item) else: compStr = item.ToString() for i in range(self.listBox.count()): comboItemstr = self.listBox.item(i).text() if compStr == comboItemstr: return True return False def Clear(self): self.listBox.clear() self.objectList = [] self.hasObject = False def Add(self, item): if not isinstance(item, str) and not isinstance(item, QString): self.listBox.addItem(item.ToString()) self.objectList.append(item) self.hasObject = True return self.listBox.addItem(item) self.hasObject = False return self.listBox.count() - 1 def Insert(self, index, item): if not isinstance(item, str): self.listBox.insertItem(index, item.ToString()) self.objectList.insert(index, item) self.hasObject = True return self.listBox.insertItem(index, item) self.hasObject = False def imageButtonClicked(self): self.emit(SIGNAL("Event_3"), self) def get_Caption(self): caption = self.captionLabel.text() findIndex = caption.indexOf("(") if findIndex > 0: val = caption.left(findIndex) return val return caption def set_Caption(self, captionStr): if captionStr == "": self.captionLabel.setText("") self.LabelWidth = 0 return if self.CaptionUnits != "" and self.CaptionUnits != None: self.captionLabel.setText(captionStr + "(" + str(self.CaptionUnits) + ")" + ":") else: self.captionLabel.setText(captionStr + ":") Caption = property(get_Caption, set_Caption, None, None) def get_CaptionUnits(self): return self.captionUnits def set_CaptionUnits(self, captionUnits): self.captionUnits = captionUnits CaptionUnits = property(get_CaptionUnits, set_CaptionUnits, None, None) def set_ButtonVisible(self, bool): self.imageButton.setVisible(bool) ButtonVisible = property(None, set_ButtonVisible, None, None) # def get_Value(self): # return self.listBox.currentIndex() # # def set_Value(self, value): # try: # self.listBox.setCurrentIndex(value) # except: # self.textBox.setText("") # Value = property(get_Value, set_Value, None, None) # def get_IsEmpty(self): # return self.listBox.currentText() == "" or self.listBox.currentIndex() == -1 # IsEmpty = property(get_IsEmpty, None, None, None) # def get_ReadOnly(self): # return self.listBox.isReadOnly() # # def set_ReadOnly(self, bool): # # self.listBox.setR.setReadOnly(bool) # # ReadOnly = property(get_ReadOnly, set_ReadOnly, None, None) def set_LabelWidth(self, width): self.captionLabel.setMinimumSize(QSize(width, 0)) self.captionLabel.setMaximumSize(QSize(width, 16777215)) LabelWidth = property(None, set_LabelWidth, None, None) def set_Width(self, width): self.listBox.setMinimumSize(QSize(width, 0)) self.listBox.setMaximumSize(QSize(width, 16777215)) Width = property(None, set_Width, None, None) def set_Button(self, imageName): if imageName == None or imageName == "": self.imageButton.setVisible(False) return icon = QIcon() icon.addPixmap(QPixmap(("Resource/" + imageName)), QIcon.Normal, QIcon.Off) self.imageButton.setIcon(icon) self.imageButton.setVisible(True) Button = property(None, set_Button, None, None) def get_SelectedIndex(self): try: return self.listBox.currentRow() except: return 0 def set_SelectedIndex(self, index): if self.listBox.count() == 0: return if index > self.listBox.count() - 1: self.listBox.setCurrentRow(0) else: self.listBox.setCurrentRow(index) SelectedIndex = property(get_SelectedIndex, set_SelectedIndex, None, None) # def get_Value(self): # return self.listBox.currentIndex() # def set_Value(self, valueStr): # if self.listBox.count() == 0: # return # self.listBox.setCurrentIndex(self.listBox.findText(valueStr)) # Value = property(get_Value, set_Value, None, None) def get_Items(self): if self.hasObject: return self.objectList itemList = [] if self.listBox.count() > 0: for i in range(self.listBox.count()): itemList.append(self.listBox.item(i).text()) return itemList def set_AddItems(self, strList): if len(strList) != 0 and not isinstance( strList[0], str) and not isinstance(strList[0], QString): for obj in strList: self.listBox.addItem(obj.ToString()) self.objectList.append(obj) self.hasObject = True return self.listBox.addItems(strList) Items = property(get_Items, set_AddItems, None, None) def get_Enabled(self): return self.listBox.isEnabled() def set_Enabled(self, bool): self.listBox.setEnabled(bool) Enabled = property(get_Enabled, set_Enabled, None, None) def get_Visible(self): return self.isVisible() def set_Visible(self, bool): self.setVisible(bool) Visible = property(get_Visible, set_Visible, None, None) def get_SelectedItem(self): if self.listBox.count() == 0: return None if self.hasObject: return self.objectList[self.SelectedIndex] return self.listBox.currentItem().text() # def set_SelectedItem(self, val): # index = self.listBox.findText(val) # self.listBox.setCurrentIndex(index) SelectedItem = property(get_SelectedItem, None, None, None)
class FiltersDialog(Window): def __init__(self, base): Window.__init__(self, base, i18n.get('filters')) self.setFixedSize(280, 360) self.expression = QLineEdit() self.expression.returnPressed.connect(self.__new_filter) self.new_button = QPushButton(i18n.get('add_filter')) self.new_button.setToolTip(i18n.get('create_a_new_filter')) self.new_button.clicked.connect(self.__new_filter) expression_box = QHBoxLayout() expression_box.addWidget(self.expression) expression_box.addWidget(self.new_button) self.list_ = QListWidget() self.list_.clicked.connect(self.__filter_clicked) self.delete_button = QPushButton(i18n.get('delete')) self.delete_button.setEnabled(False) self.delete_button.setToolTip(i18n.get('delete_selected_filter')) self.delete_button.clicked.connect(self.__delete_filter) self.clear_button = QPushButton(i18n.get('delete_all')) self.clear_button.setEnabled(False) self.clear_button.setToolTip(i18n.get('delete_all_filters')) self.clear_button.clicked.connect(self.__delete_all) button_box = QHBoxLayout() button_box.addStretch(1) button_box.addWidget(self.clear_button) button_box.addWidget(self.delete_button) layout = QVBoxLayout() layout.addLayout(expression_box) layout.addWidget(self.list_, 1) layout.addLayout(button_box) layout.setSpacing(5) layout.setContentsMargins(5, 5, 5, 5) self.setLayout(layout) self.__update() self.show() def __update(self): row = 0 self.expression.setText('') self.list_.clear() for expression in self.base.core.list_filters(): self.list_.addItem(expression) row += 1 self.__enable(True) self.delete_button.setEnabled(False) if row == 0: self.clear_button.setEnabled(False) self.expression.setFocus() def __filter_clicked(self, point): self.delete_button.setEnabled(True) self.clear_button.setEnabled(True) def __new_filter(self): expression = str(self.expression.text()) self.list_.addItem(expression) self.__save_filters() def __delete_filter(self): self.list_.takeItem(self.list_.currentRow()) self.__save_filters() def __delete_all(self): self.__enable(False) message = i18n.get('clear_filters_confirm') confirmation = self.base.show_confirmation_message(i18n.get('confirm_delete'), message) if not confirmation: self.__enable(True) return self.list_.clear() self.__save_filters() def __enable(self, value): self.list_.setEnabled(value) self.delete_button.setEnabled(value) self.clear_button.setEnabled(value) def __save_filters(self): filters = [] for i in range(self.list_.count()): filters.append(str(self.list_.item(i).text())) self.base.save_filters(filters) self.__update()
class FiltersDialog(Window): def __init__(self, base): Window.__init__(self, base, i18n.get('filters')) self.setFixedSize(280, 360) self.expression = QLineEdit() self.expression.returnPressed.connect(self.__new_filter) self.new_button = QPushButton(i18n.get('add_filter')) self.new_button.setToolTip(i18n.get('create_a_new_filter')) self.new_button.clicked.connect(self.__new_filter) expression_box = QHBoxLayout() expression_box.addWidget(self.expression) expression_box.addWidget(self.new_button) self.list_ = QListWidget() self.list_.clicked.connect(self.__filter_clicked) self.delete_button = QPushButton(i18n.get('delete')) self.delete_button.setEnabled(False) self.delete_button.setToolTip(i18n.get('delete_selected_filter')) self.delete_button.clicked.connect(self.__delete_filter) self.clear_button = QPushButton(i18n.get('delete_all')) self.clear_button.setEnabled(False) self.clear_button.setToolTip(i18n.get('delete_all_filters')) self.clear_button.clicked.connect(self.__delete_all) button_box = QHBoxLayout() button_box.addStretch(1) button_box.addWidget(self.clear_button) button_box.addWidget(self.delete_button) layout = QVBoxLayout() layout.addLayout(expression_box) layout.addWidget(self.list_, 1) layout.addLayout(button_box) layout.setSpacing(5) layout.setContentsMargins(5, 5, 5, 5) self.setLayout(layout) self.__update() self.show() def __update(self): row = 0 self.expression.setText('') self.list_.clear() for expression in self.base.core.list_filters(): self.list_.addItem(expression) row += 1 self.__enable(True) self.delete_button.setEnabled(False) if row == 0: self.clear_button.setEnabled(False) self.expression.setFocus() def __filter_clicked(self, point): self.delete_button.setEnabled(True) self.clear_button.setEnabled(True) def __new_filter(self): expression = str(self.expression.text()) self.list_.addItem(expression) self.__save_filters() def __delete_filter(self): self.list_.takeItem(self.list_.currentRow()) self.__save_filters() def __delete_all(self): self.__enable(False) message = i18n.get('clear_filters_confirm') confirmation = self.base.show_confirmation_message( i18n.get('confirm_delete'), message) if not confirmation: self.__enable(True) return self.list_.clear() self.__save_filters() def __enable(self, value): self.list_.setEnabled(value) self.delete_button.setEnabled(value) self.clear_button.setEnabled(value) def __save_filters(self): filters = [] for i in range(self.list_.count()): filters.append(str(self.list_.item(i).text())) self.base.save_filters(filters) self.__update()