diff options
Diffstat (limited to 'examples/corelib/settingseditor/settingseditor.py')
-rw-r--r-- | examples/corelib/settingseditor/settingseditor.py | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/examples/corelib/settingseditor/settingseditor.py b/examples/corelib/settingseditor/settingseditor.py index 266ddda4e..f87a2f4b5 100644 --- a/examples/corelib/settingseditor/settingseditor.py +++ b/examples/corelib/settingseditor/settingseditor.py @@ -7,14 +7,20 @@ import sys from PySide6.QtCore import (QByteArray, QDate, QDateTime, QDir, QEvent, QPoint, - QRect, QRegularExpression, QSettings, QSize, QTime, QTimer, Qt) + QRect, QRegularExpression, QSettings, QSize, QTime, + QTimer, Qt, Slot) from PySide6.QtGui import (QAction, QColor, QIcon, QIntValidator, - QDoubleValidator, QRegularExpressionValidator, QValidator) + QDoubleValidator, QRegularExpressionValidator, + QValidator) from PySide6.QtWidgets import (QAbstractItemView, QApplication, - QCheckBox, QComboBox, QFileDialog, QDialog, QDialogButtonBox, QGridLayout, - QGroupBox, QHeaderView, QInputDialog, QItemDelegate, QLabel, QLineEdit, - QMainWindow, QMessageBox, QStyle, QSpinBox, QStyleOptionViewItem, - QTableWidget, QTableWidgetItem, QTreeWidget, QTreeWidgetItem, QVBoxLayout) + QCheckBox, QComboBox, QFileDialog, QDialog, + QDialogButtonBox, QGridLayout, + QGroupBox, QHeaderView, QInputDialog, + QItemDelegate, QLabel, QLineEdit, + QMainWindow, QMessageBox, QStyle, QSpinBox, + QStyleOptionViewItem, QTableWidget, + QTableWidgetItem, QTreeWidget, QTreeWidgetItem, + QVBoxLayout) class TypeChecker: @@ -144,6 +150,7 @@ class MainWindow(QMainWindow): self.setWindowTitle("Settings Editor") self.resize(500, 600) + @Slot() def open_settings(self): if self.location_dialog is None: self.location_dialog = LocationDialog(self) @@ -156,9 +163,10 @@ class MainWindow(QMainWindow): self.set_settings_object(settings) self.fallbacks_action.setEnabled(True) + @Slot() def open_inifile(self): file_name, _ = QFileDialog.getOpenFileName(self, "Open INI File", - '', "INI Files (*.ini *.conf)") + '', "INI Files (*.ini *.conf)") if file_name: self.load_ini_file(file_name) @@ -170,77 +178,71 @@ class MainWindow(QMainWindow): self.set_settings_object(settings) self.fallbacks_action.setEnabled(False) + @Slot() def open_property_list(self): file_name, _ = QFileDialog.getOpenFileName(self, - "Open Property List", '', "Property List Files (*.plist)") + "Open Property List", '', + "Property List Files (*.plist)") if file_name: settings = QSettings(file_name, QSettings.NativeFormat) self.set_settings_object(settings) self.fallbacks_action.setEnabled(False) + @Slot() def open_registry_path(self): path, ok = QInputDialog.getText(self, "Open Registry Path", - "Enter the path in the Windows registry:", - QLineEdit.Normal, 'HKEY_CURRENT_USER\\') + "Enter the path in the Windows registry:", + QLineEdit.Normal, 'HKEY_CURRENT_USER\\') if ok and path != '': settings = QSettings(path, QSettings.NativeFormat) self.set_settings_object(settings) self.fallbacks_action.setEnabled(False) + @Slot() def about(self): QMessageBox.about(self, "About Settings Editor", - "The <b>Settings Editor</b> example shows how to access " - "application settings using Qt.") - - def create_actions(self): - self._open_settings_act = QtGui.QAction("&Open Application Settings...", - self, shortcut="Ctrl+O", triggered=self.openSettings) - - self._open_ini_file_act = QtGui.QAction("Open I&NI File...", self, - shortcut="Ctrl+N", triggered=self.openIniFile) - - self._open_property_list_act = QtGui.QAction("Open macOS &Property List...", - self, shortcut="Ctrl+P", triggered=self.openPropertyList) + "The <b>Settings Editor</b> example shows how to access " + "application settings using Qt.") def create_actions(self): self.open_settings_action = QAction("&Open Application Settings...", - self, shortcut="Ctrl+O", triggered=self.open_settings) + self, shortcut="Ctrl+O", triggered=self.open_settings) self.open_ini_file_action = QAction("Open I&NI File...", self, - shortcut="Ctrl+N", triggered=self.open_inifile) + shortcut="Ctrl+N", triggered=self.open_inifile) - self.open_property_list_action = QAction("Open macOS &Property List...", - self, shortcut="Ctrl+P", triggered=self.open_property_list) + self.open_property_list_action = QAction("Open macOS &Property List...", self, + shortcut="Ctrl+P", + triggered=self.open_property_list) if sys.platform != 'darwin': self.open_property_list_action.setEnabled(False) self.open_registry_path_action = QAction( - "Open Windows &Registry Path...", self, shortcut="Ctrl+G", - triggered=self.open_registry_path) + "Open Windows &Registry Path...", self, shortcut="Ctrl+G", + triggered=self.open_registry_path) if sys.platform != 'win32': self.open_registry_path_action.setEnabled(False) self.refresh_action = QAction("&Refresh", self, shortcut="Ctrl+R", - enabled=False, triggered=self.settings_tree.refresh) + enabled=False, triggered=self.settings_tree.refresh) - self.exit_action = QAction("E&xit", self, shortcut="Ctrl+Q", - triggered=self.close) + self.exit_action = QAction("E&xit", self, shortcut="Ctrl+Q", triggered=self.close) self.auto_refresh_action = QAction("&Auto-Refresh", self, - shortcut="Ctrl+A", checkable=True, enabled=False) + shortcut="Ctrl+A", checkable=True, enabled=False) self.auto_refresh_action.triggered[bool].connect(self.settings_tree.set_auto_refresh) self.auto_refresh_action.triggered[bool].connect(self.refresh_action.setDisabled) self.fallbacks_action = QAction("&Fallbacks", self, - shortcut="Ctrl+F", checkable=True, enabled=False) + shortcut="Ctrl+F", checkable=True, enabled=False) self.fallbacks_action.triggered[bool].connect(self.settings_tree.set_fallbacks_enabled) self.about_action = QAction("&About", self, triggered=self.about) self.about_Qt_action = QAction("About &Qt", self, - triggered=qApp.aboutQt) + triggered=qApp.aboutQt) # noqa: F821 def create_menus(self): self.file_menu = self.menuBar().addMenu("&File") @@ -473,6 +475,7 @@ class SettingsTree(QTreeWidget): def sizeHint(self): return QSize(800, 600) + @Slot(bool) def set_auto_refresh(self, autoRefresh): self.auto_refresh = autoRefresh @@ -483,15 +486,18 @@ class SettingsTree(QTreeWidget): else: self.refresh_timer.stop() + @Slot(bool) def set_fallbacks_enabled(self, enabled): if self.settings is not None: self.settings.setFallbacksEnabled(enabled) self.refresh() + @Slot() def maybe_refresh(self): if self.state() != QAbstractItemView.EditingState: self.refresh() + @Slot() def refresh(self): if self.settings is None: return @@ -499,7 +505,7 @@ class SettingsTree(QTreeWidget): # The signal might not be connected. try: self.itemChanged.disconnect(self.update_setting) - except: + except Exception: pass self.settings.sync() @@ -522,7 +528,6 @@ class SettingsTree(QTreeWidget): key = ancestor.text(0) + '/' + key ancestor = ancestor.parent() - d = item.data(2, Qt.UserRole) self.settings.setValue(key, item.data(2, Qt.UserRole)) if self.auto_refresh: @@ -694,7 +699,7 @@ class VariantDelegate(QItemDelegate): value = editor.value() else: value = self.value_from_lineedit(editor, model, index) - if not value is None: + if value is not None: model.setData(index, value, Qt.UserRole) model.setData(index, self.display_text(value), Qt.DisplayRole) |