-
-
Notifications
You must be signed in to change notification settings - Fork 39
UBA Context Plugins
UBA context plugins are plugins accessible from right-click context menu.
They are displayed at the end of context menu.
A valid plugin file should be written in python file extension ".py".
Read https://github.com/eliranwong/UniqueBible/wiki/UBA-Plugins for other types of UBA plugins.
All UBA context plugins are placed in folder "plugins/context/" inside UniqueBible home directory.
You need to have "enablePlugins" checked on "Set Config Flags" window.
config.mainWindow points to the mainWindow of UBA. This gives developer an access point of UBA built-in functions.
The text selected by user before a right-click is assigned to config.pluginContext, with which plugin could process selected text.
The widget where context menu is called from is pointed by config.contextSource, so developer can distinguish whether it is called from bible window or study window.
A context plugin could be as simple as below, to display selected text in a dialog window.
import config
config.mainWindow.displayMessage(config.pluginContext)
The following two lines print all html codes:
import config
config.contextSource.page().toHtml(print)
You may use context plugin as a shortcut to a particular resource, e.g.
Save these two lines below as a file in folder "UniqueBible/plugins/context/" and name it "WordNet.py".
You can then select a word, right-click and select "WordNet" to search this word in a third party dictionary called "wordnet".
import config
config.mainWindow.runTextCommand("SEARCHTHIRDDICTIONARY:::wordnet:::{0}".format(config.pluginContext))
You may have multiple files for a plugin and some of which are shared library files, which you do not want to display on context menu.
You can do this by placing them into a sub-folder. Python files placed inside a sub-folder within the directory "plugins/context/" are not displayed on context menu.
https://github.com/eliranwong/UniqueBible/tree/master/plugins/context