From 79ce2f61c5ab98dc4034ed018ab66a6eab3ccbff Mon Sep 17 00:00:00 2001 From: guinux Date: Sat, 16 Feb 2013 17:27:46 +0100 Subject: [PATCH] little fixes and progress on tray --- .gitignore | 2 +- data/networkmanager/99_update_pamac_tray | 10 +++ pamac-check-updates | 10 +++ pamac-tray | 77 ++++++++++++++++++------ pamac/main.py | 2 +- pamac/pamac-daemon.py | 2 +- 6 files changed, 80 insertions(+), 23 deletions(-) create mode 100755 data/networkmanager/99_update_pamac_tray create mode 100755 pamac-check-updates diff --git a/.gitignore b/.gitignore index 31d7fdc..bec93b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ __pycache__ .goutputstream* -test.py +test* diff --git a/data/networkmanager/99_update_pamac_tray b/data/networkmanager/99_update_pamac_tray new file mode 100755 index 0000000..0bb2e42 --- /dev/null +++ b/data/networkmanager/99_update_pamac_tray @@ -0,0 +1,10 @@ +#!/bin/sh + +INTERFACE=$1 # The interface which is brought up or down +STATUS=$2 # The new state of the interface + +case "$STATUS" in + 'up') # $INTERFACE is up + pamac-check-updates + ;; +esac diff --git a/pamac-check-updates b/pamac-check-updates new file mode 100755 index 0000000..29d604c --- /dev/null +++ b/pamac-check-updates @@ -0,0 +1,10 @@ +#! /usr/bin/python +# -*-coding:utf-8-*- + +from pamac import transaction + +print('check_updates') +transaction.get_handle() +transaction.Refresh() +transaction.CheckUpdates() +transaction.StopDaemon() diff --git a/pamac-tray b/pamac-tray index 1b1faf9..47b0928 100755 --- a/pamac-tray +++ b/pamac-tray @@ -5,23 +5,20 @@ from gi.repository import Gtk from subprocess import Popen from pamac import transaction import dbus +import threading bus = dbus.SystemBus() class Tray: - def __init__(self, icon, info): - self.icon = icon - self.info = info + def __init__(self): 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 = Gtk.ImageMenuItem('Install/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 = Gtk.ImageMenuItem('Run pamac-manager') self.menuItem.connect('activate', self.execute_manager, self.statusIcon) self.menu.append(self.menuItem) self.menuItem = Gtk.ImageMenuItem('Quit') @@ -29,7 +26,6 @@ class Tray: 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']) @@ -38,6 +34,7 @@ class Tray: Popen(['/usr/bin/pamac-manager']) def quit_tray(self, widget, data = None): + t.shutdown() Gtk.main_quit() def popup_menu_cb(self, widget, button, time, data = None): @@ -46,14 +43,38 @@ class Tray: 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 update_icon(self, icon, info): + self.statusIcon.set_from_file(icon) + self.statusIcon.set_tooltip_markup(info) -def handle_reply(reply): +class PeriodicTask(threading.Thread): + """Thread that executes a task every N seconds""" + def __init__(self): + threading.Thread.__init__(self) + self._finished = threading.Event() + self._interval = 60 + + def setInterval(self, interval): + """Set the number of seconds we sleep between executing our task""" + self._interval = interval + + def shutdown(self): + """Stop this thread""" + self._finished.set() + + def run(self): + while 1: + if self._finished.isSet(): + return + self.task() + # sleep for interval or until shutdown + self._finished.wait(self._interval) + + def task(self): + Popen(['/usr/bin/pamac-check-updates']) + +def set_icon(*arg): + print('set-icon') do_syncfirst, updates = transaction.get_updates() if updates: icon = '/usr/share/pamac/icons/24x24/status/update-normal.png' @@ -61,7 +82,21 @@ def handle_reply(reply): else: icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png' info = ' No update available' - tray = Tray(icon, info) + tray.update_icon(icon, info) + +def handle_error(error): + global tray + print('error',error) + icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png' + info = ' No update available' + tray = Tray() + tray.update_icon(icon, info) + transaction.StopDaemon() + +def handle_reply(reply): + global tray + tray = Tray() + set_icon() transaction.StopDaemon() def do_refresh(): @@ -69,8 +104,10 @@ def do_refresh(): transaction.get_handle() transaction.Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000) -bus.add_signal_receiver(handle_reply, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAvailableUpdates") +bus.add_signal_receiver(set_icon, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAvailableUpdates") -if __name__ == "__main__": - do_refresh() - Gtk.main() +tray = None +do_refresh() +t = PeriodicTask() +t.start() +#Gtk.main() diff --git a/pamac/main.py b/pamac/main.py index f3cd39e..945171c 100644 --- a/pamac/main.py +++ b/pamac/main.py @@ -558,7 +558,7 @@ class Handler: transaction.to_remove = [] check_conflicts(transaction_dict.values()) if transaction.to_add: - if transaction.init_transaction(noconflicts = True, unneeded = True): + if transaction.init_transaction(noconflicts = True): for pkgname in transaction.to_add: transaction.Add(pkgname) for pkgname in transaction.to_remove: diff --git a/pamac/pamac-daemon.py b/pamac/pamac-daemon.py index 4f63237..1bc8b6e 100644 --- a/pamac/pamac-daemon.py +++ b/pamac/pamac-daemon.py @@ -184,7 +184,7 @@ class PamacDBusService(dbus.service.Object): for pkg in config.handle.get_localdb().pkgcache: candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs()) if candidate: - EmitAvailableUpdates(self, True) + self.EmitAvailableUpdates(True) return @dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')