Fix column coloring to allow #xxxxxx in the GUI processing.

This commit is contained in:
Charles Haley 2014-04-14 16:37:14 +02:00
parent 920526b86d
commit 78bcebb4d0

View File

@ -50,10 +50,9 @@ def default_image():
class ColumnColor(object): # {{{ class ColumnColor(object): # {{{
def __init__(self, formatter, colors): def __init__(self, formatter):
self.mi = None self.mi = None
self.formatter = formatter self.formatter = formatter
self.colors = colors
def __call__(self, id_, key, fmt, db, color_cache): def __call__(self, id_, key, fmt, db, color_cache):
if id_ in color_cache and key in color_cache[id_]: if id_ in color_cache and key in color_cache[id_]:
@ -62,14 +61,12 @@ class ColumnColor(object): # {{{
try: try:
if self.mi is None: if self.mi is None:
self.mi = db.new_api.get_proxy_metadata(id_) self.mi = db.new_api.get_proxy_metadata(id_)
color = self.formatter.safe_format(fmt, self.mi, '', self.mi) color = QColor(self.formatter.safe_format(fmt, self.mi, '', self.mi))
if color in self.colors: if color.isValid():
color = QColor(color) color = QVariant(color)
if color.isValid(): color_cache[id_][key] = color
color = QVariant(color) self.mi = None
color_cache[id_][key] = color return color
self.mi = None
return color
except: except:
pass pass
# }}} # }}}
@ -172,9 +169,8 @@ class BooksModel(QAbstractTableModel): # {{{
self.db = None self.db = None
self.formatter = SafeFormat() self.formatter = SafeFormat()
self.colors = frozenset([unicode(c) for c in QColor.colorNames()])
self._clear_caches() self._clear_caches()
self.column_color = ColumnColor(self.formatter, self.colors) self.column_color = ColumnColor(self.formatter)
self.column_icon = ColumnIcon(self.formatter, self) self.column_icon = ColumnIcon(self.formatter, self)
self.book_on_device = None self.book_on_device = None