Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Make SpyderPalette inherit from QDarkStyle palettes and remove QStylePalette #21844

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions spyder/api/widgets/comboboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)

# Local imports
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.stylesheet import AppStyle, WIN


Expand All @@ -56,7 +56,7 @@ class _SpyderComboBoxDelegate(QStyledItemDelegate):
def paint(self, painter, option, index):
data = index.data(Qt.AccessibleDescriptionRole)
if data and data == "separator":
painter.setPen(QColor(QStylePalette.COLOR_BACKGROUND_6))
painter.setPen(QColor(SpyderPalette.COLOR_BACKGROUND_6))
painter.drawLine(
option.rect.left() + AppStyle.MarginSize,
option.rect.center().y(),
Expand Down Expand Up @@ -149,7 +149,7 @@ def _generate_stylesheet(self):
# Make color of hovered combobox items match the one used in other
# Spyder widgets
css["QComboBox QAbstractItemView::item:selected:active"].setValues(
backgroundColor=QStylePalette.COLOR_BACKGROUND_3,
backgroundColor=SpyderPalette.COLOR_BACKGROUND_3,
)

return css
Expand Down Expand Up @@ -231,8 +231,8 @@ def hidePopup(self):
# Make borders rounded when popup is not visible. This doesn't work
# reliably on Mac.
self._css.QComboBox.setValues(
borderBottomLeftRadius=QStylePalette.SIZE_BORDER_RADIUS,
borderBottomRightRadius=QStylePalette.SIZE_BORDER_RADIUS,
borderBottomLeftRadius=SpyderPalette.SIZE_BORDER_RADIUS,
borderBottomRightRadius=SpyderPalette.SIZE_BORDER_RADIUS,
)

self.setStyleSheet(self._css.toString())
Expand Down
14 changes: 7 additions & 7 deletions spyder/api/widgets/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Local imports
from spyder.api.config.fonts import SpyderFontType, SpyderFontsMixin
from spyder.utils.qthelpers import add_actions, set_menu_icons, SpyderAction
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.stylesheet import AppStyle, MAC, WIN


Expand Down Expand Up @@ -391,12 +391,12 @@ def _generate_stylesheet(cls):
paddingTop=f'{2 * AppStyle.MarginSize}px',
paddingBottom=f'{2 * AppStyle.MarginSize}px',
# This uses the same color as the separator
border=f"1px solid {QStylePalette.COLOR_BACKGROUND_6}"
border=f"1px solid {SpyderPalette.COLOR_BACKGROUND_6}"
)

# Set the right background color This is the only way to do it!
css['QWidget:disabled QMenu'].setValues(
backgroundColor=QStylePalette.COLOR_BACKGROUND_3,
backgroundColor=SpyderPalette.COLOR_BACKGROUND_3,
)

# Add padding around separators to prevent that hovering on items hides
Expand Down Expand Up @@ -426,19 +426,19 @@ def _generate_stylesheet(cls):
# Set hover and pressed state of items
for state in ['selected', 'pressed']:
if state == 'selected':
bg_color = QStylePalette.COLOR_BACKGROUND_4
bg_color = SpyderPalette.COLOR_BACKGROUND_4
else:
bg_color = QStylePalette.COLOR_BACKGROUND_5
bg_color = SpyderPalette.COLOR_BACKGROUND_5

css[f"QMenu::item:{state}"].setValues(
backgroundColor=bg_color,
borderRadius=QStylePalette.SIZE_BORDER_RADIUS
borderRadius=SpyderPalette.SIZE_BORDER_RADIUS
)

# Set disabled state of items
for state in ['disabled', 'selected:disabled']:
css[f"QMenu::item:{state}"].setValues(
color=QStylePalette.COLOR_DISABLED,
color=SpyderPalette.COLOR_DISABLED,
backgroundColor="transparent"
)

Expand Down
6 changes: 3 additions & 3 deletions spyder/api/widgets/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Local imports
from spyder.api.exceptions import SpyderAPIError
from spyder.api.widgets.mixins import SpyderWidgetMixin
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.qthelpers import create_waitspinner


Expand Down Expand Up @@ -187,8 +187,8 @@ def _stylesheet(self):
stylesheet = ("QToolTip {{background-color: {background_color};"
"color: {color};"
"border: none}}").format(
background_color=QStylePalette.COLOR_ACCENT_2,
color=QStylePalette.COLOR_TEXT_1
background_color=SpyderPalette.COLOR_ACCENT_2,
color=SpyderPalette.COLOR_TEXT_1
)
return stylesheet

Expand Down
4 changes: 2 additions & 2 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
from spyder.utils import encoding, programs
from spyder.utils.icon_manager import ima
from spyder.utils.misc import select_port, getcwd_or_home
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.qthelpers import file_uri, qapplication, start_file
from spyder.utils.stylesheet import APP_STYLESHEET

Expand Down Expand Up @@ -298,7 +298,7 @@ def signal_handler(signum, frame=None):
"restart your computer: <br><br><span "
"style=\'color: {color}\'><b>netsh winsock reset "
"</b></span><br>").format(
color=QStylePalette.COLOR_BACKGROUND_4)
color=SpyderPalette.COLOR_BACKGROUND_4)
)
else:
self.open_files_server = socket.socket(socket.AF_INET,
Expand Down
4 changes: 2 additions & 2 deletions spyder/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from spyder.utils.external.dafsa.dafsa import DAFSA
from spyder.utils.image_path_manager import get_image_path
from spyder.utils.installers import running_installer_test
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.qthelpers import file_uri, qapplication

# For spyder-ide/spyder#7447.
Expand Down Expand Up @@ -264,7 +264,7 @@ def set_links_color(app):

This was taken from QDarkstyle, which is MIT licensed.
"""
color = QStylePalette.COLOR_ACCENT_4
color = SpyderPalette.COLOR_ACCENT_4
qcolor = QColor(color)

app_palette = app.palette()
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/appearance/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from spyder.config.manager import CONF
from spyder.plugins.appearance.widgets import SchemeEditor
from spyder.utils import syntaxhighlighters
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.stylesheet import AppStyle
from spyder.widgets.simplecodeeditor import SimpleCodeEditor

Expand Down Expand Up @@ -490,7 +490,7 @@ def is_dark_interface(self):
We need to do this because when applying settings we can't
detect correctly the current theme.
"""
return dark_color(QStylePalette.COLOR_BACKGROUND_1)
return dark_color(SpyderPalette.COLOR_BACKGROUND_1)

def color_scheme_and_ui_theme_mismatch(self, color_scheme, ui_theme):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Local imports
from spyder.api.preferences import SpyderPreferencesTab
from spyder.config.base import _
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette


class IntrospectionConfigTab(SpyderPreferencesTab):
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, parent):
'preload_modules'
)
modules_textedit.textbox.setStyleSheet(
f"border: 1px solid {QStylePalette.COLOR_BACKGROUND_2};"
f"border: 1px solid {SpyderPalette.COLOR_BACKGROUND_2};"
)

advanced_layout = QVBoxLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from spyder.config.base import _
from spyder.plugins.completion.api import SUPPORTED_LANGUAGES
from spyder.utils.misc import check_connection_port
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.programs import find_program
from spyder.widgets.helperwidgets import ItemDelegate
from spyder.widgets.simplecodeeditor import SimpleCodeEditor
Expand Down Expand Up @@ -500,7 +500,7 @@ def __init__(self, parent):
self.widths = []

# Needed to compensate for the HTMLDelegate color selection unawareness
self.text_color = QStylePalette.COLOR_TEXT_1
self.text_color = SpyderPalette.COLOR_TEXT_1

def sortByName(self):
"""Qt Override."""
Expand Down
8 changes: 4 additions & 4 deletions spyder/plugins/console/widgets/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

from spyder.plugins.editor.widgets.base import TextEditBaseWidget
from spyder.plugins.console.utils.ansihandler import ANSIEscapeCodeHandler
from spyder.utils.palette import QStylePalette, SpyderPalette
from spyder.utils.palette import SpyderPalette


MAIN_BG_COLOR = QStylePalette.COLOR_BACKGROUND_1
MAIN_DEFAULT_FG_COLOR = QStylePalette.COLOR_TEXT_1
MAIN_BG_COLOR = SpyderPalette.COLOR_BACKGROUND_1
MAIN_DEFAULT_FG_COLOR = SpyderPalette.COLOR_TEXT_1
MAIN_ERROR_FG_COLOR = SpyderPalette.COLOR_ERROR_1
MAIN_TB_FG_COLOR = QStylePalette.COLOR_ACCENT_3
MAIN_TB_FG_COLOR = SpyderPalette.COLOR_ACCENT_3
MAIN_PROMPT_FG_COLOR = SpyderPalette.COLOR_SUCCESS_1

def insert_text_to(cursor, text, fmt):
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/debugger/widgets/breakpoint_table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from spyder.api.widgets.main_widget import PluginMainWidgetMenus
from spyder.api.widgets.mixins import SpyderWidgetMixin
from spyder.utils.sourcecode import disambiguate_fname
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette


# --- Constants
Expand Down Expand Up @@ -205,8 +205,8 @@ def __init__(self, parent, data):
css.setValues(
borderTopLeftRadius='0px',
borderBottomLeftRadius='0px',
borderTopRightRadius=QStylePalette.SIZE_BORDER_RADIUS,
borderBottomRightRadius=QStylePalette.SIZE_BORDER_RADIUS,
borderTopRightRadius=SpyderPalette.SIZE_BORDER_RADIUS,
borderBottomRightRadius=SpyderPalette.SIZE_BORDER_RADIUS,
)
self.setStyleSheet(css.toString())

Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/debugger/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
FramesBrowser, FramesBrowserState)
from spyder.plugins.debugger.widgets.breakpoint_table_view import (
BreakpointTableView, BreakpointTableViewActions)
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette


# =============================================================================
Expand Down Expand Up @@ -187,7 +187,7 @@ def __init__(self, name=None, plugin=None, parent=None):
# This is necessary so that the border radius is maintained when
# showing/hiding the breakpoints table
self.splitter.setStyleSheet(
f"border-radius: {QStylePalette.SIZE_BORDER_RADIUS}"
f"border-radius: {SpyderPalette.SIZE_BORDER_RADIUS}"
)

# Layout
Expand Down Expand Up @@ -768,7 +768,7 @@ def _update_stylesheet(self, is_table_shown=False):
if is_table_shown:
border_radius = '0px'
else:
border_radius = QStylePalette.SIZE_BORDER_RADIUS
border_radius = SpyderPalette.SIZE_BORDER_RADIUS

css = qstylizer.style.StyleSheet()
css.setValues(
Expand Down
1 change: 0 additions & 1 deletion spyder/plugins/editor/panels/codefolding.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ def _add_fold_decoration(self, block, end_line):
deco.select_line()
deco.set_background(self._get_scope_highlight_color())
deco.set_full_width(flag=True, clear=True)

self._block_decos[start_line] = deco
self.editor.decorations.add(deco, key='folded')

Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,7 @@ def create_new_cell(self):
cursor.movePosition(QTextCursor.StartOfBlock)
cursor.insertText(firstline)
cursor.endEditBlock()

# ---- Kill ring handlers
# Taken from Jupyter's QtConsole
# Copyright (c) 2001-2015, IPython Development Team
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/editor/widgets/editorstack/editorstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from spyder.py3compat import to_text_string
from spyder.utils import encoding, sourcecode, syntaxhighlighters
from spyder.utils.misc import getcwd_or_home
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.qthelpers import mimedata2url, create_waitspinner
from spyder.utils.stylesheet import PANES_TABBAR_STYLESHEET
from spyder.widgets.tabs import BaseTabs
Expand Down Expand Up @@ -701,7 +701,7 @@ def create_top_widgets(self):
css.QToolBar.setValues(
margin='0px',
padding='4px',
borderBottom=f'1px solid {QStylePalette.COLOR_BACKGROUND_4}'
borderBottom=f'1px solid {SpyderPalette.COLOR_BACKGROUND_4}'
)
self.top_toolbar.setStyleSheet(css.toString())

Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/editor/widgets/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from spyder.config.base import running_under_pytest
from spyder.plugins.editor.widgets.editorstack.editorstack import EditorStack
from spyder.py3compat import qbytearray_to_str
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -275,6 +275,6 @@ def set_layout_settings(self, settings, dont_goto=None):
def _stylesheet(self):
css = qstylizer.style.StyleSheet()
css.QSplitter.setValues(
background=QStylePalette.COLOR_BACKGROUND_1
background=SpyderPalette.COLOR_BACKGROUND_1
)
return css.toString()
6 changes: 3 additions & 3 deletions spyder/plugins/findinfiles/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
MAX_PATH_HISTORY, SearchInComboBox)
from spyder.plugins.findinfiles.widgets.search_thread import SearchThread
from spyder.utils.misc import regexp_error_msg
from spyder.utils.palette import QStylePalette, SpyderPalette
from spyder.utils.palette import SpyderPalette, SpyderPalette
from spyder.utils.stylesheet import AppStyle
from spyder.widgets.comboboxes import PatternComboBox
from spyder.widgets.helperwidgets import PaneEmptyWidget


# ---- Constants
# -----------------------------------------------------------------------------
MAIN_TEXT_COLOR = QStylePalette.COLOR_TEXT_1
MAIN_TEXT_COLOR = SpyderPalette.COLOR_TEXT_1
MAX_COMBOBOX_WIDTH = AppStyle.FindMinWidth + 80 # In pixels
MIN_COMBOBOX_WIDTH = AppStyle.FindMinWidth - 80 # In pixels

Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(self, name=None, plugin=None, parent=None):
_("Search the content of text files in any directory using the "
"search box.")
)

self.search_text_edit = PatternComboBox(
self,
items=search_text,
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/findinfiles/widgets/results_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from spyder.plugins.findinfiles.widgets.search_thread import (
ELLIPSIS, MAX_RESULT_LENGTH)
from spyder.utils import icon_manager as ima
from spyder.utils.palette import QStylePalette
from spyder.utils.palette import SpyderPalette
from spyder.utils.stylesheet import AppStyle
from spyder.widgets.onecolumntree import OneColumnTree

Expand Down Expand Up @@ -127,7 +127,7 @@ class ItemDelegate(QStyledItemDelegate):
def __init__(self, parent):
super().__init__(parent)
self._margin = None
self._background_color = QColor(QStylePalette.COLOR_BACKGROUND_3)
self._background_color = QColor(SpyderPalette.COLOR_BACKGROUND_3)
self.width = 0

def paint(self, painter, option, index):
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/findinfiles/widgets/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
SearchInComboBoxItems
)
from spyder.plugins.findinfiles.widgets.search_thread import SearchThread
from spyder.utils.palette import QStylePalette, SpyderPalette
from spyder.utils.palette import SpyderPalette, SpyderPalette
from spyder.utils.stylesheet import APP_STYLESHEET


Expand Down Expand Up @@ -249,15 +249,15 @@ def test_truncate_result_with_different_input(findinfiles, qtbot, line_input):
line_input_expected = line_input

expected_result = (
f'<span style="color:{QStylePalette.COLOR_TEXT_1}">'
f'<span style="color:{SpyderPalette.COLOR_TEXT_1}">'
f'{line_input_expected[:slice_start]}'
f'<span style="background-color:{SpyderPalette.COLOR_OCCURRENCE_4}">'
f'{line_input_expected[slice_start:slice_end]}</span>'
f'{line_input_expected[slice_end:]}</span>'
)

# when
thread = SearchThread(None, '', text_color=QStylePalette.COLOR_TEXT_1)
thread = SearchThread(None, '', text_color=SpyderPalette.COLOR_TEXT_1)
truncated_line = thread.truncate_result(line_input, slice_start,
slice_end)
# then
Expand Down
Loading