toxygen/docs/plugin_api.md

58 lines
3.0 KiB
Markdown
Raw Permalink Normal View History

2017-04-06 18:28:34 +00:00
# Plugins API
2016-05-28 10:06:13 +00:00
In Toxygen plugin is single python (supported Python 3.4 - 3.6) module (.py file) and directory with data associated with it.
2016-05-28 10:06:13 +00:00
Every module must contain one class derived from PluginSuperClass defined in [plugin_super_class.py](/src/plugins/plugin_super_class.py). Instance of this class will be created by PluginLoader class (defined in [plugin_support.py](/src/plugin_support.py) ). This class can enable/disable plugins and send data to it.
2016-07-10 21:38:25 +00:00
Every plugin has its own full name and unique short name (1-5 symbols). Main app can get it using special methods.
2016-05-28 10:06:13 +00:00
All plugin's data should be stored in following structure:
```
/plugins/
|---plugin_short_name.py
|---/plugin_short_name/
|---settings.json
2016-08-01 19:07:01 +00:00
|---readme.txt
2016-05-28 19:43:51 +00:00
|---logs.txt
2016-05-28 10:06:13 +00:00
|---other_files
```
2016-07-10 21:38:25 +00:00
Plugin MUST override:
2017-04-06 18:28:34 +00:00
- __init__ with params: tox (Tox instance), profile (Profile instance), settings (Settings instance), encrypt_save (ToxES instance). Call super().__init__ with params plugin_full_name, plugin_short_name, tox, profile, settings, encrypt_save.
2016-07-10 21:38:25 +00:00
2016-05-28 10:06:13 +00:00
Plugin can override following methods:
- get_description - this method should return plugin description.
2016-07-10 21:38:25 +00:00
- get_menu - plugins allowed to add items in friend menu. User can open this menu making right click on friend in friends list. This method should return list of QAction's. Plugin must connect to QAction's triggered() signal.
2016-05-28 10:06:13 +00:00
- get_window - plugins can have GUI, this method should return window instance or None for plugins without GUI.
- start - plugin was started.
- stop - plugin was stopped.
2016-05-28 19:43:51 +00:00
- close - app is closing, stop plugin.
2016-07-10 21:38:25 +00:00
- command - new command to plugin. Command can be entered in message field in format '/plugin <plugin_short_name> <command>'. Command 'help' should show list of supported commands.
2016-05-28 10:06:13 +00:00
- lossless_packet - callback - incoming lossless packet from friend.
- lossy_packet - callback - incoming lossy packet from friend.
2016-07-10 21:38:25 +00:00
- friend_connected - callback - friend became online. Note that it called from friend_connection_status callback so friend is not really connected and ready for sending packets.
2016-05-28 10:06:13 +00:00
Other methods:
2016-07-10 21:38:25 +00:00
- send_lossless - this method sends custom lossless packet. Plugins MUST send lossless packets using this method.
- send_lossy - this method sends custom lossy packet. Plugins MUST send lossy packets using this method.
2016-05-28 10:06:13 +00:00
- load_settings - loads settings stored in default location.
- save_settings - saves settings to default location.
2016-07-10 21:38:25 +00:00
- load_translator - loads translations. Translations must be stored in directory with plugin's data. Files with translations must have the same name as in main app (example: ru_RU.qm).
2016-05-28 10:06:13 +00:00
2016-05-28 19:43:51 +00:00
About import:
2016-07-10 21:38:25 +00:00
Import statement will not work in case you import module that wasn't previously imported by main program and user uses precompiled binary. It's recommended to use importlib module instead: importlib.import_module(module_name)
2016-05-28 19:43:51 +00:00
About GUI:
GUI is available via PyQt5. Plugin can have no GUI at all.
2016-05-28 19:43:51 +00:00
Exceptions:
2016-07-10 21:38:25 +00:00
Plugin's methods MUST NOT raise exceptions.
2016-05-28 19:43:51 +00:00
2017-04-06 18:28:34 +00:00
# Examples
2016-05-28 19:43:51 +00:00
2017-03-04 20:35:46 +00:00
You can find examples in [official repo](https://github.com/toxygen-project/toxygen_plugins)
2016-05-28 10:06:13 +00:00