diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2022-09-29 00:27:51 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-09-29 17:13:19 +0200 |
commit | e0c117e14f0d6c9edc1d0d6c06fce47c2ae1ca57 (patch) | |
tree | 32b37bfccbf89608b847873b7ec591f15bd696d2 /doc/it/weechat_plugin_api.it.adoc | |
parent | b978de5f846453cde80cdfd81d38e7706092a7ab (diff) | |
download | weechat-e0c117e14f0d6c9edc1d0d6c06fce47c2ae1ca57.zip |
doc/api: Add types for Python callbacks
Diffstat (limited to 'doc/it/weechat_plugin_api.it.adoc')
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 87bfb7b51..ec955dcd7 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -6301,7 +6301,7 @@ Script (Python): def config_new(name: str, callback_reload: str, callback_reload_data: str) -> str: ... # esempio -def my_config_reload_cb(data, config_file): +def my_config_reload_cb(data: str, config_file: str) -> int: # ... return weechat.WEECHAT_RC_OK @@ -6570,26 +6570,26 @@ def config_new_section(config_file: str, name: str, callback_delete_option: str, callback_delete_option_data: str) -> str: ... # esempio -def my_section_read_cb(data, config_file, section, option_name, value): +def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE # return weechat.WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND # return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR -def my_section_write_cb(data, config_file, section_name): +def my_section_write_cb(data: str, config_file: str, section_name: str) -> int: # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_write_default_cb(data, config_file, section_name): +def my_section_write_default_cb(data: str, config_file: str, section_name: str) -> int: # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_create_option_cb(data, config_file, section, option_name, value): +def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE -def my_section_delete_option_cb(data, config_file, section, option): +def my_section_delete_option_cb(data: str, config_file: str, section: str, option: str) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED @@ -6831,15 +6831,15 @@ def config_new_option(config_file: str, section: str, name: str, type: str, desc callback_delete: str, callback_delete_data: str) -> str: ... # esempio -def option4_check_value_cb(data, option, value): +def option4_check_value_cb(data: str, option: str, value: str) -> int: # ... return 1 # return 0 -def option4_change_cb(data, option): +def option4_change_cb(data: str, option: str) -> int: # ... -def option4_delete_cb(data, option): +def option4_delete_cb(data: str, option: str) -> int: # ... option1 = weechat.config_new_option(config_file, section, "option1", "boolean", @@ -7967,7 +7967,7 @@ Script (Python): def config_write_option(config_file: str, option: str) -> int: ... # esempio -def my_section_write_cb(data, config_file, section_name): +def my_section_write_cb(data: str, config_file: str, section_name: str) -> int: weechat.config_write_line(config_file, "my_section", "") weechat.config_write_option(config_file, option) return weechat.WEECHAT_RC_OK @@ -8021,7 +8021,7 @@ Script (Python): def config_write_line(config_file: str, option_name: str, value: str) -> int: ... # esempio -def my_section_write_cb(data, config_file, section_name): +def my_section_write_cb(data: str, config_file: str, section_name: str) -> int: weechat.config_write_line(config_file, "my_section", "") weechat.config_write_line(config_file, "option", "value") return weechat.WEECHAT_RC_OK @@ -9338,7 +9338,7 @@ def hook_command(command: str, description: str, args: str, args_description: st completion: str, callback: str, callback_data: str) -> str: ... # esempio -def my_command_cb(data, buffer, args): +def my_command_cb(data: str, buffer: str, args: str) -> int: # ... return weechat.WEECHAT_RC_OK @@ -9447,7 +9447,7 @@ Script (Python): def hook_completion(completion_item: str, description: str, callback: str, callback_data: str) -> str: ... # esempio -def my_completion_cb(data, completion_item, buffer, completion): +def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: weechat.completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT) weechat.completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT) return weechat.WEECHAT_RC_OK @@ -9540,7 +9540,7 @@ Script (Python): def hook_command_run(command: str, callback: str, callback_data: str) -> str: ... # esempio -def my_command_run_cb(data, buffer, command): +def my_command_run_cb(data: str, buffer: str, command: str) -> int: weechat.prnt("", "Sto mangiando il completamento!") return weechat.WEECHAT_RC_OK_EAT @@ -9620,7 +9620,7 @@ Script (Python): def hook_timer(interval: int, align_second: int, max_calls: int, callback: str, callback_data: str) -> str: ... # esempio -def my_timer_cb(data, remaining_calls): +def my_timer_cb(data: str, remaining_calls: str) -> int: # ... return weechat.WEECHAT_RC_OK @@ -9708,7 +9708,7 @@ Script (Python): def hook_fd(fd: int, flag_read: int, flag_write: int, flag_exception: int, callback: str, callback_data: str) -> str: ... # esempio -def my_fd_cb(data, fd): +def my_fd_cb(data: str, fd: int) -> int: # ... return weechat.WEECHAT_RC_OK @@ -9920,7 +9920,7 @@ Script (Python): def hook_process(command: str, timeout: int, callback: str, callback_data: str) -> str: ... # example with an external command -def my_process_cb(data, command, return_code, out, err): +def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int: if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: weechat.prnt("", "Error with command '%s'" % command) return weechat.WEECHAT_RC_OK @@ -9935,12 +9935,12 @@ def my_process_cb(data, command, return_code, out, err): hook = weechat.hook_process("ls", 5000, "my_process_cb", "") # example with a script function -def get_status(data): +def get_status(data: str) -> str: # do something blocking... # ... return "this is the result" -def my_process_cb(data, command, return_code, out, err): +def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int: if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: weechat.prnt("", "Error with command '%s'" % command) return weechat.WEECHAT_RC_OK @@ -10153,7 +10153,7 @@ Script (Python): def hook_process_hashtable(command: str, options: Dict[str, str], timeout: int, callback: str, callback_data: str) -> str: ... # esempio -def my_process_cb(data, command, return_code, out, err): +def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int: if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: weechat.prnt("", "Error with command '%s'" % command) return weechat.WEECHAT_RC_OK @@ -10358,7 +10358,7 @@ def hook_connect(proxy: str, address: str, port: int, ipv6: int, retry: int, loc callback: str, callback_data: str) -> str: ... # esempio -def my_connect_cb(data, status, gnutls_rc, sock, error, ip_address): +def my_connect_cb(data: str, status: int, gnutls_rc: int, sock: int, error: str, ip_address: str) -> int: if status == WEECHAT_HOOK_CONNECT_OK: # ... elif status == WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND: @@ -10655,7 +10655,7 @@ Script (Python): def hook_line(buffer_type: str, buffer_name: str, tags: str, callback: str, callback_data: str) -> str: ... # esempio -def my_line_cb(data, line): +def my_line_cb(data: str, line: Dict[str, str]) -> Dict[str, str]: # force a highlight on the line return {"highlight": "1"} @@ -10774,7 +10774,7 @@ Script (Python): def hook_print(buffer: str, tags: str, message: str, strip_colors: int, callback: str, callback_data: str) -> str: ... # esempio -def my_print_cb(data, buffer, date, tags, displayed, highlight, prefix, message): +def my_print_cb(data: str, buffer: str, date: str, tags: str, displayed: int, highlight: int, prefix: str, message: str) -> int: if int(highlight): # ... return weechat.WEECHAT_RC_OK @@ -11605,7 +11605,7 @@ Script (Python): def hook_signal(signal: str, callback: str, callback_data: str) -> str: ... # esempio -def my_signal_cb(data, signal, signal_data): +def my_signal_cb(data: str, signal: str, signal_data: str) -> int: # ... return weechat.WEECHAT_RC_OK @@ -11957,7 +11957,7 @@ Script (Python): def hook_hsignal(signal: str, callback: str, callback_data: str) -> str: ... # esempio -def my_hsignal_cb(data, signal, hashtable): +def my_hsignal_cb(data: str, signal: str, hashtable: Dict[str, str]) -> int: # ... return weechat.WEECHAT_RC_OK @@ -12116,7 +12116,7 @@ Script (Python): [source,python] ---- -def test_whois_cb(data, signal, hashtable): +def test_whois_cb(data: str, signal: str, hashtable: Dict[str, str]) -> int: weechat.prnt("", "error = %s" % hashtable["error"]) weechat.prnt("", "output = %s" % hashtable["output"]) return weechat.WEECHAT_RC_OK @@ -12272,7 +12272,7 @@ Script (Python): def hook_config(option: str, callback: str, callback_data: str) -> str: ... # esempio -def my_config_cb(data, option, value): +def my_config_cb(data: str, option: str, value: str) -> int: # ... return weechat.WEECHAT_RC_OK @@ -12448,7 +12448,7 @@ Script (Python): def hook_modifier(modifier: str, callback: str, callback_data: str) -> str: ... # esempio -def my_modifier_cb(data, modifier, modifier_data, string): +def my_modifier_cb(data: str, modifier: str, modifier_data: str, string: str) -> str: return "%s xxx" % string hook = weechat.hook_modifier("weechat_print", "my_modifier_cb", "") @@ -12657,7 +12657,7 @@ def hook_info(info_name: str, description: str, args_description: str, callback: str, callback_data: str) -> str: ... # esempio -def my_info_cb(data, info_name, arguments): +def my_info_cb(data: str, info_name: str, arguments: str) -> str: return "some_info" hook = weechat.hook_info("my_info", "Some info", "Info about arguments", @@ -12743,7 +12743,7 @@ def hook_info_hashtable(info_name: str, description: str, args_description: str, output_description: str, callback: str, callback_data: str) -> str: ... # esempio -def my_info_hashtable_cb(data, info_name, hashtable): +def my_info_hashtable_cb(data: str, info_name: str, hashtable: Dict[str, str]) -> Dict[str, str]: return {"test_key": "test_value"} hook = weechat.hook_info_hashtable("my_info_hashtable", "Some info", @@ -12837,7 +12837,7 @@ def hook_infolist(infolist_name: str, description: str, pointer_description: str args_description: str, callback: str, callback_data: str) -> str: ... # esempio -def my_infolist_cb(data, infolist_name, pointer, arguments): +def my_infolist_cb(data: str, infolist_name: str, pointer: str, arguments: str) -> str: # build infolist # ... return my_infolist @@ -13122,7 +13122,7 @@ Script (Python): def hook_focus(area: str, callback: str, callback_data: str) -> str: ... # esempio -def my_focus_nicklist_cb(data, info): +def my_focus_nicklist_cb(data: str, info: Dict[str, str]) -> Dict[str, str]: # build dict # ... return my_dict @@ -13205,7 +13205,7 @@ Script (Python): def hook_set(hook: str, property: str, value: str) -> int: ... # esempio -def my_process_cb(data, command, return_code, out, err): +def my_process_cb(data: str, command: str, return_code: int, out: str, err: str) -> int: # ... return weechat.WEECHAT_RC_OK @@ -13397,11 +13397,11 @@ def buffer_new(name: str, input_callback: str, input_callback_data: str, close_callback: str, close_callback_data: str) -> str: ... # esempio -def my_input_cb(data, buffer, input_data): +def my_input_cb(data: str, buffer: str, input_data: str) -> int: weechat.prnt(buffer, "Testo: %s" % input_data) return weechat.WEECHAT_RC_OK -def my_close_cb(data, buffer): +def my_close_cb(data: str, buffer: str) -> int: weechat.prnt("", "Il buffer '%s' verrà chiuso!" % weechat.buffer_get_string(buffer, "name")) return weechat.WEECHAT_RC_OK @@ -13524,11 +13524,11 @@ def buffer_new_props(name: str, properties: Dict[str, str], close_callback: str, close_callback_data: str) -> str: ... # esempio -def my_input_cb(data, buffer, input_data): +def my_input_cb(data: str, buffer: str, input_data: str) -> int: weechat.prnt(buffer, "Testo: %s" % input_data) return weechat.WEECHAT_RC_OK -def my_close_cb(data, buffer): +def my_close_cb(data: str, buffer: str) -> int: weechat.prnt("", "Il buffer '%s' verrà chiuso!" % weechat.buffer_get_string(buffer, "name")) return weechat.WEECHAT_RC_OK @@ -15636,13 +15636,13 @@ see example below (supported only in WeeChat ≥ 0.4.2). def bar_item_new(name: str, build_callback: str, build_callback_data: str) -> str: ... # esempio (callback without "buffer" and "extra_info") -def my_build_callback(data, item, window): +def my_build_callback(data: str, item: str, window: str) -> str: return "my content" bar_item = weechat.bar_item_new("myitem", "my_build_callback", "") # example (callback with all arguments, for WeeChat ≥ 0.4.2) -def my_build_callback2(data, item, window, buffer, extra_info): +def my_build_callback2(data: str, item: str, window: str, buffer: str, extra_info: Dict[str, str]) -> str: return "my content" bar_item2 = weechat.bar_item_new("(extra)myitem2", "my_build_callback2", "") # WeeChat ≥ 0.4.2 @@ -16252,7 +16252,7 @@ Script (Python): def completion_get_string(completion: str, property: str) -> str: ... # esempio -def my_completion_cb(data, completion_item, buffer, completion): +def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: # ottiene l'argomento del comando args = weechat.completion_get_string(completion, "args") # completamento che dipende dagli argomenti |