Пример #1
0
    def applyConfig(self, configdict, **kwargs):
        """extending :meth:`TaurusBaseWidget.applyConfig` to restore the splitter config

        :param configdict: (dict)

        .. seealso:: :meth:`TaurusBaseWidget.applyConfig`, :meth:`createConfig`
        """
        # first do the basic stuff...
        TaurusWidget.applyConfig(self, configdict, **kwargs)
        # restore the splitter config
        self._splitter.restoreState(
            Qt.QByteArray(configdict['splitter/state']))
Пример #2
0
    def createQConfig(self):
        '''
        returns the current configuration status encoded as a QByteArray. This
        state can therefore be easily stored using QSettings

        :return: (QByteArray) (in the current implementation this is just a
                 pickled configdict encoded as a QByteArray

        .. seealso:: :meth:`restoreQConfig`
        '''
        from taurus.external.qt import Qt
        import pickle
        configdict = self.createConfig(allowUnpickable=False)
        return Qt.QByteArray(pickle.dumps(configdict))
Пример #3
0
    def saveSettings(self, group=None):
        '''Saves the current state to the temporary file

        :param group: (str) a prefix that will be added to the keys to be
                       saved (no prefix by default)
        '''
        if group is not None:
            self._settings.beginGroup(group)

        # store the config dict
        self._settings.setValue("TaurusConfig", Qt.QVariant(
            Qt.QByteArray(pickle.dumps(self._configurationDictionaries[group]))))
        if group is not None:
            self._settings.endGroup()
Пример #4
0
    def loadSettings(self, settings=None, group=None, ignoreGeometry=False, factorySettingsFileName=None):
        '''restores the application settings previously saved with :meth:`saveSettings`.

        .. note:: This method should be called explicitly from derived classes after all
                  initialization is done

        :param settings: (QSettings or None) a QSettings object. If None given,
                         the default one returned by :meth:`getQSettings` will
                         be used
        :param group: (str) a prefix that will be added to the keys to be
                       loaded (no prefix by default)
        :param ignoreGeometry: (bool) if True, the geometry of the MainWindow
                               won't be restored
        :param factorySettingsFileName: (str) file name of a ini file containing the default
                                        settings to be used as a fallback in
                                        case the settings file is not found
                                        (e.g., the first time the application is
                                        launched after installation)
        '''
        if settings is None:
            settings = self.getQSettings()
            if len(settings.allKeys()) == 0:
                fname = factorySettingsFileName or self.getFactorySettingsFileName()
                if os.path.exists(fname):
                    self.info('Importing factory settings from "%s"' % fname)
                    self.importSettingsFile(fname)
                return

        if group is not None:
            settings.beginGroup(group)
        if not ignoreGeometry:
            ba = settings.value("MainWindow/Geometry") or Qt.QByteArray()
            self.restoreGeometry(ba)
        # restore the Taurus config
        try:
            ba = settings.value("TaurusConfig") or Qt.QByteArray()
            self.applyQConfig(ba)
        except Exception as e:
            msg = ('Problem loading configuration from "{}". '
                   + 'Some settings may not be restored.\n'
                   + ' Reason: {}'
                   ).format(str(settings.fileName()), e)
            self.error(msg)
            Qt.QMessageBox.warning(
                self, 'Error Loading settings', msg, Qt.QMessageBox.Ok)
        ba = settings.value("MainWindow/State") or Qt.QByteArray()
        self.restoreState(ba)
        # hide all dockwidgets (so that they are shown only if they were
        # present in the settings)
        dockwidgets = [c for c in self.children(
        ) if isinstance(c, Qt.QDockWidget)]
        for d in dockwidgets:
            r = self.restoreDockWidget(d)
            d.hide()
        ba = settings.value("MainWindow/State") or Qt.QByteArray()
        self.restoreState(ba)

        if group is not None:
            settings.endGroup()
        self.updatePerspectivesMenu()
        self.info('MainWindow settings restored')