From 0716c1d8499eaa638bfa30bdf42386e894f83a7d Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Tue, 25 Feb 2025 08:06:13 -0700 Subject: [PATCH] initial with whitespace fixe --- pywmreceived.py | 54 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/pywmreceived.py b/pywmreceived.py index 7554e42..a6bed49 100755 --- a/pywmreceived.py +++ b/pywmreceived.py @@ -81,18 +81,17 @@ class Application(wmoo.Application): self.draw_all_text() - def update(self): - wmoo.Application.update(self) - self._count += 1 - if self._count <= 3: - return + def update(self): + wmoo.Application.update(self) + self._count += 1 + if self._count <= 3: + return self._count = 0 if self._flasher: self._flasher -= 1 self.toggle_backlight(True) - - + palette = { ".": "#767C6F", "+": "#010101", @@ -280,6 +279,19 @@ patterns = [ ] +# Example signal handler (replace with your actual handler) +def handle_received_im_msg(sender, message): + """Handles the ReceivedIMMsg signal from the PurpleService.""" + print(f"Received message from {sender}: {message}") + # Process the message here + +def handle_sending_im_msg(sender, message): + """Handles the ReceivedIMMsg signal from the PurpleService.""" + print(f"Received message from {sender}: {message}") + # Process the message here + + + def main(): """ The main entry point of the application. @@ -296,6 +308,34 @@ def main(): app.draw_background() app.draw_all_text() app.addCallback(app.toggle_backlight, 'buttonrelease', area=(2,2,62,62)) + + """this contains the eventLoop. events are examined and if a + callback has been registered, it is called, passing it the event as + argument. + """ + + # Initialize DBus mainloop + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + bus = dbus.SessionBus() # Or dbus.SystemBus() if it's a system service + + try: + purple_service = bus.get_object('im.pidgin.purple.PurpleService', '/im/pidgin/purple/PurpleObject') + purple_service.connect_to_signal("ReceivedIMMsg", handle_received_im_msg, dbus_interface="im.pidgin.purple.PurpleInterface") + purple_service.connect_to_signal("SendingIMMsg", handle_sending_im_msg, dbus_interface="im.pidgin.purple.PurpleInterface") + except dbus.exceptions.DBusException as e: + print(f"Error connecting to PurpleService: {e}") + purple_service = None # Handle the case where the service isn't available + + def check_dbus(): + """Check for and process DBus messages.""" + # This is a placeholder. DBus messages are handled automatically by the mainloop. + # You don't need to explicitly fetch them. The signal handlers you connect + # (like the commented-out example above) will be called when signals arrive. + return True # Keep the GLib.timeout_add running + + # Add a GLib timeout to periodically check for DBus messages (though it's mostly for keeping the loop alive) + GLib.timeout_add(100, check_dbus) # Check every 100 milliseconds + app.run()