Skip to content

Commit

Permalink
Merge from 5.x: PR #21763
Browse files Browse the repository at this point in the history
Fixes #21733
  • Loading branch information
ccordoba12 committed Feb 3, 2024
2 parents 12e7033 + 672d440 commit b7db1b7
Showing 1 changed file with 45 additions and 52 deletions.
97 changes: 45 additions & 52 deletions spyder/plugins/application/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@


class ApplicationConfigPage(PluginConfigPage):
APPLY_CONF_PAGE_SETTINGS = True

def __init__(self, plugin, parent):
super().__init__(plugin, parent)
self.pre_apply_callback = self.perform_checks

def setup_page(self):
newcb = self.create_checkbox
Expand Down Expand Up @@ -188,56 +191,59 @@ def set_open_file(state):
screen_resolution_label.setWordWrap(True)
screen_resolution_label.setOpenExternalLinks(True)

normal_radio = self.create_radiobutton(
_("Normal"),
'normal_screen_resolution',
button_group=screen_resolution_bg)
self.normal_radio = self.create_radiobutton(
_("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)

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)
_("Enable auto high DPI scaling"),
'high_dpi_scaling',
button_group=screen_resolution_bg,
tip=_("Set this for high DPI displays"),
restart=True
)

self.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
)

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)
regex=r"[1-9]+(?:\.[0-9]*)(;[1-9]+(?:\.[0-9]*))*",
restart=True
)

normal_radio.radiobutton.toggled.connect(
self.normal_radio.radiobutton.toggled.connect(
self.custom_scaling_edit.textbox.setDisabled)
auto_scale_radio.radiobutton.toggled.connect(
self.custom_scaling_edit.textbox.setDisabled)
custom_scaling_radio.radiobutton.toggled.connect(
self.custom_scaling_radio.radiobutton.toggled.connect(
self.custom_scaling_edit.textbox.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.radiobutton, 1, 0)
screen_resolution_inner_layout.addWidget(
auto_scale_radio.radiobutton.help_label, 1, 1)
screen_resolution_inner_layout.addWidget(
custom_scaling_radio.radiobutton, 2, 0)
self.custom_scaling_radio.radiobutton, 2, 0)
screen_resolution_inner_layout.addWidget(
custom_scaling_radio.radiobutton.help_label, 2, 1)
self.custom_scaling_radio.radiobutton.help_label, 2, 1)
screen_resolution_inner_layout.addWidget(
self.custom_scaling_edit.textbox, 2, 2)
screen_resolution_inner_layout.addWidget(
Expand All @@ -260,27 +266,13 @@ def set_open_file(state):

self.create_tab(_("Advanced settings"), advanced_widget)

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)
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.radiobutton.isChecked():
scale_factor = self.custom_scaling_edit.textbox.text()
if scale_factor == "":
self.normal_radio.radiobutton.setChecked(True)
self.changed_options.add('high_dpi_custom_scale_factors')

um = self.plugin.get_plugin(Plugins.UpdateManager, error=False)
Expand All @@ -290,7 +282,6 @@ def apply_settings(self, options):
):
um.update_manager_status.set_no_status()

self.plugin.apply_settings()

def _save_lang(self):
"""
Expand All @@ -306,9 +297,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:<br><br>"
"<tt>{}</tt>").format(traceback.format_exc()),
QMessageBox.Ok)
QMessageBox.Ok
)
return

0 comments on commit b7db1b7

Please sign in to comment.