Exemple #1
0
 def deleteSettings(self, groupName=None):
     """ Deletes registry items from the persistent store.
     """
     groupName = groupName if groupName else self.settingsGroupName
     settings = QtCore.QSettings()
     logger.info("Deleting {} from: {}".format(groupName, settings.fileName()))
     removeSettingsGroup(groupName)
Exemple #2
0
    def cloneWindow(self):
        """ Opens a new window with the same inspector as the current window.
        """
        # Save current window settings.
        settings = QtCore.QSettings()
        settings.beginGroup(
            self.argosApplication.windowGroupName(self.windowNumber))
        try:
            self.saveProfile(settings)

            # Create new window with the freshly baked settings of the current window.
            name = self.inspectorRegItem.fullName
            newWindow = self.argosApplication.addNewMainWindow(
                settings=settings, inspectorFullName=name)
        finally:
            settings.endGroup()

        # Select the current item in the new window.
        currentItem, _currentIndex = self.repoWidget.repoTreeView.getCurrentItem(
        )
        if currentItem:
            newWindow.trySelectRtiByPath(currentItem.nodePath)

        # Move the new window 24 pixels to the bottom right and raise it to the front.
        newGeomRect = newWindow.geometry()
        logger.debug("newGeomRect: x={}".format(newGeomRect.x()))
        newGeomRect.moveTo(newGeomRect.x() + 24, newGeomRect.y() + 24)

        newWindow.setGeometry(newGeomRect)
        logger.debug("newGeomRect: x={}".format(newGeomRect.x()))

        newWindow.raise_()
Exemple #3
0
    def readViewSettings(self, settings=None):  # TODO: rename to readProfile?
        """ Reads the persistent program settings

            :param settings: optional QSettings object which can have a group already opened.
            :returns: True if the header state was restored, otherwise returns False
        """
        if settings is None:
            settings = QtCore.QSettings()
        logger.debug("Reading settings from: {}".format(settings.group()))

        self.restoreGeometry(settings.value("geometry"))
        self.restoreState(settings.value("state"))

        self.repoWidget.repoTreeView.readViewSettings('repo_tree/header_state',
                                                      settings)
        self.configWidget.configTreeView.readViewSettings(
            'config_tree/header_state', settings)

        #self._configTreeModel.readModelSettings('config_model', settings)
        settings.beginGroup('cfg_inspectors')
        try:
            for key in settings.childKeys():
                json = settings.value(key)
                self._inspectorsNonDefaults[key] = ctiLoads(json)
        finally:
            settings.endGroup()

        identifier = settings.value("inspector", None)
        try:
            if identifier:
                self.setInspectorById(identifier)
        except KeyError as ex:
            logger.warn("No inspector with ID {!r}.: {}".format(
                identifier, ex))
Exemple #4
0
    def saveProfile(self, settings=None):
        """ Writes the view settings to the persistent store
        """
        self._updateNonDefaultsForInspector(self.inspectorRegItem,
                                            self.inspector)

        if settings is None:
            settings = QtCore.QSettings()
        logger.debug("Writing settings to: {}".format(settings.group()))

        settings.beginGroup('cfg_inspectors')
        try:
            for key, nonDefaults in self._inspectorsNonDefaults.items():
                if nonDefaults:
                    settings.setValue(key, ctiDumps(nonDefaults))
                    logger.debug("Writing non defaults for {}: {}".format(
                        key, nonDefaults))
        finally:
            settings.endGroup()

        self.configWidget.configTreeView.saveProfile(
            "config_tree/header_state", settings)
        self.repoWidget.repoTreeView.saveProfile("repo_tree/header_state",
                                                 settings)

        settings.setValue("geometry", self.saveGeometry())
        settings.setValue("state", self.saveState())

        identifier = self.inspectorRegItem.identifier if self.inspectorRegItem else ''
        settings.setValue("inspector", identifier)
Exemple #5
0
    def setUp(self):
        self.app = getQApplicationInstance()

        self.groupName = '__test__'
        self.qs = QtCore.QSettings()
        self.qs.remove(self.groupName) # start with clean slate
        self.qs.beginGroup(self.groupName)
Exemple #6
0
 def deleteProfile(self, profile):
     """ Removes a profile from the persistent settings
     """
     profGroupName = self.profileGroupName(profile)
     logger.debug("Resetting profile settings: {}".format(profGroupName))
     settings = QtCore.QSettings()
     settings.remove(profGroupName)
Exemple #7
0
 def saveProfile(self, key, settings=None):
     """ Writes the view settings to the persistent store
         :param key: key where the setting will be read from
         :param settings: optional QSettings object which can have a group already opened.
     """
     #logger.debug("Writing view settings for: {}".format(key))
     if settings is None:
         settings = QtCore.QSettings()
     settings.setValue(key, self.horizontalHeader().saveState())
Exemple #8
0
    def __obsolete__saveProfile(self, key, settings=None):
        """ Writes the view settings to the persistent store
            :param key: key where the setting will be read from
            :param settings: optional QSettings object which can have a group already opened.
        """
        logger.debug("Writing model settings for: {}".format(key))
        if settings is None:
            settings = QtCore.QSettings()

        values = self.invisibleRootItem.getNonDefaultsDict()
        values_json = ctiDumps(values)
        settings.setValue(key, values_json)
Exemple #9
0
    def saveSettings(self, groupName=None):
        """ Writes the registry items into the persistent settings store.
        """
        groupName = groupName if groupName else self.settingsGroupName
        settings = QtCore.QSettings()
        logger.info("Saving {} to: {}".format(groupName, settings.fileName()))

        settings.remove(groupName) # start with a clean slate
        settings.beginGroup(groupName)
        try:
            for itemNr, item in enumerate(self.items):
                key = "item-{:03d}".format(itemNr)
                value = repr(item.asDict())
                settings.setValue(key, value)
        finally:
            settings.endGroup()
Exemple #10
0
    def loadSettings(self, groupName=None):
        """ Reads the registry items from the persistent settings store.
        """
        groupName = groupName if groupName else self.settingsGroupName
        settings = QtCore.QSettings()
        logger.info("Reading {!r} from: {}".format(groupName, settings.fileName()))

        settings.beginGroup(groupName)
        self.clear()
        try:
            for key in settings.childKeys():
                if key.startswith('item'):
                    dct = ast.literal_eval(settings.value(key))
                    regItem = self._itemClass.createFromDict(dct)
                    self.registerItem(regItem)
        finally:
            settings.endGroup()
Exemple #11
0
    def loadOrInitSettings(self, groupName=None):
        """ Reads the registry items from the persistent settings store, falls back on the
            default plugins if there are no settings in the store for this registry.
        """
        groupName = groupName if groupName else self.settingsGroupName
        settings = QtCore.QSettings()

        #for key in sorted(settings.allKeys()):
        #    print(key)

        if containsSettingsGroup(groupName, settings):
            self.loadSettings(groupName)
        else:
            logger.info("Group {!r} not found, falling back on default settings".format(groupName))
            for item in self.getDefaultItems():
                self.registerItem(item)
            self.saveSettings(groupName)
            assert containsSettingsGroup(groupName, settings), \
                "Sanity check failed. {} not found".format(groupName)
Exemple #12
0
    def readViewSettings(self, key, settings=None):
        """ Reads the persistent program settings

            :param key: key where the setting will be read from
            :param settings: optional QSettings object which can have a group already opened.
            :returns: True if the header state was restored, otherwise returns False
        """
        #logger.debug("Reading view settings for: {}".format(key))
        if settings is None:
            settings = QtCore.QSettings()

        horizontal_header = self.horizontalHeader()
        header_restored = horizontal_header.restoreState(settings.value(key))

        # update actions
        for col, action in enumerate(horizontal_header.actions()):
            is_checked = not horizontal_header.isSectionHidden(col)
            action.setChecked(is_checked)

        return header_restored
Exemple #13
0
    def saveProfile(self):
        """ Writes the current profile settings to the persistent store
        """
        if not self.profile:
            logger.warning("No profile defined (no settings saved)")
            return

        settings = QtCore.QSettings()
        logger.debug("Writing settings to: {}".format(settings.fileName()))

        profGroupName = self.profileGroupName()
        settings.remove(profGroupName) # start with a clean slate

        assert self.mainWindows, "no main windows found"
        for winNr, mainWindow in enumerate(self.mainWindows):
            settings.beginGroup(self.windowGroupName(winNr))
            try:
                mainWindow.saveProfile(settings)
            finally:
                settings.endGroup()
Exemple #14
0
    def loadProfile(self, profile, inspectorFullName=None):
        """ Reads the persistent program settings for the current profile.

            If inspectorFullName is given, a window with this inspector will be created if it wasn't
            already created in the profile. All windows with this inspector will be raised.
        """
        settings = QtCore.QSettings()
        logger.info("Reading profile {!r} from: {}".format(profile, settings.fileName()))

        self._profile = profile
        profGroupName = self.profileGroupName(profile)

        # Instantiate windows from groups
        settings.beginGroup(profGroupName)
        try:
            for windowGroupName in settings.childGroups():
                if windowGroupName.startswith('window'):
                    settings.beginGroup(windowGroupName)
                    try:
                        self.addNewMainWindow(settings=settings)
                    finally:
                        settings.endGroup()
        finally:
            settings.endGroup()

        if inspectorFullName is not None:
            windows = [win for win in self._mainWindows
                       if win.inspectorFullName == inspectorFullName]
            if len(windows) == 0:
                logger.info("Creating window for inspector: {!r}".format(inspectorFullName))
                try:
                    win = self.addNewMainWindow(inspectorFullName=inspectorFullName)
                except KeyError:
                    logger.warn("No inspector found with ID: {}".format(inspectorFullName))
            else:
                for win in windows:
                    win.raise_()

        if len(self.mainWindows) == 0:
            logger.info("No open windows in profile (creating one).")
            self.addNewMainWindow(inspectorFullName=DEFAULT_INSPECTOR)
Exemple #15
0
    def __obsolete__readModelSettings(self, key, settings):
        """ Reads the persistent program settings.

            Will reset the model and thus collapse all nodes.

            :param key: key where the setting will be read from
            :param settings: optional QSettings object which can have a group already opened.
            :returns: True if the header state was restored, otherwise returns False
        """
        if settings is None:
            settings = QtCore.QSettings()

        valuesJson = settings.value(key, None)

        if valuesJson:
            values = ctiLoads(valuesJson)
            self.beginResetModel()
            self.invisibleRootItem.setValuesFromDict(values)
            self.endResetModel()
        else:
            logger.warn("No settings found at: {}".format(key))
Exemple #16
0
 def deleteAllProfiles(self):
     """ Returns a list of all profiles
     """
     settings = QtCore.QSettings()
     for profGroupName in QtCore.QSettings().childGroups():
         settings.remove(profGroupName)