Clean up config color handling

This commit is contained in:
Florian Bruhin 2014-07-17 16:06:14 +02:00
parent 34d1449cd2
commit abf5fbc063
3 changed files with 38 additions and 35 deletions

View File

@ -773,11 +773,11 @@ DATA = OrderedDict([
"Text color of the completion widget."), "Text color of the completion widget."),
('completion.bg', ('completion.bg',
SettingValue(types.Color(), '#333333'), SettingValue(types.QssColor(), '#333333'),
"Text color of the completion widget."), "Text color of the completion widget."),
('completion.item.bg', ('completion.item.bg',
SettingValue(types.Color(), '${completion.bg}'), SettingValue(types.QssColor(), '${completion.bg}'),
"Background color of completion widget items."), "Background color of completion widget items."),
('completion.category.fg', ('completion.category.fg',
@ -785,16 +785,16 @@ DATA = OrderedDict([
"Foreground color of completion widget category headers."), "Foreground color of completion widget category headers."),
('completion.category.bg', ('completion.category.bg',
SettingValue(types.Color(), 'qlineargradient(x1:0, y1:0, x2:0, y2:1, ' SettingValue(types.QssColor(), 'qlineargradient(x1:0, y1:0, x2:0, y2:1, '
'stop:0 #888888, stop:1 #505050)'), 'stop:0 #888888, stop:1 #505050)'),
"Background color of the completion widget category headers."), "Background color of the completion widget category headers."),
('completion.category.border.top', ('completion.category.border.top',
SettingValue(types.Color(), 'black'), SettingValue(types.QssColor(), 'black'),
"Top border color of the completion widget category headers."), "Top border color of the completion widget category headers."),
('completion.category.border.bottom', ('completion.category.border.bottom',
SettingValue(types.Color(), '${completion.category.border.top}'), SettingValue(types.QssColor(), '${completion.category.border.top}'),
"Bottom border color of the completion widget category headers."), "Bottom border color of the completion widget category headers."),
('completion.item.selected.fg', ('completion.item.selected.fg',
@ -802,70 +802,70 @@ DATA = OrderedDict([
"Foreground color of the selected completion item."), "Foreground color of the selected completion item."),
('completion.item.selected.bg', ('completion.item.selected.bg',
SettingValue(types.Color(), '#e8c000'), SettingValue(types.QssColor(), '#e8c000'),
"Background color of the selected completion item."), "Background color of the selected completion item."),
('completion.item.selected.border.top', ('completion.item.selected.border.top',
SettingValue(types.Color(), '#bbbb00'), SettingValue(types.QssColor(), '#bbbb00'),
"Top border color of the completion widget category headers."), "Top border color of the completion widget category headers."),
('completion.item.selected.border.bottom', ('completion.item.selected.border.bottom',
SettingValue(types.Color(), '${completion.item.selected.border.top}'), SettingValue(types.QssColor(), '${completion.item.selected.border.top}'),
"Bottom border color of the selected completion item."), "Bottom border color of the selected completion item."),
('completion.match.fg', ('completion.match.fg',
SettingValue(types.Color(), '#ff4444'), SettingValue(types.QssColor(), '#ff4444'),
"Foreground color of the matched text in the completion."), "Foreground color of the matched text in the completion."),
('statusbar.bg', ('statusbar.bg',
SettingValue(types.Color(), 'black'), SettingValue(types.QssColor(), 'black'),
"Foreground color of the statusbar."), "Foreground color of the statusbar."),
('statusbar.fg', ('statusbar.fg',
SettingValue(types.Color(), 'white'), SettingValue(types.QssColor(), 'white'),
"Foreground color of the statusbar."), "Foreground color of the statusbar."),
('statusbar.bg.error', ('statusbar.bg.error',
SettingValue(types.Color(), 'red'), SettingValue(types.QssColor(), 'red'),
"Background color of the statusbar if there was an error."), "Background color of the statusbar if there was an error."),
('statusbar.bg.prompt', ('statusbar.bg.prompt',
SettingValue(types.Color(), 'darkblue'), SettingValue(types.QssColor(), 'darkblue'),
"Background color of the statusbar if there is a prompt."), "Background color of the statusbar if there is a prompt."),
('statusbar.bg.insert', ('statusbar.bg.insert',
SettingValue(types.Color(), 'darkgreen'), SettingValue(types.QssColor(), 'darkgreen'),
"Background color of the statusbar in insert mode."), "Background color of the statusbar in insert mode."),
('statusbar.progress.bg', ('statusbar.progress.bg',
SettingValue(types.Color(), 'white'), SettingValue(types.QssColor(), 'white'),
"Background color of the progress bar."), "Background color of the progress bar."),
('statusbar.url.fg', ('statusbar.url.fg',
SettingValue(types.Color(), '${statusbar.fg}'), SettingValue(types.QssColor(), '${statusbar.fg}'),
"Default foreground color of the URL in the statusbar."), "Default foreground color of the URL in the statusbar."),
('statusbar.url.fg.success', ('statusbar.url.fg.success',
SettingValue(types.Color(), 'lime'), SettingValue(types.QssColor(), 'lime'),
"Foreground color of the URL in the statusbar on successful " "Foreground color of the URL in the statusbar on successful "
"load."), "load."),
('statusbar.url.fg.error', ('statusbar.url.fg.error',
SettingValue(types.Color(), 'orange'), SettingValue(types.QssColor(), 'orange'),
"Foreground color of the URL in the statusbar on error."), "Foreground color of the URL in the statusbar on error."),
('statusbar.url.fg.warn', ('statusbar.url.fg.warn',
SettingValue(types.Color(), 'yellow'), SettingValue(types.QssColor(), 'yellow'),
"Foreground color of the URL in the statusbar when there's a " "Foreground color of the URL in the statusbar when there's a "
"warning."), "warning."),
('statusbar.url.fg.hover', ('statusbar.url.fg.hover',
SettingValue(types.Color(), 'aqua'), SettingValue(types.QssColor(), 'aqua'),
"Foreground color of the URL in the statusbar for hovered " "Foreground color of the URL in the statusbar for hovered "
"links."), "links."),
('tab.fg', ('tab.fg',
SettingValue(types.Color(), 'white'), SettingValue(types.QtColor(), 'white'),
"Foreground color of tabs."), "Foreground color of tabs."),
('tab.bg.odd', ('tab.bg.odd',
@ -877,11 +877,11 @@ DATA = OrderedDict([
"Background color of unselected even tabs."), "Background color of unselected even tabs."),
('tab.bg.selected', ('tab.bg.selected',
SettingValue(types.Color(), 'black'), SettingValue(types.QtColor(), 'black'),
"Background color of selected tabs."), "Background color of selected tabs."),
('tab.bg.bar', ('tab.bg.bar',
SettingValue(types.Color(), '#555555'), SettingValue(types.QssColor(), '#555555'),
"Background color of the tabbar."), "Background color of the tabbar."),
('tab.indicator.start', ('tab.indicator.start',
@ -901,7 +901,7 @@ DATA = OrderedDict([
"Color gradient interpolation system for the tab indicator."), "Color gradient interpolation system for the tab indicator."),
('tab.seperator', ('tab.seperator',
SettingValue(types.Color(), '#555555'), SettingValue(types.QssColor(), '#555555'),
"Color for the tab seperator."), "Color for the tab seperator."),
('hints.fg', ('hints.fg',
@ -923,7 +923,7 @@ DATA = OrderedDict([
"Foreground color for downloads."), "Foreground color for downloads."),
('downloads.bg.bar', ('downloads.bg.bar',
SettingValue(types.Color(), 'black'), SettingValue(types.QssColor(), 'black'),
"Background color for the download bar."), "Background color for the download bar."),
('downloads.bg.start', ('downloads.bg.start',

View File

@ -494,14 +494,14 @@ class CssColor(BaseType):
def validate(self, value): def validate(self, value):
if value.startswith('-'): if value.startswith('-'):
# custom function name, won't validate. # custom function name, won't validate.
return pass
if QColor.isValidColor(value): elif QColor.isValidColor(value):
pass pass
else: else:
raise ValidationError(value, "must be a valid CSS color") raise ValidationError(value, "must be a valid color")
class Color(CssColor): class QssColor(CssColor):
"""Base class for a color value. """Base class for a color value.
@ -509,15 +509,18 @@ class Color(CssColor):
_GRADIENTS: Valid gradient function names. _GRADIENTS: Valid gradient function names.
""" """
typestr = 'color' typestr = 'qss-color'
_GRADIENTS = ('qlineargradient', 'qradialgradient', 'qconicalgradient') _GRADIENTS = ('qlineargradient', 'qradialgradient', 'qconicalgradient')
def validate(self, value): def validate(self, value):
if any([value.startswith(start) for start in Color._GRADIENTS]): if any([value.startswith(start) for start in self._GRADIENTS]):
# We can't validate this further. # We can't validate this further.
return pass
super().validate(value) elif QColor.isValidColor(value):
pass
else:
raise ValidationError(value, "must be a valid color")
class Font(BaseType): class Font(BaseType):

View File

@ -229,9 +229,9 @@ class TabBar(QTabBar):
color = config.get('colors', 'tab.bg.odd') color = config.get('colors', 'tab.bg.odd')
else: else:
color = config.get('colors', 'tab.bg.even') color = config.get('colors', 'tab.bg.even')
tab.palette.setColor(QPalette.Window, QColor(color)) tab.palette.setColor(QPalette.Window, color)
tab.palette.setColor(QPalette.WindowText, tab.palette.setColor(QPalette.WindowText,
QColor(config.get('colors', 'tab.fg'))) config.get('colors', 'tab.fg'))
indicator_color = self.tabData(idx) indicator_color = self.tabData(idx)
if indicator_color is None: if indicator_color is None:
indicator_color = QColor() indicator_color = QColor()