def __init__(self, parent, **params): self.parent = parent self.__completed_count__ = 0 self.selectedRow = None self.params = Params(**params) labels = [ "", # first column is checkable column QT_I18N("datasource.files.column.filename", "Filename"), QT_I18N("datasource.files.column.size", "Size"), QT_I18N("datasource.files.column.path", "File path") ] self.labels = QStringList(labels) self.filesTableView = TableViewWidget( parent, selectionBehavior=QAbstractItemView.SelectRows, selectionMode=QAbstractItemView.SingleSelection, enabled_precheck_handler=self.params.enabled_precheck_handler) if self.params.model: self.filesTableView.setModel(self.params.model) self.filesTableView.model().setHorizontalHeaderLabels(labels) self.filesTableView.setEditTriggers(QAbstractItemView.NoEditTriggers) if self.params.onClickedAction: self.filesTableView.connect(self.filesTableView, SIGNAL('clicked(QModelIndex)'), self.params.onClickedAction) if not self.filesTableView.model() == None: #a signal used when selected row state is changed self.filesTableView.connect( self.filesTableView.model(), SIGNAL('itemChanged(QStandardItem *)'), self.__itemChanged__) if self.params.sorting: self.filesTableView.setSortingEnabled(True)
def create_toolbar_button(parent, toolbar, button_type, **params): params = Params(**params) params.handler = getattr(params, button_type.handler_callable_name, None) if params.handler == None and button_type.handler_name: if hasattr(parent, button_type.handler_name): params.handler = getattr(parent, button_type.handler_name) elif hasattr(parent.parentWidget(), button_type.handler_name): params.handler = getattr(parent.parentWidget(), button_type.handler_name) elif hasattr(params, button_type.handler_name): params.handler = getattr(params, button_type.handler_name) title = nvl(params.button_title, button_type.title) handler = params.handler #give ability to call addition toolbar handler after proper button handler if button_type.handler_callable_name and \ hasattr(button_type, 'after_toolbar_handler'): class ActionToolbarHandler(): def __init__(self, button_handler, toolbar, after_toolbar_handler): self.__button_handler__ = button_handler self.__toolbar__ = toolbar self.__after_toolbar_handler__ = after_toolbar_handler def __call__(self): self.__button_handler__() self.__after_toolbar_handler__(toolbar) #replace button handler with toolbar button handler handler = ActionToolbarHandler(handler, toolbar, getattr(button_type, 'after_toolbar_handler')) actionSpec = ActionSpec(iconId=button_type.icon_id, handler=handler, title=title) toolbar.addWidget(ToolButtonCommon(toolbar, action=create_action(toolbar, actionSpec)))
class GlobalSeparatorWidget(SeparatorWidget): def __init__(self, parent, **params): super(GlobalSeparatorWidget, self).__init__(parent, **params) self.params = Params(**params) self.globalSettingsCheckBox = None if self.params.globalHandler: self.globalSettingsCheckBox = CheckBoxWidget( self.separatorsGroupBox, i18n="separator.global.separator", i18n_def="Global separator") self.separatorsGroupBox.connect(self.globalSettingsCheckBox, SIGNAL("clicked()"), self.globalSettingsButtonClicked) def globalSettingsButtonClicked(self, clicked=None): if clicked: self.globalSettingsCheckBox.setChecked(clicked) if self.globalSettingsCheckBox.isChecked(): if not self.predefinedSeparatorsButtonsGroup.checkedButton() \ == None \ or not is_empty(self.customSeparatorEdit.text()): self.predefinedSeparatorsComposite.setEnabled(False) self.params.globalHandler(True, self.getSeparatorSign()) else: self.globalSettingsCheckBox.setChecked(False) InformationWindow(message='A separator must be chosen !') else: self.predefinedSeparatorsComposite.setEnabled(True) self.params.globalHandler(False) def setGlobalSeparatorAsDefault(self): self.globalSettingsButtonClicked(True)
def __init__(self, parent, **params): super(DockWidgetWidget, self).__init__(nvl(params.get('title', None), ''), parent) if params.get('not_add_widget_to_parent_layout', None) == None: params['not_add_widget_to_parent_layout'] = True prepareWidget(parent=parent, widget=self, **params) self.params = Params(**params) if self.params.use_scroll_area == None: self.params.use_scroll_area = True if not self.params.dock_widget_location_changed == None: self.connect(self, DOCK_WIDGET_LOCATION_CHANGED_SIGNAL, self.__dock_widget_location_changed__) self.setObjectName(self.__class__.__name__) self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea | Qt.TopDockWidgetArea | Qt.BottomDockWidgetArea) layout = nvl(self.params.layout, QVBoxLayout()) if hasattr(layout, 'setMargin'): layout.setMargin(0) self.scrollArea = None if self.params.use_scroll_area: self.scrollArea = QScrollArea(self) self.dockComposite = CompositeWidget( self, layout=layout, not_add_widget_to_parent_layout=True) if self.params.use_scroll_area: self.scrollArea.setWidget(self.dockComposite) self.scrollArea.setWidgetResizable(True) self.setWidget(self.scrollArea) else: self.setWidget(self.dockComposite)
def __init__(self, parent, model, **params): super(TachogramPlotDatasourceListWidget, self).__init__(parent, add_widget_to_parent=True, layout=QVBoxLayout()) self.params = Params(**params) toolbars = ToolBarManager( self, CheckUncheckToolBarWidget, OperationalToolBarWidget, toolbar_close_handler=self.params.close_tachogram_plot_handler) self.layout().addWidget(toolbars) self.__showTachogramsButton__ = PushButtonWidget( self, i18n="poincare.plot.show.tachograms.button", i18n_def="Show tachograms", enabled=False, clicked_handler=self.__showTachogramsHandler__, enabled_precheck_handler=self.__enabledPrecheckHandler__) self.__allowTachogramsDuplicationButton__ = CheckBoxWidget( self, i18n="poincare.plot.allow.tachograms.duplications.button", i18n_def="Allow tachograms duplication", enabled=False, enabled_precheck_handler=self.__enabledPrecheckHandler__) self.__closeAllTachogramsButton__ = PushButtonWidget( self, i18n="poincare.plot.close.all.tachograms.button", i18n_def="Close all tachograms", enabled=False, clicked_handler=self.__closeTachogramsHandler__) self.__datasourceList__ = \ ListWidgetWidget(self, list_item_clicked_handler=self.__datasourceItemClickedHandler__, # @IgnorePep8 list_item_double_clicked_handler=self.__datasourceDoubleItemClickedHandler__, # @IgnorePep8 selectionMode=QAbstractItemView.MultiSelection, selectionBehavior=QAbstractItemView.SelectRows) if len(model) > 0: for row in range(len(model)): fileSpecification = model[row] ListWidgetItemWidget(self.__datasourceList__, text=fileSpecification.filename, data=fileSpecification) else: ListWidgetItemWidget(self.__datasourceList__, text='model not specified or incorrect type') self.__filesPreviewButton__ = PushButtonWidget( self, i18n="poincare.plot.files.preview.button", i18n_def="Files preview", enabled=False, clicked_handler=self.__filesPreviewHandler__, enabled_precheck_handler=self.__enabledPrecheckHandler__)
class CommonWidget(QWidget, Common): def __init__(self, parent, **params): super(CommonWidget, self).__init__(parent) prepareWidget(parent=parent, widget=self, **params) self.params = Params(**params) def hideEvent(self, event): if self.params.hide_event_handler: self.params.hide_event_handler(event) super(CommonWidget, self).hideEvent(event)
def __init__(self, parent, **params): super(GlobalSeparatorWidget, self).__init__(parent, **params) self.params = Params(**params) self.globalSettingsCheckBox = None if self.params.globalHandler: self.globalSettingsCheckBox = CheckBoxWidget( self.separatorsGroupBox, i18n="separator.global.separator", i18n_def="Global separator") self.separatorsGroupBox.connect(self.globalSettingsCheckBox, SIGNAL("clicked()"), self.globalSettingsButtonClicked)
def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Miscellaneous') super(MiscellaneousWidget, self).__init__(parent, **params) LabelWidget(self, i18n_def='Data window shift: 1') self.params = Params(**params) self.params.data_accessor.addListener( self, __MiscellaneousVectorListener__(self)) self.__window_size__ = __DataWindowSizeWidget__( self, self.params.data_accessor) self.__unitsWidget__ = TimeUnitsWidget( self, i18n_def='Units', default_unit=self.params.data_accessor.signal_x_unit, change_unit_handler=self.changeUnit, layout=QHBoxLayout()) self.__unitsWidget__.addUnit(OrderUnit) self.__use_parameters__ = CompositeWidget(self, layout=QHBoxLayout()) self.__use_buffer__ = CheckBoxWidget(self.__use_parameters__, i18n_def='Use buffer', checked=True) self.__use_identity_line__ = CheckBoxWidget( self.__use_parameters__, i18n_def='Use identity line', checked=True) self.__sample_step__ = __SampleStepWidget__(self, self.params.data_accessor) self.__stepper_size__ = __StepperSizeWidget__( self, self.params.data_accessor)
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 __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 __init__(self, parent, **params): #super(TachogramPlotCanvas, self).__init__(parent, # not_add_widget_to_parent_layout=True) self.params = Params(**params) self.title_manager = __TitleManager__( NormalTachogramPlotEngine.DEFAULT_TITLE) self.data_accessor = self.params.data_accessor # alias self.data_accessor.addListener(self, __CanvasDataVectorListener__(self)) # @IgnorePep8 self.fig = Figure() self.axes = self.fig.add_subplot(111) self.__current_plot_engine__ = None FigureCanvas.__init__(self, self.fig) self.title_text = self.fig.suptitle(self.title_manager.title, fontsize=12) self.plot(NormalTachogramPlotEngine) # automatic layout adjustment to use available space more efficiently self.fig.tight_layout() self.setParent(parent) FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) self.__dropper__ = CopyDropper(self, STATISTIC_MIME_ID)
def __set_title__(self, **params): params = Params(**params) if params.filter_name: self.__canvas__.title_manager.addTitlePart('filtered', params.filter_name) if params.remove_filter_names: self.__canvas__.title_manager.removeTitlePart('filtered')
def __init__(self, parent, **params): super(DockWidgetWidget, self).__init__( nvl(params.get('title', None), ''), parent) if params.get('not_add_widget_to_parent_layout', None) == None: params['not_add_widget_to_parent_layout'] = True prepareWidget(parent=parent, widget=self, **params) self.params = Params(**params) if self.params.use_scroll_area == None: self.params.use_scroll_area = True if not self.params.dock_widget_location_changed == None: self.connect(self, DOCK_WIDGET_LOCATION_CHANGED_SIGNAL, self.__dock_widget_location_changed__) self.setObjectName(self.__class__.__name__) self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea | Qt.TopDockWidgetArea | Qt.BottomDockWidgetArea) layout = nvl(self.params.layout, QVBoxLayout()) if hasattr(layout, 'setMargin'): layout.setMargin(0) self.scrollArea = None if self.params.use_scroll_area: self.scrollArea = QScrollArea(self) self.dockComposite = CompositeWidget(self, layout=layout, not_add_widget_to_parent_layout=True) if self.params.use_scroll_area: self.scrollArea.setWidget(self.dockComposite) self.scrollArea.setWidgetResizable(True) self.setWidget(self.scrollArea) else: self.setWidget(self.dockComposite)
def __init__(self, **params): ''' Constructor ''' self.__params__ = Params(**params) if self.__params__.signal_unit is None: self.__params__.signal_unit = Millisecond
def __init__(self, parent, **params): self.params = Params(**params) self.__splitter_idx__ = 0 self.data_vectors_accessor_group = \ self.params.data_vectors_accessor_group # alias if not self.data_vectors_accessor_group == None: self.main_data_accessor = \ self.data_vectors_accessor_group.group_data_vector_accessor else: self.main_data_accessor = self.params.data_accessor # alias super(PoincarePlotSettingsDockWidget, self).__init__(parent, title=params.get('title', 'Poincare plot settings'), **params) self.__splitter__ = SplitterWidget(self.dockComposite, orientation=Qt.Vertical) self.__splitter__.setHandleWidth(5) self.__createStatisticsWidget__(QVBoxLayout()) self.__createFiltersWidget__(QHBoxLayout()) self.__createOutputSpecificationWidget__(QVBoxLayout()) self.__createMiscellaneousWidget__(QVBoxLayout()) parent.addDockWidget(Qt.LeftDockWidgetArea, self)
def invoke(self, **params): local_params = Params(**params) if self.__plugin__ == None: return if self.__host_stack_object__ == None: return if self.__host_stack_object__: for signal in self.__plugin__.signals: _params = [] for param in signal.params: if not param.key == None: _params.append(getattr(local_params, param.key)) elif not param.value == None: if param.value.title() in ('True', 'False'): _params.append(param.value.title() == 'True') elif param.value == "None": _params.append(None) else: _params.append(param.value) if local_params.activity_description \ and local_params.activity_params: ActivityManager.saveActivity( PluginActivity( self.__ident__, description=local_params.activity_description, **get_subdict(params, keys=local_params.activity_params))) if len(params) > 0: self.__host_stack_object__.emit(signal.resolveIdent, *_params) else: self.__host_stack_object__.emit(signal.resolveIdent)
def __init__(self, parent, **params): params = Params(**params) super(ListWidgetItemWidget, self).__init__(nvl(params.text, ''), parent) #store in data buffer of list item for later use if params.data: self.setData(Qt.UserRole, QVariant(params.data))
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 __init__(self, parent=None, create_menus=True, main_workspace_name=GLOBALS.WORKSPACE_NAME, main_widget_name=GLOBALS.TAB_MAIN_NAME, **params): super(ApplicationMainWindow, self).__init__(parent) self.params = Params(**params) self.setObjectName(GLOBALS.MAIN_WINDOW_NAME) self.setWindowTitle(self.params.window_title) if create_menus == True: menuBuilder = QTMenuBuilder(self) menuBuilder.createMenus() if GLOBALS.START_MENU_ID: if menuBuilder.invokeMenuItem(GLOBALS.START_MENU_ID): sys.exit(0) self.applicationMainTabWidget = None if main_workspace_name: self.applicationMainTabWidget = TabWidgetCommon( self, object_name=main_workspace_name, not_add_widget_to_parent_layout=True) if main_widget_name: self.mainWidget = MainTabItemWindow( self.applicationMainTabWidget) self.applicationMainTabWidget.addTab(self.mainWidget, main_widget_name) self.setCentralWidget(self.applicationMainTabWidget) self.connect(self, ADD_TAB_ITEM_WIDGET_SIGNAL, self.addTabWidget)
def __init__(self, parent, **params): self.parent = parent self.__completed_count__ = 0 self.selectedRow = None self.params = Params(**params) labels = ["", # first column is checkable column QT_I18N("datasource.files.column.filename", "Filename"), QT_I18N("datasource.files.column.size", "Size"), QT_I18N("datasource.files.column.path", "File path")] self.labels = QStringList(labels) self.filesTableView = TableViewWidget(parent, selectionBehavior=QAbstractItemView.SelectRows, selectionMode=QAbstractItemView.SingleSelection, enabled_precheck_handler=self.params.enabled_precheck_handler) if self.params.model: self.filesTableView.setModel(self.params.model) self.filesTableView.model().setHorizontalHeaderLabels(labels) self.filesTableView.setEditTriggers(QAbstractItemView.NoEditTriggers) if self.params.onClickedAction: self.filesTableView.connect(self.filesTableView, SIGNAL('clicked(QModelIndex)'), self.params.onClickedAction) if not self.filesTableView.model() == None: #a signal used when selected row state is changed self.filesTableView.connect(self.filesTableView.model(), SIGNAL('itemChanged(QStandardItem *)'), self.__itemChanged__) if self.params.sorting: self.filesTableView.setSortingEnabled(True)
def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Statistics') super(StatisticsSelectionWidget, self).__init__(parent, **params) self.params = Params(**params) if self.params.statistics_base_classes == None: self.params.statistics_base_classes = [Asymmetry] if self.params.data_accessor: self.params.data_accessor.addListener( self, __StatisticsSelectionVectorListener__(self)) self.__createButtons__() self.__createTable__() self.__createModel__() self.__fillStatistics__(self.params.statistics_base_classes)
def __init__(self, default, **params): params = Params(**params) self.active = nvl(params.active, default.active) self.button_groups = nvl(params.button_groups, default.button_groups) self.handler_name = nvl(params.handler_name, default.handler_name) self.icon_id = nvl(params.icon_id, default.icon_id) self.title = nvl(params.title, default.title) self.handler_callable_name = default.handler_callable_name
def __init__(self, **params): self.params = Params(**params) self.__iconId = self.params.iconId self.__tipId = self.params.tipId self.__signal = self.params.signal self.__slot = self.params.handler self.__title = self.params.title self.__checkable = ("True" == str(self.params.checkable))
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)
def __init__(self, parent, **params): self.params = Params(**params) super(TabularDataVectorPreviewDockWidget, self).__init__(parent, title=params.get('title', 'Data preview'), **params) self.data_accessor = self.params.data_accessor # alias self.__createPreviewWidget__(QVBoxLayout()) parent.addDockWidget(Qt.RightDockWidgetArea, self)
def __init__(self, _parent, _mime_id, **params): self.__mime_id__ = _mime_id self.__parent__ = _parent params = Params(**params) self.__parent__.setDragEnabled(True) if params.drag_only: if hasattr(self, 'setDragDropMode'): self.__parent__.setDragDropMode(QAbstractItemView.DragOnly) self.__objects__ = {}
def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Selected poincare plot datasources') super(PoincarePlotDatasourcesTableWidget, self).__init__(parent, **params) self.params = Params(**params) self.__createTable__() self.__createModel__()
def data(self, _data): self.__params__ = Params(signal=_data.signal, signal_plus=_data.signal_plus, signal_minus=_data.signal_minus, annotation=_data.annotation, signal_unit=_data.signal_unit, time=_data.time, signal_header=_data.signal_header, annotation_header=_data.annotation_header, time_header=_data.time_header)
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 __init__(self, parent, data_vector_accessor_list, label_text=None, max_value=None, **params): self.parent = parent self.label_text = nvl(label_text, "Poincare plot generation") self.max_value = max_value self.__data_vector_accessor_list__ = data_vector_accessor_list self.params = Params(**params)
def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Files') super(FilesTrackerWidget, self).__init__(parent, **params) self.params = Params(**params) self.__create_oper_buttons__() self.__createTable__() self.__createModel__() self.__create_misc_buttons__()
def __init__(self, parent, **params): super(TachogramPlotCompositeWidget, self).__init__(parent, **params) self.params = Params(**params) self.data_accessor = get_data_accessor_from_file_specification( self, self.params.file_specification) self.addToolBar(OperationalToolBarWidget(self)) self.addToolBar(PoincareToolBarWidget(self)) signal_unit = get_unit_by_class_name( self.params.file_specification.signal_unit_class_name) self.setCentralWidget(__TachogramPlot__(self, signal_unit=signal_unit))
def __init__(self, parent, **params): self.params = Params(**params) self.data_accessor = self.params.data_accessor # alias super(OutcomeFilesTrackerDockWidget, self).__init__(parent, title=params.get('title', 'Outcome files tracker'), **params) self.__createFilesTrackerWidget__(QVBoxLayout()) parent.addDockWidget(Qt.RightDockWidgetArea, self)
def __init__(self, parent, **params): self.params = Params(**params) super(TachogramPlotStatisticsDockWidget, self).__init__(parent, title=params.get('title', 'Tachogram plot statistics'), **params) self.data_accessor = self.params.data_accessor # alias self.data_accessor.addListener( self, __TachogramStatisticsDataVectorListener__(self)) self.__createStatisticsWidget__(QVBoxLayout()) parent.addDockWidget(Qt.RightDockWidgetArea, self)
def __init__(self, parent, model, **params): super(TachogramPlotDatasourceListWidget, self).__init__(parent, add_widget_to_parent=True, layout=QVBoxLayout()) self.params = Params(**params) toolbars = ToolBarManager(self, CheckUncheckToolBarWidget, OperationalToolBarWidget, toolbar_close_handler=self.params.close_tachogram_plot_handler) self.layout().addWidget(toolbars) self.__showTachogramsButton__ = PushButtonWidget(self, i18n="poincare.plot.show.tachograms.button", i18n_def="Show tachograms", enabled=False, clicked_handler=self.__showTachogramsHandler__, enabled_precheck_handler=self.__enabledPrecheckHandler__) self.__allowTachogramsDuplicationButton__ = CheckBoxWidget(self, i18n="poincare.plot.allow.tachograms.duplications.button", i18n_def="Allow tachograms duplication", enabled=False, enabled_precheck_handler=self.__enabledPrecheckHandler__) self.__closeAllTachogramsButton__ = PushButtonWidget(self, i18n="poincare.plot.close.all.tachograms.button", i18n_def="Close all tachograms", enabled=False, clicked_handler=self.__closeTachogramsHandler__) self.__datasourceList__ = \ ListWidgetWidget(self, list_item_clicked_handler=self.__datasourceItemClickedHandler__, # @IgnorePep8 list_item_double_clicked_handler=self.__datasourceDoubleItemClickedHandler__, # @IgnorePep8 selectionMode=QAbstractItemView.MultiSelection, selectionBehavior=QAbstractItemView.SelectRows) if len(model) > 0: for row in range(len(model)): fileSpecification = model[row] ListWidgetItemWidget(self.__datasourceList__, text=fileSpecification.filename, data=fileSpecification) else: ListWidgetItemWidget(self.__datasourceList__, text='model not specified or incorrect type') self.__filesPreviewButton__ = PushButtonWidget(self, i18n="poincare.plot.files.preview.button", i18n_def="Files preview", enabled=False, clicked_handler=self.__filesPreviewHandler__, enabled_precheck_handler=self.__enabledPrecheckHandler__)
def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Statistics') super(StatisticsSelectionWidget, self).__init__(parent, **params) self.params = Params(**params) if self.params.statistics_base_classes == None: self.params.statistics_base_classes = [Asymmetry] if self.params.data_accessor: self.params.data_accessor.addListener(self, __StatisticsSelectionVectorListener__(self)) self.__createButtons__() self.__createTable__() self.__createModel__() self.__fillStatistics__(self.params.statistics_base_classes)
class FilesTableView(object): def __init__(self, parent, **params): self.parent = parent self.__completed_count__ = 0 self.selectedRow = None self.params = Params(**params) labels = ["", # first column is checkable column QT_I18N("datasource.files.column.filename", "Filename"), QT_I18N("datasource.files.column.size", "Size"), QT_I18N("datasource.files.column.path", "File path")] self.labels = QStringList(labels) self.filesTableView = TableViewWidget(parent, selectionBehavior=QAbstractItemView.SelectRows, selectionMode=QAbstractItemView.SingleSelection, enabled_precheck_handler=self.params.enabled_precheck_handler) if self.params.model: self.filesTableView.setModel(self.params.model) self.filesTableView.model().setHorizontalHeaderLabels(labels) self.filesTableView.setEditTriggers(QAbstractItemView.NoEditTriggers) if self.params.onClickedAction: self.filesTableView.connect(self.filesTableView, SIGNAL('clicked(QModelIndex)'), self.params.onClickedAction) if not self.filesTableView.model() == None: #a signal used when selected row state is changed self.filesTableView.connect(self.filesTableView.model(), SIGNAL('itemChanged(QStandardItem *)'), self.__itemChanged__) if self.params.sorting: self.filesTableView.setSortingEnabled(True) def reload(self): if self.filesTableView.model().rowCount() > 0: self.filesTableView.resizeColumnsToContents() self.filesTableView.scrollToTop() def __itemChanged__(self, item): self.changeCompleteState(1, 'add' if item.checkState() == Qt.Checked else 'sub') def addRow(self, row): self.filesTableView.model().appendRow(row) def clear(self): self.filesTableView.model().removeRows(0, self.filesTableView.model().rowCount()) self.minCompleteState() def getSelectedPathAndFilename(self): return self.getPathAndFilename(self.selectedRow) def getPathAndFilename(self, modelIdx): if not modelIdx == None: model = modelIdx.model() path = model.item(modelIdx.row(), 3) filename = model.item(modelIdx.row(), 1) return FilePath(str(path.text()), str(filename.text())) def onClickedAction(self, selectedRow): self.selectedRow = selectedRow #do not remove leave as an useful example #checked = self.__rowChecked__(selectedRow) def getSelectedItems(self): return [self.filesTableView.model().item(row) for row in range(0, self.filesTableView.model().rowCount()) if self.filesTableView.model().item(row).checkState() == Qt.Checked] def setCheckedRowState(self, idx, state): self.filesTableView.model().item(idx).setCheckState(state) def getRowCount(self): return self.filesTableView.model().rowCount() def setEnabled(self, enabled): self.filesTableView.setEnabled(enabled) def resizeColumnsToContents(self): self.filesTableView.resizeColumnsToContents() def changeCompleteState(self, value=0, operation='set'): """ a method instead of emitting a signal completeChanged() which is intercepted by QWizard to enable/disable next, previous buttons based on value returned by isComplete method of a wizard page set up wizard operational's buttons enable states, because use of the completeChange signal causes jump to the beginning of a table view instead of sticking to the position where it was already and also dim of a selected row is observed """ if operation == 'set' and value != 0: self.__completed_count__ = value elif operation == 'add': self.__completed_count__ = self.__completed_count__ + value elif operation == 'sub': if self.__completed_count__ - value >= 0: self.__completed_count__ = self.__completed_count__ - value #self.emit(SIGNAL("completeChanged()")) if self.params.wizardButtons and self.params.wizard_handler: for button in self.params.wizardButtons: self.params.wizard_handler().button(button).setEnabled( self.isCompletedCount()) def isCompletedCount(self): return self.getCompletedCount() > 0 def getCompletedCount(self): return self.__completed_count__ def maxCompleteState(self): self.changeCompleteState(self.getRowCount()) def minCompleteState(self): self.changeCompleteState(0) def getModel(self): return self.filesTableView.model() def setColumnHidden(self, column, hide=True): self.filesTableView.setColumnHidden(column, hide) def getSelectedRow(self): return self.selectedRow def model(self): return self.filesTableView.model() def count(self): return self.filesTableView.model().rowCount() def getSelectedRowCount(self): return len(self.filesTableView.selectedIndexes()) / len(self.labels) def selectRow(self, row, emulate_click=True): self.filesTableView.selectRow(row) if emulate_click: model = self.filesTableView.model() for column in range(model.columnCount()): if self.filesTableView.isColumnHidden(column) == False: #simulate a click on the first visible column self.filesTableView.emit(SIGNAL('clicked(QModelIndex)'), model.index(row, column)) break
class TachogramPlotDatasourceListWidget(CommonWidget): def __init__(self, parent, model, **params): super(TachogramPlotDatasourceListWidget, self).__init__(parent, add_widget_to_parent=True, layout=QVBoxLayout()) self.params = Params(**params) toolbars = ToolBarManager(self, CheckUncheckToolBarWidget, OperationalToolBarWidget, toolbar_close_handler=self.params.close_tachogram_plot_handler) self.layout().addWidget(toolbars) self.__showTachogramsButton__ = PushButtonWidget(self, i18n="poincare.plot.show.tachograms.button", i18n_def="Show tachograms", enabled=False, clicked_handler=self.__showTachogramsHandler__, enabled_precheck_handler=self.__enabledPrecheckHandler__) self.__allowTachogramsDuplicationButton__ = CheckBoxWidget(self, i18n="poincare.plot.allow.tachograms.duplications.button", i18n_def="Allow tachograms duplication", enabled=False, enabled_precheck_handler=self.__enabledPrecheckHandler__) self.__closeAllTachogramsButton__ = PushButtonWidget(self, i18n="poincare.plot.close.all.tachograms.button", i18n_def="Close all tachograms", enabled=False, clicked_handler=self.__closeTachogramsHandler__) self.__datasourceList__ = \ ListWidgetWidget(self, list_item_clicked_handler=self.__datasourceItemClickedHandler__, # @IgnorePep8 list_item_double_clicked_handler=self.__datasourceDoubleItemClickedHandler__, # @IgnorePep8 selectionMode=QAbstractItemView.MultiSelection, selectionBehavior=QAbstractItemView.SelectRows) if len(model) > 0: for row in range(len(model)): fileSpecification = model[row] ListWidgetItemWidget(self.__datasourceList__, text=fileSpecification.filename, data=fileSpecification) else: ListWidgetItemWidget(self.__datasourceList__, text='model not specified or incorrect type') self.__filesPreviewButton__ = PushButtonWidget(self, i18n="poincare.plot.files.preview.button", i18n_def="Files preview", enabled=False, clicked_handler=self.__filesPreviewHandler__, enabled_precheck_handler=self.__enabledPrecheckHandler__) def __datasourceItemClickedHandler__(self, listItem): self.emit(ENABLEMEND_SIGNAL, listItem.isSelected()) def __showTachogramsHandler__(self): self.__showTachograms__(self.__getFilesSpecifications__(selected=True)) def __filesPreviewHandler__(self): showFilesPreviewDialog(self.__getFilesSpecifications__(selected=True)) def __datasourceDoubleItemClickedHandler__(self, listItem): self.__showTachograms__(self.__getFilesSpecifications__([listItem])) def __showTachograms__(self, files_specifications): progressManager = ProgressDialogManager(self, label_text="Create tachograms", max_value=len(files_specifications)) firstFocus = True checked = self.__allowTachogramsDuplicationButton__.isChecked() with progressManager as progress: for idx in range(progress.maximum()): if (progress.wasCanceled()): break progress.increaseCounter() tachogram_plot = self.params.add_tachogram_plot_handler( files_specifications[idx], checked, firstFocus) if firstFocus and tachogram_plot: firstFocus = False self.__datasourceList__.clearSelection() def __enabledPrecheckHandler__(self, widget): """ only interested widgets return bool value others return none value """ if widget in (self.__showTachogramsButton__, self.__allowTachogramsDuplicationButton__, self.__filesPreviewButton__): return len(self.__datasourceList__.selectedIndexes()) > 0 def __closeTachogramsHandler__(self): if self.params.close_tachograms_handler: if self.params.close_tachograms_handler(): self.__closeAllTachogramsButton__.setEnabled(False) self.toolbar_uncheck_handler() def toolbar_uncheck_handler(self): self.__datasourceList__.clearSelection() self.emit(ENABLEMEND_SIGNAL, False) def toolbar_check_handler(self): self.__datasourceList__.selectAll() self.emit(ENABLEMEND_SIGNAL, True) def toolbar_maximum_handler(self): maximize_widget(self) def toolbar_restore_handler(self): restore_widget(self) def enabledCloseAllTachogramsButton(self, enabled): self.__closeAllTachogramsButton__.setEnabled(enabled) def __getFilesSpecifications__(self, list_items=None, selected=False): if selected: # get files specifications from selected items list_items = self.__datasourceList__.selectedItems() #acquired from data buffer of list items file specification objects return [list_item.getData() for list_item in list_items] def getSelectedFilesSpecifications(self): """ method returns selected files specifications in tachogram plot list widget """ return self.__getFilesSpecifications__(selected=True)
class TableViewWidget(QTableView, Common): def __init__(self, parent, **params): super(TableViewWidget, self).__init__(parent) prepareWidget(parent=parent, widget=self, **params) self.params = Params(**params) self.__checked_count__ = 0 self.__scroll_contents_by_handler__ = None @property def checked_count(self): """ return number of rows at check state (if any) if return -1 than mean table view is not checkable """ return self.__checked_count__ if self.is_checkable else -1 @property def is_checkable(self): """ return true if a table is checkable """ model = self.model() if not model == None: for idx in range(model.rowCount()): if model.item(idx).isCheckable(): return True return False def changeCheckStatForAll(self, _check): """ method changes check state (True/False) for the whole table view """ if not self.is_checkable: return self.setEnabled(False) count = self.model().rowCount() progressManager = ProgressDialogManager(self, label_text=("Checking..." if _check else "Unchecking..."), max_value=count) with progressManager as progress: for idx in range(count): if (progress.wasCanceled()): break progress.increaseCounter() self.model().item(idx).setCheckState(Qt.Checked if _check else Qt.Unchecked) self.setEnabled(True) def setModel(self, model): super(TableViewWidget, self).setModel(model) #signal used when selected row check state is changed self.connect(self.model(), ITEM_CHANGED_SIGNAL, self.__itemChanged__) if self.params.rows_inserted_handler: self.connect(self.model(), ROWS_INSERTED_SIGNAL, self.params.rows_inserted_handler) def __itemChanged__(self, item): if item.isCheckable(): if item.checkState() == Qt.Checked: self.__checked_count__ = self.__checked_count__ + 1 else: self.__checked_count__ = self.__checked_count__ - 1 if self.params.change_check_count_handler: self.params.change_check_count_handler(self.__checked_count__) if self.params.check_handler: self.params.check_handler(item) def clearRows(self): """ method deletes all rows """ model = self.model() if model: if hasattr(model, 'removeRows'): self.__checked_count__ = 0 model.removeRows(0, model.rowCount()) def setScrollContentsByHandler(self, _handler): """ set up a handler which will be invoked when scrolling happens """ self.__scroll_contents_by_handler__ = _handler def scrollContentsBy(self, dx, dy): """ overriding a method invoked when scrolling happens """ super(TableViewWidget, self).scrollContentsBy(dx, dy) if (dx != 0 or dy != 0) and \ not self.__scroll_contents_by_handler__ == None: self.__scroll_contents_by_handler__()
class StatisticsSelectionWidget(GroupBoxWidget): #this value is set up in __createModel__ method VALUE_COLUMN = 0 """ widget which gives ability to select statistics """ @temporarySettingsDecorator() def __init__(self, parent, **params): get_or_put(params, 'layout', QVBoxLayout()) get_or_put(params, 'i18n_def', 'Statistics') super(StatisticsSelectionWidget, self).__init__(parent, **params) self.params = Params(**params) if self.params.statistics_base_classes == None: self.params.statistics_base_classes = [Asymmetry] if self.params.data_accessor: self.params.data_accessor.addListener(self, __StatisticsSelectionVectorListener__(self)) self.__createButtons__() self.__createTable__() self.__createModel__() self.__fillStatistics__(self.params.statistics_base_classes) def __createTable__(self): self.__table__ = TableViewWidget(self, change_check_count_handler=self.params.change_selection_count_handler, # @IgnorePep8 check_handler=self.__check_handler__) self.__table__.setSelectionMode(QAbstractItemView.MultiSelection) self.__table__.setSelectionBehavior(QAbstractItemView.SelectRows) def __createModel__(self): model = __StatisticsSelectionModel__(self) labels = QStringList(["Statistic", "Description", "Value"]) StatisticsSelectionWidget.VALUE_COLUMN = labels.indexOf("Value") model.setNumValueColumn(StatisticsSelectionWidget.VALUE_COLUMN) model.setHorizontalHeaderLabels(labels) self.__table__.setModel(model) self.__table__.setColumnHidden(StatisticsSelectionWidget.VALUE_COLUMN, True) def __createButtons__(self): buttons_composite = CompositeWidget(self, layout=QHBoxLayout()) PushButtonWidget(buttons_composite, i18n_def="Select all", clicked_handler=self.__select_all_handler__) PushButtonWidget(buttons_composite, i18n_def="Unselect all", clicked_handler=self.__unselect_all_handler__) def __select_all_handler__(self): self.__table__.changeCheckStatForAll(True) def __unselect_all_handler__(self): self.__table__.changeCheckStatForAll(False) def __fillStatistics__(self, _statistics_base_classes): model = self.__table__.model() model.removeRows(0, model.rowCount()) self.__statistics_classes__ = [] for base_class in _statistics_base_classes: for subclass in get_subclasses(base_class): self.__statistics_classes__.append(subclass) #sort alphabetically cmp_stat = lambda x, y: cmp(x.__name__, y.__name__) self.__statistics_classes__ = sorted(self.__statistics_classes__, cmp_stat) for statistic_class in self.__statistics_classes__: check_column = QStandardItem('%s' % statistic_class.__name__) check_column.setCheckState(Qt.Unchecked) check_column.setCheckable(True) description_column = QStandardItem(str(statistic_class().description)) # @IgnorePep8 value_column = QStandardItem('') model.appendRow([check_column, description_column, value_column]) @property def statistics_classes(self): return self.__statistics_classes__ def getSelectedStatisticsClasses(self): selected_classes = [] model = self.__table__.model() for idx in range(model.rowCount()): item = model.item(idx) if item.isCheckable() and item.checkState() == Qt.Checked: selected_classes.append(self.__statistics_classes__[idx]) return selected_classes def setStatisticsValues(self, values_map): """ method to set up statistics values """ if values_map == None: return #show value column self.__table__.setColumnHidden(StatisticsSelectionWidget.VALUE_COLUMN, False) for statistic_class in values_map: row = self.__statistics_classes__.index(statistic_class) self.__table__.model().setItem(row, StatisticsSelectionWidget.VALUE_COLUMN, QStandardItem(str(values_map[statistic_class]))) def __check_handler__(self, item): """ handler invoked when a user check selected row in statistics table view, the parameter is an model's item """ if self.params.check_handler: if item.isCheckable(): statistic_class = self.__statistics_classes__[item.row()] #parameters of outer handler check_handler are #statistics object and whether is checked or unchecked self.params.check_handler(statistic_class(), item.checkState() == Qt.Checked) def checkStatistic(self, _statistic): """ method checks statistic identified by a parameter - statistic class """ row = self.__statistics_classes__.index(_statistic) if row >= 0: item = self.__table__.model().item(row) if item.isCheckable(): item.setCheckState(Qt.Checked) def __getSelectedStatisticsClassesNames__(self): return [statistic_class.__name__ for statistic_class in self.getSelectedStatisticsClasses()] @temporarySetterDecorator(name='selected_statistics', _conv=QVariant.toPyObject, _getter_handler=__getSelectedStatisticsClassesNames__) def __setSelectedStatistics__(self, _statistics_class_names): if not _statistics_class_names == None: model = self.__table__.model() for idx in range(model.rowCount()): item = model.item(idx) if item.isCheckable() and item.checkState() == Qt.Unchecked \ and self.__statistics_classes__[idx].__name__ in _statistics_class_names: # @IgnorePep8 item.setCheckState(Qt.Checked)
def __init__(self, parent, **params): super(TableViewWidget, self).__init__(parent) prepareWidget(parent=parent, widget=self, **params) self.params = Params(**params) self.__checked_count__ = 0 self.__scroll_contents_by_handler__ = None
class PoincarePlotMovieMaker(object): """ class used to generate poincare plot movie """ def __init__(self, data_vector, movie_parameters, **params): self.p = movie_parameters if not self.p.movie_name == None: self.params = Params(**params) mpl.rcParams['patch.edgecolor'] = 'none' mpl.rcParams['savefig.edgecolor'] = 'none' self.source = get_filename(self.params.reference_filename) self.__prefixed_movie_name__ = self.__get_prefixed_movie_name__() self.__prefixed_movie_dir__ = self.__get_prefixed_movie_dir__() if not self.params.filter_manager == None: data_vector = self.params.filter_manager.run_filters( data_vector) _max = pl.amax(data_vector.signal) _min = pl.amin(data_vector.signal) self.time = data_vector.time margin = 50 self.signal_size = len(data_vector.signal) self.range = [_min - margin, _max + margin, _min - margin, _max + margin] self.x_data = pl.zeros(self.signal_size) self.y_data = pl.zeros(self.signal_size) self.old_signal_plus = None self.idx = 0 self.active_color = get_extended_color_array( movie_parameters.movie_active_color) self.inactive_color = get_extended_color_array( movie_parameters.movie_inactive_color) self.centroid_color = get_extended_color_array( movie_parameters.movie_centroid_color) self.message = None self.core_nums = multiprocessing.cpu_count() * self.p.movie_multiprocessing_factor # @IgnorePep8 self.pp_spec_manager = MiniPoincarePlotSpecManager() self.pp_spec_manager.movie_dir = self.__prefixed_movie_dir__ self.pp_spec_manager.movie_name = self.__prefixed_movie_name__ self.pp_spec_manager.movie_dpi = self.p.movie_dpi self.pp_spec_manager.movie_fps = self.p.movie_fps self.pp_spec_manager.movie_height = self.p.movie_height self.pp_spec_manager.movie_width = self.p.movie_width self.pp_spec_manager.active_color = self.active_color self.pp_spec_manager.inactive_color = self.inactive_color self.pp_spec_manager.centroid_color = self.centroid_color self.pp_spec_manager.active_point_size = self.p.movie_active_size self.pp_spec_manager.inactive_point_size = \ self.p.movie_inactive_size self.pp_spec_manager.centroid_point_size = \ self.p.movie_centroid_size self.pp_spec_manager.show_plot_legends = \ self.p.movie_show_plot_legends self.pp_spec_manager.x_label = self.p.x_label self.pp_spec_manager.y_label = self.p.y_label self.pp_spec_manager.clean_frames = self.p.movie_clean_frames self.pp_spec_manager.movie_title = self.p.movie_title self.pp_spec_manager.movie_frame_step = self.p.movie_frame_step self.pp_spec_manager.movie_identity_line = self.p.movie_identity_line self.pp_spec_manager.movie_hour_label = self.p.movie_hour_label self.pp_spec_manager.movie_minute_label = self.p.movie_minute_label self.pp_spec_manager.movie_second_label = self.p.movie_second_label self.pp_spec_manager.movie_time_label_in_line = self.p.movie_time_label_in_line self.pp_spec_manager.movie_time_label_font_size = self.p.movie_time_label_font_size self.pp_spec_manager.movie_time_label_prefix = self.p.movie_time_label_prefix self.pp_spec_manager.movie_title_font_size = self.p.movie_title_font_size self.pp_spec_manager.movie_axis_font_size = self.p.movie_axis_font_size self.pp_spec_manager.movie_axis_font = self.p.movie_axis_font self.pp_spec_manager.movie_title_font = self.p.movie_title_font self.pp_spec_manager.movie_tick_font = self.p.movie_tick_font self.pp_spec_manager.movie_frame_pad = self.p.movie_frame_pad self.pp_spec_manager.movie_create_time_label = self.p.movie_create_time_label self.pp_spec_manager.movie_frame_filename_with_time = self.p.movie_frame_filename_with_time self.pp_specs_managers = [] self.pp_specs_managers.append(self.pp_spec_manager) self.sub_dir_counter = 0 self.scatter = None self.legend_text = None self.pp_specs = [] self.cum_inactive = 0 self._pp_spec_old = None self.s_size = 0 # current calculated signal size def add_data_vector_segment(self, data_vector_segment, last_segment=False): self.message = None if self.__prefixed_movie_name__ == None: return if last_segment: self.__save_frames__() return frame_name = '%s_%06d' % (self.__prefixed_movie_name__, self.idx) frame_file = as_path(self.__prefixed_movie_dir__, frame_name + '.png') #skip_frame = True if self.idx < self.p.movie_skip_to_frame or \ # (self.p.movie_skip_frames and os.path.exists(frame_file)) \ # else False skip_frame = False mean_plus = pl.mean(data_vector_segment.signal_plus) mean_minus = pl.mean(data_vector_segment.signal_minus) s_plus = len(data_vector_segment.signal_plus) _pp_spec = MiniPoincarePlotSpec() _pp_spec.idx = self.idx _pp_spec.s_plus = s_plus _pp_spec.mean_plus = mean_plus _pp_spec.mean_minus = mean_minus _pp_spec.range = self.range _pp_spec.frame_file = frame_file if self.idx == 0: self.s_size = s_plus self.x_data.put(pl.arange(s_plus), data_vector_segment.signal_plus) self.y_data.put(pl.arange(s_plus), data_vector_segment.signal_minus) ok = True old_s_plus = 0 _pp_spec.level = 0 _pp_spec.active_start = 0 _pp_spec.active_stop = s_plus else: old_s_plus = len(self.old_signal_plus) ok = False if s_plus >= old_s_plus: if pl.all(self.old_signal_plus \ == data_vector_segment.signal_plus[:old_s_plus]): old_size = self.s_size new_size = old_size + s_plus - old_s_plus if new_size > old_size: _pp_spec.active_start = old_size _pp_spec.active_stop = new_size if new_size > len(self.x_data): raise Exception( 'New size is greater then the signal size !') self.x_data.put(pl.arange(old_size, new_size), data_vector_segment.signal_plus[old_s_plus - s_plus:]) self.y_data.put(pl.arange(old_size, new_size), data_vector_segment.signal_minus[old_s_plus - s_plus:]) _pp_spec.inactive_stop = \ self._pp_spec_old.inactive_stop self.s_size = new_size _pp_spec.level = 1 ok = True else: for idx in xrange(1, old_s_plus): if pl.all(self.old_signal_plus[idx:] \ == data_vector_segment.signal_plus[idx - 1: old_s_plus - idx]): old_size = self.s_size new_size = old_size + s_plus - (old_s_plus - idx) if new_size > len(self.x_data): raise Exception( 'New size is greater then the signal size !') if new_size > old_size: _pp_spec.active_start = old_size _pp_spec.active_stop = new_size self.x_data.put(pl.arange(old_size, new_size), data_vector_segment.signal_plus[ old_s_plus - idx:]) self.y_data.put(pl.arange(old_size, new_size), data_vector_segment.signal_minus[ old_s_plus - idx:]) self.s_size = new_size _d = self.s_size - s_plus _pp_spec.inactive_start = _d - idx _pp_spec.inactive_stop = _d _pp_spec.level = 3 ok = True break else: for idx in xrange(1, old_s_plus): if idx + s_plus <= old_s_plus \ and pl.all( self.old_signal_plus[idx:idx + s_plus] \ == data_vector_segment.signal_plus): _d = self.s_size - old_s_plus _pp_spec.inactive_start = _d _pp_spec.inactive_stop = _d + idx if _pp_spec.inactive_stop + s_plus < self.s_size: _pp_spec.inactive_start_2 = \ _pp_spec.inactive_stop + s_plus _pp_spec.inactive_stop_2 = self.s_size _pp_spec.level = 2 ok = True break if ok == True and skip_frame == False: _pp_spec.x_data = self.x_data _pp_spec.y_data = self.y_data _pp_spec.cum_inactive = self.cum_inactive _pp_spec.s_size = self.s_size #print('PP_SPEC: ' + str(_p)) self.pp_spec_manager.addMiniPoincarePlotSpec(_pp_spec) if self.idx > 0 and \ (self.p.movie_bin_size > 0 and ((self.idx % self.p.movie_bin_size) == 0)): if len(self.pp_specs_managers) >= self.core_nums: if self.p.movie_calculate_all_frames == False: self.__save_frames__() self.pp_specs_managers = [] old_pp_spec_manager = self.pp_spec_manager self.pp_spec_manager = MiniPoincarePlotSpecManager() self.pp_spec_manager.movie_dir = self.__prefixed_movie_dir__ self.pp_spec_manager.movie_name = self.__prefixed_movie_name__ self.pp_spec_manager.movie_dpi = self.p.movie_dpi self.pp_spec_manager.movie_fps = self.p.movie_fps self.pp_spec_manager.movie_height = self.p.movie_height self.pp_spec_manager.movie_width = self.p.movie_width self.pp_spec_manager.active_color = self.active_color self.pp_spec_manager.inactive_color = self.inactive_color self.pp_spec_manager.centroid_color = self.centroid_color self.pp_spec_manager.active_point_size = \ self.p.movie_active_size self.pp_spec_manager.inactive_point_size = \ self.p.movie_inactive_size self.pp_spec_manager.centroid_point_size = \ self.p.movie_centroid_size self.pp_spec_manager.show_plot_legends = \ self.p.movie_show_plot_legends self.pp_spec_manager.x_label = self.p.x_label self.pp_spec_manager.y_label = self.p.y_label self.pp_spec_manager.clean_frames = self.p.movie_clean_frames self.pp_spec_manager.movie_title = self.p.movie_title self.pp_spec_manager.movie_frame_step = self.p.movie_frame_step self.pp_spec_manager.movie_identity_line = self.p.movie_identity_line self.pp_spec_manager.movie_hour_label = self.p.movie_hour_label self.pp_spec_manager.movie_minute_label = self.p.movie_minute_label self.pp_spec_manager.movie_second_label = self.p.movie_second_label self.pp_spec_manager.movie_time_label_in_line = self.p.movie_time_label_in_line self.pp_spec_manager.movie_time_label_font_size = self.p.movie_time_label_font_size self.pp_spec_manager.movie_time_label_prefix = self.p.movie_time_label_prefix self.pp_spec_manager.movie_title_font_size = self.p.movie_title_font_size self.pp_spec_manager.movie_axis_font_size = self.p.movie_axis_font_size self.pp_spec_manager.movie_axis_font = self.p.movie_axis_font self.pp_spec_manager.movie_title_font = self.p.movie_title_font self.pp_spec_manager.movie_tick_font = self.p.movie_tick_font self.pp_spec_manager.movie_frame_pad = self.p.movie_frame_pad self.pp_spec_manager.movie_create_time_label = self.p.movie_create_time_label self.pp_spec_manager.movie_frame_filename_with_time = self.p.movie_frame_filename_with_time #add all previous pp specs for pp_spec in old_pp_spec_manager.getMiniPoincarePlotSpecs(): self.pp_spec_manager.addPreviousPoincarePlotSpecMinimum( pp_spec) old_pp_spec_manager = None self.pp_specs_managers.append(self.pp_spec_manager) self.message = 'Prepare frame: %s' % (frame_name) elif ok == True and skip_frame == True: self.message = 'Skip frame %s' % (frame_name) elif ok == False: print('s_plus: ' + str(s_plus) + ' old_s_plus: ' + str(old_s_plus)) print('old_signal_plus: ' + str(self.old_signal_plus)) print('signal_plus: ' + str(data_vector_segment.signal_plus)) raise Exception('Error for idx ' + str(self.idx)) if _pp_spec.inactive_start >= 0 and _pp_spec.inactive_stop >= 0: #if time array is not None use it as array for cumulative time if not self.time == None: self.cum_inactive += pl.sum( self.time[ _pp_spec.inactive_start:_pp_spec.inactive_stop]) else: self.cum_inactive += pl.sum( self.x_data[ _pp_spec.inactive_start:_pp_spec.inactive_stop]) self.old_signal_plus = data_vector_segment.signal_plus self.idx = self.idx + 1 self._pp_spec_old = _pp_spec #gc.collect() # this invocation slow down process of movie generation def save_movie(self): if not self.__prefixed_movie_name__ == None and self.p.movie_not_save == False: # @IgnorePep8 output_file = generate_movie(self.__prefixed_movie_name__, self.__prefixed_movie_dir__, self.p.movie_width, self.p.movie_height, self.p.movie_fps, movie_clean_frames=self.p.movie_clean_frames) self.message = "Poincare plot movie %s is created !" \ % as_path(self.__prefixed_movie_dir__, output_file) @property def info_message(self): return self.message def __save_frames__(self): size = len(self.pp_specs_managers) if size > 0: #create output movie dir if it is not present create_dir(self.pp_specs_managers[0].movie_dir) if self.p.movie_multiprocessing_factor > 0: for specs_managers in get_chunks(self.pp_specs_managers, self.core_nums): pool = multiprocessing.Pool(processes=self.core_nums #,maxtasksperchild=self.p.movie_multiprocessing_factor ) if not self.params.info_message_handler == None: self.params.info_message_handler('Generating frames' + (' ' * 20)) pool.map(self.__poincare_plot_function__, specs_managers, #self.pp_specs_managers, #chunksize=self.p.movie_multiprocessing_factor #chunksize=20 ) pool.close() gc.collect() else: _function = self.__poincare_plot_function__ for pp_spec_manager in self.pp_specs_managers: _function(pp_spec_manager) @property def __poincare_plot_function__(self): if self.p.movie_animated: return create_mini_poincare_plot_animated_generation elif self.p.movie_standard_generation: return create_mini_poincare_plot_standard_generation elif self.p.movie_experimental_code: return create_mini_poincare_plot_experimental else: #the default choice return create_mini_poincare_plot_fast_generation def __get_prefixed_movie_name__(self): """ method prefixed movie_name by source name and output_prefix """ movie_name = self.p.movie_name #append source filename movie_name = '%s_%s' % (self.source, movie_name) \ if self.p.movie_prefixed_by_source else movie_name #append output_prefix return movie_name if is_empty(self.p.output_prefix) \ else '%s_%s' % (self.p.output_prefix, movie_name) def __get_prefixed_movie_dir__(self): """ method returns prefixed movie_dir by source name and output_prefix """ movie_dir = self.p.movie_dir prefix = self.p.output_prefix + '_' \ if not is_empty(self.p.output_prefix) else '' return as_path(movie_dir, prefix + 'm_' + self.source) \ if self.p.movie_prefixed_by_source else movie_dir
def __init__(self, data_vector, movie_parameters, **params): self.p = movie_parameters if not self.p.movie_name == None: self.params = Params(**params) mpl.rcParams['patch.edgecolor'] = 'none' mpl.rcParams['savefig.edgecolor'] = 'none' self.source = get_filename(self.params.reference_filename) self.__prefixed_movie_name__ = self.__get_prefixed_movie_name__() self.__prefixed_movie_dir__ = self.__get_prefixed_movie_dir__() if not self.params.filter_manager == None: data_vector = self.params.filter_manager.run_filters( data_vector) _max = pl.amax(data_vector.signal) _min = pl.amin(data_vector.signal) self.time = data_vector.time margin = 50 self.signal_size = len(data_vector.signal) self.range = [_min - margin, _max + margin, _min - margin, _max + margin] self.x_data = pl.zeros(self.signal_size) self.y_data = pl.zeros(self.signal_size) self.old_signal_plus = None self.idx = 0 self.active_color = get_extended_color_array( movie_parameters.movie_active_color) self.inactive_color = get_extended_color_array( movie_parameters.movie_inactive_color) self.centroid_color = get_extended_color_array( movie_parameters.movie_centroid_color) self.message = None self.core_nums = multiprocessing.cpu_count() * self.p.movie_multiprocessing_factor # @IgnorePep8 self.pp_spec_manager = MiniPoincarePlotSpecManager() self.pp_spec_manager.movie_dir = self.__prefixed_movie_dir__ self.pp_spec_manager.movie_name = self.__prefixed_movie_name__ self.pp_spec_manager.movie_dpi = self.p.movie_dpi self.pp_spec_manager.movie_fps = self.p.movie_fps self.pp_spec_manager.movie_height = self.p.movie_height self.pp_spec_manager.movie_width = self.p.movie_width self.pp_spec_manager.active_color = self.active_color self.pp_spec_manager.inactive_color = self.inactive_color self.pp_spec_manager.centroid_color = self.centroid_color self.pp_spec_manager.active_point_size = self.p.movie_active_size self.pp_spec_manager.inactive_point_size = \ self.p.movie_inactive_size self.pp_spec_manager.centroid_point_size = \ self.p.movie_centroid_size self.pp_spec_manager.show_plot_legends = \ self.p.movie_show_plot_legends self.pp_spec_manager.x_label = self.p.x_label self.pp_spec_manager.y_label = self.p.y_label self.pp_spec_manager.clean_frames = self.p.movie_clean_frames self.pp_spec_manager.movie_title = self.p.movie_title self.pp_spec_manager.movie_frame_step = self.p.movie_frame_step self.pp_spec_manager.movie_identity_line = self.p.movie_identity_line self.pp_spec_manager.movie_hour_label = self.p.movie_hour_label self.pp_spec_manager.movie_minute_label = self.p.movie_minute_label self.pp_spec_manager.movie_second_label = self.p.movie_second_label self.pp_spec_manager.movie_time_label_in_line = self.p.movie_time_label_in_line self.pp_spec_manager.movie_time_label_font_size = self.p.movie_time_label_font_size self.pp_spec_manager.movie_time_label_prefix = self.p.movie_time_label_prefix self.pp_spec_manager.movie_title_font_size = self.p.movie_title_font_size self.pp_spec_manager.movie_axis_font_size = self.p.movie_axis_font_size self.pp_spec_manager.movie_axis_font = self.p.movie_axis_font self.pp_spec_manager.movie_title_font = self.p.movie_title_font self.pp_spec_manager.movie_tick_font = self.p.movie_tick_font self.pp_spec_manager.movie_frame_pad = self.p.movie_frame_pad self.pp_spec_manager.movie_create_time_label = self.p.movie_create_time_label self.pp_spec_manager.movie_frame_filename_with_time = self.p.movie_frame_filename_with_time self.pp_specs_managers = [] self.pp_specs_managers.append(self.pp_spec_manager) self.sub_dir_counter = 0 self.scatter = None self.legend_text = None self.pp_specs = [] self.cum_inactive = 0 self._pp_spec_old = None self.s_size = 0 # current calculated signal size
def __init__(self, parent, **params): super(CommonWidget, self).__init__(parent) prepareWidget(parent=parent, widget=self, **params) self.params = Params(**params)
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)