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__)
Exemplo n.º 2
0
class ActivityDockWidget(DockWidgetWidget):
    """
    a dock widget for activities
    """
    def __init__(self, parent, **params):
        super(ActivityDockWidget, self).__init__(parent,
                                    title=params.get('title', 'Activities'),
                                    **params)
        self.setObjectName("ActivityDockWidget")
        self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea |
                             Qt.TopDockWidgetArea | Qt.BottomDockWidgetArea)
        layout = QVBoxLayout()
        layout.setMargin(0)  # no margin for internal layout
        self.dockComposite = CompositeWidget(self, layout=layout,
                                        not_add_widget_to_parent_layout=True)
        self.listWidget = ListWidgetWidget(self.dockComposite,
                list_item_double_clicked_handler=self.__list_item_handler__,
                selectionMode=QAbstractItemView.MultiSelection,
                sizePolicy=QSizePolicy(QSizePolicy.Expanding,
                                       QSizePolicy.Expanding))
        for activity in ActivityManager.getActivities(PLUGIN_ACTIVITY_TYPE):
            if activity:
                ListWidgetItemWidget(self.listWidget,
                                 text=activity.label,
                                 data=activity)

        self.clearAll = PushButtonWidget(self.dockComposite,
                            i18n="clear.all.activity.button",
                            i18n_def="Clear all activities",
                            clicked_handler=self.__clear_list__)

        self.setWidget(self.dockComposite)
        parent.addDockWidget(Qt.RightDockWidgetArea, self)

        SignalDispatcher.addSignalSubscriber(self,
                                             ADD_ACTIVITY_SIGNAL,
                                             self.__add_activity__)
        SignalDispatcher.addSignalSubscriber(self,
                                             CLEAR_ACTIVITIES_SIGNAL,
                                             self.__clear_list__)

    def __list_item_handler__(self, listItem):
        data = listItem.data(Qt.UserRole)
        if data:
            activity = data.toPyObject()
            if activity:
                activity()

    def __add_activity__(self, activity):
        if activity:
            ListWidgetItemWidget(self.listWidget,
                                 text=activity.label,
                                 data=activity)

    def __clear_list__(self):
        ActivityManager.clearActivities()
        self.listWidget.clear()
Exemplo n.º 3
0
class ActivityDockWidget(DockWidgetWidget):
    """
    a dock widget for activities
    """
    def __init__(self, parent, **params):
        super(ActivityDockWidget,
              self).__init__(parent,
                             title=params.get('title', 'Activities'),
                             **params)
        self.setObjectName("ActivityDockWidget")
        self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea
                             | Qt.TopDockWidgetArea | Qt.BottomDockWidgetArea)
        layout = QVBoxLayout()
        layout.setMargin(0)  # no margin for internal layout
        self.dockComposite = CompositeWidget(
            self, layout=layout, not_add_widget_to_parent_layout=True)
        self.listWidget = ListWidgetWidget(
            self.dockComposite,
            list_item_double_clicked_handler=self.__list_item_handler__,
            selectionMode=QAbstractItemView.MultiSelection,
            sizePolicy=QSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding))
        for activity in ActivityManager.getActivities(PLUGIN_ACTIVITY_TYPE):
            if activity:
                ListWidgetItemWidget(self.listWidget,
                                     text=activity.label,
                                     data=activity)

        self.clearAll = PushButtonWidget(self.dockComposite,
                                         i18n="clear.all.activity.button",
                                         i18n_def="Clear all activities",
                                         clicked_handler=self.__clear_list__)

        self.setWidget(self.dockComposite)
        parent.addDockWidget(Qt.RightDockWidgetArea, self)

        SignalDispatcher.addSignalSubscriber(self, ADD_ACTIVITY_SIGNAL,
                                             self.__add_activity__)
        SignalDispatcher.addSignalSubscriber(self, CLEAR_ACTIVITIES_SIGNAL,
                                             self.__clear_list__)

    def __list_item_handler__(self, listItem):
        data = listItem.data(Qt.UserRole)
        if data:
            activity = data.toPyObject()
            if activity:
                activity()

    def __add_activity__(self, activity):
        if activity:
            ListWidgetItemWidget(self.listWidget,
                                 text=activity.label,
                                 data=activity)

    def __clear_list__(self):
        ActivityManager.clearActivities()
        self.listWidget.clear()
    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 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 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)