style: Use a collection.UserDict.
This commit is contained in:
parent
5a975d1b90
commit
1d5cae3146
@ -20,6 +20,7 @@
|
|||||||
"""Utilities related to the look&feel of qutebrowser."""
|
"""Utilities related to the look&feel of qutebrowser."""
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
import collections
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
import sip
|
import sip
|
||||||
@ -68,7 +69,7 @@ def update_stylesheet(obj):
|
|||||||
obj.setStyleSheet(get_stylesheet(obj.STYLESHEET))
|
obj.setStyleSheet(get_stylesheet(obj.STYLESHEET))
|
||||||
|
|
||||||
|
|
||||||
class ColorDict(dict):
|
class ColorDict(collections.UserDict):
|
||||||
|
|
||||||
"""A dict aimed at Qt stylesheet colors."""
|
"""A dict aimed at Qt stylesheet colors."""
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ class ColorDict(dict):
|
|||||||
"""
|
"""
|
||||||
if isinstance(val, QColor):
|
if isinstance(val, QColor):
|
||||||
raise TypeError("QColor passed to ColorDict!")
|
raise TypeError("QColor passed to ColorDict!")
|
||||||
super().__setitem__(key, val)
|
self.data[key] = val
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Override dict __getitem__.
|
"""Override dict __getitem__.
|
||||||
@ -99,7 +100,7 @@ class ColorDict(dict):
|
|||||||
In all other cases, return the plain value.
|
In all other cases, return the plain value.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
val = super().__getitem__(key)
|
val = self.data[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.config.exception("No color defined for {}!".format(key))
|
log.config.exception("No color defined for {}!".format(key))
|
||||||
return ''
|
return ''
|
||||||
@ -111,7 +112,7 @@ class ColorDict(dict):
|
|||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
class FontDict(dict):
|
class FontDict(collections.UserDict):
|
||||||
|
|
||||||
"""A dict aimed at Qt stylesheet fonts."""
|
"""A dict aimed at Qt stylesheet fonts."""
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ class FontDict(dict):
|
|||||||
In all other cases, return font: <value>.
|
In all other cases, return font: <value>.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
val = super().__getitem__(key)
|
val = self.data[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return ''
|
return ''
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user