From ab380cd297d0aef9462e5d7377eb293f7818fe00 Mon Sep 17 00:00:00 2001 From: Abhorrent_Anger Date: Tue, 29 Oct 2019 15:50:49 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 + lednotification.py | 128 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 lednotification.py diff --git a/.gitignore b/.gitignore index e61bca2..d676810 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,5 @@ dmypy.json # Pyre type checker .pyre/ +# VSCode +.vscode \ No newline at end of file diff --git a/lednotification.py b/lednotification.py new file mode 100644 index 0000000..eee27d2 --- /dev/null +++ b/lednotification.py @@ -0,0 +1,128 @@ +import subprocess +from time import sleep + +import prof + +focused = False + +def call_command(state_on=True): + if state_on: + command = prof.settings_string_get("lednotification", "command_on", "xset led 3") + else: + command = prof.settings_string_get("lednotification", "command_off", "xset -led 3") + subprocess.call(command) + +def enable_led(state_on=True): # Can be expanded for different ways to call LED changes + call_command(state_on) + +def led_notify(sender): + global focused + focused = False + blink = prof.settings_string_get("lednotification", "blink", "off") + if blink != "off": + sleep_interval = 0.5 if blink == "on" else blink + while not focused: + enable_led(True) + sleep(sleep_interval) + enable_led(False) + else: + enable_led(True) + +def prof_on_chat_win_focus(): + on_focus() + +def prof_on_room_win_focus(): + rooms = prof.settings_string_get("lednotification", "rooms", "off") + if rooms == "on": + on_focus() + +def on_focus(): + global focused + focused = True + enable_led(False) + +def prof_post_chat_message_display(barejid, resource, message): + enabled = prof.settings_string_get("lednotification", "enabled", "on") + if enabled == "on": + led_notify(barejid) + return message + +def prof_post_room_message_display(barejid, nick, message): + enabled = prof.settings_string_get("lednotification", "enabled", "on") + rooms = prof.settings_string_get("lednotification", "rooms", "off") + if enabled == "on" and rooms == "on": + led_notify(barejid) + return message + +def prof_post_priv_message_display(barejid, nick, message): + enabled = prof.settings_string_get("lednotification", "enabled", "on") + if enabled == "on": + led_notify(barejid) + return message + +def _cmd_say(arg1=None, arg2=None, arg3=None): + if arg1 == "on": + prof.settings_string_set("lednotification", "enabled", "on") + prof.cons_show("LED notifications enabled") + elif arg1 == "off": + prof.settings_string_set("lednotification", "enabled", "off") + prof.cons_show("LED notifications disabled") + elif arg1 == "command": + if arg2 == None or arg3 == None: + prof.cons_bad_cmd_usage("/lednotification") + elif arg2 == "on": + prof.settings_string_set("lednotification", "command_on", arg3) + prof.cons_show("LED notification enable command set to: " + arg3) + elif arg2 == "off": + prof.settings_string_set("lednotification", "command_off", arg3) + prof.cons_show("LED notification disable command set to: " + arg3) + elif arg1 == "blink": + if arg2 == None: + prof.cons_bad_cmd_usage("/lednotification") + else: + prof.settings_string_set("lednotification", "blink", arg2) + prof.cons_show("LED notification blinking set to: " + arg2) + elif arg1 == "rooms": + if arg2 == None: + prof.cons_bad_cmd_usage("/lednotification") + else: + prof.settings_string_set("lednotification", "rooms", arg2) + prof.cons_show("LED notifications notifications for rooms set to: " + arg2) + else: + enabled = prof.settings_string_get("lednotification", "enabled", "on") + command_on = prof.settings_string_get("lednotification", "command_on", "xset led 3") + command_off = prof.settings_string_get("lednotification", "command_off", "xset -led 3") + rooms = prof.settings_string_get("lednotification", "rooms", "off") + blink = prof.settings_string_get("lednotification", "blink", "off") + prof.cons_show("LED notification plugin settings:") + prof.cons_show("enabled: " + enabled) + prof.cons_show("command on: " + command_on) + prof.cons_show("command off: " + command_off) + prof.cons_show("blink: " + blink) + prof.cons_show("rooms: " + rooms) + +def prof_init(version, status, account_name, fulljid): + synopsis = [ + "/lednotification on|off", + "/lednotification command on 'command'", + "/lednotification command off 'command'", + "/lednotification blink on|off|interval", + "/lednotification rooms on|off"] + 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"], + ["blink ", "Turn LED blinking on or off, set blinking interval"], + ["rooms ", "Turn notifications for rooms on or off"]] + examples = [ + "/lednotification on", + "/lednotification command on 'xset led 3'", + "/lednotification rooms off", + "/lednotification blink on", + "/lednotification blink 0.5"] + + prof.register_command("/lednotification", 0, 2, synopsis, description, args, examples, _cmd_say) + prof.completer_add("/lednotification", ["on", "off", "blink", "rooms"]) + prof.completer_add("/lednotification blink", ["on", "off"]) + prof.completer_add("/lednotification rooms", ["on", "off"]) \ No newline at end of file