Example #1
0
    def _init(self):
        self._uiFile = "pluginsConfigDialog.ui"
        self._tabs = OrderedDict()
        self._fields = {}

        # Add a general tab
        self._addTab('Main', TAB_MAIN)
    def _init(self):
        self._uiFile = "pluginsConfigDialog.ui"
        self._tabs = OrderedDict()
        self._fields = {}

        # Add a general tab
        self._addTab('Main', TAB_MAIN)
Example #3
0
    def _addTab(self, tabName, tabLabel):
        """ Add a new tab to the tab widget.

        @param tabName: name of the new tab
        @type tabName: str

        @param tabLabel: label to use for the tab (for translations)
        @type tabLabel: str
        """
        self._tabs[tabName] = tabLabel
        self._fields[tabName] = OrderedDict()
Example #4
0
class AbstractPluginController(AbstractModalDialogController):
    """ Plugin controller.

    Used for the configuration dialog of the plugin.
    The dialog is mainly a tab widget where all options
    of the plugin are listed, as name/widget list.
    """
    def _init(self):
        self._uiFile = "pluginsConfigDialog.ui"
        self._tabs = OrderedDict()
        self._fields = {}

        # Add a general tab
        self._addTab('Main', TAB_MAIN)

    def _addTab(self, tabName, tabLabel):
        """ Add a new tab to the tab widget.

        @param tabName: name of the new tab
        @type tabName: str

        @param tabLabel: label to use for the tab (for translations)
        @type tabLabel: str
        """
        self._tabs[tabName] = tabLabel
        self._fields[tabName] = OrderedDict()

    def _addWidget(self, tabName, label, widgetClass, widgetParams, configKey):
        """ Add a new widget.

        @param tabName: name of the tab where to add the widget
        @type tabName: str

        @param label: associated label of the option
        @type label: str

        @param widgetClass: widget class to use for the option
        @type widgetClass: QtGui.QWidget

        @param widgetParams: params to give to the widget
        @type widgetParams: tuple

        @param configKey: key for the config.
        @type configKey: str
        """
        widget = widgetClass(*widgetParams)
        self._fields[tabName][label] = {
            'widget': widget,
            'configKey': configKey
        }
        self._fields[tabName][label]['widget'].setValue(
            self._model._config[configKey])  # Hugly!
        widget.connectSlot(self._valueChanged)

    def _initWidgets(self):
        self._view.setWindowTitle("%s %s" %
                                  (self._model.name, self._model.capacity))

        # Create the Gui fields
        self._defineGui()

        # Populate GUI with fields
        widgets = {}
        for tabName, tabLabel in self._tabs.iteritems():
            if tabName == 'Main':
                widget = self._view.mainTab
                formLayout = self._view.formLayout
            else:
                widget = QtGui.QWidget(self._view)
                formLayout = QtGui.QFormLayout(widget)
                widget.setLayout(formLayout)
                self._view.tabWidget.addTab(widget, tabLabel)
                Logger().debug(
                    "AbstractPluginController._initWidgets(): created '%s' tab"
                    % tabName)
            for label, field in self._fields[tabName].iteritems():
                widgets[label] = field['widget']
                field['widget'].setParent(widget)
                labelWidget = QtGui.QLabel(label)
                labelWidget.setSizePolicy(QtGui.QSizePolicy.Preferred,
                                          QtGui.QSizePolicy.MinimumExpanding)
                formLayout.addRow(labelWidget, field['widget'])
                Logger().debug(
                    "AbstractPluginController._initWidgets(): added '%s' field"
                    % label)

        self._view.adjustSize()

    def _getWidget(self, tabName, label):
        """ Get the specified widget.

        @param tabName: tab name
        @type tabName: str

        @param label: label name
        @type label: str
        """
        return self._fields[tabName][label]['widget']

    def _setTabEnabled(self, tabName, enable):
        """ Enable/disable specified tab.

        @param tabName: tab name
        @type tabName: str

        @param enable: flag to enabled/disable tab
        Label@type enable: bool
        """
        for index, tabName_ in enumerate(self._tabs.iterkeys()):
            if tabName_ == tabName:
                self._view.tabWidget.setTabEnabled(index, enable)
                break
        else:
            raise ValueError("Unknown %s tab" % repr(tabName))

    def _onAccepted(self):
        """ Ok button has been clicked.
        """
        Logger().trace("AbstractPluginController._onAccepted()")
        for tabName in self._tabs.keys():
            for label, field in self._fields[tabName].iteritems():
                value = field['widget'].value()
                if isinstance(value, QtCore.QString):
                    value = unicode(value)
                self._model._config[field['configKey']] = value
        Logger().debug("AbstractPluginController._onAccepted(): config=%s" %
                       self._model._config)
        self._model._saveConfig()
        if self._model.isConnected():
            self._model.configure()

    def _defineGui(self):
        """ Define the GUI.

        The widgets for the plugin config. dialog are defined here.
        """
        raise NotImplementedError(
            "AbstractPluginController._defineGui() must be overloaded")

    def _valueChanged(self, value=None):
        """ A widget value has changed.

        #@param widget: widget which changed
        #@type widget: QtGui.QWidget

        @param value: new value
        @type value: any type

        @todo: retreive widget
        """
        #Logger().debug("AbstractPluginController._valueChanged(): value=%s" % repr(value))
        pass

    # Interface
    def refreshView(self):
        pass
Example #5
0
 def __init__(self):
     """ Init the Presets object.
     """
     super(Presets, self).__init__()
     self.__presets = OrderedDict()
Example #6
0
class Presets(object):
    """ Presets object.

    Contain a set of Preset.
    """
    def __init__(self):
        """ Init the Presets object.
        """
        super(Presets, self).__init__()
        self.__presets = OrderedDict()

    def add(self, preset):
        """ Add a preset.

        @param preset: the preset to add
        @type preset {Preset}
        """
        if self.__presets.has_key(preset.getName()):
            Logger().warning("Presets.add(): Preset '%s' alreay in presets table. Overwriting..." % preset.getName())
        self.__presets[preset.getName()] = preset

    def nameToIndex(self, name):
        """ Get the index of the preset.

        Mainly use by the GUI for combobox.

        @param name: name of the preset to get the index
        @type name: str
        """
        for iIndex, (iName, iPreset) in enumerate(self.__presets.iteritems()):
            if name == iName:
                return iIndex
        raise ValueError("Preset '%s' not found" % name)

    def getByIndex(self, index):
        """ Get the index.

        Mainly use by the GUI for combobox.

        @param index: index of the preset to get the name
        @type index: int
        """
        for iIndex, (iName, iPreset) in enumerate(self.__presets.iteritems()):
            if index == iIndex:
                return iPreset
        raise ValueError("No Preset at index '%d'" % index)

    def getByName(self, name):
        """ Return the preset from its given name.

        @param name: name of the preset
        @type name: str

        @return: preset
        @rtype: {Preset}
        """
        for iName, iPreset in self.__presets.iteritems():
            if name == iName:
                return iPreset
        raise ValueError("Preset '%s' not found" % name)

    def getAll(self):
        """ Get all presets.
        """
        return copy.deepcopy(self.__presets)
Example #7
0
 def __init__(self):
     """ Init the Presets object.
     """
     super(Presets, self).__init__()
     self.__presets = OrderedDict()
Example #8
0
class Presets(object):
    """ Presets object.

    Contain a set of Preset.
    """
    def __init__(self):
        """ Init the Presets object.
        """
        super(Presets, self).__init__()
        self.__presets = OrderedDict()

    def add(self, preset):
        """ Add a preset.

        @param preset: the preset to add
        @type preset {Preset}
        """
        if self.__presets.has_key(preset.getName()):
            Logger().warning(
                "Presets.add(): Preset '%s' alreay in presets table. Overwriting..."
                % preset.getName())
        self.__presets[preset.getName()] = preset

    def nameToIndex(self, name):
        """ Get the index of the preset.

        Mainly use by the GUI for combobox.

        @param name: name of the preset to get the index
        @type name: str
        """
        for iIndex, (iName, iPreset) in enumerate(self.__presets.iteritems()):
            if name == iName:
                return iIndex
        raise ValueError("Preset '%s' not found" % name)

    def getByIndex(self, index):
        """ Get the index.

        Mainly use by the GUI for combobox.

        @param index: index of the preset to get the name
        @type index: int
        """
        for iIndex, (iName, iPreset) in enumerate(self.__presets.iteritems()):
            if index == iIndex:
                return iPreset
        raise ValueError("No Preset at index '%d'" % index)

    def getByName(self, name):
        """ Return the preset from its given name.

        @param name: name of the preset
        @type name: str

        @return: preset
        @rtype: {Preset}
        """
        for iName, iPreset in self.__presets.iteritems():
            if name == iName:
                return iPreset
        raise ValueError("Preset '%s' not found" % name)

    def getAll(self):
        """ Get all presets.
        """
        return copy.deepcopy(self.__presets)
class AbstractPluginController(AbstractModalDialogController):
    """ Plugin controller.

    Used for the configuration dialog of the plugin.
    The dialog is mainly a tab widget where all options
    of the plugin are listed, as name/widget list.
    """
    def _init(self):
        self._uiFile = "pluginsConfigDialog.ui"
        self._tabs = OrderedDict()
        self._fields = {}

        # Add a general tab
        self._addTab('Main', TAB_MAIN)

    def _addTab(self, tabName, tabLabel):
        """ Add a new tab to the tab widget.

        @param tabName: name of the new tab
        @type tabName: str

        @param tabLabel: label to use for the tab (for translations)
        @type tabLabel: str
        """
        self._tabs[tabName] = tabLabel
        self._fields[tabName] = OrderedDict()

    def _addWidget(self, tabName, label, widgetClass, widgetParams, configKey):
        """ Add a new widget.

        @param tabName: name of the tab where to add the widget
        @type tabName: str

        @param label: associated label of the option
        @type label: str

        @param widgetClass: widget class to use for the option
        @type widgetClass: QtGui.QWidget

        @param widgetParams: params to give to the widget
        @type widgetParams: tuple

        @param configKey: key for the config.
        @type configKey: str
        """
        widget = widgetClass(*widgetParams)
        self._fields[tabName][label] = {'widget': widget, 'configKey': configKey}
        self._fields[tabName][label]['widget'].setValue(self._model._config[configKey])  # Hugly!
        widget.connectSlot(self._valueChanged)

    def _initWidgets(self):
        self._view.setWindowTitle("%s %s" % (self._model.name, self._model.capacity))

        # Create the Gui fields
        self._defineGui()

        # Populate GUI with fields
        widgets = {}
        for tabName, tabLabel in self._tabs.iteritems():
            if tabName == 'Main':
                widget = self._view.mainTab
                formLayout = self._view.formLayout
            else:
                widget = QtGui.QWidget(self._view)
                formLayout = QtGui.QFormLayout(widget)
                widget.setLayout(formLayout)
                self._view.tabWidget.addTab(widget, tabLabel)
                Logger().debug("AbstractPluginController._initWidgets(): created '%s' tab" % tabName)
            for label, field in self._fields[tabName].iteritems():
                widgets[label] = field['widget']
                field['widget'].setParent(widget)
                labelWidget = QtGui.QLabel(label)
                labelWidget.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.MinimumExpanding)
                formLayout.addRow(labelWidget, field['widget'])
                Logger().debug("AbstractPluginController._initWidgets(): added '%s' field" % label)

        self._view.adjustSize()

    def _getWidget(self, tabName, label):
        """ Get the specified widget.

        @param tabName: tab name
        @type tabName: str

        @param label: label name
        @type label: str
        """
        return self._fields[tabName][label]['widget']

    def _setTabEnabled(self, tabName, enable):
        """ Enable/disable specified tab.

        @param tabName: tab name
        @type tabName: str

        @param enable: flag to enabled/disable tab
        Label@type enable: bool
        """
        for index, tabName_ in enumerate(self._tabs.iterkeys()):
            if tabName_ == tabName:
                self._view.tabWidget.setTabEnabled(index, enable)
                break
        else:
            raise ValueError("Unknown %s tab" % repr(tabName))

    def _onAccepted(self):
        """ Ok button has been clicked.
        """
        Logger().trace("AbstractPluginController._onAccepted()")
        for tabName in self._tabs.keys():
            for label, field in self._fields[tabName].iteritems():
                value = field['widget'].value()
                if isinstance(value, QtCore.QString):
                    value = unicode(value)
                self._model._config[field['configKey']] = value
        Logger().debug("AbstractPluginController._onAccepted(): config=%s" % self._model._config)
        self._model._saveConfig()
        if self._model.isConnected():
            self._model.configure()

    def _defineGui(self):
        """ Define the GUI.

        The widgets for the plugin config. dialog are defined here.
        """
        raise NotImplementedError("AbstractPluginController._defineGui() must be overloaded")

    def _valueChanged(self, value=None):
        """ A widget value has changed.

        #@param widget: widget which changed
        #@type widget: QtGui.QWidget

        @param value: new value
        @type value: any type

        @todo: retreive widget
        """
        #Logger().debug("AbstractPluginController._valueChanged(): value=%s" % repr(value))
        pass

    # Interface
    def refreshView(self):
        pass