Before you start developing plugins, you need to know how to run the source code. See the README.md for the development introduction.
- Go to
COMTool/plugins
dir - Create a plugin file like
myplugin.py
- Write a class in
myplugin.py
, and inherit from.base.Plugin_Base
, and name must bePlugin
e.g.
from .base import Plugin_Base
class Plugin(Plugin_Base):
pass
-
Edit your plugin class, implement variables and functions inherit from
Plugin_Base
, and you can use translate in your code by function_
, e.g._("hello")
. Example plugin see myplugin.py -
Add plugin in COMTool/plugins/init.py to enable plugin
from . import myplugin
plugins = [..., myplugin.Plugin]
- OK, all works done! Just run program to see our plugin
python COMTool/Main.py
- Create a project dir and a
myplugin.py
file (any name is ok) - Wite a plugin the as we said in section one, emample file see myplugin.py, and the plugin class' name must be
Plugin
- Bootup COMTool, click plugins list and select add new plugin
And there's some points should be pay attention:
- When load plugin, the plugin's path will be insert to the start of
sys.path
, so you should name your files carefully, it's recommended to name all files to be likelycomtool_plugin_xxx.py
- Comtool binary executable packed with
pyinstaller
, only packed some package comtool used, so if your plugin contain some special package, there's some resolution:- Just keep your plugin clean, no special package import
- Or copy them to dir root dir of binary executable file too
- Or use comtool program install as python package(installed by pip)
Create a python package, example: COMTool/plugins/myplugin2
- Package name must be
comtool_plugin_xxx
- Build package with
python setup.py sdist bdist_wheel
- You can upload your package to
pypi.org
, bytwine upload ./dist/*
- Then user can install your package by
pip install comtool-plugin-xxx
, then comtool will automatically load plugin
If you want to let your plugin support i18n(internationalization):
- Just like COMTool/plugins/myplugin2 did, create a
plugin_18n.py
to define_
function, and use it in your plugin like_("Hello")
- Use
comtool-i18n -p <package path> prepare
first, e.g.comtool-i18n -p COMTool/plugins/myplugin2/comtool_plugin_myplugin2 prepare
to find strings need to translate in your code automatically, this will generatemessages.pot
andpo
files inlocales
directory - Translate
po
files manually - Run
comtool-i18n -p <package name> finish
to generatemo
files inlocales
directory setup.py
should include translate binary files (*.mo
) to package data, so user can use these translation
Connection plugin just the same as the plugins, have an base class COMM
in COMTool/conn/init.py, just:
-
Create a new file in
COMTool/conn
directory likeconn_serial.py
,conn_ssh.py
,conn_tcp_udp.py
, and implement the methods ofCOMM
class'. -
Add your connection class to COMTool/conn/init.py
-
That's all, run COMTool
python COMTool/Main.py