Skip to content

Commit

Permalink
Application: Prevent setting an empty custom scale factor
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Feb 3, 2024
1 parent 269cd5c commit 3e2ba3b
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions spyder/plugins/application/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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):
"""
Expand Down

0 comments on commit 3e2ba3b

Please sign in to comment.