Skip to content

UBA Context Plugins

Eliran Wong edited this page Apr 23, 2022 · 12 revisions

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.

File Location

All UBA context plugins are placed in folder "plugins/context/" inside UniqueBible home directory.

Enable Plugins

You need to have "enablePlugins" checked on "Set Config Flags" window.

config.mainWindow

config.mainWindow points to the mainWindow of UBA. This gives developer an access point of UBA built-in functions.

config.pluginContext

The text selected by user before a right-click is assigned to config.pluginContext, with which plugin could process selected text.

config.contextSource

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.

An example

A context plugin could be as simple as below, to display selected text in a dialog window.

import config

config.mainWindow.displayMessage(config.pluginContext)

Another example

The following two lines print all html codes:

import config

config.contextSource.page().toHtml(print)

Use as a Shortcut

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))

Hide supporting files from context menu

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.

Real Examples

https://github.com/eliranwong/UniqueBible/tree/master/plugins/context

Clone this wiki locally