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: Fix showing text in the dark theme for keyboard sequences in the Shortcurts page (Preferences) #21215

Merged
merged 2 commits into from
Aug 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from spyder.plugins.completion.api import SUPPORTED_LANGUAGES
from spyder.plugins.completion.providers.languageserver.widgets import (
LSPServerTable)
from spyder.utils.icon_manager import ima


LSP_URL = "https://microsoft.github.io/language-server-protocol"

Expand All @@ -45,7 +45,7 @@ def __init__(self, parent):

# Servers table
table_group = QGroupBox(_('Available servers:'))
self.table = LSPServerTable(self, text_color=ima.MAIN_FG_COLOR)
self.table = LSPServerTable(self)
self.table.setMaximumHeight(150)
table_layout = QVBoxLayout()
table_layout.addWidget(self.table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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.programs import find_program
from spyder.widgets.helperwidgets import ItemDelegate
from spyder.widgets.simplecodeeditor import SimpleCodeEditor
Expand Down Expand Up @@ -484,7 +485,7 @@ def get_options(self):


class LSPServersModel(QAbstractTableModel):
def __init__(self, parent, text_color=None, text_color_highlight=None):
def __init__(self, parent):
QAbstractTableModel.__init__(self)
self._parent = parent

Expand All @@ -498,17 +499,7 @@ def __init__(self, parent, text_color=None, text_color_highlight=None):
self.widths = []

# Needed to compensate for the HTMLDelegate color selection unawareness
palette = parent.palette()
if text_color is None:
self.text_color = palette.text().color().name()
else:
self.text_color = text_color

if text_color_highlight is None:
self.text_color_highlight = \
palette.highlightedText().color().name()
else:
self.text_color_highlight = text_color_highlight
self.text_color = QStylePalette.COLOR_TEXT_1

def sortByName(self):
"""Qt Override."""
Expand Down Expand Up @@ -582,11 +573,11 @@ def reset(self):


class LSPServerTable(QTableView):
def __init__(self, parent, text_color=None):
def __init__(self, parent):
QTableView.__init__(self, parent)
self._parent = parent
self.delete_queue = []
self.source_model = LSPServersModel(self, text_color=text_color)
self.source_model = LSPServersModel(self)
self.setModel(self.source_model)
self.setItemDelegateForColumn(CMD, ItemDelegate(self))
self.setSelectionBehavior(QAbstractItemView.SelectRows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class SnippetsModel(QAbstractTableModel):
TRIGGER = 0
DESCRIPTION = 1

def __init__(self, parent, text_color=None, text_color_highlight=None):
def __init__(self, parent):
QAbstractTableModel.__init__(self)
self.parent = parent

Expand All @@ -418,19 +418,6 @@ def __init__(self, parent, text_color=None, text_color_highlight=None):
self.label = QLabel()
self.widths = []

# Needed to compensate for the HTMLDelegate color selection unawareness
palette = parent.palette()
if text_color is None:
self.text_color = palette.text().color().name()
else:
self.text_color = text_color

if text_color_highlight is None:
self.text_color_highlight = \
palette.highlightedText().color().name()
else:
self.text_color_highlight = text_color_highlight

def sortByName(self):
self.snippets = sorted(self.snippets, key=lambda x: x.trigger_text)
self.reset()
Expand Down Expand Up @@ -493,9 +480,9 @@ def __init__(self, parent):
self.awaiting_queue = {}
self.parent = parent

def get_model(self, table, language, text_color=None):
def get_model(self, table, language):
if language not in self.models:
language_model = SnippetsModel(table, text_color=text_color)
language_model = SnippetsModel(table)
to_add = self.awaiting_queue.pop(language, [])
self.load_snippets(language, language_model, to_add=to_add)
self.models[language] = language_model
Expand Down Expand Up @@ -660,13 +647,12 @@ def import_snippets(self, filename):


class SnippetTable(QTableView):
def __init__(self, parent, proxy, language=None, text_color=None):
def __init__(self, parent, proxy, language=None):
super(SnippetTable, self).__init__()
self._parent = parent
self.language = language
self.proxy = proxy
self.source_model = proxy.get_model(
self, language.lower(), text_color=text_color)
self.source_model = proxy.get_model(self, language.lower())
self.setModel(self.source_model)
self.setItemDelegateForColumn(CMD, ItemDelegate(self))
self.setSelectionBehavior(QAbstractItemView.SelectRows)
Expand Down
11 changes: 3 additions & 8 deletions spyder/plugins/shortcuts/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@

"""Shortcut configuration page."""

# Standard library imports
import re

# Third party imports
from qtpy import PYQT5
from qtpy.QtWidgets import (QHBoxLayout, QLabel, QMessageBox, QPushButton,
QVBoxLayout)

# Local imports
from spyder.api.preferences import PluginConfigPage
from spyder.api.translations import _
from spyder.plugins.shortcuts.widgets.table import (ShortcutFinder,
ShortcutsTable)
from spyder.utils.icon_manager import ima
from spyder.plugins.shortcuts.widgets.table import (
ShortcutFinder, ShortcutsTable)


class ShortcutsConfigPage(PluginConfigPage):
APPLY_CONF_PAGE_SETTINGS = True

def setup_page(self):
# Widgets
self.table = ShortcutsTable(self, text_color=ima.MAIN_FG_COLOR)
self.table = ShortcutsTable(self)
self.finder = ShortcutFinder(self.table, self.table.set_regex)
self.label_finder = QLabel(_('Search: '))
self.reset_btn = QPushButton(_("Reset to default values"))
Expand Down
25 changes: 7 additions & 18 deletions spyder/plugins/shortcuts/widgets/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from spyder.api.translations import _
from spyder.config.manager import CONF
from spyder.utils.icon_manager import ima
from spyder.utils.palette import QStylePalette
from spyder.utils.qthelpers import create_toolbutton
from spyder.utils.stringmatching import get_search_regex, get_search_scores
from spyder.widgets.helperwidgets import (
Expand Down Expand Up @@ -500,7 +501,7 @@ def save(self):


class ShortcutsModel(QAbstractTableModel):
def __init__(self, parent, text_color=None, text_color_highlight=None):
def __init__(self, parent):
QAbstractTableModel.__init__(self)
self._parent = parent

Expand All @@ -514,17 +515,8 @@ def __init__(self, parent, text_color=None, text_color_highlight=None):
self.widths = []

# Needed to compensate for the HTMLDelegate color selection unawarness
palette = parent.palette()
if text_color is None:
self.text_color = palette.text().color().name()
else:
self.text_color = text_color

if text_color_highlight is None:
self.text_color_highlight = \
palette.highlightedText().color().name()
else:
self.text_color_highlight = text_color_highlight
self.text_color = QStylePalette.COLOR_TEXT_1
self.text_color_highlight = QStylePalette.COLOR_TEXT_1

def current_index(self):
"""Get the currently selected index in the parent table view."""
Expand Down Expand Up @@ -573,6 +565,7 @@ def data(self, index, role=Qt.DisplayRole):
return to_qvariant(text)
elif column == SEQUENCE:
text = QKeySequence(key).toString(QKeySequence.NativeText)
text = '<p style="color:{0}">{1}</p>'.format(color, text)
return to_qvariant(text)
elif column == SEARCH_SCORE:
# Treating search scores as a table column simplifies the
Expand Down Expand Up @@ -652,16 +645,12 @@ def reset(self):


class ShortcutsTable(HoverRowsTableView):
def __init__(self, parent=None, text_color=None,
text_color_highlight=None):
def __init__(self, parent=None):
HoverRowsTableView.__init__(self, parent)
self._parent = parent
self.finder = None
self.shortcut_data = None
self.source_model = ShortcutsModel(
self,
text_color=text_color,
text_color_highlight=text_color_highlight)
self.source_model = ShortcutsModel(self)
self.proxy_model = ShortcutsSortFilterProxy(self)
self.last_regex = ''

Expand Down