forked from cromer/pamac-classic
72 lines
2.2 KiB
Python
Executable File
72 lines
2.2 KiB
Python
Executable File
#! /usr/bin/python
|
|
# -*-coding:utf-8-*-
|
|
|
|
from gi.repository import Gtk
|
|
from subprocess import Popen
|
|
from pamac import transaction
|
|
|
|
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()
|
|
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)
|
|
self.menu.append(self.menuItem)
|
|
self.menuItem = Gtk.ImageMenuItem('Quit')
|
|
self.menuItem.connect('activate', self.quit_tray, self.statusIcon)
|
|
self.menu.append(self.menuItem)
|
|
|
|
self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
|
|
self.statusIcon.set_visible(1)
|
|
|
|
def execute_update(self, widget, event, data = None):
|
|
Popen(['/usr/bin/pamac-updater'])
|
|
|
|
def execute_manager(self, widget, event, data = None):
|
|
Popen(['/usr/bin/pamac-manager'])
|
|
|
|
def quit_tray(self, widget, data = None):
|
|
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)
|
|
|
|
def handle_error(error):
|
|
print('error',error)
|
|
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png'
|
|
info = ' No update available'
|
|
tray = Tray(icon, info)
|
|
transaction.StopDaemon()
|
|
|
|
def handle_reply(reply):
|
|
do_syncfirst, updates = transaction.get_updates()
|
|
if updates:
|
|
icon = '/usr/share/pamac/icons/24x24/status/update-normal.png'
|
|
info = str(len(updates))+' update(s) available'
|
|
else:
|
|
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png'
|
|
info = ' No update available'
|
|
tray = Tray(icon, info)
|
|
transaction.StopDaemon()
|
|
|
|
def do_refresh():
|
|
"""Sync databases like pacman -Sy"""
|
|
transaction.get_handle()
|
|
transaction.Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
|
|
|
|
if __name__ == "__main__":
|
|
do_refresh()
|
|
Gtk.main()
|