From d5c55ea62122e2b856a5b4966bdc636267bdb22b Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 23 Feb 2016 23:30:31 +0000 Subject: [PATCH] Fixed python test plugins to use new API --- tests/python-test.py | 247 +++++++++++++++++++--------- tests/python-thread.py | 8 +- tests/test-c-plugin/test-c-plugin.c | 14 +- 3 files changed, 181 insertions(+), 88 deletions(-) diff --git a/tests/python-test.py b/tests/python-test.py index f572eed..65496f5 100644 --- a/tests/python-test.py +++ b/tests/python-test.py @@ -1,119 +1,206 @@ import prof -def _timer_test(): - prof.cons_show("python-test: timer fired.") - prof.cons_alert() +plugin_win = "Python Test" -def _handle_upper(win, line): - upper = line.upper(); - prof.win_show(win, upper) - prof.win_show_red(win, upper + " red"); - prof.win_show_yellow(win, upper + " yellow") - prof.win_show_green(win, upper + " green") - prof.win_show_cyan(win, upper + " cyan") +def _handle_win_input(win, line): + prof.win_show(win, "Input received: " + line) -def _cmd_python(msg): - if msg: - prof.cons_show("python-test: /python command called, arg = " + msg) +def create_win(): + if prof.win_exists(plugin_win) == False: + prof.win_create(plugin_win, _handle_win_input) + +def cmd_pythontest(arg1=None, arg2=None, arg3=None): + if arg1 == "consalert": + create_win() + prof.win_focus(plugin_win) + prof.cons_alert() + prof.win_show(plugin_win, "called -> prof.cons_alert") + elif arg1 == "consshow": + if arg2 != None: + create_win() + prof.win_focus(plugin_win) + prof.cons_show(arg2) + prof.win_show(plugin_win, "called -> prof.cons_show: " + arg2) + else: + prof.cons_bad_cmd_usage("/python-test") + elif arg1 == "sendline": + if arg2 != None: + create_win() + prof.win_focus(plugin_win) + prof.send_line(arg2) + prof.win_show(plugin_win, "called -> prof.send_line: " + arg2) + else: + prof.cons_bad_cmd_usage("/python-test") + elif arg1 == "notify": + if arg2 != None: + create_win() + prof.win_focus(plugin_win) + prof.notify(arg2, 5000, "python-test plugin") + prof_win_show(plugin_win, "called -> prof.notify: " + arg2) + else: + prof.cons_bad_cmd_usage("/python-test") + elif arg1 == "get": + if arg2 == None: + prof.cons_bad_cmd_usage("/python-test") + elif arg2 == "recipient": + create_win() + recipient = prof.get_current_recipient(); + if recipient != None: + prof.win_focus(plugin_win) + prof.win_show(plugin_win, "called -> prof.get_current_recipient: " + recipient) + else: + prof.win_focus(plugin_win) + prof.win_show(plugin_win, "called -> prof_get_current_recipient: ") + elif arg2 == "room": + create_win() + room = prof.get_current_muc(); + if room != None: + prof.win_focus(plugin_win) + prof_win_show(plugin_win, "called -> prof_get_current_muc: " + room) + else: + prof.win_focus(plugin_win) + prof.win_show(plugin_win, "called -> prof_get_current_muc: ") + else: + prof.cons_bad_cmd_usage("/python-test") + elif arg1 == "log": + if arg2 == None: + prof.cons_bad_cmd_usage("/python-test") + elif arg2 == "debug": + if arg3 == None: + prof.cons_bad_cmd_usage("/python-test") + else: + create_win() + prof.win_focus(plugin_win) + prof.log_debug(arg3) + prof.win_show(plugin_win, "called -> prof.log_debug: " + arg3) + elif arg2 == "info": + if arg3 == None: + prof.cons_bad_cmd_usage("/python-test") + else: + create_win() + prof.win_focus(plugin_win) + prof.log_info(arg3) + prof.win_show(plugin_win, "called -> prof.log_info: " + arg3) + elif arg2 == "warning": + if arg3 == None: + prof.cons_bad_cmd_usage("/python-test") + else: + create_win() + prof.win_focus(plugin_win) + prof.log_warning(arg3) + prof.win_show(plugin_win, "called -> prof.log_warning: " + arg3) + elif arg2 == "error": + if arg3 == None: + prof.cons_bad_cmd_usage("/python-test") + else: + create_win() + prof.win_focus(plugin_win) + prof.log_error(arg3) + prof.win_show(plugin_win, "called -> prof.log_error: " + arg3) + else: + prof.cons_bad_cmd_usage("/c-test") else: - prof.cons_show("python-test: /python command called with no arg") - -def _cmd_ac(arg1=None, arg2=None): - prof.cons_show("python-test: /py_complete called") - -def _cmd_upper(line): - win_tag = "Python Plugin" - if prof.win_exists(win_tag) == False: - prof.win_create(win_tag, _handle_upper) - prof.win_focus(win_tag) - if line: - _handle_upper(win_tag, line) - -def _cmd_notify(): - prof.notify("python-test: notify", 2000, "Plugins") - -def _cmd_vercheck(): - prof.send_line("/vercheck") - prof.cons_show("python-test: sent \"/vercheck\" command") + prof.cons_bad_cmd_usage("/c-test") def prof_init(version, status): - prof.cons_show("python-test: init, " + version + ", " + status) - prof.register_command("/python", 0, 1, "/python [arg]", "python-test", "python-test", _cmd_python) - prof.register_command("/py_upper", 1, 1, "/py_upper string", "python-test", "python-test", _cmd_upper) - prof.register_command("/py_notify", 0, 0, "/py_notify", "python-test", "python-test", _cmd_notify) - prof.register_command("/py_vercheck", 0, 0, "/py_vercheck", "python-test", "python-test", _cmd_vercheck) - prof.register_ac("/py_complete", [ "aaaa", "bbbb", "bcbcbc" ]) - prof.register_ac("/py_complete aaaa", [ "one", "two", "three", "four" ]) - prof.register_ac("/py_complete bcbcbc", [ "james", "jim", "jane", "bob" ]) - prof.register_command("/py_complete", 0, 2, "/py_complete [arg1] [arg2]", "python-test", "python-test", _cmd_ac) - prof.register_timed(_timer_test, 30) + prof.win_create(plugin_win, _handle_win_input) + + synopsis = [ + "/python-test consalert", + "/python-test consshow ", + "/python-test notify ", + "/python-test sendline ", + "/python-test get recipient|room", + "/python-test log debug|info|warning|error " + ] + description = "Python test plugins. All commands focus the plugin window." + args = [ + [ "consalert", "Highlight the console window in the status bar" ], + [ "consshow ", "Show the message in the console window" ], + [ "notify ", "Send a desktop notification with message" ], + [ "sendline ", "Pass line to profanity to process" ], + [ "get recipient", "Show the current chat recipient, if in a chat window" ], + [ "get room", "Show the current room JID, if ina a chat room"], + [ "log debug|info|warning|error ", "Log a message at the specified level" ] + ] + examples = [ + "/python-test sendline /about", + "/python-test log debug \"Test debug message\"" + ] + + prof.register_command("/python-test", 1, 3, synopsis, description, args, examples, cmd_pythontest) + + prof.register_ac("/python-test", + [ "consalert", "consshow", "notify", "sendline", "get", "log" ] + ) + prof.register_ac("/python-test get", + [ "recipient", "room" ] + ) + prof.register_ac("/python-test log", + [ "debug", "info", "warning", "error" ] + ) def prof_on_start(): - prof.cons_show("python-test: prof_on_start") - prof.log_debug("python-test: logged debug") - prof.log_info("python-test: logged info") - prof.log_warning("python-test: logged warning") - prof.log_error("python-test: logged error") + create_win() + prof.win_show(plugin_win, "fired -> prof_on_start") def prof_on_shutdown(): - prof.log_info("python-test: prof_on_shutdown") + create_win() + prof.win_show(plugin_win, "fired -> prof_on_shutdown") def prof_on_connect(account_name, fulljid): - prof.cons_show("python-test: prof_on_connect, " + account_name + ", " + fulljid) + create_win() + prof.win_show(plugin_win, "fired -> prof_on_connect: " + account_name + ", " + fulljid) def prof_on_disconnect(account_name, fulljid): - prof.cons_show("python-test: prof_on_disconnect, " + account_name + ", " + fulljid) + create_win() + prof.win_show(plugin_win, "fired -> prof_on_disconnect: " + account_name + ", " + fulljid) def prof_pre_chat_message_display(jid, message): - prof.cons_show("python-test: prof_pre_chat_message_display, " + jid + ", " + message) - prof.cons_alert() - return message + "[PY_pre_chat_message_display]" + create_win() + prof.win_show(plugin_win, "fired -> prof_pre_chat_message_display: " + jid + ", " + message) def prof_post_chat_message_display(jid, message): - prof.cons_show("python-test: prof_post_chat_message_display, " + jid + ", " + message) - prof.cons_alert() + create_win() + prof.win_show(plugin_win, "fired -> prof_post_chat_message_display: " + jid + ", " + message) def prof_pre_chat_message_send(jid, message): - prof.cons_show("python-test: prof_pre_chat_message_send, " + jid + ", " + message) - prof.cons_alert() - return message + "[PY_pre_chat_message_send]" + create_win() + prof.win_show(plugin_win, "fired -> prof_pre_chat_message_send: " + jid + ", " + message) def prof_post_chat_message_send(jid, message): - prof.cons_show("python-test: prof_post_chat_message_send, " + jid + ", " + message) - prof.cons_alert() + create_win() + prof.win_show(plugin_win, "fired -> prof_post_chat_message_send: " + jid + ", " + message) def prof_pre_room_message_display(room, nick, message): - prof.cons_show("python-test: prof_pre_room_message_display, " + room + ", " + nick + ", " + message) - prof.cons_alert() - return message + "[PY_pre_room_message_display]" + create_win() + prof.win_show(plugin_win, "fired -> prof_pre_room_message_display: " + room ", " + nick + ", " + message) def prof_post_room_message_display(room, nick, message): - prof.cons_show("python-test: prof_post_room_message_display, " + room + ", " + nick + ", " + message) - prof.cons_alert() + create_win() + prof.win_show(plugin_win, "fired -> prof_post_room_message_display: " + room + ", " + nick + ", " + message) def prof_pre_room_message_send(room, message): - prof.cons_show("python-test: prof_pre_room_message_send, " + room + ", " + message) - prof.cons_alert() - return message + "[PY_pre_room_message_send]" + create_win() + prof.win_show(plugin_win, "fired -> prof_pre_room_message_send: " + room + ", " + message) def prof_post_room_message_send(room, message): - prof.cons_show("python-test: prof_post_room_message_send, " + room + ", " + message) - prof.cons_alert() + create_win() + prof.win_show(plugin_win, "fired -> prof_post_room_message_send: " + room + ", " + message) def prof_pre_priv_message_display(room, nick, message): - prof.cons_show("python-test: prof_pre_priv_message_display, " + room + ", " + nick + ", " + message) - prof.cons_alert() - return message + "[PY_pre_priv_message_display]" + create_win() + prof.win_show(plugin_win, "fired -> prof_pre_priv_message_display: " + room + ", " + nick + ", " + message) def prof_post_priv_message_display(room, nick, message): - prof.cons_show("python-test: prof_post_priv_message_display, " + room + ", " + nick + ", " + message) - prof.cons_alert() + create_win() + prof.win_show(plugin_win, "fired -> prof_post_priv_message_display: " + room + ", " + nick + ", " + message) def prof_pre_priv_message_send(room, nick, message): - prof.cons_show("python-test: prof_pre_priv_message_send, " + room + ", " + nick + ", " + message) - prof.cons_alert() - return message + "[PY_pre_priv_message_send]" + create_win() + prof.win_show(plugin_win, "fired -> prof_pre_priv_message_send: " + room + ", " + nick + ", " + message) def prof_post_priv_message_send(room, nick, message): - prof.cons_show("python-test: prof_post_priv_message_send, " + room + ", " + nick + ", " + message) - prof.cons_alert() \ No newline at end of file + create_win() + prof.win_show(plugin_win, "fired -> prof_post_priv_message_send: " + room + ", " + nick + ", " + message) + \ No newline at end of file diff --git a/tests/python-thread.py b/tests/python-thread.py index 85fe23c..021dec0 100644 --- a/tests/python-thread.py +++ b/tests/python-thread.py @@ -18,4 +18,10 @@ def prof_init(version, status): t = threading.Thread(target=_inc_counter) t.daemon = True t.start() - prof.register_command("/count", 0, 0, "/count", "Threaded example", "Threaded example", _cmd_count) + + synopsis = [ "/count" ] + description = "Python threading example." + args = [] + examples = [] + + prof.register_command("/count", 0, 0, synopsis, description, args, examples, _cmd_count) diff --git a/tests/test-c-plugin/test-c-plugin.c b/tests/test-c-plugin/test-c-plugin.c index 4e5a94d..f12c7ce 100644 --- a/tests/test-c-plugin/test-c-plugin.c +++ b/tests/test-c-plugin/test-c-plugin.c @@ -219,13 +219,13 @@ prof_init(const char * const version, const char * const status) }; const char *description = "C test plugin. All commands focus the plugin window."; const char *args[][2] = { - { "consalert", "Highlight the console window in the status bar" }, - { "consshow ", "Show the message in the console window" }, - { "notify ", "Send a desltop notification with message" }, - { "sendline ", "Pass line to profanity to process" }, - { "get recipient", "Show the current chat recipient, if in a chat window" }, - { "get room", "Show the current room JID, if in a chat room" }, - { "log debug|info|warning|error", "Log a message at the specified level" }, + { "consalert", "Highlight the console window in the status bar" }, + { "consshow ", "Show the message in the console window" }, + { "notify ", "Send a desktop notification with message" }, + { "sendline ", "Pass line to profanity to process" }, + { "get recipient", "Show the current chat recipient, if in a chat window" }, + { "get room", "Show the current room JID, if in a chat room" }, + { "log debug|info|warning|error ", "Log a message at the specified level" }, { NULL, NULL } };