Skip to content

Commit

Permalink
Fix changing disabled colors overriding non-disabled colors
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Mar 1, 2024
1 parent a8a3bc9 commit eb05330
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/calibre/gui2/dialogs/palette.py
Expand Up @@ -12,7 +12,8 @@

from calibre.gui2 import Application, choose_files, choose_save_file, gprefs
from calibre.gui2.palette import (
default_dark_palette, default_light_palette, palette_colors, palette_from_dict,
default_dark_palette, default_light_palette, is_foreground_color, palette_colors,
palette_from_dict,
)
from calibre.gui2.widgets2 import ColorButton, Dialog

Expand Down Expand Up @@ -74,7 +75,7 @@ def __init__(self, palette: QPalette, default_palette: QPalette, mode_name: str,
self.default_palette = default_palette

for key, desc in palette_colors().items():
if 'Text' in key:
if is_foreground_color(key):
self.foreground_colors[key] = desc
elif 'Link' in key:
self.link_colors[key] = desc
Expand All @@ -91,8 +92,8 @@ def header(text):
ans.setFont(f)
return ans

def c(x, desc):
w = Color(x, desc, self, palette, default_palette, mode_name)
def c(x, desc, group=''):
w = Color(x, desc, self, palette, default_palette, mode_name, group=group)
l.addWidget(w)
self.colors.append(w)

Expand All @@ -106,7 +107,7 @@ def c(x, desc):

l.addWidget(header(_('Foreground (text) colors when disabled')))
for x, desc in self.foreground_colors.items():
c(x, desc)
c(x, desc, group='disabled')

l.addWidget(header(_('Link colors')))
for x, desc in self.link_colors.items():
Expand Down
12 changes: 8 additions & 4 deletions src/calibre/gui2/palette.py
Expand Up @@ -140,22 +140,26 @@ def palette_colors():
}


def is_foreground_color(key: str) -> bool:
return 'Text' in key


def palette_from_dict(data: dict[str, str], default_palette: QPalette) -> QPalette:

def s(key, group=QPalette.ColorGroup.All):
role = getattr(QPalette.ColorRole, key)
grp = ''
if group == QPalette.ColorGroup.Disabled:
grp = 'disabled-'
c = QColor.fromString(data.get(grp + key, ''))
grp = '-disabled'
c = QColor.fromString(data.get(key + grp, ''))
if c.isValid():
p.setColor(group, role, c)

p = QPalette()
for key in palette_colors():
s(key)
for key in ('Text', 'ButtonText', 'HighlightedText'):
s(key, QPalette.ColorGroup.Disabled)
if is_foreground_color(key):
s(key, QPalette.ColorGroup.Disabled)
return p.resolve(default_palette)


Expand Down

0 comments on commit eb05330

Please sign in to comment.