Added test function

This commit is contained in:
Abhorrent_Anger 2019-10-30 08:34:47 +02:00
parent de7024511a
commit c4c649fa88
1 changed files with 23 additions and 15 deletions

View File

@ -2,10 +2,12 @@ import subprocess
from time import sleep from time import sleep
import prof import prof
led_thread = None
last_window_jid = None last_window_jid = None
unfocused_jid = {} unfocused_jid = {}
def test_thread():
pass
def call_command(state_on=True): def call_command(state_on=True):
if state_on: if state_on:
command = prof.settings_string_get("lednotification", "command_on", "xset led 3") 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 def enable_led(state_on=True): # Can be expanded for different ways to call LED changes
call_command(state_on) call_command(state_on)
def led_notify(): def led_notify(state_on=True):
enable_led(True) enable_led(state_on)
def prof_on_chat_win_focus(barejid): def prof_on_chat_win_focus(barejid):
on_focus(barejid) on_focus(barejid)
@ -33,19 +35,13 @@ def on_focus(jid):
global focused global focused
global last_window_jid global last_window_jid
global unfocused_jid global unfocused_jid
prof.cons_show("!!!" + unfocused_jid + " ; " + bool(unfocused_jid))
focused = True focused = True
last_window_jid = jid last_window_jid = jid
unfocused_jid.pop(jid, None) unfocused_jid.pop(jid, None)
if led_thread:
led_thread.join()
led_thread = None
if not unfocused_jid: if not unfocused_jid:
enable_led(False) led_notify(False)
def prof_post_chat_message_display(barejid, resource, message): 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): if check_chat_notify(barejid):
led_notify() led_notify()
return message return message
@ -62,11 +58,9 @@ def prof_post_priv_message_display(barejid, nick, message):
def check_chat_notify(barejid): def check_chat_notify(barejid):
global unfocused_jid global unfocused_jid
is_console = prof.current_win_is_console() is_console = prof.current_win_is_console()
if last_window_jid != barejid or is_console: if last_window_jid != barejid or is_console:
unfocused_jid[barejid] = True unfocused_jid[barejid] = True
prof.cons_show("CCC##!!!" + unfocused_jid + " ; " + bool(unfocused_jid))
enabled = prof.settings_string_get("lednotification", "enabled", "on") enabled = prof.settings_string_get("lednotification", "enabled", "on")
return enabled == "on" and is_console return enabled == "on" and is_console
@ -101,6 +95,18 @@ def _cmd_say(arg1=None, arg2=None):
else: else:
prof.settings_string_set("lednotification", "rooms", arg2) prof.settings_string_set("lednotification", "rooms", arg2)
prof.cons_show("LED notifications notifications for rooms set to: " + 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: else:
enabled = prof.settings_string_get("lednotification", "enabled", "on") enabled = prof.settings_string_get("lednotification", "enabled", "on")
command_on = prof.settings_string_get("lednotification", "command_on", "xset led 3") 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 on|off",
"/lednotification command on command", "/lednotification command on command",
"/lednotification command off command", "/lednotification command off command",
"/lednotification rooms on|off"] "/lednotification rooms on|off",
"/lednotification test"]
description = "Show new notifications with LEDs" description = "Show new notifications with LEDs"
args = [ args = [
["on|off", "Enable/disable lednotification for all windows"], ["on|off", "Enable/disable lednotification for all windows"],
["command on <args>", "Command for turning the LED on"], ["command on <args>", "Command for turning the LED on"],
["command off <args>", "Command for turning the LED off"], ["command off <args>", "Command for turning the LED off"],
["rooms <args>", "Turn notifications for rooms on or off"]] ["rooms <args>", "Turn notifications for rooms on or off"],
["test", "Tests LED notification calls"]]
examples = [ examples = [
"/lednotification on", "/lednotification on",
"/lednotification command on xset led 3", "/lednotification command on xset led 3",
"/lednotification rooms off"] "/lednotification rooms off"]
prof.register_command("/lednotification", 0, 2, synopsis, description, args, examples, _cmd_say) 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"]) prof.completer_add("/lednotification rooms", ["on", "off"])