示例#1
0
    def saveConfiguration(self, fileName=etcConfigName):

        if self.amLoading:
            return

        if not fileName:
            newfile, _filter = QFileDialog.getSaveFileName(
                self, "IMBL processing configuration",
                directory=self.ui.outPath.text())
            if newfile:
                fileName = newfile
        if not fileName:
            return

        config = QSettings(fileName, QSettings.IniFormat)

        def valToSave(wdg):
            if isinstance(wdg, QtWidgets.QLineEdit):
                return wdg.text()
            elif isinstance(wdg, QtWidgets.QCheckBox):
                return wdg.isChecked()
            elif isinstance(wdg, QtWidgets.QAbstractSpinBox):
                return wdg.value()
            elif isinstance(wdg, QtWidgets.QComboBox):
                return wdg.currentText()
        for swdg in self.configObjects:
            config.setValue(swdg.objectName(), valToSave(swdg))

        config.beginWriteArray('splits')
        for crow in range(0, self.ui.splits.rowCount()-1):
            config.setArrayIndex(crow)
            config.setValue('pos', self.ui.splits.cellWidget(crow, 0).value())
        config.endArray()
示例#2
0
    def add_path(self, path):
        "Adds path to recent documents"
        recent = self.read_paths()

        # Make the path absolute, resolving any symlinks.
        path = self._resolved_if_possible(Path(path))

        # Remove the existing occurrence of path, if present.
        # A linear scan is acceptable here because the list will always
        # be very short
        try:
            recent.remove(path)
        except ValueError:
            # path is not currently in recent
            pass

        # Prepend the path
        recent.insert(0, str(path))

        # Limit to MAX_RECENT_DOCS
        recent = recent[:self.MAX_RECENT_DOCS]

        debug_print('Writing {0} recent document paths'.format(len(recent)))

        settings = QSettings()
        settings.beginWriteArray(self.KEY, len(recent))
        try:
            for index, path in enumerate(recent):
                settings.setArrayIndex(index)
                settings.setValue('path', str(path))
        finally:
            settings.endArray()
示例#3
0
    def onUploadIMDBNewSelection(self, id, title, origin=""):
        log.debug(
            "onUploadIMDBNewSelection, id: %s, title: %s, origin: %s" % (id, title, origin))
        if origin == "nfo" and not self.upload_autodetected_imdb or self.upload_autodetected_imdb == "nfo":
            self.ui.label_autodetect_imdb.setText(
                _(u'↓ Movie autodetected from .nfo file'))
            self.ui.label_autodetect_imdb.show()
        elif origin == "database" and not self.upload_autodetected_imdb:
            self.ui.label_autodetect_imdb.setText(
                _(u'↓ Movie autodetected from database'))
            self.ui.label_autodetect_imdb.show()
        else:
            self.ui.label_autodetect_imdb.hide()

        # Let's select the item with that id.
        index = self.ui.uploadIMDB.findData(id)
        if index != -1:
            self.ui.uploadIMDB.setCurrentIndex(index)
        else:
            self.ui.uploadIMDB.addItem("%s : %s" % (id, title), id)
            index = self.ui.uploadIMDB.findData(id)
            self.ui.uploadIMDB.setCurrentIndex(index)

            # Adding the new IMDB in our settings historial
            settings = QSettings()
            size = settings.beginReadArray("upload/imdbHistory")
            settings.endArray()
            settings.beginWriteArray("upload/imdbHistory")
            settings.setArrayIndex(size)
            settings.setValue("imdbId", id)
            settings.setValue("title", title)
            settings.endArray()
示例#4
0
def saveinfos():
    """Saves the info's."""
    s = QSettings()
    s.beginWriteArray("lilypondinfo")
    for i, info in enumerate(infos()):
        s.setArrayIndex(i)
        info.write(s)
    s.endArray()
示例#5
0
 def get_rois_from_settings(self):
     settings = QSettings()
     rois = []
     size = settings.beginReadArray("regions_of_interest")
     for index in range(size):
         settings.setArrayIndex(index)
         rois.append(self.get_roi_from_settings(settings))
     settings.endArray()
     return rois
示例#6
0
 def write_rois_to_settings(self, rois):
     settings = QSettings()
     settings.remove("regions_of_interest")
     settings.beginWriteArray("regions_of_interest")
     for index, (name, start, end) in enumerate(rois):
         settings.setArrayIndex(index)
         settings.setValue("name", name)
         settings.setValue("start", start)
         settings.setValue("end", end)
     settings.endArray()
示例#7
0
def writeGlyphSets(glyphSets):
    settings = QSettings()
    settings.beginWriteArray("glyphSets", len(glyphSets))
    index = 0
    for name, cset in glyphSets.items():
        settings.setArrayIndex(index)
        settings.setValue("name", name)
        settings.setValue("glyphNames", cset)
        index += 1
    settings.endArray()
示例#8
0
    def writeSettings(self):

        settings = QSettings("University of Victoria", "VPT Annotator")

        settings.beginWriteArray("annotations")
        for i, name in enumerate(self._videoControl.getAnnotationNames()):
            settings.setArrayIndex(i)
            settings.setValue("name", name)

        settings.endArray()
示例#9
0
def writeGlyphSets(glyphSets):
    settings = QSettings()
    settings.beginWriteArray("glyphSets", len(glyphSets))
    index = 0
    for name, cset in glyphSets.items():
        settings.setArrayIndex(index)
        settings.setValue("name", name)
        settings.setValue("glyphNames", cset)
        index += 1
    settings.endArray()
示例#10
0
def writeMarkColors(markColors):
    settings = QSettings()
    settings.beginWriteArray("misc/markColors")
    # serialized in UFO form
    i = 0
    for color, name in markColors:
        settings.setArrayIndex(i)
        settings.setValue("color", str(Color(color.getRgbF())))
        settings.setValue("name", name)
        i += 1
    settings.endArray()
示例#11
0
def writeMarkColors(markColors):
    settings = QSettings()
    settings.beginWriteArray("misc/markColors")
    # serialized in UFO form
    i = 0
    for color, name in markColors:
        settings.setArrayIndex(i)
        settings.setValue("color", str(Color(color.getRgbF())))
        settings.setValue("name", name)
        i += 1
    settings.endArray()
示例#12
0
 def write_settings(self):
     settings = QSettings()
     settings.beginWriteArray('upload/imdbHistory',
                              size=len(self._item_identities))
     settings.setValue("imdbId", id)
     for identity_i, identity in enumerate(self._item_identities):
         settings.setArrayIndex(identity_i)
         imdb_identity = identity.imdb_identity
         settings.setValue('imdbId', imdb_identity.get_imdb_id())
         video_identity = identity.video_identity
         settings.setValue('title', video_identity.get_name())
     settings.endArray()
示例#13
0
    def gui_save(self, ui: QWidget, settings: QSettings, uiName="uiwidget"):
        """
        save "ui" controls and values to registry "setting"

        :param ui:
        :param settings:
        :param uiName:
        :return:
        """

        namePrefix = f"{uiName}/"
        settings.setValue(namePrefix + "geometry", ui.saveGeometry())

        for name, obj in inspect.getmembers(ui):
            if not self.IsHandledType(obj):
                continue

            name = obj.objectName()
            value = None
            if isinstance(obj, QComboBox):
                index = obj.currentIndex()  # get current index from combobox
                value = obj.itemText(index)  # get the text for current index

            if isinstance(obj, QLineEdit):
                value = obj.text()

            if isinstance(obj, QTextEdit):
                value = obj.toPlainText()

            if isinstance(obj, QCheckBox):
                value = obj.isChecked()

            if isinstance(obj, QRadioButton):
                value = obj.isChecked()

            if isinstance(obj, QSpinBox):
                value = obj.value()

            if isinstance(obj, QSlider):
                value = obj.value()

            if isinstance(obj, QProgressBar):
                value = obj.value()

            if isinstance(obj, QListWidget):
                settings.beginWriteArray(name)
                for i in range(obj.count()):
                    settings.setArrayIndex(i)
                    settings.setValue(namePrefix + name, obj.item(i).text())
                settings.endArray()
            elif value is not None:
                settings.setValue(namePrefix + name, value)
示例#14
0
def readGlyphSets():
    settings = QSettings()
    size = settings.beginReadArray("glyphSets")
    glyphSets = {}
    if not size:
        glyphSets[_latinDefaultName] = _latinDefaultGlyphNames
    for i in range(size):
        settings.setArrayIndex(i)
        glyphSetName = settings.value("name", type=str)
        glyphSetGlyphNames = settings.value("glyphNames", type=str)
        glyphSets[glyphSetName] = glyphSetGlyphNames
    settings.endArray()
    return glyphSets
示例#15
0
def readGlyphSets():
    settings = QSettings()
    size = settings.beginReadArray("glyphSets")
    glyphSets = {}
    if not size:
        glyphSets[_latinDefaultName] = _latinDefaultGlyphNames
    for i in range(size):
        settings.setArrayIndex(i)
        glyphSetName = settings.value("name", type=str)
        glyphSetGlyphNames = settings.value("glyphNames", type=str)
        glyphSets[glyphSetName] = glyphSetGlyphNames
    settings.endArray()
    return glyphSets
示例#16
0
def renameUseshebang():
    s = QSettings()
    l = s.beginReadArray("lilypondinfo")
    old = []
    for i in range(l):
        s.setArrayIndex(i)
        old.append(s.value("always_use_shebang", None))
    s.endArray()
    s.beginWriteArray("lilypondinfo")
    for i in range(l):
        s.setArrayIndex(i)
        if old[i] is not None:
            s.setValue("useshebang", old[i])
            s.remove("always_use_shebang")
    s.endArray()
示例#17
0
    def restore_settings(self, settings: QSettings):
        settings.beginGroup("soap_plugin")
        if settings.value("filter_non_soap_traffic", None):
            self.filter_non_soap_traffic = settings.value("filter_non_soap_traffic") == "true"
        if settings.value("filter_methods", None):
            self.filter_methods_as_string = settings.value("filter_methods")

        size = settings.beginReadArray("clients_for_paths")
        for i in range(size):
            settings.setArrayIndex(i)
            path = settings.value("path")
            client = settings.value("client")
            self.clients_for_paths[path] = client
        settings.endArray()
        settings.endGroup()
示例#18
0
    def load_settings(self):
        settings = QSettings()

        roi_items = []

        size = settings.beginReadArray("regions_of_interest")
        for index in range(size):
            settings.setArrayIndex(index)
            roi_items.append(
                self.addRegionofInterestWithoutSettings(
                    *self.get_roi_from_settings(settings)))

        settings.endArray()

        return roi_items
示例#19
0
文件: settings.py 项目: madig/trufont
def readMarkColors():
    settings = QSettings()
    size = settings.beginReadArray("misc/markColors")
    markColors = OrderedDict()
    if not size:
        # serialized in UFO form
        markColors["Red"] = colorToQColor("1,0,0,1")
        markColors["Yellow"] = colorToQColor("1,1,0,1")
        markColors["Green"] = colorToQColor("0,1,0,1")
    for i in range(size):
        settings.setArrayIndex(i)
        markColorName = settings.value("name", type=str)
        markColor = settings.value("color", type=str)
        markColors[markColorName] = colorToQColor(markColor)
    settings.endArray()
    return markColors
示例#20
0
    def readSettings(self):

        settings = QSettings("University of Victoria", "VPT Annotator")

        size = settings.beginReadArray("annotations")
        for i in range(size):
            settings.setArrayIndex(i)
            self._videoControl.addAnnotation(settings.value("name"))

        settings.endArray()

        if len(self._videoControl.getAnnotationNames()) == 0:
            self._videoControl.addAnnotation("not playing")
            self._videoControl.addAnnotation("correct")
            self._videoControl.addAnnotation("flat hand")
            self._videoControl.addAnnotation("low wrist")
示例#21
0
    def read_settings(self):
        identities = []
        settings = QSettings()
        size = settings.beginReadArray('upload/imdbHistory')
        for identity_i in range(size):
            settings.setArrayIndex(identity_i)
            imdb_id = settings.value('imdbId')
            imdb_identity = ImdbIdentity(imdb_id=imdb_id, imdb_rating=None)
            name = settings.value('title')
            video_identity = VideoIdentity(name=name, year=None)
            identities.append(
                ProviderIdentities(video_identity=video_identity,
                                   imdb_identity=imdb_identity,
                                   provider=self))
        settings.endArray()

        self.set_imdb_data(identities)
示例#22
0
    def loadConfiguration(self, fileName=etcConfigName):

        if not fileName:
            newfile, _filter = QFileDialog.getOpenFileName(
                self, "IMBL processing configuration",
                directory=self.ui.outPath.text())
            if newfile:
                fileName = newfile
        if not os.path.exists(fileName):
            return

        self.amLoading = True
        config = QSettings(fileName, QSettings.IniFormat)

        def valToLoad(wdg, nm):
            if isinstance(wdg, QtWidgets.QLineEdit):
                wdg.setText(config.value(oName, type=str))
            elif isinstance(wdg, QtWidgets.QCheckBox):
                wdg.setChecked(config.value(oName, type=bool))
            elif isinstance(wdg, QtWidgets.QAbstractSpinBox):
                wdg.setValue(config.value(oName, type=float))
            elif isinstance(wdg, QtWidgets.QComboBox):
                txt = config.value(oName, type=str)
                didx = wdg.findText(txt)
                if not didx < 0:
                    wdg.setCurrentIndex(didx)
        for swdg in self.configObjects:
            oName = swdg.objectName()
            if config.contains(oName):
                valToLoad(swdg, oName)
            if swdg is self.ui.outPath:
                self.on_outPath_textChanged()
            if swdg is self.ui.sameBin:
                self.on_sameBin_clicked()

        while self.ui.splits.rowCount() > 1:
                self.remFromSplit(0)
        splitsize = config.beginReadArray('splits')
        for crow in range(0, splitsize):
            config.setArrayIndex(crow)
            self.addToSplit(config.value('pos', type=int))
        config.endArray()
        self.recalculateSplit()

        self.amLoading = False
示例#23
0
def readMarkColors():
    settings = QSettings()
    size = settings.beginReadArray("misc/markColors")
    if not size:
        markColors = [
            [QColor(255, 0, 0), "Red"],
            [QColor(255, 255, 0), "Yellow"],
            [QColor(0, 255, 0), "Green"],
        ]
    else:
        markColors = []
    for i in range(size):
        settings.setArrayIndex(i)
        markColor = settings.value("color", type=str)
        markColorName = settings.value("name", type=str)
        markColors.append([colorToQColor(markColor), markColorName])
    settings.endArray()
    return markColors
示例#24
0
def infos():
    """Returns all configured LilyPondInfo for the different used LilyPond versions."""
    global _infos
    if _infos is None:
        s = QSettings()
        _infos = []
        for i in range(s.beginReadArray("lilypondinfo")):
            s.setArrayIndex(i)
            info = LilyPondInfo.read(s)
            if info:
                _infos.append(info)
        s.endArray()
        if not _infos:
            info = default()
            if info.abscommand():
                _infos.append(info)
        app.aboutToQuit.connect(saveinfos)
    return _infos
示例#25
0
def readMarkColors():
    settings = QSettings()
    size = settings.beginReadArray("misc/markColors")
    if not size:
        markColors = [
            [QColor(255, 0, 0), "Red"],
            [QColor(255, 255, 0), "Yellow"],
            [QColor(0, 255, 0), "Green"],
        ]
    else:
        markColors = []
    for i in range(size):
        settings.setArrayIndex(i)
        markColor = settings.value("color", type=str)
        markColorName = settings.value("name", type=str)
        markColors.append([colorToQColor(markColor), markColorName])
    settings.endArray()
    return markColors
示例#26
0
    def saveTable(self):
        settings = QSettings(MY_ORG, MY_NAME)
        settings.beginWriteArray("entries")

        currTable = self.alertTableWidget

        for row in range(0, self.alertTableWidget.rowCount()):
            settings.setArrayIndex(row)

            settings.setValue("title", currTable.item(row, TITLE_COL).text())
            settings.setValue("interval",
                              currTable.item(row, INTERVAL_COL).text())
            settings.setValue("status", currTable.item(row, STATUS_COL).text())
            settings.setValue("webpage",
                              currTable.item(row, WEBPAGE_COL).text())

        settings.endArray()
        MainWindow.setSavedFalse.hasSaved = True
示例#27
0
    def read_paths(self):
        """Returns a list of up to MAX_RECENT_DOCS Paths. The most recently
        opened path is the first element in the list.
        """
        settings = QSettings()
        n_recent = settings.beginReadArray(self.KEY)
        try:
            n_recent = min(n_recent, self.MAX_RECENT_DOCS)
            recent = []
            debug_print('Reading {0} recent document paths'.format(n_recent))
            for index in range(n_recent):
                settings.setArrayIndex(index)
                path = settings.value("path")
                if path:
                    recent.append(self._resolved_if_possible(Path(path)))
        finally:
            settings.endArray()

        return recent
示例#28
0
    def loadTable(self):
        settings = QSettings(MY_ORG, MY_NAME)
        numRows = settings.beginReadArray("entries")

        currTable = self.alertTableWidget

        for row in range(0, numRows):
            settings.setArrayIndex(row)
            self.alertTableWidget.insertRow(row)

            currTable.setItem(row, TITLE_COL,
                              QTableWidgetItem(str(settings.value("title"))))
            currTable.setItem(
                row, INTERVAL_COL,
                QTableWidgetItem(str(settings.value("interval"))))
            currTable.setItem(row, STATUS_COL,
                              QTableWidgetItem(str(settings.value("status"))))
            currTable.setItem(row, WEBPAGE_COL,
                              QTableWidgetItem(str(settings.value("webpage"))))

        settings.endArray()
示例#29
0
    def load(self):
        settings = QSettings()
        cnt = settings.beginReadArray("RecentFiles")
        # PyQt bug: cnt is always 0, workaround with "None" test below
        i = -1
        while True:
            i += 1
            settings.setArrayIndex(i)
            try:
                s = settings.value("Filename")
                if s == None:
                    break
                self.__recent_files.append(str(s))
            except Exception as e:
                self.log.error('Loading of recent file entry %i failed: %s' %
                               (i, e))
                settings.remove("Filename")

        settings.endArray()

        self.log.debug("recent_files: %s" % self.__recent_files)

        self.addToMenu()
示例#30
0
    def setup_ui(self):
        self.ui.setupUi(self)
        self.initializeFilterLanguages()

        # SETTING UP UPLOAD_VIEW
        self.uploadModel = UploadListModel(self)
        self.ui.uploadView.setModel(self.uploadModel)
        # FIXME: This connection should be cleaner.
        self.uploadModel._main = self

        # Resizing the headers to take all the space(50/50) in the TableView
        header = self.ui.uploadView.horizontalHeader()
        header.setSectionResizeMode(QHeaderView.Stretch)

        self.ui.buttonUploadBrowseFolder.clicked.connect(
            self.onUploadBrowseFolder)
        self.ui.uploadView.activated.connect(self.onUploadClickViewCell)
        self.ui.uploadView.clicked.connect(self.onUploadClickViewCell)

        self.ui.buttonUpload.clicked.connect(self.onUploadButton)

        self.ui.buttonUploadUpRow.clicked.connect(
            self.uploadModel.onUploadButtonUpRow)
        self.ui.buttonUploadDownRow.clicked.connect(
            self.uploadModel.onUploadButtonDownRow)
        self.ui.buttonUploadPlusRow.clicked.connect(
            self.uploadModel.onUploadButtonPlusRow)
        self.ui.buttonUploadMinusRow.clicked.connect(
            self.uploadModel.onUploadButtonMinusRow)
        self.ui.buttonUploadDeleteAllRow.clicked.connect(
            self.uploadModel.onUploadButtonDeleteAllRow)

        self.ui.buttonUploadFindIMDB.clicked.connect(
            self.onButtonUploadFindIMDB)
        self.ui.uploadIMDB.activated.connect(self.onUploadSelectImdb)

        self.uploadSelectionModel = QItemSelectionModel(self.uploadModel)
        self.ui.uploadView.setSelectionModel(self.uploadSelectionModel)
        self.uploadSelectionModel.selectionChanged.connect(
            self.onUploadChangeSelection)

        self.imdbDetected.connect(self.onUploadIMDBNewSelection)

        self.releaseUpdated.connect(self.OnChangeReleaseName)

        self.ui.label_autodetect_imdb.hide()
        self.ui.label_autodetect_lang.hide()
        # print self.ui.uploadView.sizeHint ()
        # self.ui.uploadView.adjustSize()
        # self.ui.groupBox_2.adjustSize()
        # self.ui.uploadDetailsGroupBox.adjustSize()
        # self.adjustSize()

        settings = QSettings()
        optionUploadLanguage = settings.value("options/uploadLanguage", "eng")
        index = self.ui.uploadLanguages.findData(optionUploadLanguage)
        if index != -1:
            self.ui.uploadLanguages.setCurrentIndex(index)

        self.ui.uploadLanguages.adjustSize()

        size = settings.beginReadArray("upload/imdbHistory")
        for i in range(size):
            settings.setArrayIndex(i)
            imdbId = settings.value("imdbId")
            title = settings.value("title")
            self.ui.uploadIMDB.addItem("%s : %s" % (imdbId, title), imdbId)
        settings.endArray()
示例#31
0
    def gui_restore(self, ui: QWidget, settings: QSettings, uiName="uiwidget"):
        """
        restore "ui" controls with values stored in registry "settings"

        params
        ------
        :param ui:
        :param settings:
        :param uiName:

        """
        from distutils.util import strtobool

        namePrefix = f"{uiName}/"
        geometryValue = settings.value(namePrefix + "geometry")
        if geometryValue:
            ui.restoreGeometry(geometryValue)

        for name, obj in inspect.getmembers(ui):
            if not self.IsHandledType(obj):
                continue

            name = obj.objectName()
            value = None
            if not isinstance(obj, QListWidget):
                value = settings.value(namePrefix + name)
                if value is None:
                    continue

            if isinstance(obj, QComboBox):
                index = obj.findText(
                    value
                )  # get the corresponding index for specified string in combobox

                if index == -1:  # add to list if not found
                    obj.insertItems(0, [value])
                    index = obj.findText(value)
                    obj.setCurrentIndex(index)
                else:
                    obj.setCurrentIndex(
                        index)  # preselect a combobox value by index

            if isinstance(obj, QLineEdit):
                obj.setText(value)

            if isinstance(obj, QTextEdit):
                obj.setText(value)

            if isinstance(obj, QCheckBox):
                obj.setChecked(strtobool(value))

            if isinstance(obj, QRadioButton):
                obj.setChecked(strtobool(value))

            if isinstance(obj, QSlider):
                obj.setValue(int(value))

            if isinstance(obj, QSpinBox):
                obj.setValue(int(value))

            if isinstance(obj, QProgressBar):
                obj.setValue(int(value))

            if isinstance(obj, QListWidget):
                size = settings.beginReadArray(namePrefix + name)
                for i in range(size):
                    settings.setArrayIndex(i)
                    value = settings.value(namePrefix + name)
                    if value is not None:
                        obj.addItem(value)
                settings.endArray()
示例#32
0
class PugdebugSettings():

    defaults = {
        'debugger/host': '127.0.0.1',
        'debugger/port_number': 9000,
        'debugger/idekey': 'pugdebug',
        'debugger/break_at_first_line': Qt.Checked,
        'debugger/max_depth': '3',
        'debugger/max_children': '128',
        'debugger/max_data': '512',
        'path/project_root': os.path.expanduser('~'),
        'path/path_mapping': '',
        'editor/tab_width': 80,
        'editor/font_size': 12
    }

    def __init__(self):
        """Model object to handle application settings

        Sets up initial application settings.

        QSettings promises to work cross-platform.
        """
        QCoreApplication.setOrganizationName("pugdebug")
        QCoreApplication.setOrganizationDomain(
            "http://github.com/robertbasic/pugdebug")
        QCoreApplication.setApplicationName("pugdebug")
        self.application_settings = QSettings()

        self.setup_default_settings()

    def setup_default_settings(self):
        """Set the default values for settings which don't have a value."""
        for key, value in self.defaults.items():
            if not self.has(key):
                self.set(key, value)

    def get(self, key):
        return self.application_settings.value(key)

    def get_default(self, key):
        return self.defaults[key] if key in self.defaults else None

    def has(self, key):
        return self.application_settings.contains(key)

    def set(self, key, value):
        return self.application_settings.setValue(key, value)

    def remove(self, key):
        return self.application_settings.remove(key)

    def add_project(self, project):
        index = self.__get_next_index(project)

        if index is not False:
            self.application_settings.beginWriteArray('projects')
            self.application_settings.setArrayIndex(index)
            self.application_settings.setValue('projects', project)
            self.application_settings.endArray()

    def delete_project(self, project):
        size = self.application_settings.beginReadArray('projects')

        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            existing_project = self.application_settings.value('projects')

            if existing_project == project:
                self.application_settings.remove('projects')
                break

        self.application_settings.endArray()

        self.__reindex_projects_array()

    def get_projects(self):
        size = self.application_settings.beginReadArray('projects')

        projects = []
        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            projects.append(self.application_settings.value('projects'))

        self.application_settings.endArray()

        return projects

    def __get_next_index(self, project):
        size = self.application_settings.beginReadArray('projects')

        index = None

        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            existing_project = self.application_settings.value('projects')

            if existing_project == project:
                index = i
                break

        self.application_settings.endArray()

        return False if index is not None else size

    def __reindex_projects_array(self):
        size = self.application_settings.beginReadArray('projects')

        projects = set()
        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            project = self.application_settings.value('projects')

            if project is not None:
                projects.add(project)

        self.application_settings.endArray()

        self.application_settings.remove('projects')

        self.application_settings.beginWriteArray('projects')

        i = 0
        for project in projects:
            self.application_settings.setArrayIndex(i)
            self.application_settings.setValue('projects', project)
            i += 1

        self.application_settings.endArray()
示例#33
0
class PugdebugSettings():

    defaults = {
        'debugger/host': '127.0.0.1',
        'debugger/port_number': 9000,
        'debugger/idekey': 'pugdebug',
        'debugger/break_at_first_line': Qt.Checked,
        'debugger/max_depth': '3',
        'debugger/max_children': '128',
        'debugger/max_data': '512',

        'path/project_root': os.path.expanduser('~'),
        'path/path_mapping': ''
    }

    def __init__(self):
        """Model object to handle application settings

        Sets up initial application settings.

        QSettings promises to work cross-platform.
        """
        QCoreApplication.setOrganizationName("pugdebug")
        QCoreApplication.setOrganizationDomain(
            "http://github.com/robertbasic/pugdebug"
        )
        QCoreApplication.setApplicationName("pugdebug")
        self.application_settings = QSettings()

        self.setup_default_settings()

    def setup_default_settings(self):
        """Set the default values for settings which don't have a value."""
        for key, value in self.defaults.items():
            if not self.has(key):
                self.set(key, value)

    def get(self, key):
        return self.application_settings.value(key)

    def get_default(self, key):
        return self.defaults[key] if key in self.defaults else None

    def has(self, key):
        return self.application_settings.contains(key)

    def set(self, key, value):
        return self.application_settings.setValue(key, value)

    def remove(self, key):
        return self.application_settings.remove(key)

    def add_project(self, project):
        index = self.__get_next_index(project)

        if index is not False:
            self.application_settings.beginWriteArray('projects')
            self.application_settings.setArrayIndex(index)
            self.application_settings.setValue('projects', project)
            self.application_settings.endArray()

    def delete_project(self, project):
        size = self.application_settings.beginReadArray('projects')

        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            existing_project = self.application_settings.value('projects')

            if existing_project == project:
                self.application_settings.remove('projects')
                break

        self.application_settings.endArray()

        self.__reindex_projects_array()

    def get_projects(self):
        size = self.application_settings.beginReadArray('projects')

        projects = []
        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            projects.append(self.application_settings.value('projects'))

        self.application_settings.endArray()

        return projects

    def __get_next_index(self, project):
        size = self.application_settings.beginReadArray('projects')

        index = None

        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            existing_project = self.application_settings.value('projects')

            if existing_project == project:
                index = i
                break

        self.application_settings.endArray()

        return False if index is not None else size

    def __reindex_projects_array(self):
        size = self.application_settings.beginReadArray('projects')

        projects = set()
        for i in range(0, size):
            self.application_settings.setArrayIndex(i)
            project = self.application_settings.value('projects')

            if project is not None:
                projects.add(project)

        self.application_settings.endArray()

        self.application_settings.remove('projects')

        self.application_settings.beginWriteArray('projects')

        i = 0
        for project in projects:
            self.application_settings.setArrayIndex(i)
            self.application_settings.setValue('projects', project)
            i += 1

        self.application_settings.endArray()