I have created a simple status icon. Its purpose is to check the existence of files in a given time interval.
The status icon shows, and the thread is started. However, the loop does not loop: it enters the loop, but on event.wait it halts, and never continues.
I've tried to replace with time.sleep(5), but that had the same result.
I've searched anywhere, but I couldn't find an answer. What am I missing?
#! /usr/bin/env python3#-*- coding: utf-8 -*-from gi.repository import Gtkimport threadingclass CheckStatus(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.event = threading.Event() def run(self): cnt = 0 while not self.event.is_set(): cnt += 1 print((">>> check %d" % cnt)) # This shows just once self.event.wait(5) print(">>> done") def stop(self): self.event.set()class MyStatusIcon(object): def __init__(self): self.statusIcon = Gtk.StatusIcon() self.statusIcon.set_visible(True) self.statusIcon.set_from_stock(Gtk.STOCK_ABOUT) # Build status icon menu menu = Gtk.Menu() menuQuit = Gtk.MenuItem("Quit") menuQuit.connect('activate', self.quit_tray) menu.append(menuQuit) self.statusIcon.connect('popup-menu', self.popup_menu, menu) # Start thread self.check = CheckStatus() self.check.start() def popup_menu(self, widget, button, time, data): data.show_all() data.popup(None, None, None, None, button, time) def quit_tray(self, widget): # Stop the thread and quit self.check.stop() self.check.join() Gtk.main_quit()if __name__ == '__main__': # Create an instance of our GTK application try: MyStatusIcon() Gtk.main() except: pass
ليست هناك تعليقات:
إرسال تعليق