2012-12-29 11:06:44 -03:00
|
|
|
#! /usr/bin/python
|
|
|
|
# -*-coding:utf-8-*-
|
|
|
|
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
2013-01-06 15:10:13 -03:00
|
|
|
from pamac import transaction, updater, manager
|
2012-12-29 11:06:44 -03:00
|
|
|
|
2013-02-02 10:02:18 -03:00
|
|
|
already_manager = False
|
|
|
|
|
2012-12-29 11:06:44 -03:00
|
|
|
class Tray:
|
|
|
|
def __init__(self, icon, info):
|
|
|
|
self.icon = icon
|
|
|
|
self.info = info
|
|
|
|
self.statusIcon = Gtk.StatusIcon()
|
|
|
|
self.statusIcon.set_from_file(icon)
|
|
|
|
self.statusIcon.set_visible(True)
|
|
|
|
self.statusIcon.set_tooltip_markup(info)
|
|
|
|
|
|
|
|
self.menu = Gtk.Menu()
|
2013-01-06 15:10:13 -03:00
|
|
|
self.menuItem = Gtk.ImageMenuItem('Check for updates')
|
|
|
|
self.menuItem.connect('activate', self.execute_update, self.statusIcon)
|
|
|
|
self.menu.append(self.menuItem)
|
|
|
|
self.menuItem = Gtk.ImageMenuItem('Run pamac')
|
|
|
|
self.menuItem.connect('activate', self.execute_manager, self.statusIcon)
|
2012-12-29 11:06:44 -03:00
|
|
|
self.menu.append(self.menuItem)
|
|
|
|
self.menuItem = Gtk.ImageMenuItem(Gtk.STOCK_QUIT)
|
2013-01-06 15:10:13 -03:00
|
|
|
self.menuItem.connect('activate', self.quit_tray, self.statusIcon)
|
2012-12-29 11:06:44 -03:00
|
|
|
self.menu.append(self.menuItem)
|
|
|
|
|
|
|
|
self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
|
|
|
|
self.statusIcon.set_visible(1)
|
|
|
|
|
2013-01-06 15:10:13 -03:00
|
|
|
def execute_update(self, widget, event, data = None):
|
|
|
|
updater.main()
|
2012-12-29 11:06:44 -03:00
|
|
|
|
2013-01-06 15:10:13 -03:00
|
|
|
def execute_manager(self, widget, event, data = None):
|
2013-02-02 10:02:18 -03:00
|
|
|
global already_manager
|
|
|
|
if already_manager:
|
|
|
|
manager.MainWindow.show_all()
|
|
|
|
print('show')
|
|
|
|
else:
|
|
|
|
manager.main()
|
|
|
|
already_manager = True
|
2012-12-29 11:06:44 -03:00
|
|
|
|
2013-01-06 15:10:13 -03:00
|
|
|
def quit_tray(self, widget, data = None):
|
2012-12-29 11:06:44 -03:00
|
|
|
Gtk.main_quit()
|
|
|
|
|
|
|
|
def popup_menu_cb(self, widget, button, time, data = None):
|
|
|
|
if button == 3:
|
|
|
|
if data:
|
|
|
|
data.show_all()
|
|
|
|
data.popup(None, None, Gtk.StatusIcon.position_menu, self.statusIcon, 3, time)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
updates = transaction.get_updates()
|
|
|
|
if updates:
|
2013-01-06 15:10:13 -03:00
|
|
|
icon = '/usr/share/pamac/icons/24x24/status/update-normal.png'
|
2012-12-29 11:06:44 -03:00
|
|
|
info = str(len(updates))+' update(s) available'
|
|
|
|
else:
|
2013-01-06 15:10:13 -03:00
|
|
|
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png'
|
2012-12-29 11:06:44 -03:00
|
|
|
info = ' No update available'
|
|
|
|
tray = Tray(icon, info)
|
2013-01-06 15:10:13 -03:00
|
|
|
Gtk.main()
|