From 86cefe0b1d36d7de9d7a8c7734e697a58b7c923e Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 29 Jan 2024 17:22:29 -0500 Subject: [PATCH 1/3] Application: Minor code style improvements to its config page --- spyder/plugins/application/confpage.py | 57 +++++++++++++++----------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/spyder/plugins/application/confpage.py b/spyder/plugins/application/confpage.py index a287e32766b..f32c79540f8 100644 --- a/spyder/plugins/application/confpage.py +++ b/spyder/plugins/application/confpage.py @@ -178,30 +178,32 @@ def set_open_file(state): screen_resolution_label.setOpenExternalLinks(True) normal_radio = self.create_radiobutton( - _("Normal"), - 'normal_screen_resolution', - button_group=screen_resolution_bg) + _("Normal"), + 'normal_screen_resolution', + button_group=screen_resolution_bg + ) auto_scale_radio = self.create_radiobutton( - _("Enable auto high DPI scaling"), - 'high_dpi_scaling', - button_group=screen_resolution_bg, - tip=_("Set this for high DPI displays"), - restart=True) + _("Enable auto high DPI scaling"), + 'high_dpi_scaling', + button_group=screen_resolution_bg, + tip=_("Set this for high DPI displays"), + restart=True + ) custom_scaling_radio = self.create_radiobutton( - _("Set a custom high DPI scaling"), - 'high_dpi_custom_scale_factor', - button_group=screen_resolution_bg, - tip=_("Set this for high DPI displays when " - "auto scaling does not work"), - restart=True) + _("Set a custom high DPI scaling"), + 'high_dpi_custom_scale_factor', + button_group=screen_resolution_bg, + tip=_("Set this for high DPI displays when auto scaling does not " + "work"), + restart=True + ) self.custom_scaling_edit = self.create_lineedit( "", 'high_dpi_custom_scale_factors', - tip=_("Enter values for different screens " - "separated by semicolons ';'.\n" - "Float values are supported"), + tip=_("Enter values for different screens separated by semicolons " + "';'.\n Float values are supported"), alignment=Qt.Horizontal, regex=r"[0-9]+(?:\.[0-9]*)(;[0-9]+(?:\.[0-9]*))*", restart=True) @@ -243,25 +245,32 @@ def set_open_file(state): def apply_settings(self, options): if 'high_dpi_custom_scale_factors' in options: scale_factors = self.get_option( - 'high_dpi_custom_scale_factors').split(';') + 'high_dpi_custom_scale_factors' + ).split(';') + change_min_scale_factor = False for idx, scale_factor in enumerate(scale_factors[:]): scale_factor = float(scale_factor) if scale_factor < 1.0: change_min_scale_factor = True scale_factors[idx] = "1.0" + if change_min_scale_factor: scale_factors_text = ";".join(scale_factors) QMessageBox.critical( - self, _("Error"), + self, + _("Error"), _("We're sorry but setting a scale factor bellow 1.0 " "isn't possible. Any scale factor bellow 1.0 will " "be set to 1.0"), - QMessageBox.Ok) + QMessageBox.Ok + ) self.custom_scaling_edit.textbox.setText(scale_factors_text) self.set_option( - 'high_dpi_custom_scale_factors', scale_factors_text) + 'high_dpi_custom_scale_factors', scale_factors_text + ) self.changed_options.add('high_dpi_custom_scale_factors') + self.plugin.apply_settings() def _save_lang(self): @@ -278,9 +287,11 @@ def _save_lang(self): self.set_option('interface_language', value) except Exception: QMessageBox.critical( - self, _("Error"), + self, + _("Error"), _("We're sorry but the following error occurred while trying " "to set your selected language:

" "{}").format(traceback.format_exc()), - QMessageBox.Ok) + QMessageBox.Ok + ) return From 269cd5cc03d175d763e927bde4da158fb3109179 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Fri, 2 Feb 2024 18:59:38 -0500 Subject: [PATCH 2/3] Application: Prevent setting scale factors less than 1 with regex --- spyder/plugins/application/confpage.py | 36 +++----------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/spyder/plugins/application/confpage.py b/spyder/plugins/application/confpage.py index f32c79540f8..d244b094249 100644 --- a/spyder/plugins/application/confpage.py +++ b/spyder/plugins/application/confpage.py @@ -30,7 +30,6 @@ class ApplicationConfigPage(PluginConfigPage): - APPLY_CONF_PAGE_SETTINGS = True def setup_page(self): newcb = self.create_checkbox @@ -205,8 +204,9 @@ def set_open_file(state): tip=_("Enter values for different screens separated by semicolons " "';'.\n Float values are supported"), alignment=Qt.Horizontal, - regex=r"[0-9]+(?:\.[0-9]*)(;[0-9]+(?:\.[0-9]*))*", - restart=True) + regex=r"[1-9]+(?:\.[0-9]*)(;[1-9]+(?:\.[0-9]*))*", + restart=True + ) normal_radio.toggled.connect(self.custom_scaling_edit.setDisabled) auto_scale_radio.toggled.connect(self.custom_scaling_edit.setDisabled) @@ -242,36 +242,6 @@ def set_open_file(state): vlayout.addWidget(self.tabs) self.setLayout(vlayout) - def apply_settings(self, options): - if 'high_dpi_custom_scale_factors' in options: - scale_factors = self.get_option( - 'high_dpi_custom_scale_factors' - ).split(';') - - change_min_scale_factor = False - for idx, scale_factor in enumerate(scale_factors[:]): - scale_factor = float(scale_factor) - if scale_factor < 1.0: - change_min_scale_factor = True - scale_factors[idx] = "1.0" - - if change_min_scale_factor: - scale_factors_text = ";".join(scale_factors) - QMessageBox.critical( - self, - _("Error"), - _("We're sorry but setting a scale factor bellow 1.0 " - "isn't possible. Any scale factor bellow 1.0 will " - "be set to 1.0"), - QMessageBox.Ok - ) - self.custom_scaling_edit.textbox.setText(scale_factors_text) - self.set_option( - 'high_dpi_custom_scale_factors', scale_factors_text - ) - self.changed_options.add('high_dpi_custom_scale_factors') - - self.plugin.apply_settings() def _save_lang(self): """ From 3e2ba3b9366bd839142eff8cc03dc521e2a34e12 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sat, 3 Feb 2024 10:18:50 -0500 Subject: [PATCH 3/3] Application: Prevent setting an empty custom scale factor --- spyder/plugins/application/confpage.py | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/spyder/plugins/application/confpage.py b/spyder/plugins/application/confpage.py index d244b094249..5cc6538fa5a 100644 --- a/spyder/plugins/application/confpage.py +++ b/spyder/plugins/application/confpage.py @@ -31,6 +31,10 @@ class ApplicationConfigPage(PluginConfigPage): + def __init__(self, plugin, parent): + super().__init__(plugin, parent) + self.pre_apply_callback = self.perform_checks + def setup_page(self): newcb = self.create_checkbox @@ -176,7 +180,7 @@ def set_open_file(state): screen_resolution_label.setWordWrap(True) screen_resolution_label.setOpenExternalLinks(True) - normal_radio = self.create_radiobutton( + self.normal_radio = self.create_radiobutton( _("Normal"), 'normal_screen_resolution', button_group=screen_resolution_bg @@ -189,7 +193,7 @@ def set_open_file(state): restart=True ) - custom_scaling_radio = self.create_radiobutton( + self.custom_scaling_radio = self.create_radiobutton( _("Set a custom high DPI scaling"), 'high_dpi_custom_scale_factor', button_group=screen_resolution_bg, @@ -208,19 +212,21 @@ def set_open_file(state): restart=True ) - normal_radio.toggled.connect(self.custom_scaling_edit.setDisabled) + self.normal_radio.toggled.connect(self.custom_scaling_edit.setDisabled) auto_scale_radio.toggled.connect(self.custom_scaling_edit.setDisabled) - custom_scaling_radio.toggled.connect( - self.custom_scaling_edit.setEnabled) + self.custom_scaling_radio.toggled.connect( + self.custom_scaling_edit.setEnabled + ) # Layout Screen resolution screen_resolution_layout = QVBoxLayout() screen_resolution_layout.addWidget(screen_resolution_label) screen_resolution_inner_layout = QGridLayout() - screen_resolution_inner_layout.addWidget(normal_radio, 0, 0) + screen_resolution_inner_layout.addWidget(self.normal_radio, 0, 0) screen_resolution_inner_layout.addWidget(auto_scale_radio, 1, 0) - screen_resolution_inner_layout.addWidget(custom_scaling_radio, 2, 0) + screen_resolution_inner_layout.addWidget( + self.custom_scaling_radio, 2, 0) screen_resolution_inner_layout.addWidget( self.custom_scaling_edit, 2, 1) @@ -242,6 +248,14 @@ def set_open_file(state): vlayout.addWidget(self.tabs) self.setLayout(vlayout) + def perform_checks(self): + # Prevent setting an empty scale factor in case users try to do it. + # See spyder-ide/spyder#21733 for the details. + if self.custom_scaling_radio.isChecked(): + scale_factor = self.custom_scaling_edit.textbox.text() + if scale_factor == "": + self.normal_radio.setChecked(True) + self.changed_options.add('high_dpi_custom_scale_factors') def _save_lang(self): """