diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2025-07-07 08:31:38 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2025-07-07 08:32:41 +0200 |
commit | f2b300d9e01547628cd409f9666d457b5ea045ee (patch) | |
tree | daf4e52ebd5bd8d2f4e708d4e467b88cdba3f724 /macropad.pyw | |
parent | 69a6777bf3b849ec2ab0627b6ad66a57298f9d45 (diff) |
Diffstat (limited to 'macropad.pyw')
-rwxr-xr-x | macropad.pyw | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/macropad.pyw b/macropad.pyw index 6e4f922..a175931 100755 --- a/macropad.pyw +++ b/macropad.pyw @@ -15,7 +15,7 @@ from PIL import Image from zope import component import interfaces from interfaces import endpoint -from interfaces.message import IMessage, Debug +from interfaces.message import IMessage, Debug, Error import consumer from configuration import Mapping @@ -27,8 +27,6 @@ config_file = path.join(script_path, "config.ini") config = configparser.ConfigParser(delimiters="=") config.read(config_file) -mapping = Mapping(config) -component.provideUtility(mapping, interfaces.configuration.IConfiguration) # # Guess the platform and the load the corresponding event listener @@ -64,6 +62,7 @@ handler.start() class Icon(): + """Icon displayed in the notification bar.""" def __init__(self, image): menu=( @@ -101,12 +100,15 @@ class Icon(): mapping.reset() class Application(): + """ The main application. + """ def __init__(self): # Override the default function called when exception are reported tk.Tk.report_callback_exception = self.report_callback_exception self.window = tk.Tk() self.text = Text(self.window, height=8) + self.text.tag_config("error", background="red", foreground="white") ## State of the #pplication self.running = True self.visible = False @@ -137,15 +139,18 @@ class Application(): """ Launch the thread listening events from the desktop """ component.handle(Debug(platform)) + listener = None if platform == "win32": import win32 listener = win32.Listener(mapping) elif platform == 'linux': import xlib listener = xlib.Listener(mapping) - component.handle(Debug("Starting xlib")) - component.provideUtility(listener, interfaces.desktopEvent.IDesktop) - listener.start() + if listener is not None: + component.provideUtility(listener, interfaces.desktopEvent.IDesktop) + listener.start() + else: + component.handle(Error("Unsupported system %s" % platform)) def report_callback_exception(self, exc, val, tb): """ Handle exception reported inside the Tk application. @@ -191,6 +196,9 @@ class Application(): self.text.insert("1.0", "\n") self.text.insert("1.0", message.content) self.text.delete("200.0", "end") + if message.level == 0: + self.text.tag_add("error", "1.0", "1.end") + self.icon.show_hide.set() except Exception as e: print(e) @@ -212,6 +220,8 @@ if __name__ == '__main__': # Start the main application, Initializing the message listener before # listening desktop events app = Application() + mapping = Mapping(config) + component.provideUtility(mapping, interfaces.configuration.IConfiguration) app.connect_desktop() # Initialize the main loop @@ -222,4 +232,6 @@ if __name__ == '__main__': app.running = False app.window.destroy() app.icon.quit() - component.queryUtility(interfaces.desktopEvent.IDesktop).stop() + desktop = component.queryUtility(interfaces.desktopEvent.IDesktop) + if desktop is not None: + desktop.stop() |