Ejemplo n.º 1
0
    def __init__(self, parent):
        super(PlotCustomizer, self).__init__()

        self._plot_config_key = None
        self._previous_key = None
        self._plot_configs = {None: PlotConfigHistory("No_Key_Selected", PlotConfig(None))}

        self._plotConfigCreator = self._defaultPlotConfigCreator

        self._customization_dialog = CustomizePlotDialog("Customize", parent)

        self._customization_dialog.addTab("general", "General", DefaultCustomizationView())
        self._customization_dialog.addTab("style", "Style", StyleCustomizationView())
        self._customization_dialog.addTab("statistics", "Statistics", StatisticsCustomizationView())

        self._customize_limits = LimitsCustomizationView()
        self._customization_dialog.addTab("limits", "Limits", self._customize_limits)

        self._customization_dialog.applySettings.connect(self.applyCustomization)
        self._customization_dialog.undoSettings.connect(self.undoCustomization)
        self._customization_dialog.redoSettings.connect(self.redoCustomization)
        self._customization_dialog.resetSettings.connect(self.resetCustomization)
        self._customization_dialog.copySettings.connect(self.copyCustomization)

        self._revertCustomization(self.getPlotConfig())
Ejemplo n.º 2
0
    def __init__(self, parent, default_plot_settings):
        super(PlotCustomizer, self).__init__()

        self._plot_config_key = None
        self._previous_key = None
        self.default_plot_settings = default_plot_settings
        self._plot_configs = {None: PlotConfigHistory("No_Key_Selected", PlotConfig(default_plot_settings, title=None))}

        self._plotConfigCreator = self._defaultPlotConfigCreator

        self._customization_dialog = CustomizePlotDialog("Customize", parent, key=self._plot_config_key)

        self._customization_dialog.addTab("general", "General", DefaultCustomizationView())
        self._customization_dialog.addTab("style", "Style", StyleCustomizationView())
        self._customization_dialog.addTab("statistics", "Statistics", StatisticsCustomizationView())

        self._customize_limits = LimitsCustomizationView()
        self._customization_dialog.addTab("limits", "Limits", self._customize_limits)

        self._customization_dialog.applySettings.connect(self.applyCustomization)
        self._customization_dialog.undoSettings.connect(self.undoCustomization)
        self._customization_dialog.redoSettings.connect(self.redoCustomization)
        self._customization_dialog.resetSettings.connect(self.resetCustomization)
        self._customization_dialog.copySettings.connect(self.copyCustomization)
        self._customization_dialog.copySettingsToOthers.connect(self.copyCustomizationTo)
        self._revertCustomization(self.getPlotConfig())
Ejemplo n.º 3
0
class PlotCustomizer(QObject):

    settingsChanged = pyqtSignal()

    def __init__(self, parent, default_plot_settings):
        super(PlotCustomizer, self).__init__()

        self._plot_config_key = None
        self._previous_key = None
        self.default_plot_settings = default_plot_settings
        self._plot_configs = {None: PlotConfigHistory("No_Key_Selected", PlotConfig(default_plot_settings, title=None))}

        self._plotConfigCreator = self._defaultPlotConfigCreator

        self._customization_dialog = CustomizePlotDialog("Customize", parent, key=self._plot_config_key)

        self._customization_dialog.addTab("general", "General", DefaultCustomizationView())
        self._customization_dialog.addTab("style", "Style", StyleCustomizationView())
        self._customization_dialog.addTab("statistics", "Statistics", StatisticsCustomizationView())

        self._customize_limits = LimitsCustomizationView()
        self._customization_dialog.addTab("limits", "Limits", self._customize_limits)

        self._customization_dialog.applySettings.connect(self.applyCustomization)
        self._customization_dialog.undoSettings.connect(self.undoCustomization)
        self._customization_dialog.redoSettings.connect(self.redoCustomization)
        self._customization_dialog.resetSettings.connect(self.resetCustomization)
        self._customization_dialog.copySettings.connect(self.copyCustomization)
        self._customization_dialog.copySettingsToOthers.connect(self.copyCustomizationTo)
        self._revertCustomization(self.getPlotConfig())


    def _getPlotConfigHistory(self):
        """ @rtype: PlotConfigHistory """
        return self._plot_configs[self._plot_config_key]

    def undoCustomization(self):
        history = self._getPlotConfigHistory()
        history.undoChanges()
        self._revertCustomization(history.getPlotConfig())

    def redoCustomization(self):
        history = self._getPlotConfigHistory()
        history.redoChanges()
        self._revertCustomization(history.getPlotConfig())

    def resetCustomization(self):
        history = self._getPlotConfigHistory()
        history.resetChanges()
        self._revertCustomization(history.getPlotConfig())


    def applyCustomization(self):
        history = self._getPlotConfigHistory()
        plot_config = history.getPlotConfig()
        if self._customization_dialog is not None:
            for customization_view in self._customization_dialog:
                customization_view.applyCustomization(plot_config)

        history.applyChanges(plot_config)

        self._emitChangedSignal()


    def _revertCustomization(self, plot_config, emit=True):
        if self._customization_dialog is not None:
            for customization_view in self._customization_dialog:
                customization_view.revertCustomization(plot_config)

        self._emitChangedSignal(emit)

    def _emitChangedSignal(self, emit=True):
        history = self._getPlotConfigHistory()
        self._customization_dialog.setUndoRedoCopyState(history.isUndoPossible(), history.isRedoPossible(), self.isCopyPossible())

        if emit:
            self.settingsChanged.emit()

    def isCopyPossible(self):
        """ @rtype: bool """
        return len(self._plot_configs) > 2

    def copyCustomizationTo(self, keys):
        """ copies the plotconfig of the current key, to a set of other keys"""
        history = self._getPlotConfigHistory()

        for key in keys:
            if key not in self._plot_configs:
                self._plot_configs[key] = PlotConfigHistory("No_Key_Selected",
                                                            PlotConfig(self.default_plot_settings, title=None))
            source_config = history.getPlotConfig()
            source_config.setTitle(key)

            self._plot_configs[key].applyChanges(source_config)

            self._customization_dialog.addCopyableKey(key)

        self._emitChangedSignal(emit=True)


    def copyCustomization(self, key):
        key = str(key)
        if self.isCopyPossible():
            source_config = self._plot_configs[key].getPlotConfig()
            source_config.setTitle(None)

            history = self._getPlotConfigHistory()
            history.applyChanges(source_config)

            self._revertCustomization(history.getPlotConfig())

    def toggleCustomizationDialog(self):
        if self._customization_dialog.isVisible():
            self._customization_dialog.hide()
        else:
            self._customization_dialog.show()

    def _defaultPlotConfigCreator(self, title):
        return PlotConfig(title)

    def _selectiveCopyOfCurrentPlotConfig(self, title):
        return self._plotConfigCreator(title)

    def switchPlotConfigHistory(self, key):
        if key != self._plot_config_key:
            if not key in self._plot_configs:
                self._plot_configs[key] = PlotConfigHistory(key, self._selectiveCopyOfCurrentPlotConfig(key))
                self._customization_dialog.addCopyableKey(key)
            self._customization_dialog.currentPlotKeyChanged(key)
            self._previous_key = self._plot_config_key
            self._plot_config_key = key
            self._revertCustomization(self.getPlotConfig(), emit=False)

    def getPlotConfig(self):
        """ @rtype: PlotConfig """
        return self._getPlotConfigHistory().getPlotConfig()

    def setAxisTypes(self, x_axis_type, y_axis_type):
        self._customize_limits.setAxisTypes(x_axis_type, y_axis_type)

    def setPlotConfigCreator(self, func):
        self._plotConfigCreator = func
Ejemplo n.º 4
0
class PlotCustomizer(QObject):

    settingsChanged = Signal()

    def __init__(self, parent, default_plot_settings=None):
        super(PlotCustomizer, self).__init__()

        self._plot_config_key = None
        self._previous_key = None
        self.default_plot_settings = default_plot_settings
        self._plot_configs = {
            None:
            PlotConfigHistory(
                "No_Key_Selected",
                PlotConfig(plot_settings=default_plot_settings, title=None))
        }

        self._plotConfigCreator = self._defaultPlotConfigCreator

        self._customization_dialog = CustomizePlotDialog(
            "Customize", parent, key=self._plot_config_key)

        self._customization_dialog.addTab("general", "General",
                                          DefaultCustomizationView())
        self._customization_dialog.addTab("style", "Style",
                                          StyleCustomizationView())
        self._customization_dialog.addTab("statistics", "Statistics",
                                          StatisticsCustomizationView())

        self._customize_limits = LimitsCustomizationView()
        self._customization_dialog.addTab("limits", "Limits",
                                          self._customize_limits)

        self._customization_dialog.applySettings.connect(
            self.applyCustomization)
        self._customization_dialog.undoSettings.connect(self.undoCustomization)
        self._customization_dialog.redoSettings.connect(self.redoCustomization)
        self._customization_dialog.resetSettings.connect(
            self.resetCustomization)
        self._customization_dialog.copySettings.connect(self.copyCustomization)
        self._customization_dialog.copySettingsToOthers.connect(
            self.copyCustomizationTo)
        self._revertCustomization(self.getPlotConfig())

    def _getPlotConfigHistory(self):
        """ @rtype: PlotConfigHistory """
        return self._plot_configs[self._plot_config_key]

    def undoCustomization(self):
        history = self._getPlotConfigHistory()
        history.undoChanges()
        self._revertCustomization(history.getPlotConfig())

    def redoCustomization(self):
        history = self._getPlotConfigHistory()
        history.redoChanges()
        self._revertCustomization(history.getPlotConfig())

    def resetCustomization(self):
        history = self._getPlotConfigHistory()
        history.resetChanges()
        self._revertCustomization(history.getPlotConfig())

    def applyCustomization(self):
        history = self._getPlotConfigHistory()
        plot_config = history.getPlotConfig()
        if self._customization_dialog is not None:
            for customization_view in self._customization_dialog:
                customization_view.applyCustomization(plot_config)

        history.applyChanges(plot_config)

        self._emitChangedSignal()

    def _revertCustomization(self, plot_config, emit=True):
        if self._customization_dialog is not None:
            for customization_view in self._customization_dialog:
                customization_view.revertCustomization(plot_config)

        self._emitChangedSignal(emit)

    def _emitChangedSignal(self, emit=True):
        history = self._getPlotConfigHistory()
        self._customization_dialog.setUndoRedoCopyState(
            history.isUndoPossible(), history.isRedoPossible(),
            self.isCopyPossible())

        if emit:
            self.settingsChanged.emit()

    def isCopyPossible(self):
        """ @rtype: bool """
        return len(self._plot_configs) > 2

    def copyCustomizationTo(self, keys):
        """ copies the plotconfig of the current key, to a set of other keys"""
        history = self._getPlotConfigHistory()

        for key in keys:
            if key not in self._plot_configs:
                self._plot_configs[key] = PlotConfigHistory(
                    "No_Key_Selected",
                    PlotConfig(self.default_plot_settings, title=None))
            source_config = history.getPlotConfig()
            source_config.setTitle(key)

            self._plot_configs[key].applyChanges(source_config)

            self._customization_dialog.addCopyableKey(key)

        self._emitChangedSignal(emit=True)

    def copyCustomization(self, key):
        key = str(key)
        if self.isCopyPossible():
            source_config = self._plot_configs[key].getPlotConfig()
            source_config.setTitle(None)

            history = self._getPlotConfigHistory()
            history.applyChanges(source_config)

            self._revertCustomization(history.getPlotConfig())

    def toggleCustomizationDialog(self):
        if self._customization_dialog.isVisible():
            self._customization_dialog.hide()
        else:
            self._customization_dialog.show()

    def _defaultPlotConfigCreator(self, title):
        return PlotConfig(title)

    def _selectiveCopyOfCurrentPlotConfig(self, title):
        return self._plotConfigCreator(title)

    def switchPlotConfigHistory(self, key):
        if key != self._plot_config_key:
            if not key in self._plot_configs:
                self._plot_configs[key] = PlotConfigHistory(
                    key, self._selectiveCopyOfCurrentPlotConfig(key))
                self._customization_dialog.addCopyableKey(key)
            self._customization_dialog.currentPlotKeyChanged(key)
            self._previous_key = self._plot_config_key
            self._plot_config_key = key
            self._revertCustomization(self.getPlotConfig(), emit=False)

    def getPlotConfig(self):
        """ @rtype: PlotConfig """
        return self._getPlotConfigHistory().getPlotConfig()

    def setAxisTypes(self, x_axis_type, y_axis_type):
        self._customize_limits.setAxisTypes(x_axis_type, y_axis_type)

    def setPlotConfigCreator(self, func):
        self._plotConfigCreator = func