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()
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()
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()
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()
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()
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()
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()
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()
def save(self): # truncate list if necessary self.__recent_files = self.__recent_files[:MAX_SIZE] s = QSettings() s.beginWriteArray("RecentFiles") cnt = 0 for f in self.__recent_files: s.setArrayIndex(cnt) s.setValue("Filename", f) cnt += 1 s.sync()
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()
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)
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()
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
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()
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()