Index: doc-rnd/gpmi/rosetta/12_hello_menu/ID.desc =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ID.desc (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ID.desc (revision 684) @@ -0,0 +1,3 @@ +Create a new action hello() that prints "Hello world!" in a popup window, create a menu (under "Plugins/GPMI scripting/") that executes the action. + + Index: doc-rnd/gpmi/rosetta/12_hello_menu/ID.name =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ID.name (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ID.name (revision 684) @@ -0,0 +1 @@ +hello world (popup window + submenu) Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.awk =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.awk (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.awk (revision 684) @@ -0,0 +1,20 @@ +BEGIN { + PkgLoad("pcb-rnd-gpmi/actions", 0); + PkgLoad("pcb-rnd-gpmi/dialogs", 0); +} + +function ev_action(id, name, argc, x, y) +{ + dialog_report("Greeting window", "Hello world!"); +} + +function ev_gui_init(id, argc, argv) +{ + create_menu("Plugins/GPMI scripting/hello", "hello()", "h", "Ctrlw", "tooltip for hello"); +} + +BEGIN { + Bind("ACTE_action", "ev_action"); + Bind("ACTE_gui_init", "ev_gui_init"); + action_register("hello", "", "log hello world", "hello()"); +} Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.bash =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.bash (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.bash (revision 684) @@ -0,0 +1,24 @@ +#!/bin/bash + +function load_packages() +{ + GPMI PkgLoad "pcb-rnd-gpmi/actions" 0 + GPMI PkgLoad "pcb-rnd-gpmi/dialogs" 0 +} + +function ev_action() { + GPMI dialog_report "Greeting window" "Hello world!" +} + +function ev_gui_init() +{ + GPMI create_menu "Plugins/GPMI scripting/hello" "hello()" "h" "Ctrlw" "tooltip for hello" +} + +function main() +{ + load_packages + GPMI Bind "ACTE_action" "ev_action" + GPMI Bind "ACTE_gui_init" "ev_gui_init" + GPMI action_register "hello" "" "log hello world" "hello()" +} Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.html =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.html (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.html (revision 684) @@ -0,0 +1,33 @@ +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: +

Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.lua =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.lua (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.lua (revision 684) @@ -0,0 +1,14 @@ +PkgLoad("pcb-rnd-gpmi/actions", 0); +PkgLoad("pcb-rnd-gpmi/dialogs", 0); + +function ev_action(id, name, argc, x, y) + dialog_report("Greeting window", "Hello world!"); +end + +function ev_gui_init(id, argc, argv) + create_menu("Plugins/GPMI scripting/hello", "hello()", "h", "Ctrlw", "tooltip for hello"); +end + +Bind("ACTE_action", "ev_action"); +Bind("ACTE_gui_init", "ev_gui_init"); +action_register("hello", "", "log hello world", "hello()"); Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.pl =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.pl (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.pl (revision 684) @@ -0,0 +1,17 @@ +PkgLoad("pcb-rnd-gpmi/actions", 0); +PkgLoad("pcb-rnd-gpmi/dialogs", 0); + +sub ev_action { + my($id, $name, $argc, $x, $y) = @_; + dialog_report("Greeting window", "Hello world!"); +} + +sub ev_gui_init +{ + my($id, $name, $argc, $argv) = @_; + create_menu("Plugins/GPMI scripting/hello", "hello()", "h", "Ctrlw", "tooltip for hello"); +} + +Bind("ACTE_action", "ev_action"); +Bind("ACTE_gui_init", "ev_gui_init"); +action_register("hello", "", "log hello world", "hello()"); Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.py =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.py (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.py (revision 684) @@ -0,0 +1,12 @@ +PkgLoad("pcb-rnd-gpmi/actions", 0); +PkgLoad("pcb-rnd-gpmi/dialogs", 0); + +def ev_action(id, name, argc, x, y): + dialog_report("Greeting window", "Hello world!"); + +def ev_gui_init(id, argc, argv): + create_menu("Plugins/GPMI scripting/hello", "hello()", "h", "Ctrlw", "tooltip for hello"); + +Bind("ACTE_action", "ev_action"); +Bind("ACTE_gui_init", "ev_gui_init"); +action_register("hello", "", "log hello world", "hello()"); Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.rb =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.rb (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.rb (revision 684) @@ -0,0 +1,14 @@ +PkgLoad("pcb-rnd-gpmi/actions", 0); +PkgLoad("pcb-rnd-gpmi/dialogs", 0); + +def ev_action(id, name, argc, x, y) + dialog_report("Greeting window", "Hello world!"); +end + +def ev_gui_init(id, argc, argv) + create_menu("Plugins/GPMI scripting/hello", "hello()", "h", "Ctrlw", "tooltip for hello"); +end + +Bind("ACTE_action", "ev_action"); +Bind("ACTE_gui_init", "ev_gui_init"); +action_register("hello", "", "log hello world", "hello()"); Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.scm =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.scm (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.scm (revision 684) @@ -0,0 +1,12 @@ +(PkgLoad "pcb-rnd-gpmi/actions" 0) +(PkgLoad "pcb-rnd-gpmi/dialogs" 0) + +(define ev_action (lambda (id name argc x y) + (dialog_report "Greeting window" "Hello world!"))) + +(define ev_gui_init (lambda (id argc argv) + (create_menu "Plugins/GPMI scripting/hello" "hello()" "h" "Ctrlw" "tooltip for hello"))) + +(Bind "ACTE_action" "ev_action") +(Bind "ACTE_gui_init" "ev_gui_init") +(action_register "hello" "" "log hello world" "hello()") Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.stt =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.stt (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.stt (revision 684) @@ -0,0 +1,12 @@ +(PkgLoad "pcb-rnd-gpmi/actions" 0) +(PkgLoad "pcb-rnd-gpmi/dialogs" 0) + +(defun ev_action (id name argc x y) + (dialog_report "Greeting window" "Hello world!")) + +(defun ev_gui_init (id argc argv) + (create_menu "Plugins/GPMI scripting/hello" "hello()" "h" "Ctrlw" "tooltip for hello")) + +(Bind "ACTE_action" "ev_action") +(Bind "ACTE_gui_init" "ev_gui_init") +(action_register "hello" "" "log hello world" "hello()") Index: doc-rnd/gpmi/rosetta/12_hello_menu/ex.tcl =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/ex.tcl (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/ex.tcl (revision 684) @@ -0,0 +1,15 @@ +PkgLoad pcb-rnd-gpmi/actions 0 +PkgLoad pcb-rnd-gpmi/dialogs 0 + +proc ev_action {id, name, argc, x, y} { + dialog_report "Greeting window" "Hello world!" +} + +proc ev_gui_init {id, argc, argv} { + create_menu "Plugins/GPMI scripting/hello" "hello()" "h" "Ctrlw" "tooltip for hello" +} + +Bind ACTE_action ev_action +Bind ACTE_gui_init ev_gui_init +action_register "hello" "" "log hello world" "hello()" + Index: doc-rnd/gpmi/rosetta/12_hello_menu/index.html =================================================================== --- doc-rnd/gpmi/rosetta/12_hello_menu/index.html (nonexistent) +++ doc-rnd/gpmi/rosetta/12_hello_menu/index.html (revision 684) @@ -0,0 +1,58 @@ + + +<-- 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: +
    +
  • +actions + for registering the new action; +
  • +dialogs + for creating a dialog box.
+ +

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: +

    +
  • first argument is the name of the action +
  • second is the xy query string; it is empty since this action won't need coordinates to operate on +
  • third is the description that shows up in dumps and helps +
  • fourth is the syntax description (also for helps)
+ Index: doc-rnd/gpmi/rosetta/index.html =================================================================== --- doc-rnd/gpmi/rosetta/index.html (revision 683) +++ doc-rnd/gpmi/rosetta/index.html (revision 684) @@ -37,6 +37,11 @@ awk bash lua perl python ruby scheme stutter tcl Create a new action hello() that prints "Hello world!" in a popup window. + 12 + hello world (popup window + submenu) + awk bash lua perl python ruby scheme stutter tcl + Create a new action hello() that prints "Hello world!" in a popup window, create a menu (under "Plugins/GPMI scripting/") that executes the action. + 30 action: move selected objects awk bash lua perl python ruby scheme stutter tcl