-
Notifications
You must be signed in to change notification settings - Fork 12
Plugins
Sam Gillingham edited this page Jun 6, 2023
·
3 revisions
Your plugin must have the extension .py and be a normally import-able module with these 3 functions:
- name
- author
- description
- action
constant | object |
---|---|
pluginmanager.PLUGIN_ACTION_INIT | GeolinkedViewers |
pluginmanager.PLUGIN_ACTION_NEWVIEWER | ViewerWindow |
pluginmanager.PLUGIN_ACTION_NEWQUERY | QueryDockWidget |
Information on the internal classes of TuiView can be found at the Developer's Documentation page.
Viewer searched for plugins in 3 locations upon startup:
- a 'plugins' directory under where the 'tuiview' script is running
- Any directories listed in the TUIVIEW_PLUGINS_PATH environment variable. Multiple directories can be listed and separated by ':' on Unix or ';' on Windows.
- Under ~/.tuiview/plugins where ~ is the user's home directory, or c:\Users\username\ .tuiview\plugins on Windows
Here is an example of adding a custom action and a new menu to Viewer via a plugin:
...
# event handler class - must be derived from QObject
# so Qt's signal and slots system works
class MyEventHandler(QObject):
def __init__(self, viewer):
QObject.__init__(self)
self.viewer = viewer
# this function gets called when action triggered
def myEvent(self):
QMessageBox.information(self.viewer, "Viewer", "My Plugin")
def action(actioncode, viewer):
# check for the code we are interested in
if actioncode == pluginmanager.PLUGIN_ACTION_NEWVIEWER:
# create a handler class
handler = MyEventHandler(viewer)
# create an action class
myaction = QAction(viewer, triggered=handler.myEvent)
myaction.setText("My plugin Action")
# create a new menu and install the action
mymenu = viewer.menuBar().addMenu("&My Menu")
mymenu.addAction(myaction)
# make sure the object isn't garbage collected
app = QApplication.instance()
app.savePluginHandler(handler)