diff --git a/lednotification.py b/lednotification.py index d27e626..cef284d 100644 --- a/lednotification.py +++ b/lednotification.py @@ -2,10 +2,12 @@ import subprocess from time import sleep import prof -led_thread = None last_window_jid = None unfocused_jid = {} +def test_thread(): + pass + def call_command(state_on=True): if state_on: command = prof.settings_string_get("lednotification", "command_on", "xset led 3") @@ -16,8 +18,8 @@ def call_command(state_on=True): def enable_led(state_on=True): # Can be expanded for different ways to call LED changes call_command(state_on) -def led_notify(): - enable_led(True) +def led_notify(state_on=True): + enable_led(state_on) def prof_on_chat_win_focus(barejid): on_focus(barejid) @@ -33,19 +35,13 @@ def on_focus(jid): global focused global last_window_jid global unfocused_jid - prof.cons_show("!!!" + unfocused_jid + " ; " + bool(unfocused_jid)) focused = True last_window_jid = jid unfocused_jid.pop(jid, None) - if led_thread: - led_thread.join() - led_thread = None if not unfocused_jid: - enable_led(False) + led_notify(False) def prof_post_chat_message_display(barejid, resource, message): - prof.cons_show('test1234') - prof.cons_show("##!!!" + unfocused_jid + " ; " + bool(unfocused_jid)) if check_chat_notify(barejid): led_notify() return message @@ -62,11 +58,9 @@ def prof_post_priv_message_display(barejid, nick, message): def check_chat_notify(barejid): global unfocused_jid - is_console = prof.current_win_is_console() if last_window_jid != barejid or is_console: unfocused_jid[barejid] = True - prof.cons_show("CCC##!!!" + unfocused_jid + " ; " + bool(unfocused_jid)) enabled = prof.settings_string_get("lednotification", "enabled", "on") return enabled == "on" and is_console @@ -101,6 +95,18 @@ def _cmd_say(arg1=None, arg2=None): else: prof.settings_string_set("lednotification", "rooms", arg2) prof.cons_show("LED notifications notifications for rooms set to: " + arg2) + elif arg1 == "test": + barejid = "TestJidUser" + test_message_on = "Testing Receiving (LED should be on)" + test_message_off = "Testing Focus (LED should be off)" + test_message_fin = "Done testing LED notifications" + prof.cons_show(test_message_on) + prof_post_chat_message_display(barejid, barejid, test_message_on) + sleep(0.5) + prof.cons_show(test_message_off) + prof_on_chat_win_focus(barejid) + prof.cons_show(test_message_fin) + else: enabled = prof.settings_string_get("lednotification", "enabled", "on") command_on = prof.settings_string_get("lednotification", "command_on", "xset led 3") @@ -117,18 +123,20 @@ def prof_init(version, status, account_name, fulljid): "/lednotification on|off", "/lednotification command on command", "/lednotification command off command", - "/lednotification rooms on|off"] + "/lednotification rooms on|off", + "/lednotification test"] description = "Show new notifications with LEDs" args = [ ["on|off", "Enable/disable lednotification for all windows"], ["command on ", "Command for turning the LED on"], ["command off ", "Command for turning the LED off"], - ["rooms ", "Turn notifications for rooms on or off"]] + ["rooms ", "Turn notifications for rooms on or off"], + ["test", "Tests LED notification calls"]] examples = [ "/lednotification on", "/lednotification command on xset led 3", "/lednotification rooms off"] prof.register_command("/lednotification", 0, 2, synopsis, description, args, examples, _cmd_say) - prof.completer_add("/lednotification", ["on", "off", "rooms"]) + prof.completer_add("/lednotification", ["on", "off", "rooms", "test"]) prof.completer_add("/lednotification rooms", ["on", "off"]) \ No newline at end of file