def __init__(self): self._settings = {} self._settingsClient = None QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, "settings") QSettings.setDefaultFormat(QSettings.IniFormat)
def setUpClass(cls): QCoreApplication.setApplicationName("test1") QCoreApplication.setOrganizationName("org1") cls.settings_dir = tempfile.TemporaryDirectory() QSettings.setDefaultFormat(QSettings.Format.IniFormat) QSettings.setPath(QSettings.Format.IniFormat, QSettings.Scope.UserScope, cls.settings_dir.name)
def init_settings(self) -> None: if sys.platform == 'darwin': QSettings.setDefaultFormat(QSettings.IniFormat) self.settings = QSettings(self) else: try: settings_path = QStandardPaths.writableLocation( QStandardPaths.AppConfigLocation).lower() except AttributeError: if sys.platform == 'win32': settings_path = os.path.join( QDir.homePath(), 'AppData', 'Local', qApp.applicationName().lower()) elif sys.platform == 'darwin': settings_path = os.path.join( QDir.homePath(), 'Library', 'Preferences', qApp.applicationName()).lower() else: settings_path = os.path.join( QDir.homePath(), '.config', qApp.applicationName()).lower() os.makedirs(settings_path, exist_ok=True) settings_file = '%s.ini' % qApp.applicationName().lower() self.settings = QSettings( os.path.join(settings_path, settings_file), QSettings.IniFormat) if self.settings.value('geometry') is not None: self.restoreGeometry(self.settings.value('geometry')) if self.settings.value('windowState') is not None: self.restoreState(self.settings.value('windowState')) self.theme = self.settings.value('theme', 'light', type=str) self.startupvol = self.settings.value('volume', 100, type=int)
def main(): app = QApplication(sys.argv) app.setOrganizationName('Arvedui') app.setApplicationName('picup') QSettings.setDefaultFormat(QSettings.IniFormat) window = MainWindow() window.show() sys.exit(app.exec_())
def __init__(self, configuration: Configuration): super().__init__() QSettings.setDefaultFormat(QSettings.IniFormat) QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, configuration.user_settings_directory) # We fake the application and organisation name to try and use a "nicer" directory for settings. # However, an organisation name is required to ensure this works properly on all systems. # See issues like this: https://www.qtcentre.org/threads/35300-QSplitter-restoreState()-not-working self.__store = QSettings(QSettings.IniFormat, QSettings.UserScope, "nasm", "settings", self)
def main(): app = QApplication(sys.argv) app.setOrganizationName('Arvedui') app.setApplicationName('picup') QSettings.setDefaultFormat(QSettings.IniFormat) window = MainWindow() window.show() sys.exit(app.exec_())
def __init__(self, sys_argv): super(Application, self).__init__(sys_argv) self.setApplicationName("Anser") self.setOrganizationName("Anser") QSettings.setDefaultFormat(QSettings.IniFormat) #settings = QSettings() #print(str(QSettings.fileName(settings))) self.view = MainWindow() self.system = QtAnser() self.controller = MainController(self.view, self.system) self.view.show()
def init(): """ Initialize the QCoreApplication.organizationDomain, applicationName, applicationVersion and the default settings format. Will only run once. .. note:: This should not be run before QApplication has been initialized. Otherwise it can break Qt's plugin search paths. """ import pkg_resources dist = pkg_resources.get_distribution("Orange3-SingleCell") version = dist.version # Use only major.minor #version = ".".join(version.split(".", 2)[:2]) QCoreApplication.setOrganizationDomain("biolab.si") QCoreApplication.setApplicationName("scOrange") QCoreApplication.setApplicationVersion(version) QSettings.setDefaultFormat(QSettings.IniFormat) # Make it a null op. config.init = lambda: None
def init(cls): QCoreApplication.setOrganizationDomain(cls.OrganizationDomain) QCoreApplication.setApplicationName(cls.ApplicationName) QCoreApplication.setApplicationVersion(cls.ApplicationVersion) QSettings.setDefaultFormat(QSettings.IniFormat)
def main(): try: locale.setlocale(locale.LC_ALL, '') except: # Work around system locale not specified (under Linux or Mac OS) pass app = QApplication(sys.argv) QCoreApplication.setOrganizationName(version.Company) QCoreApplication.setApplicationName(version.AppName) if OpenNumismat.PORTABLE: QCoreApplication.setOrganizationName('.') QSettings.setDefaultFormat(QSettings.IniFormat) QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, OpenNumismat.PRJ_PATH) settings = Settings() if settings['error']: sys.excepthook = exceptHook if not os.path.exists(settings['reference']): # Create default dirs and files if not exists try: ref_path = os.path.dirname(settings['reference']) dst_ref = os.path.join(ref_path, 'reference.ref') if not os.path.exists(dst_ref): os.makedirs(ref_path, exist_ok=True) src_ref = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'reference_%s.ref' % settings['locale']) if not os.path.exists(src_ref): src_ref = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'reference_en.ref') shutil.copy(src_ref, dst_ref) dst_demo_db = os.path.join(OpenNumismat.HOME_PATH, 'demo.db') if not os.path.exists(dst_demo_db): os.makedirs(OpenNumismat.HOME_PATH, exist_ok=True) src_demo_db = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'demo_%s.db' % settings['locale']) if not os.path.exists(src_demo_db): src_demo_db = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'demo_en.ref') shutil.copy(src_demo_db, dst_demo_db) templates_path = os.path.join(OpenNumismat.HOME_PATH, 'templates') os.makedirs(templates_path, exist_ok=True) except: pass TemporaryDir.init(version.AppName) lang = settings['locale'] translator = QTranslator() translator.load('translations/lang_' + lang, OpenNumismat.PRJ_PATH) app.installTranslator(translator) translatorQt = QTranslator() translatorQt.load('translations/qtbase_' + lang, OpenNumismat.PRJ_PATH) app.installTranslator(translatorQt) if not settings['verify_ssl']: ssl._create_default_https_context = ssl._create_unverified_context mainWindow = MainWindow() mainWindow.show() mainWindow.raise_() # this will raise the window on Mac OS X status = app.exec_() # Clear temporary files TemporaryDir.remove() sys.exit(status)
class Settings(QDialog, Ui_Settings): """Settings dialog""" def __init__(self, parent): QDialog.__init__(self, parent) self.parent = parent self.setupUi(self) self.core = None self.plugins = [] self.emumode = [] self.combomap = {} self.qset = QSettings("m64py", "m64py") self.qset.setDefaultFormat(QSettings.IniFormat) self.add_items() self.connect_signals() def showEvent(self, event): self.set_config() def closeEvent(self, event): self.save_config() def add_items(self): self.combomap = { M64PLUGIN_RSP: (self.comboRSP, self.pushButtonRSP, Plugin(self.parent)), M64PLUGIN_GFX: (self.comboVideo, self.pushButtonVideo, Plugin(self.parent)), M64PLUGIN_AUDIO: (self.comboAudio, self.pushButtonAudio, Plugin(self.parent)), M64PLUGIN_INPUT: (self.comboInput, self.pushButtonInput, Input(self.parent)) } self.emumode = [ QRadioButton(self.tr("Pure Interpreter")), QRadioButton(self.tr("Cached Interpreter")), QRadioButton(self.tr("Dynamic Recompiler")) ] vbox = QVBoxLayout(self.groupEmuMode) for widget in self.emumode: vbox.addWidget(widget) def show_page(self, index=0): self.tabWidget.setCurrentIndex(index) self.show() def save_config(self): self.save_paths() self.save_plugins() if self.core and self.core.get_handle(): self.save_video() self.save_core() self.core.config.save_file() self.qset.sync() def set_config(self): if self.core and self.core.get_handle(): self.set_paths() self.set_plugins() self.set_video() self.set_core() def on_vidext_changed(self, state): self.parent.vidext = state self.comboResolution.setEnabled(not self.parent.vidext) self.checkFullscreen.setEnabled(not self.parent.vidext) self.parent.worker.quit() self.parent.worker.init() def connect_signals(self): self.browseLibrary.clicked.connect(lambda: self.browse_dialog( (self.pathLibrary, self.groupLibrary, False))) self.browsePlugins.clicked.connect(lambda: self.browse_dialog( (self.pathPlugins, self.groupPlugins, True))) self.browseData.clicked.connect(lambda: self.browse_dialog( (self.pathData, self.groupData, True))) self.browseROM.clicked.connect(lambda: self.browse_dialog( (self.pathROM, self.groupROM, True))) self.checkEnableVidExt.clicked.connect(self.on_vidext_changed) for plugin_type in self.combomap: self.connect_combo_signals(self.combomap[plugin_type]) def connect_combo_signals(self, combomap): combo, button, settings = combomap if settings is not None: if combo != self.comboInput: combo.activated.connect( lambda: self.set_section(combo, button, settings)) button.clicked.connect(settings.show_dialog) def browse_dialog(self, args): widget, groupbox, directory = args dialog = QFileDialog() if directory: dialog.setFileMode(QFileDialog.Directory) path = dialog.getExistingDirectory(self, groupbox.title(), widget.text(), QFileDialog.ShowDirsOnly) else: dialog.setFileMode(QFileDialog.ExistingFile) path, _ = dialog.getOpenFileName( self, groupbox.title(), widget.text(), "%s (*%s);;All files (*)" % (groupbox.title(), DLL_FILTER)) if not path: return widget.setText(path) if widget == self.pathLibrary: self.parent.worker.quit() if not self.parent.worker.core.get_handle(): self.parent.worker.init(path) if self.parent.worker.core.get_handle(): self.core = self.parent.worker.core self.set_core() self.set_video() self.parent.window_size_triggered(self.get_size_safe()) self.parent.state_changed.emit((True, False, False, False)) elif widget == self.pathPlugins: self.parent.worker.plugins_shutdown() self.parent.worker.plugins_unload() self.parent.worker.plugins_load(path) self.parent.worker.plugins_startup() self.set_plugins() def get_int_safe(self, key, default): try: return int(self.qset.value(key, default)) except ValueError: return default def get_size_safe(self): try: size = self.qset.value("size", SIZE_1X) except TypeError: size = SIZE_1X if not type(size) == tuple: size = SIZE_1X if len(size) != 2: size = SIZE_1X if type(size[0]) != int or type(size[1]) != int: size = SIZE_1X if size[0] <= 0 or size[1] <= 0: size = SIZE_1X return size def get_section(self, combo): plugin = combo.currentText() index = combo.findText(plugin) desc = combo.itemData(index) name = os.path.splitext(plugin)[0][12:] section = "-".join([n.capitalize() for n in name.split("-")[0:2]]) return section, desc def set_section(self, combo, button, settings): if settings: if combo != self.comboInput: section, desc = self.get_section(combo) settings.set_section(section, desc) self.core.config.open_section(section) items = self.core.config.parameters[ self.core.config.section].items() if items: button.setEnabled(True) else: button.setEnabled(False) else: button.setEnabled(True) else: button.setEnabled(False) def set_paths(self): path_library = self.qset.value("Paths/Library", find_library(CORE_NAME)) path_data = self.qset.value("Paths/Data", self.core.config.get_path("SharedData")) path_roms = self.qset.value("Paths/ROM") try: path_plugins = self.qset.value( "Paths/Plugins", os.path.realpath( os.path.dirname(self.parent.worker.plugin_files[0]))) except IndexError: path_plugins = "" try: self.pathROM.setText(path_roms) except TypeError: pass self.pathLibrary.setText(path_library) self.pathPlugins.setText(path_plugins) self.pathData.setText(path_data) def set_video(self): self.core.config.open_section("Video-General") self.set_resolution() self.checkEnableVidExt.setChecked( bool(self.get_int_safe("enable_vidext", 1))) self.checkFullscreen.setChecked( bool(self.core.config.get_parameter("Fullscreen"))) self.checkFullscreen.setEnabled(not self.parent.vidext) self.checkVsync.setChecked( bool(self.core.config.get_parameter("VerticalSync"))) self.checkVsync.setToolTip( self.core.config.get_parameter_help("VerticalSync").decode()) if sys.platform == "win32": self.checkKeepAspect.setChecked(False) self.checkKeepAspect.setEnabled(False) else: keep_aspect = bool(self.get_int_safe("keep_aspect", 1)) self.checkKeepAspect.setChecked(keep_aspect) disable_screensaver = bool(self.get_int_safe("disable_screensaver", 1)) self.checkDisableScreenSaver.setChecked(disable_screensaver) def set_core(self): self.core.config.open_section("Core") mode = self.core.config.get_parameter("R4300Emulator") self.emumode[mode].setChecked(True) self.checkOSD.setChecked( self.core.config.get_parameter("OnScreenDisplay")) self.checkOSD.setToolTip( self.core.config.get_parameter_help("OnScreenDisplay").decode()) self.checkNoCompiledJump.setChecked( self.core.config.get_parameter("NoCompiledJump")) self.checkNoCompiledJump.setToolTip( self.core.config.get_parameter_help("NoCompiledJump").decode()) self.checkDisableExtraMem.setChecked( self.core.config.get_parameter("DisableExtraMem")) self.checkDisableExtraMem.setToolTip( self.core.config.get_parameter_help("DisableExtraMem").decode()) delay_si = self.core.config.get_parameter("DelaySI") if delay_si is not None: self.checkDelaySI.setChecked(delay_si) else: self.checkDelaySI.setChecked(False) self.checkDelaySI.setEnabled(False) self.checkDelaySI.setToolTip( self.core.config.get_parameter_help("DelaySI").decode()) count_per_op = self.core.config.get_parameter("CountPerOp") if count_per_op is not None: self.comboCountPerOp.setCurrentIndex(count_per_op) else: self.comboCountPerOp.setEnabled(False) self.comboCountPerOp.setToolTip( self.core.config.get_parameter_help("CountPerOp").decode()) def set_plugins(self): plugin_map = self.core.plugin_map for plugin_type in self.combomap: combo, button, settings = self.combomap[plugin_type] combo.clear() for plugin in plugin_map[plugin_type].values(): (plugin_handle, plugin_path, plugin_name, plugin_desc, plugin_version) = plugin name = os.path.basename(plugin_path) combo.addItem(name) index = combo.findText(str(name)) combo.setItemData(index, plugin_desc) combo.setItemData(index, plugin_desc, Qt.ToolTipRole) current = self.qset.value( "Plugins/%s" % (PLUGIN_NAME[plugin_type]), PLUGIN_DEFAULT[plugin_type]) index = combo.findText(current) if index == -1: index = 0 combo.setCurrentIndex(index) self.set_section(combo, button, settings) def set_resolution(self): width = self.core.config.get_parameter("ScreenWidth") height = self.core.config.get_parameter("ScreenHeight") if (width, height) not in MODES: MODES.append((width, height)) self.comboResolution.clear() for mode in MODES: w, h = mode self.comboResolution.addItem("%sx%s" % (w, h), (w, h)) index = self.comboResolution.findText("%sx%s" % (width, height), Qt.MatchExactly) if index == -1: index = 0 self.comboResolution.setCurrentIndex(index) self.comboResolution.setEnabled(not self.parent.vidext) def save_paths(self): self.qset.setValue("Paths/Library", self.pathLibrary.text()) self.qset.setValue("Paths/Plugins", self.pathPlugins.text()) self.qset.setValue("Paths/Data", self.pathData.text()) self.qset.setValue("Paths/ROM", self.pathROM.text()) def save_video(self): self.core.config.open_section("Video-General") if self.parent.vidext: width, height = self.get_size_safe() else: width, height = self.comboResolution.currentText().split("x") self.core.config.set_parameter("ScreenWidth", int(width)) self.core.config.set_parameter("ScreenHeight", int(height)) self.core.config.set_parameter("Fullscreen", self.checkFullscreen.isChecked()) self.core.config.set_parameter("VerticalSync", self.checkVsync.isChecked()) self.qset.setValue("keep_aspect", int(self.checkKeepAspect.isChecked())) self.qset.setValue("disable_screensaver", int(self.checkDisableScreenSaver.isChecked())) self.qset.setValue("enable_vidext", int(self.checkEnableVidExt.isChecked())) def save_core(self): self.core.config.open_section("Core") emumode = [n for n, m in enumerate(self.emumode) if m.isChecked()][0] self.core.config.set_parameter("R4300Emulator", emumode) self.core.config.set_parameter("OnScreenDisplay", self.checkOSD.isChecked()) self.core.config.set_parameter("NoCompiledJump", self.checkNoCompiledJump.isChecked()) self.core.config.set_parameter("DisableExtraMem", self.checkDisableExtraMem.isChecked()) self.core.config.set_parameter("DelaySI", self.checkDelaySI.isChecked()) self.core.config.set_parameter("CountPerOp", self.comboCountPerOp.currentIndex()) self.core.config.set_parameter("SharedDataPath", self.pathData.text().encode()) def save_plugins(self): for plugin_type in self.combomap: combo, button, settings = self.combomap[plugin_type] self.qset.setValue("Plugins/%s" % PLUGIN_NAME[plugin_type], combo.currentText())
class Settings(QDialog, Ui_Settings): """Settings dialog""" def __init__(self, parent): QDialog.__init__(self, parent) self.parent = parent self.setupUi(self) self.core = None self.plugins = [] self.emumode = [] self.combomap = {} self.qset = QSettings("m64py", "m64py") self.qset.setDefaultFormat(QSettings.IniFormat) self.add_items() self.connect_signals() def showEvent(self, event): self.set_config() def closeEvent(self, event): self.save_config() def add_items(self): self.combomap = { M64PLUGIN_RSP: ( self.comboRSP, self.pushButtonRSP, Plugin(self.parent)), M64PLUGIN_GFX: ( self.comboVideo, self.pushButtonVideo, Plugin(self.parent)), M64PLUGIN_AUDIO: ( self.comboAudio, self.pushButtonAudio, Plugin(self.parent)), M64PLUGIN_INPUT: ( self.comboInput, self.pushButtonInput, Input(self.parent)) } self.emumode = [ QRadioButton(self.tr("Pure Interpreter")), QRadioButton(self.tr("Cached Interpreter")), QRadioButton(self.tr("Dynamic Recompiler")) ] vbox = QVBoxLayout(self.groupEmuMode) for widget in self.emumode: vbox.addWidget(widget) def show_page(self, index=0): self.tabWidget.setCurrentIndex(index) self.show() def save_config(self): self.save_paths() self.save_plugins() if self.core and self.core.get_handle(): self.save_video() self.save_core() self.core.config.save_file() self.qset.sync() def set_config(self): if self.core and self.core.get_handle(): self.set_paths() self.set_plugins() self.set_video() self.set_core() def on_vidext_changed(self, state): self.parent.vidext = state self.comboResolution.setEnabled(not self.parent.vidext) self.checkFullscreen.setEnabled(not self.parent.vidext) self.parent.worker.quit() self.parent.worker.init() def connect_signals(self): self.browseLibrary.clicked.connect(lambda: self.browse_dialog( (self.pathLibrary, self.groupLibrary, False))) self.browsePlugins.clicked.connect(lambda: self.browse_dialog( (self.pathPlugins, self.groupPlugins, True))) self.browseData.clicked.connect(lambda: self.browse_dialog( (self.pathData, self.groupData, True))) self.browseROM.clicked.connect(lambda: self.browse_dialog( (self.pathROM, self.groupROM, True))) self.checkEnableVidExt.clicked.connect(self.on_vidext_changed) for plugin_type in self.combomap: self.connect_combo_signals(self.combomap[plugin_type]) def connect_combo_signals(self, combomap): combo, button, settings = combomap if settings is not None: if combo != self.comboInput: combo.activated.connect( lambda: self.set_section(combo, button, settings)) button.clicked.connect(settings.show_dialog) def browse_dialog(self, args): widget, groupbox, directory = args dialog = QFileDialog() if directory: dialog.setFileMode(QFileDialog.Directory) path = dialog.getExistingDirectory( self, groupbox.title(), widget.text(), QFileDialog.ShowDirsOnly) else: dialog.setFileMode(QFileDialog.ExistingFile) path, _ = dialog.getOpenFileName( self, groupbox.title(), widget.text(), "%s (*%s);;All files (*)" % (groupbox.title(), DLL_FILTER)) if not path: return widget.setText(path) if widget == self.pathLibrary: self.parent.worker.quit() if not self.parent.worker.core.get_handle(): self.parent.worker.init(path) if self.parent.worker.core.get_handle(): self.core = self.parent.worker.core self.set_core() self.set_video() self.parent.window_size_triggered(self.get_size_safe()) self.parent.state_changed.emit((True, False, False, False)) elif widget == self.pathPlugins: self.parent.worker.plugins_shutdown() self.parent.worker.plugins_unload() self.parent.worker.plugins_load(path) self.parent.worker.plugins_startup() self.set_plugins() def get_int_safe(self, key, default): try: return int(self.qset.value(key, default)) except ValueError: return default def get_size_safe(self): try: size = self.qset.value("size", SIZE_1X) except TypeError: size = SIZE_1X if not type(size) == tuple: size = SIZE_1X if len(size) != 2: size = SIZE_1X if type(size[0]) != int or type(size[1]) != int: size = SIZE_1X if size[0] <= 0 or size[1] <= 0: size = SIZE_1X return size def get_section(self, combo): plugin = combo.currentText() index = combo.findText(plugin) desc = combo.itemData(index) name = os.path.splitext(plugin)[0][12:] section = "-".join([n.capitalize() for n in name.split("-")[0:2]]) return section, desc def set_section(self, combo, button, settings): if settings: if combo != self.comboInput: section, desc = self.get_section(combo) settings.set_section(section, desc) self.core.config.open_section(section) items = self.core.config.parameters[ self.core.config.section].items() if items: button.setEnabled(True) else: button.setEnabled(False) else: button.setEnabled(True) else: button.setEnabled(False) def set_paths(self): path_library = self.qset.value( "Paths/Library", find_library(CORE_NAME)) path_data = self.qset.value( "Paths/Data", self.core.config.get_path("SharedData")) path_roms = self.qset.value("Paths/ROM") try: path_plugins = self.qset.value("Paths/Plugins", os.path.realpath( os.path.dirname(self.parent.worker.plugin_files[0]))) except IndexError: path_plugins = "" try: self.pathROM.setText(path_roms) except TypeError: pass self.pathLibrary.setText(path_library) self.pathPlugins.setText(path_plugins) self.pathData.setText(path_data) def set_video(self): self.core.config.open_section("Video-General") self.set_resolution() self.checkEnableVidExt.setChecked( bool(self.get_int_safe("enable_vidext", 1))) self.checkFullscreen.setChecked( bool(self.core.config.get_parameter("Fullscreen"))) self.checkFullscreen.setEnabled(not self.parent.vidext) self.checkVsync.setChecked( bool(self.core.config.get_parameter("VerticalSync"))) self.checkVsync.setToolTip( self.core.config.get_parameter_help("VerticalSync").decode()) if sys.platform == "win32": self.checkKeepAspect.setChecked(False) self.checkKeepAspect.setEnabled(False) else: keep_aspect = bool(self.get_int_safe("keep_aspect", 1)) self.checkKeepAspect.setChecked(keep_aspect) disable_screensaver = bool(self.get_int_safe("disable_screensaver", 1)) self.checkDisableScreenSaver.setChecked(disable_screensaver) def set_core(self): self.core.config.open_section("Core") mode = self.core.config.get_parameter("R4300Emulator") self.emumode[mode].setChecked(True) self.checkOSD.setChecked( self.core.config.get_parameter("OnScreenDisplay")) self.checkOSD.setToolTip( self.core.config.get_parameter_help("OnScreenDisplay").decode()) self.checkNoCompiledJump.setChecked( self.core.config.get_parameter("NoCompiledJump")) self.checkNoCompiledJump.setToolTip( self.core.config.get_parameter_help("NoCompiledJump").decode()) self.checkDisableExtraMem.setChecked( self.core.config.get_parameter("DisableExtraMem")) self.checkDisableExtraMem.setToolTip( self.core.config.get_parameter_help("DisableExtraMem").decode()) delay_si = self.core.config.get_parameter("DelaySI") if delay_si is not None: self.checkDelaySI.setChecked(delay_si) else: self.checkDelaySI.setChecked(False) self.checkDelaySI.setEnabled(False) self.checkDelaySI.setToolTip( self.core.config.get_parameter_help("DelaySI").decode()) count_per_op = self.core.config.get_parameter("CountPerOp") if count_per_op is not None: self.comboCountPerOp.setCurrentIndex(count_per_op) else: self.comboCountPerOp.setEnabled(False) self.comboCountPerOp.setToolTip( self.core.config.get_parameter_help("CountPerOp").decode()) def set_plugins(self): plugin_map = self.core.plugin_map for plugin_type in self.combomap: combo, button, settings = self.combomap[plugin_type] combo.clear() for plugin in plugin_map[plugin_type].values(): (plugin_handle, plugin_path, plugin_name, plugin_desc, plugin_version) = plugin name = os.path.basename(plugin_path) combo.addItem(name) index = combo.findText(str(name)) combo.setItemData(index, plugin_desc) combo.setItemData(index, plugin_desc, Qt.ToolTipRole) current = self.qset.value("Plugins/%s" % ( PLUGIN_NAME[plugin_type]), PLUGIN_DEFAULT[plugin_type]) index = combo.findText(current) if index == -1: index = 0 combo.setCurrentIndex(index) self.set_section(combo, button, settings) def set_resolution(self): width = self.core.config.get_parameter("ScreenWidth") height = self.core.config.get_parameter("ScreenHeight") if (width, height) not in MODES: MODES.append((width, height)) self.comboResolution.clear() for mode in MODES: w, h = mode self.comboResolution.addItem( "%sx%s" % (w, h), (w, h)) index = self.comboResolution.findText( "%sx%s" % (width, height), Qt.MatchExactly) if index == -1: index = 0 self.comboResolution.setCurrentIndex(index) self.comboResolution.setEnabled(not self.parent.vidext) def save_paths(self): self.qset.setValue("Paths/Library", self.pathLibrary.text()) self.qset.setValue("Paths/Plugins", self.pathPlugins.text()) self.qset.setValue("Paths/Data", self.pathData.text()) self.qset.setValue("Paths/ROM", self.pathROM.text()) def save_video(self): self.core.config.open_section("Video-General") if self.parent.vidext: width, height = self.get_size_safe() else: width, height = self.comboResolution.currentText().split("x") self.core.config.set_parameter("ScreenWidth", int(width)) self.core.config.set_parameter("ScreenHeight", int(height)) self.core.config.set_parameter("Fullscreen", self.checkFullscreen.isChecked()) self.core.config.set_parameter("VerticalSync", self.checkVsync.isChecked()) self.qset.setValue("keep_aspect", int(self.checkKeepAspect.isChecked())) self.qset.setValue("disable_screensaver", int(self.checkDisableScreenSaver.isChecked())) self.qset.setValue("enable_vidext", int(self.checkEnableVidExt.isChecked())) def save_core(self): self.core.config.open_section("Core") emumode = [n for n,m in enumerate(self.emumode) if m.isChecked()][0] self.core.config.set_parameter("R4300Emulator", emumode) self.core.config.set_parameter("OnScreenDisplay", self.checkOSD.isChecked()) self.core.config.set_parameter("NoCompiledJump", self.checkNoCompiledJump.isChecked()) self.core.config.set_parameter("DisableExtraMem", self.checkDisableExtraMem.isChecked()) self.core.config.set_parameter("DelaySI", self.checkDelaySI.isChecked()) self.core.config.set_parameter("CountPerOp", self.comboCountPerOp.currentIndex()) self.core.config.set_parameter("SharedDataPath", self.pathData.text().encode()) def save_plugins(self): for plugin_type in self.combomap: combo, button, settings = self.combomap[plugin_type] self.qset.setValue("Plugins/%s" % PLUGIN_NAME[plugin_type], combo.currentText())
def start(): app = QSingleApplication(sys.argv) if platform.system().lower() == "windows": multiprocessing.freeze_support() # windows必须调用这个,不然会出错 # 异常调试 import cgitb sys.excepthook = cgitb.Hook(1, None, 5, sys.stderr, 'text') ##为了存路径到系统 QApplication.setApplicationName("PhyloSuite_settings") QApplication.setOrganizationName("PhyloSuite") QSettings.setDefaultFormat(QSettings.IniFormat) path_settings = QSettings() path_settings.setValue("thisPath", thisPath) os.chdir(thisPath) with open(thisPath + os.sep + 'style.qss', encoding="utf-8", errors='ignore') as f: qss_file = f.read() dialog = QDialog() dialog.setStyleSheet(qss_file) # 异常处理 def handle_exception(exc_type, exc_value, exc_traceback): rgx = re.compile(r'PermissionError.+?[\'\"](.+\.csv)[\'\"]') if issubclass(exc_type, KeyboardInterrupt): return sys.__excepthook__(exc_type, exc_value, exc_traceback) exception = str("".join(traceback.format_exception( exc_type, exc_value, exc_traceback))) print(exception) if rgx.search(exception): #忽略csv未关闭的报错 return msg = QMessageBox(dialog) msg.setIcon(QMessageBox.Critical) msg.setText( 'The program encountered an unforeseen problem, please report the bug at <a href="https://github.com/dongzhang0725/PhyloSuite/issues">https://github.com/dongzhang0725/PhyloSuite/issues</a> ' 'or send an email with the detailed traceback to [email protected]') msg.setWindowTitle("Error") msg.setDetailedText(exception) msg.setStandardButtons(QMessageBox.Ok) msg.exec_() sys.excepthook = handle_exception # 避免重复运行程序 if app.isRunning(): QMessageBox.information( dialog, "PhyloSuite", "<p style='line-height:25px; height:25px'>App is running!</p>") sys.exit(0) # 界面运行选择 launcher_settings = QSettings( thisPath + '/settings/launcher_settings.ini', QSettings.IniFormat) launcher_settings.setFallbacksEnabled(False) not_exe_lunch = launcher_settings.value("ifLaunch", "false") workPlace = launcher_settings.value( "workPlace", [thisPath + os.sep + "myWorkPlace"]) # 删除无效的路径 workPlace_copy = deepcopy(workPlace) for num,i in enumerate(workPlace_copy): if not os.path.exists(i): workPlace.remove(i) else: ##替换带.的路径 if re.search(r"^\.", i): workPlace[num] = os.path.abspath(i) # 如果workPlace被删干净了 if not workPlace: workPlace = [thisPath + os.sep + "myWorkPlace"] # 重新保存下路径 if len(workPlace) > 15: workPlace = workPlace[:15] # 只保留15个工作区 launcher_settings.setValue( "workPlace", workPlace) if not_exe_lunch == "true": myMainWindow = MyMainWindow(workPlace) myMainWindow.show() sys.exit(app.exec_()) else: launcher = Launcher() if launcher.exec_() == QDialog.Accepted: workPlace = launcher.WorkPlace myMainWindow = MyMainWindow(workPlace) myMainWindow.show() sys.exit(app.exec_())
# Main Function if __name__ == '__main__': # Create main app sys.argv += ['--style', 'fusion'] myApp = QGuiApplication(sys.argv) # Setting the application name and organisation # so that the default constructor of QSettings will # create an INI file on disk qApp.setApplicationName('Hamster-QML') qApp.setApplicationVersion(cVERSION) qApp.setOrganizationName('cjc') qApp.setWindowIcon(QIcon('../Resources/Images/hamster-gray_256.png')) # Setting the defaultf format for QSettins to be INI files. # I don't like stuff writing to the Registry on Windows... QSettings.setDefaultFormat(QSettings.IniFormat) # Register the Python type. Its URI is 'SortFilterModelPyQt', it's v1.0 and the type # will be called 'SortFilterModelPyQt' in QML. qmlRegisterType(SortFilterModelPyQt, 'SortFilterModelPyQt', 1, 0, 'SortFilterModelPyQt') # Create the QML Engine engine = QQmlApplicationEngine() engine.addImageProvider("images", ImageProvider()) context = engine.rootContext() # Add the namespace as 'py' in the QML context. If this is done, one can # clearly see which objects are accessed from the python side. py = Namespace() context.setContextProperty('py', py) engine.load('qml/main.qml') sys.exit(myApp.exec_())
class GCodeGenerator(QMainWindow): def __init__(self): super(GCodeGenerator, self).__init__() self.settings = QSettings("GCodeGenerator", "GcodeConfig") self.settings.setDefaultFormat(QSettings.IniFormat) self.materialFile = "millingparameters.json" self.load_ui() self.init_Material() if len(self.settings.allKeys()) > 0: self.init_settings() self.toolBoxObj = None self.gcValues = { 'mm': 'G21', 'inch': 'G20', 'trcr': 'G42', #Tool Radius Compensation Right 'trcl': 'G41', #Tool Radius Compensation Left 'trc': 'G40', #Tool Radius Compensation on (disables G41/G42) } self.window.toolBox.setCurrentIndex(0) self.window.toolBox.currentChanged.connect(self.onTabBarClicked) tbIdx = self.window.toolBox.currentIndex() self.window.toolBox.currentChanged.emit(tbIdx) self.gcodeWidget = GcodeWindow(self) self.commonGcode = CommonGcode(self) self.window.pb_gCode.clicked.connect(self.onGCodeClicked) self.window.toolBox_Pocket.currentChanged.connect( self.onPocketToolChanged) self.window.toolBox_Pocket.currentChanged.emit(0) def load_ui(self): #loader = QUiLoader() path = os.path.join(os.path.dirname(__file__), "form.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) #self.window = loader.load(ui_file, self) self.window = uic.loadUi(ui_file) ui_file.close() self.window.actionGCode_Pre_Post.triggered.connect( self.onActionGCode_Pre_Post) self.window.actionMaterial.triggered.connect(self.onActionMaterial) self.window.actionMachine_Params.triggered.connect( self.onActionMachineParams) def write_settings(self): boolean = {True: 1, False: 0} self.settings.setValue("Preamble", self.window.preamble.text()) self.settings.setValue("PostGcode", self.window.postGcode.text()) self.settings.setValue("Material", self.window.cbMaterial.currentIndex()) self.settings.setValue("Materials", self.window.cbMaterials.currentIndex()) self.settings.setValue("ToolId", self.window.toolId.text()) self.settings.setValue("SpindleSpeed", self.window.spindleSpeed.text()) self.settings.setValue("Direction_CCW", boolean[self.window.dirCCW.isChecked()]) self.settings.setValue("Direction_CW", boolean[self.window.dirCW.isChecked()]) self.settings.setValue("Unit_mm", boolean[self.window.unitMm.isChecked()]) self.settings.setValue("Unit_inch", boolean[self.window.unitInch.isChecked()]) self.settings.setValue( "ViewGcode", boolean[self.window.actionGCode_Pre_Post.isChecked()]) self.settings.setValue("ViewMaterial", boolean[self.window.actionMaterial.isChecked()]) self.settings.setValue( "ViewParams", boolean[self.window.actionMachine_Params.isChecked()]) self.settings.setValue("Speed_XY", self.window.speedXY.text()) self.settings.setValue("Speed_Z", self.window.speedZ.text()) self.settings.setValue("ToolDiameter", self.window.toolDiameter.text()) self.settings.setValue("StartZ", self.window.startZ.text()) self.settings.setValue("SafeZ", self.window.zSafe.text()) self.settings.setValue("Speed_G2G3", self.window.speedG2G3.text()) self.settings.setValue("Speed_Zg1", self.window.speedZg1.text()) self.settings.setValue("Center_X", self.window.centerX.text()) self.settings.setValue("Center_Y", self.window.centerY.text()) self.settings.setValue("DepthTotal", self.window.depthTotal.text()) self.settings.setValue("DepthStep", self.window.depthStep.text()) def init_settings(self): #print(self.settings.fileName()) #print(len(self.settings.allKeys())) self.window.actionGCode_Pre_Post.setChecked( bool(int(self.settings.value("ViewGcode")))) self.window.actionGCode_Pre_Post.triggered.emit() self.window.actionMaterial.setChecked( bool(int(self.settings.value("ViewMaterial")))) self.window.actionMaterial.triggered.emit() self.window.actionMachine_Params.setChecked( bool(int(self.settings.value("ViewParams")))) self.window.actionMachine_Params.triggered.emit() self.window.preamble.setText(self.settings.value("Preamble")) self.window.postGcode.setText(self.settings.value("PostGcode")) self.window.cbMaterial.setCurrentIndex( int(self.settings.value("Material"))) self.window.cbMaterials.setCurrentIndex( int(self.settings.value("Materials"))) self.window.toolId.setText(self.settings.value("ToolId")) self.window.spindleSpeed.setText(self.settings.value("SpindleSpeed")) self.window.dirCCW.setChecked( bool(int(self.settings.value("Direction_CCW")))) self.window.dirCW.setChecked( bool(int(self.settings.value("Direction_CW")))) self.window.unitMm.setChecked(bool(int( self.settings.value("Unit_mm")))) self.window.unitInch.setChecked( bool(int(self.settings.value("Unit_inch")))) self.window.speedXY.setText(self.settings.value("Speed_XY")) self.window.speedZ.setText(self.settings.value("Speed_Z")) self.window.toolDiameter.setText(self.settings.value("ToolDiameter")) self.window.startZ.setText(self.settings.value("StartZ")) self.window.zSafe.setText(self.settings.value("SafeZ")) self.window.speedG2G3.setText(self.settings.value("Speed_G2G3")) self.window.speedZg1.setText(self.settings.value("Speed_Zg1")) self.window.centerX.setText(self.settings.value("Center_X")) self.window.centerY.setText(self.settings.value("Center_Y")) self.window.depthTotal.setText(self.settings.value("DepthTotal")) self.window.depthStep.setText(self.settings.value("DepthStep")) def init_Material(self): with open(self.materialFile, "r") as read_file: self.dicMaterials = json.load(read_file) for (cat, v) in self.dicMaterials.items(): self.window.cbMaterial.addItem(cat) self.window.cbMaterial.currentIndexChanged.connect( self.onMaterialChanged) self.window.cbMaterials.currentIndexChanged.connect( self.onMaterialsChanged) matIdx = self.window.cbMaterial.currentIndex() self.window.cbMaterial.currentIndexChanged.emit(matIdx) def onActionGCode_Pre_Post(self): if self.window.actionGCode_Pre_Post.isChecked(): self.window.frame_Gcode.show() else: self.window.frame_Gcode.hide() def onActionMaterial(self): if self.window.actionMaterial.isChecked(): self.window.frame_Material.show() else: self.window.frame_Material.hide() def onActionMachineParams(self): if self.window.actionMachine_Params.isChecked(): self.window.groupBoxDirection.show() else: self.window.groupBoxDirection.hide() #Slot int def onTabBarClicked(self, idx): self.toolBox = None if idx == 0: from ContourArc import ContourArc contourArc = ContourArc(self) self.toolBoxObj = contourArc elif idx == 1: from ContourRoundRect import ContourRoundRectangle contourRRect = ContourRoundRectangle(self) self.toolBoxObj = contourRRect def onPocketToolChanged(self, idx): if idx == 0: from PocketCircle import PocketCircle pocketCircle = PocketCircle(self) self.toolBoxObj = pocketCircle def onMaterialChanged(self, idx): material = self.window.cbMaterial.currentText() #print(material) with open(self.materialFile, "r") as read_file: self.dicMaterials = json.load(read_file) self.window.cbMaterials.clear() for item in self.dicMaterials[material]: self.window.cbMaterials.addItem(item["Material"]) #print(item["Material"]) def onMaterialsChanged(self, idx): material = self.window.cbMaterial.currentText() materials = self.window.cbMaterials.currentText() #print(material, " ",materials) for item in self.dicMaterials[material]: if item["Material"] == materials: self.window.toolId.setText(str(item["ToolID"])) self.window.spindleSpeed.setText(str(item["Spindel-RPM"])) def onGCodeClicked(self): self.gcodeWidget.dialog.gcodeText.clear() self.gcodeWidget.dialog.gcodeText.appendPlainText( self.commonGcode.getGCode(self)) self.gcodeWidget.show()