23
from gpodder.gtkui import draw
26
'download_progress_bar': False, # draw progress bar on icon while downloading?
20
29
class gPodderExtension:
21
30
def __init__(self, container):
22
31
self.container = container
32
self.config = self.container.config
23
33
self.status_icon = None
24
35
self.gpodder = None
36
self.last_progress = 1
38
def set_icon(self, use_pixbuf=False):
27
39
path = os.path.join(os.path.dirname(__file__), '..', '..', 'icons')
28
40
icon_path = os.path.abspath(path)
30
42
theme = gtk.icon_theme_get_default()
31
43
theme.append_search_path(icon_path)
33
if theme.has_icon('gpodder'):
34
self.status_icon = gtk.status_icon_new_from_icon_name('gpodder')
45
if self.icon_name is None:
46
if theme.has_icon('gpodder'):
47
self.icon_name = 'gpodder'
49
self.icon_name = 'stock_mic'
51
if self.status_icon is None:
52
self.status_icon = gtk.status_icon_new_from_icon_name(self.icon_name)
55
# If current mode matches desired mode, nothing to do.
56
is_pixbuf = (self.status_icon.get_storage_type() == gtk.IMAGE_PIXBUF)
57
if is_pixbuf == use_pixbuf:
61
self.status_icon.set_from_icon_name(self.icon_name)
36
self.status_icon = gtk.status_icon_new_from_icon_name('stock_mic')
63
# Currently icon is not a pixbuf => was loaded by name, at which
64
# point size was automatically determined.
65
icon_size = self.status_icon.get_size()
66
icon_pixbuf = theme.load_icon(self.icon_name, icon_size, gtk.ICON_LOOKUP_USE_BUILTIN)
67
self.status_icon.set_from_pixbuf(icon_pixbuf)
38
71
self.status_icon.connect('activate', self.on_toggle_visible)
39
72
self.status_icon.set_has_tooltip(True)
40
73
self.status_icon.set_tooltip_text("gPodder")
50
83
if self.status_icon is not None:
51
84
self.status_icon.set_visible(False)
52
85
self.status_icon = None
54
88
def on_ui_object_available(self, name, ui_object):
55
89
if name == 'gpodder-gtk':
56
90
self.gpodder = ui_object
92
def get_icon_pixbuf(self):
93
assert self.status_icon is not None
94
if self.status_icon.get_storage_type() != gtk.IMAGE_PIXBUF:
95
self.set_icon(use_pixbuf=True)
96
return self.status_icon.get_pixbuf()
98
def on_download_progress(self, progress):
99
logger.debug("download progress: %f", progress)
101
if not self.config.download_progress_bar:
102
# reset the icon in case option was turned off during download
103
if self.last_progress < 1:
104
self.last_progress = 1
106
# in any case, we're now done
110
self.set_icon() # no progress bar
111
self.last_progress = progress
114
# Only update in 3-percent-steps to save some resources
115
if abs(progress-self.last_progress) < 0.03 and progress > self.last_progress:
118
icon = self.get_icon_pixbuf().copy()
119
progressbar = draw.progressbar_pixbuf(icon.get_width(), icon.get_height(), progress)
120
progressbar.composite(icon, 0, 0, icon.get_width(), icon.get_height(), 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255)
122
self.status_icon.set_from_pixbuf(icon)
123
self.last_progress = progress