Reset to basic state

This commit is contained in:
Fredrick W. Warren 2025-02-24 21:20:01 -07:00
parent 2ff964b1ac
commit 958ec6e86d

View File

@ -6,17 +6,11 @@ Copyright (C) 2006 Mario Frasca
Licensed under the GNU General Public License. Licensed under the GNU General Public License.
""" """
import asyncio
import signal
import logging import logging
from dbus_next.aio import MessageBus
from dbus_next import Message
from wmdocklib import wmoo as wmoo from wmdocklib import wmoo as wmoo
line_height = 9 line_height = 9
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -286,58 +280,10 @@ patterns = [
] ]
def main():
# 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():
""" """
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', app = Application(font_name='5x8',
margin = 3, margin = 3,
bg=0, bg=0,
@ -350,52 +296,8 @@ async def run_application():
app.draw_background() app.draw_background()
app.draw_all_text() app.draw_all_text()
app.addCallback(app.toggle_backlight, 'buttonrelease', area=(2,2,62,62)) app.addCallback(app.toggle_backlight, 'buttonrelease', area=(2,2,62,62))
await app.run() 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()
if __name__ == '__main__': if __name__ == '__main__':
try: main()
asyncio.run(main())
except KeyboardInterrupt:
logger.info("Program terminated by user.")