little fixes and progress on tray
This commit is contained in:
parent
91f3411f28
commit
79ce2f61c5
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
.goutputstream*
|
.goutputstream*
|
||||||
test.py
|
test*
|
||||||
|
10
data/networkmanager/99_update_pamac_tray
Executable file
10
data/networkmanager/99_update_pamac_tray
Executable file
@ -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
|
10
pamac-check-updates
Executable file
10
pamac-check-updates
Executable file
@ -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()
|
75
pamac-tray
75
pamac-tray
@ -5,23 +5,20 @@ from gi.repository import Gtk
|
|||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
from pamac import transaction
|
from pamac import transaction
|
||||||
import dbus
|
import dbus
|
||||||
|
import threading
|
||||||
|
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
|
|
||||||
class Tray:
|
class Tray:
|
||||||
def __init__(self, icon, info):
|
def __init__(self):
|
||||||
self.icon = icon
|
|
||||||
self.info = info
|
|
||||||
self.statusIcon = Gtk.StatusIcon()
|
self.statusIcon = Gtk.StatusIcon()
|
||||||
self.statusIcon.set_from_file(icon)
|
|
||||||
self.statusIcon.set_visible(True)
|
self.statusIcon.set_visible(True)
|
||||||
self.statusIcon.set_tooltip_markup(info)
|
|
||||||
|
|
||||||
self.menu = Gtk.Menu()
|
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.menuItem.connect('activate', self.execute_update, self.statusIcon)
|
||||||
self.menu.append(self.menuItem)
|
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.menuItem.connect('activate', self.execute_manager, self.statusIcon)
|
||||||
self.menu.append(self.menuItem)
|
self.menu.append(self.menuItem)
|
||||||
self.menuItem = Gtk.ImageMenuItem('Quit')
|
self.menuItem = Gtk.ImageMenuItem('Quit')
|
||||||
@ -29,7 +26,6 @@ class Tray:
|
|||||||
self.menu.append(self.menuItem)
|
self.menu.append(self.menuItem)
|
||||||
|
|
||||||
self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
|
self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
|
||||||
self.statusIcon.set_visible(1)
|
|
||||||
|
|
||||||
def execute_update(self, widget, event, data = None):
|
def execute_update(self, widget, event, data = None):
|
||||||
Popen(['/usr/bin/pamac-updater'])
|
Popen(['/usr/bin/pamac-updater'])
|
||||||
@ -38,6 +34,7 @@ class Tray:
|
|||||||
Popen(['/usr/bin/pamac-manager'])
|
Popen(['/usr/bin/pamac-manager'])
|
||||||
|
|
||||||
def quit_tray(self, widget, data = None):
|
def quit_tray(self, widget, data = None):
|
||||||
|
t.shutdown()
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
def popup_menu_cb(self, widget, button, time, data = None):
|
def popup_menu_cb(self, widget, button, time, data = None):
|
||||||
@ -46,14 +43,38 @@ class Tray:
|
|||||||
data.show_all()
|
data.show_all()
|
||||||
data.popup(None, None, Gtk.StatusIcon.position_menu, self.statusIcon, 3, time)
|
data.popup(None, None, Gtk.StatusIcon.position_menu, self.statusIcon, 3, time)
|
||||||
|
|
||||||
def handle_error(error):
|
def update_icon(self, icon, info):
|
||||||
print('error',error)
|
self.statusIcon.set_from_file(icon)
|
||||||
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png'
|
self.statusIcon.set_tooltip_markup(info)
|
||||||
info = ' No update available'
|
|
||||||
tray = Tray(icon, info)
|
|
||||||
transaction.StopDaemon()
|
|
||||||
|
|
||||||
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()
|
do_syncfirst, updates = transaction.get_updates()
|
||||||
if updates:
|
if updates:
|
||||||
icon = '/usr/share/pamac/icons/24x24/status/update-normal.png'
|
icon = '/usr/share/pamac/icons/24x24/status/update-normal.png'
|
||||||
@ -61,7 +82,21 @@ def handle_reply(reply):
|
|||||||
else:
|
else:
|
||||||
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png'
|
icon = '/usr/share/pamac/icons/24x24/status/update-enhancement.png'
|
||||||
info = ' No update available'
|
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()
|
transaction.StopDaemon()
|
||||||
|
|
||||||
def do_refresh():
|
def do_refresh():
|
||||||
@ -69,8 +104,10 @@ def do_refresh():
|
|||||||
transaction.get_handle()
|
transaction.get_handle()
|
||||||
transaction.Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
|
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__":
|
tray = None
|
||||||
do_refresh()
|
do_refresh()
|
||||||
Gtk.main()
|
t = PeriodicTask()
|
||||||
|
t.start()
|
||||||
|
#Gtk.main()
|
||||||
|
@ -558,7 +558,7 @@ class Handler:
|
|||||||
transaction.to_remove = []
|
transaction.to_remove = []
|
||||||
check_conflicts(transaction_dict.values())
|
check_conflicts(transaction_dict.values())
|
||||||
if transaction.to_add:
|
if transaction.to_add:
|
||||||
if transaction.init_transaction(noconflicts = True, unneeded = True):
|
if transaction.init_transaction(noconflicts = True):
|
||||||
for pkgname in transaction.to_add:
|
for pkgname in transaction.to_add:
|
||||||
transaction.Add(pkgname)
|
transaction.Add(pkgname)
|
||||||
for pkgname in transaction.to_remove:
|
for pkgname in transaction.to_remove:
|
||||||
|
@ -184,7 +184,7 @@ class PamacDBusService(dbus.service.Object):
|
|||||||
for pkg in config.handle.get_localdb().pkgcache:
|
for pkg in config.handle.get_localdb().pkgcache:
|
||||||
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
|
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
|
||||||
if candidate:
|
if candidate:
|
||||||
EmitAvailableUpdates(self, True)
|
self.EmitAvailableUpdates(True)
|
||||||
return
|
return
|
||||||
|
|
||||||
@dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')
|
@dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')
|
||||||
|
Loading…
Reference in New Issue
Block a user