You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
toxygen/docs/plugin_api.md

58 lines
3.0 KiB
Markdown

7 years ago
# Plugins API
2 years ago
In Toxygen plugin is single python module (.py file) and directory with data associated with it.
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.
8 years ago
Every plugin has its own full name and unique short name (1-5 symbols). Main app can get it using special methods.
All plugin's data should be stored in following structure:
```
/plugins/
|---plugin_short_name.py
|---/plugin_short_name/
|---settings.json
8 years ago
|---readme.txt
8 years ago
|---logs.txt
|---other_files
```
8 years ago
Plugin MUST override:
7 years ago
- __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.
8 years ago
Plugin can override following methods:
- get_description - this method should return plugin description.
8 years ago
- 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.
- 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.
8 years ago
- close - app is closing, stop plugin.
8 years ago
- 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.
- lossless_packet - callback - incoming lossless packet from friend.
- lossy_packet - callback - incoming lossy packet from friend.
8 years ago
- 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.
Other methods:
8 years ago
- 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.
- load_settings - loads settings stored in default location.
- save_settings - saves settings to default location.
8 years ago
- 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).
8 years ago
About import:
8 years ago
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)
8 years ago
About GUI:
GUI is available via PyQt5. Plugin can have no GUI at all.
8 years ago
Exceptions:
8 years ago
Plugin's methods MUST NOT raise exceptions.
8 years ago
7 years ago
# Examples
8 years ago
7 years ago
You can find examples in [official repo](https://github.com/toxygen-project/toxygen_plugins)