class SlaveAnnotationFilterWidget(CommonAnnotationFilterWidget): def __init__(self, parent, **params): super(SlaveAnnotationFilterWidget, self).__init__(parent, **params) self.data_accessor.addListener(self, __AnnotationFilterDataVectorListener__(self)) self.setAnnotationsButtons(self.data_accessor.annotation) @property def action_button(self): return self.__action_button__ def createActionButton(self): self.__action_button__ = CheckBoxWidget(self, i18n_def='Use filter') self.__action_button__.setChecked(False) self.__action_button__.setEnabled(False) def setAnnotationsButtons(self, _annotation): empty = is_empty(_annotation) or pl.sum(_annotation) == 0 self.set_title(empty) if empty: self.reset() else: unique = list(pl.unique(_annotation)) if len(unique) == self.buttons_count: self.setEnabledAnnotations(ALL_ANNOTATIONS) else: self.setEnabledAnnotations(unique) self.setUncheckNotAnnotations(unique) if self.isAllUnchecked(): self.__action_button__.setChecked(False) self.__action_button__.setEnabled(False)
class SquareFilterWidget(GroupBoxWidget): """ graphical representation of a square filter """ def __init__(self, parent, **params): get_or_put(params, 'layout', QHBoxLayout()) self.params = Params(**params) self.data_accessor = self.params.data_accessor # alias i18n_def = "Square filter " + self.data_accessor.signal_unit.display_label # @IgnorePep8 super(SquareFilterWidget, self).__init__(parent, i18n_def=i18n_def, **params) self.__filter__ = SquareFilter() LabelWidget(self, i18n_def="Min value") self.__min_value__ = NumberEditWidget(self, text_changed_handler=self.__min_handler__) LabelWidget(self, i18n_def="Max value") self.__max_value__ = NumberEditWidget(self, text_changed_handler=self.__max_handler__) if self.params.use_apply_button: self.__action_button__ = PushButtonWidget(self, i18n_def='Apply', clicked_handler=self.__filter_handler__) else: self.__action_button__ = CheckBoxWidget(self, i18n_def='Use filter', clicked_handler=self.__use_handler__) self.data_accessor.addListener(self, __SquareFilterDataVectorListener__(self)) self.__action_button__.setChecked(False) self.reset() def __use_handler__(self): if not self.params.use_apply_button: if not self.isCorrectSignalRange(self.data_accessor.signal): self.__action_button__.setChecked(False) def __filter_handler__(self): if self.isCorrectSignalRange(self.data_accessor.signal): run_filter(self.parent(), self.__filter__, self.data_accessor, filter_name='square') def isCorrectSignalRange(self, _signal): _min = pl.amin(_signal) if _min >= self.__filter__.min_value and \ _min <= self.__filter__.max_value: return True _max = pl.amax(_signal) if _max >= self.__filter__.min_value and \ _max <= self.__filter__.max_value: return True if _min <= self.__filter__.min_value and \ _max >= self.__filter__.max_value: return True InformationWindow(message="Signal data out of range !") return False def __min_handler__(self, text): self.__filter__.min_value = text self.__check_range__(self.__min_value__) def __max_handler__(self, text): self.__filter__.max_value = text self.__check_range__(self.__max_value__) def __check_range__(self, _widget): message = self.__filter__.check() if message == None: self.__action_button__.setEnabled(True) _widget.setToolTip('') self.__action_button__.setToolTip('') return True else: _widget.setToolTip(message) self.__action_button__.setToolTip(message) self.__action_button__.setEnabled(False) if not self.params.use_apply_button: self.__action_button__.setChecked(False) return False def useFilter(self): return self.__action_button__.isChecked() \ if not self.params.use_apply_button else False def getFilter(self): return self.__filter__ def reset(self): self.setSquareFilterParams(SquareFilterParams( int(pl.amin(self.data_accessor.signal)), int(pl.amax(self.data_accessor.signal)), True)) def setEnabled(self, _enabled): self.__min_value__.setEnabled(_enabled) self.__max_value__.setEnabled(_enabled) def setSquareFilterParams(self, square_filter_params): """ set up square filter widget parameters """ self.__filter__.min_value = square_filter_params.min_value self.__min_value__.setText(self.__filter__.min_value) self.__filter__.max_value = square_filter_params.max_value self.__max_value__.setText(self.__filter__.max_value) if not self.params.use_apply_button: self.__action_button__.setChecked(square_filter_params.use_filter) def getSquareFilterParams(self): return SquareFilterParams(self.__filter__.min_value, self.__filter__.max_value, self.useFilter())
class CommonAnnotationFilterWidget(GroupBoxWidget): def __init__(self, parent, **params): get_or_put(params, 'layout', QHBoxLayout()) super(CommonAnnotationFilterWidget, self).__init__(parent, **params) self.params = Params(**params) self.data_accessor = self.params.data_accessor # alias self.__filter__ = AnnotationFilter() self.__createAnnotationButtons__() self.createActionButton() self.__activateActionButton__(False) @property def action_button(self): pass @property def excluded_annotations(self): annotations = [] for button in self.__button_group__.buttons(): if button.isChecked(): if button == self.__all_button__: return ALL_ANNOTATIONS annotations.append(int(button.text())) return annotations def setEnabledAnnotations(self, _annotations): for button in self.__button_group__.buttons(): if button == self.__all_button__: button.setEnabled(ALL_ANNOTATIONS == _annotations) elif ALL_ANNOTATIONS == _annotations or \ int(button.text()) in _annotations: button.setEnabled(True) else: button.setEnabled(False) def setDisabledAnnotations(self, _annotations): for button in self.__button_group__.buttons(): if button == self.__all_button__: button.setEnabled(not ALL_ANNOTATIONS == _annotations) elif ALL_ANNOTATIONS == _annotations or \ int(button.text()) in _annotations: button.setEnabled(False) def disableIfAllChecked(self): for button in self.__button_group__.buttons(): if not button == self.__all_button__ and not button.isChecked(): return self.__all_button__.setEnabled(False) def reset(self): self.__button_group__.setEnabled(True) self.__button_group__.setAllChecked(False) self.__activateActionButton__(False) @property def use_filter(self): return self.__button_group__.isAnyChecked() @property def annotation_filter(self): return self.__filter__ def set_title(self, empty): if empty: self.setTitle("Annotation filter [NOT ACTIVE - data already filtered]") # @IgnorePep8 self.setEnabled(False) else: self.setTitle("Annotation filter") self.setEnabled(True) @property def buttons_count(self): return len(self.__button_group__.buttons()) def setUncheckNotAnnotations(self, _annotations): for button in self.__button_group__.buttons(): if button == self.__all_button__: button.setChecked(False) else: if int(button.text()) not in _annotations: button.setChecked(False) def setCheckedAnnotations(self, _annotations): """ check all buttons in accordance with annotations """ for button in self.__button_group__.buttons(): if not button == self.__all_button__: if int(button.text()) in _annotations: button.setChecked(True) def isAllUnchecked(self): return self.__button_group__.isAllUnchecked() def __createAnnotationButtons__(self): self.__button_group__ = ButtonGroupWidget(self) unique_annotations0 = get_unique_annotations( self.data_accessor.annotation0) empty = is_empty(unique_annotations0) self.set_title(empty) self.__all_button__ = CheckBoxWidget(self, i18n_def='ALL', clicked_handler=self.__all_button_handler__) self.__button_group__.addButton(self.__all_button__) for unique_annotation in unique_annotations0: annotationCheckBox = CheckBoxWidget(self, i18n_def=str(unique_annotation)) self.__button_group__.addButton(annotationCheckBox) self.__button_group__.setExclusive(False) self.__button_group__.connect(self.__button_group__, BUTTON_CLICKED_SIGNAL, self.__button_handler__) def __button_handler__(self, button): if button.isChecked(): if button == self.__all_button__: self.__setCheckedAnnotationsButtons__(False) self.__setEnabledAnnotationsButtons__(False) else: self.__all_button__.setChecked(False) self.__activateActionButton__(True) else: if button == self.__all_button__ or \ self.__button_group__.isAllUnchecked(): self.__activateActionButton__(False) if button == self.__all_button__: self.__setEnabledAnnotationsButtons__(True) def __all_button_handler__(self): self.__button_handler__(self.__all_button__) def __setCheckedAnnotationsButtons__(self, _checked): for button in self.__button_group__.buttons(): if not button == self.__all_button__: button.setChecked(_checked) def __setEnabledAnnotationsButtons__(self, _enabled): for button in self.__button_group__.buttons(): if not button == self.__all_button__: button.setEnabled(_enabled) def __activateActionButton__(self, _activate): self.action_button.setEnabled(_activate) if _activate == False and hasattr(self.action_button, 'setChecked'): self.action_button.setChecked(False) def useFilter(self): return self.action_button.isChecked() \ if hasattr(self.action_button, 'isChecked') else False def getFilter(self): return self.__filter__ def setAnnotationFilterParams(self, annotation_filter_params): """ set up annotation filter widget parameters """ if not annotation_filter_params.all_annotations: if not annotation_filter_params.annotations == None: self.setEnabledAnnotations(annotation_filter_params.annotations) # @IgnorePep8 self.setCheckedAnnotations(annotation_filter_params.annotations) # @IgnorePep8 self.__all_button__.setChecked( annotation_filter_params.all_annotations) self.__all_button__.setEnabled(True) self.__action_button__.setChecked(annotation_filter_params.use_filter) if annotation_filter_params.use_filter or \ annotation_filter_params.all_annotations or \ not annotation_filter_params.annotations == None: self.__action_button__.setEnabled(True) def getAnnotationFilterParams(self): all_annotations = False annotations = self.excluded_annotations if annotations == ALL_ANNOTATIONS \ or self.__all_button__.isChecked(): all_annotations = True annotations = None if not annotations == None and len(annotations) == 0: annotations = None return AnnotationFilterParams(annotations, all_annotations, self.useFilter())
class CommonAnnotationFilterWidget(GroupBoxWidget): def __init__(self, parent, **params): get_or_put(params, 'layout', QHBoxLayout()) super(CommonAnnotationFilterWidget, self).__init__(parent, **params) self.params = Params(**params) self.data_accessor = self.params.data_accessor # alias self.__filter__ = AnnotationFilter() self.__createAnnotationButtons__() self.createActionButton() self.__activateActionButton__(False) @property def action_button(self): pass @property def excluded_annotations(self): annotations = [] for button in self.__button_group__.buttons(): if button.isChecked(): if button == self.__all_button__: return ALL_ANNOTATIONS annotations.append(int(button.text())) return annotations def setEnabledAnnotations(self, _annotations): for button in self.__button_group__.buttons(): if button == self.__all_button__: button.setEnabled(ALL_ANNOTATIONS == _annotations) elif ALL_ANNOTATIONS == _annotations or \ int(button.text()) in _annotations: button.setEnabled(True) else: button.setEnabled(False) def setDisabledAnnotations(self, _annotations): for button in self.__button_group__.buttons(): if button == self.__all_button__: button.setEnabled(not ALL_ANNOTATIONS == _annotations) elif ALL_ANNOTATIONS == _annotations or \ int(button.text()) in _annotations: button.setEnabled(False) def disableIfAllChecked(self): for button in self.__button_group__.buttons(): if not button == self.__all_button__ and not button.isChecked(): return self.__all_button__.setEnabled(False) def reset(self): self.__button_group__.setEnabled(True) self.__button_group__.setAllChecked(False) self.__activateActionButton__(False) @property def use_filter(self): return self.__button_group__.isAnyChecked() @property def annotation_filter(self): return self.__filter__ def set_title(self, empty): if empty: self.setTitle( "Annotation filter [NOT ACTIVE - data already filtered]" ) # @IgnorePep8 self.setEnabled(False) else: self.setTitle("Annotation filter") self.setEnabled(True) @property def buttons_count(self): return len(self.__button_group__.buttons()) def setUncheckNotAnnotations(self, _annotations): for button in self.__button_group__.buttons(): if button == self.__all_button__: button.setChecked(False) else: if int(button.text()) not in _annotations: button.setChecked(False) def setCheckedAnnotations(self, _annotations): """ check all buttons in accordance with annotations """ for button in self.__button_group__.buttons(): if not button == self.__all_button__: if int(button.text()) in _annotations: button.setChecked(True) def isAllUnchecked(self): return self.__button_group__.isAllUnchecked() def __createAnnotationButtons__(self): self.__button_group__ = ButtonGroupWidget(self) unique_annotations0 = get_unique_annotations( self.data_accessor.annotation0) empty = is_empty(unique_annotations0) self.set_title(empty) self.__all_button__ = CheckBoxWidget( self, i18n_def='ALL', clicked_handler=self.__all_button_handler__) self.__button_group__.addButton(self.__all_button__) for unique_annotation in unique_annotations0: annotationCheckBox = CheckBoxWidget( self, i18n_def=str(unique_annotation)) self.__button_group__.addButton(annotationCheckBox) self.__button_group__.setExclusive(False) self.__button_group__.connect(self.__button_group__, BUTTON_CLICKED_SIGNAL, self.__button_handler__) def __button_handler__(self, button): if button.isChecked(): if button == self.__all_button__: self.__setCheckedAnnotationsButtons__(False) self.__setEnabledAnnotationsButtons__(False) else: self.__all_button__.setChecked(False) self.__activateActionButton__(True) else: if button == self.__all_button__ or \ self.__button_group__.isAllUnchecked(): self.__activateActionButton__(False) if button == self.__all_button__: self.__setEnabledAnnotationsButtons__(True) def __all_button_handler__(self): self.__button_handler__(self.__all_button__) def __setCheckedAnnotationsButtons__(self, _checked): for button in self.__button_group__.buttons(): if not button == self.__all_button__: button.setChecked(_checked) def __setEnabledAnnotationsButtons__(self, _enabled): for button in self.__button_group__.buttons(): if not button == self.__all_button__: button.setEnabled(_enabled) def __activateActionButton__(self, _activate): self.action_button.setEnabled(_activate) if _activate == False and hasattr(self.action_button, 'setChecked'): self.action_button.setChecked(False) def useFilter(self): return self.action_button.isChecked() \ if hasattr(self.action_button, 'isChecked') else False def getFilter(self): return self.__filter__ def setAnnotationFilterParams(self, annotation_filter_params): """ set up annotation filter widget parameters """ if not annotation_filter_params.all_annotations: if not annotation_filter_params.annotations == None: self.setEnabledAnnotations( annotation_filter_params.annotations) # @IgnorePep8 self.setCheckedAnnotations( annotation_filter_params.annotations) # @IgnorePep8 self.__all_button__.setChecked( annotation_filter_params.all_annotations) self.__all_button__.setEnabled(True) self.__action_button__.setChecked(annotation_filter_params.use_filter) if annotation_filter_params.use_filter or \ annotation_filter_params.all_annotations or \ not annotation_filter_params.annotations == None: self.__action_button__.setEnabled(True) def getAnnotationFilterParams(self): all_annotations = False annotations = self.excluded_annotations if annotations == ALL_ANNOTATIONS \ or self.__all_button__.isChecked(): all_annotations = True annotations = None if not annotations == None and len(annotations) == 0: annotations = None return AnnotationFilterParams(annotations, all_annotations, self.useFilter())
class ChooseColumnsDataPage(QWizardPage): def __init__(self, _parent, datasource_page_id): QWizardPage.__init__(self, parent=_parent) self.datasource_page_id = datasource_page_id self.pageLayout = None self.headersTablePreview = None self.__dataFilesHeaders__ = {} self.__signalColumnIndexes__ = {} # includes selected signal column indexes @IgnorePep8 self.__annotationColumnIndexes__ = {} # includes selected annotation column indexes @IgnorePep8 self.__timeColumnIndexes__ = {} # includes selected [optional] time column indexes @IgnorePep8 self.__globalSeparator__ = None self.__globalCheckBox__ = None self.__globalIndex__ = GlobalIndex(None, None, None) self.__headerWidgets__ = [] self.__widgetsHorizontalHeader__ = None self.__signal_header_element__ = HeaderElement('signal', 'signal', self.__signalWidgetHandler__) # @IgnorePep8 self.__annotation_header_element__ = HeaderElement('annotation', 'annotation', self.__annotationWidgetHandler__) # @IgnorePep8 self.__time_header_element__ = HeaderElement('time', 'time', self.__timeWidgetHandler__) # @IgnorePep8 def initializePage(self): self.setTitle('Choose column data') #self.setSubTitle('Choose column specific data') if self.pageLayout == None: self.pageLayout = QVBoxLayout() self.setLayout(self.pageLayout) self.__createTableView__(self.pageLayout) #select the first row self.filesTableView.selectRow(0) self.separatorWidget.setGlobalSeparatorAsDefault() def __createTableView__(self, pageLayout): self.tableViewComposite = CompositeWidget(self, layout=QVBoxLayout()) datasource_page = self.wizard().page(self.datasource_page_id) model = CheckStateProxySortFilterModel(self) model.setSourceModel(datasource_page.getDatasourceModel()) model.setDynamicSortFilter(True) self.filesTableView = FilesTableView(self.tableViewComposite, model=model, onClickedAction=self.onClickedAction, wizardButtons=(QWizard.NextButton,), wizard_handler=self.wizard, sorting=True) self.filesTableView.setColumnHidden(0, True) self.filePreviewButton = PushButtonWidget(self.tableViewComposite, i18n="datasource.file.preview.button", i18n_def="File preview", enabled=False, clicked_handler=self.filePreviewAction) self.separatorWidget = GlobalSeparatorWidget(self.tableViewComposite, separatorHandler=self.__separatorHandler__, globalHandler=self.__globalSeparatorHandler__, enabled=False) self.__createHeaderPreviewGroup__() self.__activity__ = ActivityWidget(self) self.__timeUnitsGroup__ = self.__createTimeUnitsGroup__() def __createTimeUnitsGroup__(self): return TimeUnitsWidget(self.tableViewComposite, i18n_def='Signal time unit') def onClickedAction(self, idx): self.filePreviewButton.setEnabled(True) self.filesTableView.onClickedAction( self.filesTableView.model().mapToSource(idx)) #global separator could be None self.__createFileHeadersPreview__(self.__globalSeparator__) if self.__globalSeparator__: self.separatorWidget.setSeparator(self.__globalSeparator__) else: self.separatorWidget.setSeparator(self.__getSelectedSeparator__()) self.separatorWidget.setEnabled(True) def filePreviewAction(self): showFilesPreviewDialog( self.filesTableView.getSelectedPathAndFilename()) def __separatorHandler__(self, _separator): self.__createFileHeadersPreview__(_separator) def __globalSeparatorHandler__(self, _checked, _separator=None): self.__globalSeparator__ = _separator def __createFileHeadersPreview__(self, _separator=None): dataFileHeader = self.__getDataFileHeader__(_separator) if dataFileHeader == None: return self.__createHeadersTablePreview__() colCount = dataFileHeader.getHeadersCount() model = self.__createHeadersTablePreviewModel__(colCount) self.__widgetsHorizontalHeader__ = WidgetsHorizontalHeader( self.headersTablePreview) # create header line pathFile = self.filesTableView.getSelectedPathAndFilename() self.__headerWidgets__ = [] for headerLine in dataFileHeader.getHeadersLines(1): for num, header in enumerate(headerLine): widget = HeaderWidget(self.__widgetsHorizontalHeader__, header, [self.__signal_header_element__, self.__annotation_header_element__, self.__time_header_element__]) self.__headerWidgets__.append(widget) # some value of global indicator have to be not None if not nvl(*self.__globalIndex__) == None: widget.enabledAll(False) if self.__globalIndex__.signal == num: # signal index widget.check(self.__signal_header_element__.name) elif self.__globalIndex__.annotation == num: # annotation index @IgnorePep8 widget.check(self.__annotation_header_element__.name) if self.__globalIndex__.time == num: # time index widget.check(self.__time_header_element__.name) elif self.__signalColumnIndexes__.get(pathFile) == num: widget.check(self.__signal_header_element__.name) elif self.__annotationColumnIndexes__.get(pathFile) == num: widget.check(self.__annotation_header_element__.name) elif self.__timeColumnIndexes__.get(pathFile) == num: widget.check(self.__time_header_element__.name) self.__widgetsHorizontalHeader__.setWidgets(self.__headerWidgets__) # create data lines for rowData in dataFileHeader.getDataLines(): modelData = list() for idx in range(colCount): modelData.append(QStandardItem(rowData[idx] if colCount <= len(rowData) else "")) model.appendRow(modelData) self.fileHeaderPreviewGroup.setEnabled(True) self.fileHeaderPreviewGroup.show() def __getDataFileHeader__(self, _separator=None): pathFile = self.filesTableView.getSelectedPathAndFilename() if pathFile == None: ErrorWindow(message="The file must be selected !") else: return self.__createDataFileHeader__(pathFile, _separator) def __createHeadersTablePreviewModel__(self, colNumber): model = PreviewDataViewModel(self.headersTablePreview) labels = QStringList(create_list("", colNumber)) model.setHorizontalHeaderLabels(labels) self.headersTablePreview.setModel(model) return model def __createHeadersTablePreview__(self): self.__createHeaderPreviewGroup__() self.headersTablePreview = TableViewWidget(self.fileHeaderPreviewGroup, selectionBehavior=QAbstractItemView.SelectRows, selectionMode=QAbstractItemView.SingleSelection) self.__globalCheckBox__ = CheckBoxWidget( self.fileHeaderPreviewGroup, i18n="global.data.column.index", i18n_def="Global columns indexes", clicked_handler=self.__globalClicked__) if self.__globalIndex__.signal: self.__globalCheckBox__.setChecked(True) def __createDataFileHeader__(self, pathFile, _separator): dataFileHeader = self.__dataFilesHeaders__.get(pathFile, None) if dataFileHeader == None: dataFileHeader = DataFileHeader(pathFile) self.__dataFilesHeaders__[pathFile] = dataFileHeader if _separator == None: _separator = dataFileHeader.getSeparator() if _separator == None: #try to discover a separator based on file data _separator = dataFileHeader.getSeparator(generate=True) dataFileHeader.setSeparator(_separator) return dataFileHeader def __getSelectedSeparator__(self): pathFile = self.filesTableView.getSelectedPathAndFilename() if pathFile: dataFileHeader = self.__dataFilesHeaders__.get(pathFile) if dataFileHeader: return dataFileHeader.getSeparator() # for future use def __setSeparatorForAll__(self, _separator=None): model = self.filesTableView.model() for row in range(model.rowCount()): #it's necessity to alter model index of QSortFilterProxyModel type #into source model index of QStandardItemModel type idx = model.mapToSource(model.index(row, 0)) pathFile = self.filesTableView.getPathAndFilename(idx) if pathFile: self.__createDataFileHeader__(pathFile, _separator) def __signalWidgetHandler__(self, _widget): self.__widgetHandler__(_widget, self.__signal_header_element__.name) def __annotationWidgetHandler__(self, _widget): self.__widgetHandler__(_widget, self.__annotation_header_element__.name) # @IgnorePep8 def __timeWidgetHandler__(self, _widget): self.__widgetHandler__(_widget, self.__time_header_element__.name) def __widgetHandler__(self, _widget, _type): checked = _widget.isChecked(_type) pathFile = self.filesTableView.getSelectedPathAndFilename() if checked: for num, widget in enumerate(self.__headerWidgets__): if widget == _widget: if _type == self.__signal_header_element__.name: _widget.uncheck(self.__annotation_header_element__.name) # @IgnorePep8 self.__signalColumnIndexes__[pathFile] = num elif _type == self.__annotation_header_element__.name: _widget.uncheck(self.__signal_header_element__.name) _widget.uncheck(self.__time_header_element__.name) self.__annotationColumnIndexes__[pathFile] = num elif _type == self.__time_header_element__.name: _widget.uncheck(self.__annotation_header_element__.name) # @IgnorePep8 self.__timeColumnIndexes__[pathFile] = num else: if _type == self.__signal_header_element__.name: widget.uncheck(self.__signal_header_element__.name) elif _type == self.__annotation_header_element__.name: widget.uncheck(self.__annotation_header_element__.name) elif _type == self.__time_header_element__.name: widget.uncheck(self.__time_header_element__.name) self.__globalCheckBox__.setEnabled(True) else: if _type == self.__signal_header_element__.name: self.__signalColumnIndexes__[pathFile] = None elif _type == self.__annotation_header_element__.name: self.__annotationColumnIndexes__[pathFile] = None elif _type == self.__time_header_element__.name: self.__timeColumnIndexes__[pathFile] = None def __globalClicked__(self): _signal = None _annotation = None _time = None if self.__globalCheckBox__.isChecked(): for num, widget in enumerate(self.__headerWidgets__): if widget.isChecked(self.__signal_header_element__.name): _signal = num if widget.isChecked(self.__annotation_header_element__.name): _annotation = num if widget.isChecked(self.__time_header_element__.name): _time = num index = GlobalIndex(_signal, _annotation, _time) if index.signal == None: self.__globalCheckBox__.setChecked(False) InformationWindow(None, message='At least signal column has to be selected !') return else: for num, widget in enumerate(self.__headerWidgets__): widget.enabledAll(False) self.__globalIndex__ = index self.__setGlobalIndexForAll__(self.__globalIndex__) else: for widget in self.__headerWidgets__: widget.enabledAll(True) self.__globalIndex__ = GlobalIndex(None, None, None) def __setGlobalIndexForAll__(self, _globalIndex): model = self.filesTableView.model() for row in range(model.rowCount()): #it's necessity to alter model index of QSortFilterProxyModel type #into source model index of QStandardItemModel type idx = model.mapToSource(model.index(row, 0)) pathFile = self.filesTableView.getPathAndFilename(idx) if pathFile: self.__signalColumnIndexes__[pathFile] = _globalIndex.signal if _globalIndex.annotation: # annontation global index self.__annotationColumnIndexes__[pathFile] = \ _globalIndex.annotation if _globalIndex.time: # time global index self.__timeColumnIndexes__[pathFile] = \ _globalIndex.time 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 validatePage(self): filesSpecificationModel = DatasourceFilesSpecificationModel() for (_path, _filename, _signalIndex, _annotationIndex, _timeIndex, _separator) in \ self.__getFilesSpec__(indexes=True, separators=True): if _signalIndex == None: ErrorWindow(message=("No signal column for the file %s !" % (_filename))) return False if _separator == None: ErrorWindow(message=("No separator for file %s !" % (_filename))) return False filesSpecificationModel.appendRow(_path, _filename, _signalIndex, _annotationIndex, _timeIndex, _separator, self.__timeUnitsGroup__.getUnit()) PluginsManager.invokePlugin(PluginsNames.TACHOGRAM_PLOT_PLUGIN_NAME, inspect.stack(), model=filesSpecificationModel.getAsFilesSpecifications(), activity_description=self.__activity__.description(), activity_params=['model']) return True def __getFilesSpec__(self, _pathfile=True, indexes=False, use_global_index=True, separators=False, use_global_separator=True): filesSpec = [] model = self.filesTableView.model() for row in range(model.rowCount()): #it's necessity to alter model index of QSortFilterProxyModel type #into source model index of QStandardItemModel type idx = model.mapToSource(model.index(row, 0)) pathFile = self.filesTableView.getPathAndFilename(idx) if pathFile: fileSpec = [] if _pathfile == True: fileSpec.extend(pathFile) if indexes == True: signalIndex = self.__signalColumnIndexes__.get(pathFile) if signalIndex == None and use_global_index == True and \ not self.__globalIndex__.signal == None: signalIndex = self.__globalIndex__.signal fileSpec.append(signalIndex) annotationIndex = self.__annotationColumnIndexes__.get( pathFile) if annotationIndex == None and use_global_index == True \ and not self.__globalIndex__.annotation == None: annotationIndex = self.__globalIndex__.annotation fileSpec.append(annotationIndex) timeIndex = self.__timeColumnIndexes__.get(pathFile) if timeIndex == None and use_global_index == True \ and not self.__globalIndex__.time == None: timeIndex = self.__globalIndex__.time fileSpec.append(timeIndex) if separators == True: separator = None dataFileHeader = self.__dataFilesHeaders__.get(pathFile) if not dataFileHeader == None: separator = dataFileHeader.getSeparator() if separator == None and use_global_separator == True: separator = self.__globalSeparator__ fileSpec.append(separator) filesSpec.append(tuple(fileSpec)) return filesSpec
class StatisticsWidget(GroupBoxWidget): """ widget adds an action of statistics calculations into statistics widget """ def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Statistics') super(StatisticsWidget, self).__init__(parent, **params) self.params = Params(**params) self.data_accessors = [] self.main_data_accessor = None if not self.params.data_vectors_accessor_group == None: self.data_accessors = self.params.data_vectors_accessor_group.data_vectors_accessors # @IgnorePep8 self.main_data_accessor = self.params.data_vectors_accessor_group.group_data_vector_accessor # @IgnorePep8 elif not self.params.data_accessor == None: self.main_data_accessor = self.params.data_accessor self.data_accessors = [self.main_data_accessor] for data_accessor in self.data_accessors: data_accessor.addListener(self, __StatisticsVectorListener__(self)) self.__createButtons__() self.__statistics_widget__ = StatisticsSelectionWidget(self, layout=QVBoxLayout(), i18n_def='', check_handler=self.__change_statistics_handler__) self.__summary_statistics_widget__ = SummaryStatisticsSelectionWidget( self, layout=QVBoxLayout(), i18n_def='Summary statistics', check_handler=self.__change_statistics_handler__) def __createButtons__(self): buttons_composite = CompositeWidget(self, layout=QHBoxLayout()) self.__calculate_button__ = PushButtonWidget(buttons_composite, i18n_def="Calculate statistics", clicked_handler=self.__calculate_statistics_handler__) self.__enabled_calculation_button__(False) self.__save_outcomes_button__ = CheckBoxWidget(buttons_composite, i18n_def="Save outcomes", enabled=False) #if parameter save_outcomes_fixed_state is not None #then it's equal to checked state of save outcomes button #and this state couldn't be change later by a user if self.params.save_outcomes_fixed_state: self.__save_outcomes_button__.setChecked( self.params.save_outcomes_fixed_state) def __calculate_statistics_handler__(self): if len(self.data_accessors) == 0: return self.main_data_accessor.prepareParametersContainer() #processing many data accessors objects: #self.data_accessors object contains many data_accessor objects which #have to be treated in the same way as self.main_data_accessor object, #that means they must have the same parameters for data_accessor in self.data_accessors: data_accessor.parameters_container = self.main_data_accessor.parameters_container # @IgnorePep8 formatted_summary_statistics = [] save_csv = self.__save_outcomes_button__.isChecked() check_level = CoreParameters.MEDIUM_CHECK_LEVEL if save_csv else CoreParameters.LOW_CHECK_LEVEL # @IgnorePep8 pp_generator_progress_bar = PoincarePlotGeneratorProgressBar(self, self.data_accessors, label_text='Statistics calculation', check_level=check_level, save_csv=save_csv, formatted_summary_statistics=formatted_summary_statistics, output_file_listener=self.params.output_file_listener) pp_generator_progress_bar.start() if pp_generator_progress_bar.interrupted() == False and \ len(formatted_summary_statistics) == 1: #summary statistics values are updated only in the case #of one data accessor object self.__summary_statistics_widget__.setStatisticsValues( formatted_summary_statistics[0]) def __change_statistics_handler__(self, _statistic, _checked): """ handler invoked when number of selected rows is changing """ if not _checked: if len(self.getSelectedStatisticsClasses()) > 0 or \ len(self.getSelectedSummaryStatisticsClasses()) > 0: _checked = True self.__enabled_calculation_button__(_checked) #only if this parameter is None save outcomes button's check state #could be changed if self.params.save_outcomes_fixed_state == None: self.__save_outcomes_button__.setEnabled(_checked) def getSelectedStatisticsClasses(self): return self.__statistics_widget__.getSelectedStatisticsClasses() def getSelectedSummaryStatisticsClasses(self): return self.__summary_statistics_widget__.getSelectedStatisticsClasses() # @IgnorePep8 def __enabled_calculation_button__(self, _enabled): """ method sets background color of 'Calculate statistics' button to red if the button is disabled foreground color is set up to brown otherwise to black """ if _enabled == False: self.__calculate_button__.setStyleSheet("background-color: red; color: brown") # @IgnorePep8 else: self.__calculate_button__.setStyleSheet("background-color: red; color: black") # @IgnorePep8 self.__calculate_button__.setEnabled(_enabled)
class StatisticsWidget(GroupBoxWidget): """ widget adds an action of statistics calculations into statistics widget """ def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Statistics') super(StatisticsWidget, self).__init__(parent, **params) self.params = Params(**params) self.data_accessors = [] self.main_data_accessor = None if not self.params.data_vectors_accessor_group == None: self.data_accessors = self.params.data_vectors_accessor_group.data_vectors_accessors # @IgnorePep8 self.main_data_accessor = self.params.data_vectors_accessor_group.group_data_vector_accessor # @IgnorePep8 elif not self.params.data_accessor == None: self.main_data_accessor = self.params.data_accessor self.data_accessors = [self.main_data_accessor] for data_accessor in self.data_accessors: data_accessor.addListener(self, __StatisticsVectorListener__(self)) self.__createButtons__() self.__statistics_widget__ = StatisticsSelectionWidget( self, layout=QVBoxLayout(), i18n_def='', check_handler=self.__change_statistics_handler__) self.__summary_statistics_widget__ = SummaryStatisticsSelectionWidget( self, layout=QVBoxLayout(), i18n_def='Summary statistics', check_handler=self.__change_statistics_handler__) def __createButtons__(self): buttons_composite = CompositeWidget(self, layout=QHBoxLayout()) self.__calculate_button__ = PushButtonWidget( buttons_composite, i18n_def="Calculate statistics", clicked_handler=self.__calculate_statistics_handler__) self.__enabled_calculation_button__(False) self.__save_outcomes_button__ = CheckBoxWidget( buttons_composite, i18n_def="Save outcomes", enabled=False) #if parameter save_outcomes_fixed_state is not None #then it's equal to checked state of save outcomes button #and this state couldn't be change later by a user if self.params.save_outcomes_fixed_state: self.__save_outcomes_button__.setChecked( self.params.save_outcomes_fixed_state) def __calculate_statistics_handler__(self): if len(self.data_accessors) == 0: return self.main_data_accessor.prepareParametersContainer() #processing many data accessors objects: #self.data_accessors object contains many data_accessor objects which #have to be treated in the same way as self.main_data_accessor object, #that means they must have the same parameters for data_accessor in self.data_accessors: data_accessor.parameters_container = self.main_data_accessor.parameters_container # @IgnorePep8 formatted_summary_statistics = [] save_csv = self.__save_outcomes_button__.isChecked() check_level = CoreParameters.MEDIUM_CHECK_LEVEL if save_csv else CoreParameters.LOW_CHECK_LEVEL # @IgnorePep8 pp_generator_progress_bar = PoincarePlotGeneratorProgressBar( self, self.data_accessors, label_text='Statistics calculation', check_level=check_level, save_csv=save_csv, formatted_summary_statistics=formatted_summary_statistics, output_file_listener=self.params.output_file_listener) pp_generator_progress_bar.start() if pp_generator_progress_bar.interrupted() == False and \ len(formatted_summary_statistics) == 1: #summary statistics values are updated only in the case #of one data accessor object self.__summary_statistics_widget__.setStatisticsValues( formatted_summary_statistics[0]) def __change_statistics_handler__(self, _statistic, _checked): """ handler invoked when number of selected rows is changing """ if not _checked: if len(self.getSelectedStatisticsClasses()) > 0 or \ len(self.getSelectedSummaryStatisticsClasses()) > 0: _checked = True self.__enabled_calculation_button__(_checked) #only if this parameter is None save outcomes button's check state #could be changed if self.params.save_outcomes_fixed_state == None: self.__save_outcomes_button__.setEnabled(_checked) def getSelectedStatisticsClasses(self): return self.__statistics_widget__.getSelectedStatisticsClasses() def getSelectedSummaryStatisticsClasses(self): return self.__summary_statistics_widget__.getSelectedStatisticsClasses( ) # @IgnorePep8 def __enabled_calculation_button__(self, _enabled): """ method sets background color of 'Calculate statistics' button to red if the button is disabled foreground color is set up to brown otherwise to black """ if _enabled == False: self.__calculate_button__.setStyleSheet( "background-color: red; color: brown") # @IgnorePep8 else: self.__calculate_button__.setStyleSheet( "background-color: red; color: black") # @IgnorePep8 self.__calculate_button__.setEnabled(_enabled)
class SquareFilterWidget(GroupBoxWidget): """ graphical representation of a square filter """ def __init__(self, parent, **params): get_or_put(params, 'layout', QHBoxLayout()) self.params = Params(**params) self.data_accessor = self.params.data_accessor # alias i18n_def = "Square filter " + self.data_accessor.signal_unit.display_label # @IgnorePep8 super(SquareFilterWidget, self).__init__(parent, i18n_def=i18n_def, **params) self.__filter__ = SquareFilter() LabelWidget(self, i18n_def="Min value") self.__min_value__ = NumberEditWidget( self, text_changed_handler=self.__min_handler__) LabelWidget(self, i18n_def="Max value") self.__max_value__ = NumberEditWidget( self, text_changed_handler=self.__max_handler__) if self.params.use_apply_button: self.__action_button__ = PushButtonWidget( self, i18n_def='Apply', clicked_handler=self.__filter_handler__) else: self.__action_button__ = CheckBoxWidget( self, i18n_def='Use filter', clicked_handler=self.__use_handler__) self.data_accessor.addListener( self, __SquareFilterDataVectorListener__(self)) self.__action_button__.setChecked(False) self.reset() def __use_handler__(self): if not self.params.use_apply_button: if not self.isCorrectSignalRange(self.data_accessor.signal): self.__action_button__.setChecked(False) def __filter_handler__(self): if self.isCorrectSignalRange(self.data_accessor.signal): run_filter(self.parent(), self.__filter__, self.data_accessor, filter_name='square') def isCorrectSignalRange(self, _signal): _min = pl.amin(_signal) if _min >= self.__filter__.min_value and \ _min <= self.__filter__.max_value: return True _max = pl.amax(_signal) if _max >= self.__filter__.min_value and \ _max <= self.__filter__.max_value: return True if _min <= self.__filter__.min_value and \ _max >= self.__filter__.max_value: return True InformationWindow(message="Signal data out of range !") return False def __min_handler__(self, text): self.__filter__.min_value = text self.__check_range__(self.__min_value__) def __max_handler__(self, text): self.__filter__.max_value = text self.__check_range__(self.__max_value__) def __check_range__(self, _widget): message = self.__filter__.check() if message == None: self.__action_button__.setEnabled(True) _widget.setToolTip('') self.__action_button__.setToolTip('') return True else: _widget.setToolTip(message) self.__action_button__.setToolTip(message) self.__action_button__.setEnabled(False) if not self.params.use_apply_button: self.__action_button__.setChecked(False) return False def useFilter(self): return self.__action_button__.isChecked() \ if not self.params.use_apply_button else False def getFilter(self): return self.__filter__ def reset(self): self.setSquareFilterParams( SquareFilterParams(int(pl.amin(self.data_accessor.signal)), int(pl.amax(self.data_accessor.signal)), True)) def setEnabled(self, _enabled): self.__min_value__.setEnabled(_enabled) self.__max_value__.setEnabled(_enabled) def setSquareFilterParams(self, square_filter_params): """ set up square filter widget parameters """ self.__filter__.min_value = square_filter_params.min_value self.__min_value__.setText(self.__filter__.min_value) self.__filter__.max_value = square_filter_params.max_value self.__max_value__.setText(self.__filter__.max_value) if not self.params.use_apply_button: self.__action_button__.setChecked(square_filter_params.use_filter) def getSquareFilterParams(self): return SquareFilterParams(self.__filter__.min_value, self.__filter__.max_value, self.useFilter())