Skip to content

Commit

Permalink
Preferences: Make several adjustments per operating system
Browse files Browse the repository at this point in the history
- Set default and min sizes for its dialog.
- Increase items padding on Linux.
- Decrease contents area width on Windows and increase it on Linux.
- Adjust min height of editor config page to avoid clipped text.
  • Loading branch information
ccordoba12 committed Oct 24, 2023
1 parent 7c7c396 commit 66700f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
4 changes: 3 additions & 1 deletion spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@
('preferences',
{
'enable': True,
'dialog_size': (990, 715),
'dialog_size': (
(1010, 725) if MAC else ((900, 670) if WIN else (950, 690))
),
}),
('project_explorer',
{
Expand Down
19 changes: 16 additions & 3 deletions spyder/plugins/editor/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

"""Editor config page."""

import os
import sys

from qtpy.QtWidgets import (QGridLayout, QGroupBox, QHBoxLayout, QLabel,
QVBoxLayout)

Expand Down Expand Up @@ -37,16 +40,26 @@ def __init__(self, plugin, parent):
self.add_newline_box = None
self.remove_trail_newline_box = None

# *********************** IMPORTANT NOTES *****************************
# * This value needs to be ajusted if we add new options to the
# "Advanced settings" tab.
# * We need to do this so that the text of some options is not clipped.
if os.name == "nt":
min_height = 620
elif sys.platform == "darwin":
min_height = 760
else:
min_height = 670

self.setMinimumHeight(min_height)

def get_name(self):
return _("Editor")

def get_icon(self):
return ima.icon('edit')

def setup_page(self):
# We need to set this so that the text of some options is not clipped
self.setMinimumHeight(670)

newcb = self.create_checkbox

# --- Display tab ---
Expand Down
28 changes: 19 additions & 9 deletions spyder/plugins/preferences/widgets/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

# Standard library imports
import sys

# Third party imports
from qtpy.QtCore import QSize, Qt, Signal, Slot
from qtpy.QtGui import QFontMetricsF
Expand Down Expand Up @@ -44,9 +41,13 @@ class ConfigDialog(QDialog, SpyderFontsMixin):

# Constants
ITEMS_MARGIN = 2 * AppStyle.MarginSize
ITEMS_PADDING = AppStyle.MarginSize
CONTENTS_WIDTH = 230
ITEMS_PADDING = (
AppStyle.MarginSize if (MAC or WIN) else 2 * AppStyle.MarginSize
)
CONTENTS_WIDTH = 230 if MAC else (200 if WIN else 240)
ICON_SIZE = 20
MIN_WIDTH = 940 if MAC else (875 if WIN else 920)
MIN_HEIGHT = 700 if MAC else (660 if WIN else 670)

def __init__(self, parent=None):
QDialog.__init__(self, parent)
Expand All @@ -59,6 +60,10 @@ def __init__(self, parent=None):
self._is_shown = False
self._separators = []

# Size
self.setMinimumWidth(self.MIN_WIDTH)
self.setMinimumHeight(self.MIN_HEIGHT)

# Widgets
self.pages_widget = QStackedWidget(self)
self.contents_widget = QListWidget(self)
Expand Down Expand Up @@ -189,7 +194,12 @@ def add_separator(self):
# Solution taken from https://stackoverflow.com/a/24819554/438386
item = QListWidgetItem(self.contents_widget)
item.setFlags(Qt.NoItemFlags)
item.setSizeHint(QSize(9, 9))

size = (
AppStyle.MarginSize * 3 if (MAC or WIN)
else AppStyle.MarginSize * 5
)
item.setSizeHint(QSize(size, size))

hline = QFrame(self.contents_widget)
hline.setFrameShape(QFrame.HLine)
Expand Down Expand Up @@ -318,7 +328,7 @@ def _add_tooltips(self):
scrollbar = self.contents_widget.verticalScrollBar()

if scrollbar.isVisible():
if sys.platform == 'darwin':
if MAC:
# This is a crude heuristic to detect if we need to add
# tooltips on Mac. However, it's the best we can do
# (the approach for other OSes below ends up adding
Expand All @@ -341,7 +351,7 @@ def _adjust_items_margin(self):
We need to do this only in Mac because Qt doesn't account for the
scrollbar width in most widgets.
"""
if sys.platform == 'darwin':
if MAC:
scrollbar = self.contents_widget.verticalScrollBar()
extra_margin = (
AppStyle.MacScrollBarWidth if scrollbar.isVisible() else 0
Expand All @@ -367,7 +377,7 @@ def _adjust_separators_width(self):
We need to do this only in Mac because Qt doesn't set the widths
correctly when there are elided items.
"""
if sys.platform == 'darwin':
if MAC:
scrollbar = self.contents_widget.verticalScrollBar()
for sep in self._separators:
if self.CONTENTS_WIDTH != 230:
Expand Down

0 comments on commit 66700f0

Please sign in to comment.