From de11bc484cd31e340d70e3690d584d189bf99cc5 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Sun, 9 Jun 2024 22:17:14 +0300 Subject: [PATCH] Make Windows the default window style on windows, not GTK+ --- src/bitmessageqt/__init__.py | 18 ++++++++++++++---- src/bitmessageqt/settings.py | 12 +++++------- src/bitmessageqt/tests/settings.py | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 7f767b03..1b1a7885 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -62,6 +62,9 @@ except ImportError: get_plugins = False +is_windows = sys.platform.startswith('win') + + # TODO: rewrite def powQueueSize(): """Returns the size of queues.workerQueue including current unfinished work""" @@ -80,7 +83,7 @@ def openKeysFile(): keysfile = os.path.join(state.appdata, 'keys.dat') if 'linux' in sys.platform: subprocess.call(["xdg-open", keysfile]) - elif sys.platform.startswith('win'): + elif is_windows: os.startfile(keysfile) # pylint: disable=no-member @@ -868,7 +871,7 @@ class MyForm(settingsmixin.SMainWindow): """ startonlogon = config.safeGetBoolean( 'bitmessagesettings', 'startonlogon') - if sys.platform.startswith('win'): # Auto-startup for Windows + if is_windows: # Auto-startup for Windows RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" settings = QtCore.QSettings( RUN_PATH, QtCore.QSettings.NativeFormat) @@ -4233,6 +4236,14 @@ class BitmessageQtApplication(QtGui.QApplication): # Unique identifier for this application uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c' + @staticmethod + def get_windowstyle(): + """Get window style set in config or default""" + return config.safeGet( + 'bitmessagesettings', 'windowstyle', + 'Windows' if is_windows else 'GTK+' + ) + def __init__(self, *argv): super(BitmessageQtApplication, self).__init__(*argv) id = BitmessageQtApplication.uuid @@ -4241,8 +4252,7 @@ class BitmessageQtApplication(QtGui.QApplication): QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org") QtCore.QCoreApplication.setApplicationName("pybitmessageqt") - self.setStyle( - config.safeGet('bitmessagesettings', 'windowstyle', 'GTK+')) + self.setStyle(self.get_windowstyle()) font = config.safeGet('bitmessagesettings', 'font') if font: diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 44cad4c9..eec3d69f 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -45,6 +45,7 @@ class SettingsDialog(QtGui.QDialog): super(SettingsDialog, self).__init__(parent) widgets.load('settings.ui', self) + self.app = QtGui.QApplication.instance() self.parent = parent self.firstrun = firstrun self.config = config_obj @@ -87,14 +88,13 @@ class SettingsDialog(QtGui.QDialog): """Adjust all widgets state according to config settings""" # pylint: disable=too-many-branches,too-many-statements - current_style = config.safeGet( - 'bitmessagesettings', 'windowstyle', 'GTK+') + current_style = self.app.get_windowstyle() for i, sk in enumerate(QtGui.QStyleFactory.keys()): self.comboBoxStyle.addItem(sk) if sk == current_style: self.comboBoxStyle.setCurrentIndex(i) - self.save_font_setting(QtGui.QApplication.instance().font()) + self.save_font_setting(self.app.font()) if not self.parent.tray.isSystemTrayAvailable(): self.groupBoxTray.setEnabled(False) @@ -148,7 +148,7 @@ class SettingsDialog(QtGui.QDialog): "MainWindow", "Tray notifications not yet supported on your OS.")) - if 'win' not in sys.platform and not self.parent.desktop: + if not sys.platform.startswith('win') and not self.parent.desktop: self.checkBoxStartOnLogon.setDisabled(True) self.checkBoxStartOnLogon.setText(_translate( "MainWindow", "Start-on-login not yet supported on your OS.")) @@ -372,9 +372,7 @@ class SettingsDialog(QtGui.QDialog): self.checkBoxReplyBelow.isChecked())) window_style = str(self.comboBoxStyle.currentText()) - if self.config.safeGet( - 'bitmessagesettings', 'windowstyle', 'GTK+' - ) != window_style or self.config.safeGet( + if self.app.get_windowstyle() != window_style or self.config.safeGet( 'bitmessagesettings', 'font' ) != self.font_setting: self.config.set('bitmessagesettings', 'windowstyle', window_style) diff --git a/src/bitmessageqt/tests/settings.py b/src/bitmessageqt/tests/settings.py index 170f8f40..bad28ed7 100644 --- a/src/bitmessageqt/tests/settings.py +++ b/src/bitmessageqt/tests/settings.py @@ -43,7 +43,8 @@ class TestSettings(TestBase): self.assertIs(style_setting, None) self.assertIs(font_setting, None) style_control = self.dialog.comboBoxStyle - self.assertEqual(style_control.currentText(), 'GTK+') + self.assertEqual( + style_control.currentText(), self.app.get_windowstyle()) def call_font_dialog(): """A function to get the open font dialog and accept it"""