From 958ec6e86d0a8e97e4ed0005cf05af04da44035d Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Mon, 24 Feb 2025 21:20:01 -0700 Subject: [PATCH] Reset to basic state --- pywmreceived.py | 106 ++---------------------------------------------- 1 file changed, 4 insertions(+), 102 deletions(-) diff --git a/pywmreceived.py b/pywmreceived.py index 705b2a1..7554e42 100755 --- a/pywmreceived.py +++ b/pywmreceived.py @@ -6,17 +6,11 @@ Copyright (C) 2006 Mario Frasca Licensed under the GNU General Public License. """ -import asyncio -import signal import logging -from dbus_next.aio import MessageBus -from dbus_next import Message from wmdocklib import wmoo as wmoo - line_height = 9 - logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -286,58 +280,10 @@ patterns = [ ] - -# Define the signal handler outside of any function -def on_received_im_msg(message): - if message.member == 'ReceivedImMsg': - print("ReceivedImMsg signal received with arguments:") - for arg in message.body: - print(f" - {arg}") - -async def run_dbus(): +def main(): """ - Sets up the DBus connection, adds the signal handler, and listens for signals. + The main entry point of the application. """ - # Connect to the session bus - bus = await MessageBus().connect() - - # Define the service and object path - service_name = 'im.pidgin.purple.PurpleService' - object_path = '/im/pidgin/purple/PurpleObject' - interface_name = 'im.pidgin.purple.PurpleInterface' - - # Add the signal handler to the bus - bus.add_message_handler(on_received_im_msg) - - # Construct the match rule for the signal - match_rule = ( - f"type='signal'," - f"interface='{interface_name}'," - f"member='ReceivedImMsg'" - ) - - # Create the AddMatch message - add_match_message = Message( - destination='org.freedesktop.DBus', - path='/org/freedesktop/DBus', - interface='org.freedesktop.DBus', - member='AddMatch', - signature='s', - body=[match_rule] - ) - - # Send the AddMatch message to subscribe to the signal - await bus.call(add_match_message) - - # Inform the user that the program is listening for signals - print("Listening for ReceivedImMsg signals...") - - # Keep the program running to listen for signals - await asyncio.Future() # Run forever - - - -async def run_application(): app = Application(font_name='5x8', margin = 3, bg=0, @@ -350,52 +296,8 @@ async def run_application(): app.draw_background() app.draw_all_text() app.addCallback(app.toggle_backlight, 'buttonrelease', area=(2,2,62,62)) - await app.run() - - - -async def main(): - # Connect to the session bus - bus = await MessageBus().connect() - - # Define the service and object path - service_name = 'im.pidgin.purple.PurpleService' - object_path = '/im/pidgin/purple/PurpleObject' - interface_name = 'im.pidgin.purple.PurpleInterface' - - # Add the signal handler to the bus - bus.add_message_handler(on_received_im_msg) - - # Construct the match rule for the signal - match_rule = ( - f"type='signal'," - f"interface='{interface_name}'," - f"member='ReceivedImMsg'" - ) - - # Create the AddMatch message - add_match_message = Message( - destination='org.freedesktop.DBus', - path='/org/freedesktop/DBus', - interface='org.freedesktop.DBus', - member='AddMatch', - signature='s', - body=[match_rule] - ) - - # Send the AddMatch message to subscribe to the signal - await bus.call(add_match_message) - - # Inform the user that the program is listening for signals - print("Listening for ReceivedImMsg signals...") - - # Keep the program running to listen for signals - # await run_application() - await asyncio.Future() + app.run() if __name__ == '__main__': - try: - asyncio.run(main()) - except KeyboardInterrupt: - logger.info("Program terminated by user.") \ No newline at end of file + main() \ No newline at end of file