diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/isodumper.py | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index 16e6804..540b0b1 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -25,11 +25,9 @@ # Requires python3-parted -# ensure we're using the latest build, if called from our build environment + import sys import importlib -import logging - try: from isodumper import version except: @@ -49,6 +47,10 @@ import gettext from subprocess import Popen, PIPE from pydbus import SystemBus +import logging +import threading +from gi.repository import GLib +from queue import SimpleQueue import psutil import manatools.args as args @@ -162,7 +164,7 @@ class ParseCLI(args.AppArgs): class IsoDumper(object): - def get_devices(self): + def get_devices(self, selected=None): self.list = self.u.find_devices() while len(self.list) == 0: if self.nodevDialog(): @@ -173,7 +175,9 @@ class IsoDumper(object): if len(self.list) > 0: for name, path, size in self.list: if size != 0: - self.devicelist.addItem(str(name + ' (' + path.lstrip() + ') ' + self.sizeof_fmt(size)), False) + label = str(name + ' (' + path.lstrip() + ') ' + self.sizeof_fmt(size)) + sel = (label == selected) if selected else False + self.devicelist.addItem(label, sel) return True def udev_wait(self, operation): @@ -202,6 +206,14 @@ class IsoDumper(object): self.dialog.recalcLayout() self.restore() + def update_list_on_event(self): + selitem = self.devicelist.selectedItem().label() + self.devicelist.deleteAllItems() + self.get_devices(selected = selitem) + if self.devicelist.selectedItem().label() != selitem: + self.restore() + self.dialog.recalcLayout() + def device_selected(self): selitem = self.devicelist.selectedItem() if selitem is not None: @@ -505,6 +517,8 @@ class IsoDumper(object): self.write_logfile() self.dialog.destroy() self.dialog = None + self.glib_loop.quit() + self.glib_thread.join() def write_logfile(self): logpath = os.path.join(os.path.expanduser('~'), '.isodumper') @@ -694,7 +708,23 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog self.device_selected() self.dialog.recalcLayout() self.ancrage.showChild() - + self.uEventQueue = SimpleQueue() + self.glib_loop = GLib.MainLoop() + self.glib_thread = threading.Thread(target=self.glib_mainloop, args=(self.glib_loop,)) + self.glib_thread.start() + + + def glib_mainloop(self, loop): + ''' + thread function for glib main loop + listen to signal from udisks + ''' + self.u.iface["org.freedesktop.DBus.ObjectManager"].InterfacesAdded.connect(self.device_changed) + loop.run() + + def device_changed(self, a, b): + self.uEventQueue.put({'event': "device-changed", 'value': True}) + def ask_format(self): atelier = yui.YUI.widgetFactory() dialog = atelier.createPopupDialog() @@ -790,7 +820,7 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog def handleevent(self): self.traitement = None while True: - event = self.dialog.waitForEvent() + event = self.dialog.waitForEvent(100) if event.eventType() == yui.YEvent.CancelEvent: self.close() break @@ -854,6 +884,12 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog pass if event.widget() == self.aboutbt: self.aboutDialog() + try: + item = self.uEventQueue.get_nowait() + if item['event'] == "device-changed": + self.update_list_on_event() + except Exception as e: + pass def run(self): try: |