Skip to content

Commit

Permalink
Colorize symbolic icons for dark mode
Browse files Browse the repository at this point in the history
ref #150
  • Loading branch information
diegogangl committed Sep 11, 2020
1 parent b245c11 commit ed81e4d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
28 changes: 25 additions & 3 deletions GTG/gtk/browser/cell_renderer_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@


class CellRendererTags(Gtk.CellRenderer):

SYMBOLIC_ICONS = (
'emblem-documents-symbolic',
'task-past-due-symbolic',
'system-search-symbolic',
)

__gproperties__ = {
'tag_list': (GObject.TYPE_PYOBJECT,
"Tag list", "A list of tags", GObject.PARAM_READWRITE),
Expand Down Expand Up @@ -70,13 +77,16 @@ def __count_viewable_tags(self):
return count

# Class methods
def __init__(self):
def __init__(self, config):
super().__init__()
self.tag_list = None
self.tag = None
self.xpad = 1
self.ypad = 1
self.PADDING = 1
self.config = config



def do_set_property(self, pspec, value):
if pspec.name == "tag-list":
Expand All @@ -103,6 +113,11 @@ def do_render(self, cr, widget, background_area, cell_area, flags):
else:
return

if self.config.get('dark_mode'):
symbolic_color = Gdk.RGBA(0.9, 0.9, 0.9, 1)
else:
symbolic_color = Gdk.RGBA(0, 0, 0, 1)

# Drawing context
gdkcontext = cr
gdkcontext.set_antialias(cairo.ANTIALIAS_NONE)
Expand All @@ -126,8 +141,15 @@ def do_render(self, cr, widget, background_area, cell_area, flags):

if my_tag_icon:
try:
pixbuf = Gtk.IconTheme.get_default().load_icon(
my_tag_icon, 16, 0)
icon_theme = Gtk.IconTheme.get_default()

if my_tag_icon in self.SYMBOLIC_ICONS:
info = icon_theme.lookup_icon(my_tag_icon, 16, 0)
load = info.load_symbolic(symbolic_color)
pixbuf = load[0]
else:
pixbuf = icon_theme.load_icon(my_tag_icon, 16, 0)

Gdk.cairo_set_source_pixbuf(gdkcontext, pixbuf,
rect_x, rect_y)
gdkcontext.paint()
Expand Down
4 changes: 2 additions & 2 deletions GTG/gtk/browser/treeview_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def tags_treeview(self, tree):
# Tags color
col_name = 'color'
col = {}
render_tags = CellRendererTags()
render_tags = CellRendererTags(self.config)
render_tags.set_property('ypad', 5)
col['title'] = _("Tags")
col['renderer'] = ['tag', render_tags]
Expand Down Expand Up @@ -422,7 +422,7 @@ def common_desc_for_tasks(self, tree, title_label):
# "tags" column (no title)
col_name = 'tags'
col = {}
render_tags = CellRendererTags()
render_tags = CellRendererTags(self.config)
render_tags.set_property('xalign', 0.0)
col['renderer'] = ['tag_list', render_tags]
col['value'] = [GObject.TYPE_PYOBJECT, self.get_task_tags_column_contents]
Expand Down

0 comments on commit ed81e4d

Please sign in to comment.