<-- back to the index of Rosetta examples

hello world (popup window + submenu)

Create a new action hello() that prints "Hello world!" in a popup window, create a menu (under "Plugins/GPMI scripting/") that executes the action.

Example implementations

awk | bash | lua | pl | py | rb | scm | stt | tcl

Explanation, step by step

Load packages the script depends on:

Create a function ev_action that will be called when any of the actions registered by the script is executed. The script registers only one action, so it does not need to check which action caused the function to be called.

When the action event is called, use dialog_report to pop up a report dialog. First argument donates the name (title) of the window, the second is the text printed in the window.

Create a function ev_gui_init that will be called when the gui has been initialized - this is the right moment to register new menus in the GUI. Put the new menu item in the "Plugins/GPMI scripting/" menu by convention, and set hot key to ctrl+w. The menu should execute action hello().

In the "main" section of the script, bind event ACTE_action to our local function ev_action - this gets ev_action to be called when any of the actions registered by this script is executed. Also bind ev_gui_init so that the new menu can be safely created.

Finally use action_register to register the action: