def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) super(FiltersWidget, self).__init__(parent, **params) self.params = Params(**params) self.data_accessor = self.params.data_accessor # alias #if self.params.use_apply_button == True: if 1 == 1: self.data_accessor.addListener(self, __FilterActivatedDataVectorListener__(self)) filtersGroup = GroupBoxWidget(self, layout=QVBoxLayout(), i18n_def=params.get('title', 'Filters')) annotation_widget_class = params.get('annotation_widget_class', False) if annotation_widget_class: self.__annotation_filter__ = annotation_widget_class( filtersGroup, data_accessor=self.data_accessor) else: self.__annotation_filter__ = CommonAnnotationFilterWidget( filtersGroup, data_accessor=self.data_accessor) self.__square_filter__ = SquareFilterWidget(filtersGroup, data_accessor=self.data_accessor, use_apply_button=self.params.use_apply_button) if params.get('restore_button', False): self.__restore_button__ = PushButtonWidget(filtersGroup, i18n_def='Back to unfiltered data', clicked_handler=self.__restore_handler__, enabled=False)
def __createHeaderPreviewGroup__(self): if hasattr(self, 'fileHeaderPreviewGroup'): self.fileHeaderPreviewGroup.deleteLater() self.fileHeaderPreviewGroup = GroupBoxWidget(self.tableViewComposite, i18n="datasource.file.header.preview", i18n_def="Header preview", layout=QVBoxLayout(), hidden=True, enabled=False)
def __init__(self, parent, **params): get_or_put(params, 'i18n_def', 'Separator') self.params = Params(**params) self.separatorsGroupBox = GroupBoxWidget(parent, i18n="separator.widget.group.title", i18n_def=nvl(self.params.i18n_def, "Separator"), layout=QVBoxLayout()) self.predefinedSeparatorsComposite = CompositeWidget( self.separatorsGroupBox, layout=QHBoxLayout()) self.predefinedSeparatorsButtonsGroup = ButtonGroupWidget( self.predefinedSeparatorsComposite) self.predefinedSeparatorsSpecs = Separator.getSeparatorsSpec( separator_label_handler) for separatorSpec in self.predefinedSeparatorsSpecs: label = separatorSpec.label if not label == Separator.CUSTOM.label: # @UndefinedVariable predefinedSeparatorCheckBox = CheckBoxWidget( self.predefinedSeparatorsComposite) #attach artificially a separatorSpec object used later in #def setSeparator(self, _separator) method predefinedSeparatorCheckBox.separator_spec = separatorSpec predefinedSeparatorCheckBox.setText(label) predefinedSeparatorCheckBox.sep_spec = separatorSpec if self.params.default_separator and \ separatorSpec.id_ == self.params.default_separator.id_: predefinedSeparatorCheckBox.setChecked(True) self.predefinedSeparatorsButtonsGroup.addButton( predefinedSeparatorCheckBox) self.separatorsGroupBox.connect(self.predefinedSeparatorsButtonsGroup, SIGNAL("buttonClicked(QAbstractButton *)"), self.predefinedSeparatorButtonClicked) if not self.params.no_custom_separator == True: self.customSeparatorCheckBox = CheckBoxWidget( self.predefinedSeparatorsComposite, i18n="separator.custom.checkbox", i18n_def="Custom") self.customSeparatorCheckBox.sep_spec = Separator.CUSTOM self.separatorsGroupBox.connect(self.customSeparatorCheckBox, SIGNAL("clicked()"), self.customSeparatorButtonClicked) self.customSeparatorEdit = LineEditWidget( self.predefinedSeparatorsComposite, maxLength=15, width=get_width_of_n_letters(14), text_changed_handler=self.customSeparatorButtonClicked, enabled=False) self.setEnabled(self.params.enabled)
def __createFilesGroupBox(self, pageLayout): self.filesGroupBox = GroupBoxWidget( self, i18n="datasource.files.group.title", i18n_def="Files", layout=QVBoxLayout()) self.__createFileConstraintsComposite__(self.filesGroupBox) self.__createReloadButton__(self.filesGroupBox) self.__createTableView__(self.filesGroupBox) self.__createFilesOperationsComposite__(self.filesGroupBox) self.changeEnablemend(False) self.chooseRootDirButton.setEnabled(True)
class SeparatorWidget(object): """ widget used to choose a separator sign """ def __init__(self, parent, **params): get_or_put(params, 'i18n_def', 'Separator') self.params = Params(**params) self.separatorsGroupBox = GroupBoxWidget(parent, i18n="separator.widget.group.title", i18n_def=nvl(self.params.i18n_def, "Separator"), layout=QVBoxLayout()) self.predefinedSeparatorsComposite = CompositeWidget( self.separatorsGroupBox, layout=QHBoxLayout()) self.predefinedSeparatorsButtonsGroup = ButtonGroupWidget( self.predefinedSeparatorsComposite) self.predefinedSeparatorsSpecs = Separator.getSeparatorsSpec( separator_label_handler) for separatorSpec in self.predefinedSeparatorsSpecs: label = separatorSpec.label if not label == Separator.CUSTOM.label: # @UndefinedVariable predefinedSeparatorCheckBox = CheckBoxWidget( self.predefinedSeparatorsComposite) #attach artificially a separatorSpec object used later in #def setSeparator(self, _separator) method predefinedSeparatorCheckBox.separator_spec = separatorSpec predefinedSeparatorCheckBox.setText(label) predefinedSeparatorCheckBox.sep_spec = separatorSpec if self.params.default_separator and \ separatorSpec.id_ == self.params.default_separator.id_: predefinedSeparatorCheckBox.setChecked(True) self.predefinedSeparatorsButtonsGroup.addButton( predefinedSeparatorCheckBox) self.separatorsGroupBox.connect(self.predefinedSeparatorsButtonsGroup, SIGNAL("buttonClicked(QAbstractButton *)"), self.predefinedSeparatorButtonClicked) if not self.params.no_custom_separator == True: self.customSeparatorCheckBox = CheckBoxWidget( self.predefinedSeparatorsComposite, i18n="separator.custom.checkbox", i18n_def="Custom") self.customSeparatorCheckBox.sep_spec = Separator.CUSTOM self.separatorsGroupBox.connect(self.customSeparatorCheckBox, SIGNAL("clicked()"), self.customSeparatorButtonClicked) self.customSeparatorEdit = LineEditWidget( self.predefinedSeparatorsComposite, maxLength=15, width=get_width_of_n_letters(14), text_changed_handler=self.customSeparatorButtonClicked, enabled=False) self.setEnabled(self.params.enabled) def getSeparatorSign(self): sign = self.__getPredefinedSeparatorSign__() if sign: return sign if not self.params.no_custom_separator == True: return self.__getCustomSeparatorSign__() def predefinedSeparatorButtonClicked(self, button): if not self.params.no_custom_separator == True: self.__customSeparatorClear__() if self.params.separatorHandler and \ not self.predefinedSeparatorsButtonsGroup.checkedButton() == None: self.params.separatorHandler(self.__getPredefinedSeparatorSign__()) def customSeparatorButtonClicked(self): checked = self.customSeparatorCheckBox.isChecked() separator = self.__getCustomSeparatorSign__() if checked and self.params.separatorHandler and separator: self.params.separatorHandler(separator) self.customSeparatorEdit.setEnabled(checked) if checked: self.__uncheckPredefinedButtons__() self.customSeparatorEdit.setFocus() def __getPredefinedSeparatorSign__(self): button = self.predefinedSeparatorsButtonsGroup.checkedButton() if not button == None: for (sign, _, label) in self.predefinedSeparatorsSpecs: if button.text() == label: return sign def __getCustomSeparatorSign__(self): if self.customSeparatorCheckBox.isChecked(): return str(self.customSeparatorEdit.text()) def setEnabled(self, enabled): if not enabled == None: self.separatorsGroupBox.setEnabled(enabled) def setSeparator(self, _separator): if _separator: separatorSign = Separator.getSeparatorSign(_separator) if separatorSign == Separator.WHITE_SPACE: for button in self.predefinedSeparatorsButtonsGroup.buttons(): if button.separator_spec.id_ == Separator.WHITE_SPACE.id_: # @UndefinedVariable @IgnorePep8 button.setChecked(True) return elif separatorSign == Separator.CUSTOM: self.customSeparatorEdit.setText(_separator) self.__uncheckPredefinedButtons__() elif not separatorSign == Separator.NONE: for button in self.predefinedSeparatorsButtonsGroup.buttons(): if button.sep_spec.id_ == separatorSign.id_: if not self.params.no_custom_separator == True: self.__customSeparatorClear__() button.setChecked(True) return def __customSeparatorClear__(self): self.customSeparatorCheckBox.setChecked(False) self.customSeparatorEdit.setText("") self.customSeparatorEdit.setEnabled(False) def __uncheckPredefinedButtons__(self): #to uncheck button included in a button group one have to use a trick: #change to none exclusive state behaviour of the button group, then #uncheck checked button and reverse to previous exclusive state of #the button group if self.predefinedSeparatorsButtonsGroup.checkedButton(): self.predefinedSeparatorsButtonsGroup.setExclusive(False) self.predefinedSeparatorsButtonsGroup.checkedButton().setChecked( False) self.predefinedSeparatorsButtonsGroup.setExclusive(True)