| 1 | WxGUI Toolboxes
|
|---|
| 2 | ===============
|
|---|
| 3 |
|
|---|
| 4 | Introduction
|
|---|
| 5 | ------------
|
|---|
| 6 |
|
|---|
| 7 | wxGUI toolboxes enables GUI customization and organization of menu (and other
|
|---|
| 8 | views) according to user needs.
|
|---|
| 9 |
|
|---|
| 10 | XML files are used for code generation and in case of toolboxes enables
|
|---|
| 11 | wxGUI (menu) customization.
|
|---|
| 12 |
|
|---|
| 13 | Currently, all the files described here are related to the menus which are
|
|---|
| 14 | generated from these files. The most of the files described here are
|
|---|
| 15 | the part of implementation of toolboxes in wxGUI.
|
|---|
| 16 |
|
|---|
| 17 | Each XML file has a DTD file which can by used for validation. XSD files are
|
|---|
| 18 | not provided (but this can change in the future). Some file types can occur
|
|---|
| 19 | multiple times, some occur only once.
|
|---|
| 20 |
|
|---|
| 21 | Note that in XML context, the term *tag* partially overlaps with the term
|
|---|
| 22 | *element*. Element emphasizes the XML structure, XML object model and
|
|---|
| 23 | content of these objects. Tag emphasizes the markup and the name of the element.
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | Files overview
|
|---|
| 27 | --------------
|
|---|
| 28 |
|
|---|
| 29 | Files related to toolboxes
|
|---|
| 30 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|---|
| 31 |
|
|---|
| 32 | GRASS source code contains these XML files:
|
|---|
| 33 |
|
|---|
| 34 | * ``gui/wxpython/xml/main_menu.xml``
|
|---|
| 35 | * ``gui/wxpython/xml/toolboxes.xml``
|
|---|
| 36 | * ``gui/wxpython/xml/wxgui_items.xml``
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | GRASS distribution contains these XML files:
|
|---|
| 40 |
|
|---|
| 41 | * ``etc/gui/wxpython/xml/main_menu.xml``
|
|---|
| 42 | * ``etc/gui/wxpython/xml/toolboxes.xml``
|
|---|
| 43 | * ``etc/gui/wxpython/xml/wxgui_items.xml``
|
|---|
| 44 | * ``etc/gui/wxpython/xml/module_items.xml`` (generated during compilation)
|
|---|
| 45 | * ``etc/gui/wxpython/xml/menudata.xml`` (generated during compilation)
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | GRASS directory (``.grass7``) in user home directory
|
|---|
| 49 | (i.e., ``$HOME`` on Unix) contains these XML files:
|
|---|
| 50 |
|
|---|
| 51 | * ``toolboxes/main_menu.xml`` (created by user)
|
|---|
| 52 | * ``toolboxes/toolboxes.xml`` (created by user)
|
|---|
| 53 | * ``toolboxes/menudata.xml`` (generated on wxGUI startup)
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | .. graphviz::
|
|---|
| 57 |
|
|---|
| 58 | digraph toolboxes {
|
|---|
| 59 | graph [rankdir="LR"];
|
|---|
| 60 | node [shape="record", style="rounded"];
|
|---|
| 61 |
|
|---|
| 62 | menudata [label="menudata.xml in distribution", shape="note", URL="#menudata-file"];
|
|---|
| 63 | umenudata [label="menudata.xml in user home", shape="note", URL="#menudata-file"];
|
|---|
| 64 | toolboxes [label="toolboxes.xml in distribution", shape="note", URL="#toolboxes-file"];
|
|---|
| 65 | utoolboxes [label="toolboxes.xml in user home", shape="note", URL="#toolboxes-file"];
|
|---|
| 66 | main_menu [label="main_menu.xml in distribution", shape="note", URL="#main-menu-file"];
|
|---|
| 67 | umain_menu [label="main_menu.xml in user home", shape="note", URL="#main-menu-file"];
|
|---|
| 68 |
|
|---|
| 69 | wxgui_items [label="wxgui_items.xml in distribution", shape="note", URL="#wxgui-items-file"];
|
|---|
| 70 | module_items [label="module_items.xml in distribution", shape="note", URL="#module-items-file"];
|
|---|
| 71 |
|
|---|
| 72 | menustrings [label="menustrings.py\n(used for translations)", shape="note"];
|
|---|
| 73 |
|
|---|
| 74 | module_items -> menudata;
|
|---|
| 75 | wxgui_items -> menudata;
|
|---|
| 76 | main_menu -> menudata;
|
|---|
| 77 | toolboxes -> menudata;
|
|---|
| 78 |
|
|---|
| 79 | module_items -> umenudata;
|
|---|
| 80 | wxgui_items -> umenudata;
|
|---|
| 81 | toolboxes -> umenudata;
|
|---|
| 82 | main_menu -> umenudata;
|
|---|
| 83 | umain_menu -> umenudata;
|
|---|
| 84 | utoolboxes -> umenudata;
|
|---|
| 85 |
|
|---|
| 86 | menudata -> menustrings;
|
|---|
| 87 |
|
|---|
| 88 | // guimenu [label="Main menu in wxGUI", shape="box3d"];
|
|---|
| 89 | // menustrings -> guimenu;
|
|---|
| 90 | // menudata -> guimenu;
|
|---|
| 91 | // umenudata -> guimenu;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | Other files
|
|---|
| 96 | ^^^^^^^^^^^
|
|---|
| 97 |
|
|---|
| 98 | GRASS source code contains these XML files:
|
|---|
| 99 |
|
|---|
| 100 | * ``gui/wxpython/xml/menudata_gmodeler.xml``
|
|---|
| 101 | * ``gui/wxpython/xml/menudata_psmap.xml``
|
|---|
| 102 |
|
|---|
| 103 | In GRASS distribution these XML files are in the ``etc/gui/wxpython/xml``
|
|---|
| 104 | directory.
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | Generation of files and menu
|
|---|
| 108 | ----------------------------
|
|---|
| 109 |
|
|---|
| 110 | As noted in the section \ref toolboxesFilesOverview, there are files in the
|
|---|
| 111 | GRASS distribution and in the user home directory (particularly in
|
|---|
| 112 | ``.grass7/tooboxes`` subdirectory).
|
|---|
| 113 |
|
|---|
| 114 | When user doesn't have any ``toolboxes.xml`` or ``main_menu.xml`` files in the
|
|---|
| 115 | home directory, file ``menudata.xml`` included in the distribution is used to
|
|---|
| 116 | build a menu.
|
|---|
| 117 |
|
|---|
| 118 | When ``toolboxes.xml`` or ``main_menu.xml`` file (in user home directory) is newer
|
|---|
| 119 | than ``menudata.xml`` in user home directory or ``menudata.xml`` does not exists
|
|---|
| 120 | in user home directory, the ``menudata.xml`` is generated when GUI starts.
|
|---|
| 121 |
|
|---|
| 122 | When ``menudata.xml`` in user home directory is fresh enough,
|
|---|
| 123 | it is used to create a menu.
|
|---|
| 124 |
|
|---|
| 125 | When ``toolboxes.xml`` or ``main_menu.xml`` file is not in user home directory
|
|---|
| 126 | but ``menudata.xml`` is, the file is re-generated (each time the GUI starts).
|
|---|
| 127 | So, if you just have your own ``main_menu.xml``, it is better to create also
|
|---|
| 128 | a ``toolboxes.xml`` file with no toolboxes (note that you still need to create
|
|---|
| 129 | a valid XML toolbox file).
|
|---|
| 130 | Similarly, if you have only the ``toolboxes.xml`` file it
|
|---|
| 131 | is better to copy the ``main_menu.xml`` file from distribution into your home
|
|---|
| 132 | directory.
|
|---|
| 133 |
|
|---|
| 134 | When reading the main_menu file, user toolboxes are expanded first and then
|
|---|
| 135 | toolboxes from distribution are expanded.
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | Toolboxes file
|
|---|
| 139 | --------------
|
|---|
| 140 |
|
|---|
| 141 | This file contains definition of toolboxes. A toolbox contains references
|
|---|
| 142 | (links) to other items, namely ``<module-items>``, ``<wxgui-items>``
|
|---|
| 143 | and other toolboxes using tag ``<subtoolbox>``. Tag ``<separator>`` is
|
|---|
| 144 | used when the view supports some kind of visual separators to group parts
|
|---|
| 145 | of the toolbox (or menu).
|
|---|
| 146 |
|
|---|
| 147 | Items are referenced using ``name`` attribute. In case of ``<module-items>``,
|
|---|
| 148 | ``<wxgui-items>`` also subelements can be added to create new items or to
|
|---|
| 149 | replace subelements values from item definition.
|
|---|
| 150 |
|
|---|
| 151 | .. graphviz::
|
|---|
| 152 |
|
|---|
| 153 | graph toolboxes {
|
|---|
| 154 | graph [rankdir="LR"];
|
|---|
| 155 | node [shape="record", style="rounded"];
|
|---|
| 156 |
|
|---|
| 157 | // ∞ causes Doxygen warning but it's harmless for dot and html output
|
|---|
| 158 |
|
|---|
| 159 | toolboxes -- toolbox [label="1..∞"];
|
|---|
| 160 |
|
|---|
| 161 | toolbox -- label;
|
|---|
| 162 | toolbox -- items [label="1..∞"];
|
|---|
| 163 |
|
|---|
| 164 | items -- "module-item" [label="0..1"];
|
|---|
| 165 | items -- "wxgui-item" [label="0..1"];
|
|---|
| 166 | items -- subtoolbox [label="0..1"];
|
|---|
| 167 | items -- separator [label="0..1"];
|
|---|
| 168 |
|
|---|
| 169 | milabel [label="label"];
|
|---|
| 170 |
|
|---|
| 171 | "module-item" -- milabel;
|
|---|
| 172 | "module-item" -- module [label="0..1"];
|
|---|
| 173 | "module-item" -- description [label="0..1"];
|
|---|
| 174 | "module-item" -- keywords [label="0..1"];
|
|---|
| 175 |
|
|---|
| 176 | wilabel [label="label"];
|
|---|
| 177 | widescription [label="description"];
|
|---|
| 178 | wikeywords [label="keywords"];
|
|---|
| 179 |
|
|---|
| 180 | "wxgui-item" -- wilabel [label="0..1"];
|
|---|
| 181 | "wxgui-item" -- handler [label="0..1"];
|
|---|
| 182 | "wxgui-item" -- "related-module" [label="0..1"];
|
|---|
| 183 | "wxgui-item" -- command [label="0..1"];
|
|---|
| 184 | "wxgui-item" -- widescription [label="0..1"];
|
|---|
| 185 | "wxgui-item" -- wikeywords [label="0..1"];
|
|---|
| 186 | "wxgui-item" -- shortcut [label="0..1"];
|
|---|
| 187 | "wxgui-item" -- "wx-id" [label="0..1"];
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 | Main menu file
|
|---|
| 193 | --------------
|
|---|
| 194 |
|
|---|
| 195 | File has a layout similar to the \ref toolboxesFile but contains only one
|
|---|
| 196 | toolbox (``<toolbox>``) which can contain only subtoolboxes
|
|---|
| 197 | (``<subtoolbox>`` elements) and one special
|
|---|
| 198 | element ``<user-toolboxes-list>`` which will be replaced by a menu with the list
|
|---|
| 199 | of toolboxes in the user toolbox file.
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | Modules items file
|
|---|
| 203 | ------------------
|
|---|
| 204 |
|
|---|
| 205 | The file contains information obtained from modules' interface descriptions.
|
|---|
| 206 | The structure of one ``module-item`` is the same as in the \ref toolboxesFile
|
|---|
| 207 | but some subelements are mandatory.
|
|---|
| 208 |
|
|---|
| 209 | File contained in distribution is generated during compilation from available
|
|---|
| 210 | modules using the script ``gui/wxpython/tools/build_modules_xml.py``.
|
|---|
| 211 |
|
|---|
| 212 | Element ``<module>`` is the name of the executable, e.g. ``r.info``.
|
|---|
| 213 |
|
|---|
| 214 | Element ``<label>`` is currently not present. It represents the short label in
|
|---|
| 215 | menu and it is added in toolboxes.
|
|---|
| 216 |
|
|---|
| 217 | Element ``<description>`` is created from module's description (or if
|
|---|
| 218 | it exists, label concatenated with description).
|
|---|
| 219 |
|
|---|
| 220 | Element ``<keywords>`` is created from module's keywords.
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | wxGUI items file
|
|---|
| 224 | ----------------
|
|---|
| 225 |
|
|---|
| 226 | The file contains definitions of wxGUI actions which can be accessed for
|
|---|
| 227 | example, from menu.
|
|---|
| 228 | The structure of one ``wxgui-item`` is the same as in \ref toolboxesFile
|
|---|
| 229 | but some subelements are mandatory.
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 | Menudata file
|
|---|
| 233 | -------------
|
|---|
| 234 |
|
|---|
| 235 | Historically, menudata.xml file was in the source codes and was partially
|
|---|
| 236 | maintained by the script ``gui/wxpython/tools/update_menudata.py``
|
|---|
| 237 | which updated the description and keywords (based on module's
|
|---|
| 238 | label or description, and keywords).
|
|---|
| 239 | Other items (menu structure, menu item labels and non-module only items) were
|
|---|
| 240 | edited in the menudata.xml file directly.
|
|---|
| 241 |
|
|---|
| 242 | Currently, the file is generated during compilation or at startup. It serves
|
|---|
| 243 | as an intermediate layer between all toolboxes XMLs and GUI menu tree
|
|---|
| 244 | generation.
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 | How to write a custom toolbox
|
|---|
| 248 | -----------------------------
|
|---|
| 249 |
|
|---|
| 250 | To create a new toolbox use ``<toolbox>`` tag:
|
|---|
| 251 |
|
|---|
| 252 | .. code-block:: xml
|
|---|
| 253 |
|
|---|
| 254 | <toolbox name="MyRaster">
|
|---|
| 255 | <label>My &raster</label>
|
|---|
| 256 | <items>
|
|---|
| 257 | <!-- ... -->
|
|---|
| 258 | </items>
|
|---|
| 259 | </toolbox>
|
|---|
| 260 |
|
|---|
| 261 | To create a new item which represents a module use ``<module-item>`` tag:
|
|---|
| 262 |
|
|---|
| 263 | .. code-block:: xml
|
|---|
| 264 |
|
|---|
| 265 | <module-item name="r.buffer">
|
|---|
| 266 | <label>Buffer rasters</label>
|
|---|
| 267 | </module-item>
|
|---|
| 268 |
|
|---|
| 269 | This works for modules contained in distribution. For modules from addons or
|
|---|
| 270 | some your modules which are on path use ``<module-item>`` tag together with
|
|---|
| 271 | ``<module>`` tag:
|
|---|
| 272 |
|
|---|
| 273 | .. code-block:: xml
|
|---|
| 274 |
|
|---|
| 275 | <module-item name="r.agent">
|
|---|
| 276 | <label>Buffer rasters</label>
|
|---|
| 277 | <module>r.agent</module>
|
|---|
| 278 | </module-item>
|
|---|
| 279 |
|
|---|
| 280 | The name of a module is duplicated in the XML but anyway, try to keep ``name``
|
|---|
| 281 | attribute and ``module`` element in sync.
|
|---|
| 282 |
|
|---|
| 283 | To create a new item which triggers some wxGUI action defined in distribution
|
|---|
| 284 | use ``<wxgui-item>`` tag:
|
|---|
| 285 |
|
|---|
| 286 | .. code-block:: xml
|
|---|
| 287 |
|
|---|
| 288 | <wxgui-item name="RasterMapCalculator"/>
|
|---|
| 289 |
|
|---|
| 290 | Note that now it is not possible to create custom wxGUI items.
|
|---|
| 291 |
|
|---|
| 292 | To include an existing toolbox use ``<subtoolbox>`` tag:
|
|---|
| 293 |
|
|---|
| 294 | .. code-block:: xml
|
|---|
| 295 |
|
|---|
| 296 | <subtoolbox name="NeighborhoodAnalysis"/>
|
|---|
| 297 |
|
|---|
| 298 | To create a submenu in your new menu (toolbox), you need to create a new toolbox
|
|---|
| 299 | and include this toolbox.
|
|---|
| 300 |
|
|---|
| 301 | To create your custom main menu create a file main_menu.xml in your user home
|
|---|
| 302 | directory, in ``.grass7/toolboxes`` subdirectory. Directory ``.grass7`` may be
|
|---|
| 303 | hidden directory on your system. The XML file should contain the definition of
|
|---|
| 304 | only one toolbox. The name attribute and label element are not used but should
|
|---|
| 305 | be filled for documentation purposes and future compatibility.
|
|---|
| 306 |
|
|---|
| 307 | If you want to base your toolbox or main menu on existing toolbox or main menu
|
|---|
| 308 | copy the part of existing XML file from GRASS GIS distribution (installation)
|
|---|
| 309 | directory or GRASS GIS source code. If you want to include some existing
|
|---|
| 310 | toolboxes or wxGUI items defined in GRASS GIS you need to look to these files
|
|---|
| 311 | too and find the proper ``name`` attributes.
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 | Example
|
|---|
| 315 | ^^^^^^^
|
|---|
| 316 |
|
|---|
| 317 | Files should be placed in user home directory in ``.grass7/toolboxes``
|
|---|
| 318 | subdirectory, e.g. ``/home/john/.grass7/toolboxes``.
|
|---|
| 319 |
|
|---|
| 320 | toolboxes.xml
|
|---|
| 321 | """""""""""""
|
|---|
| 322 |
|
|---|
| 323 | .. code-block:: xml
|
|---|
| 324 |
|
|---|
| 325 | <?xml version="1.0" encoding="UTF-8"?>
|
|---|
| 326 | <!DOCTYPE toolboxes SYSTEM "toolboxes.dtd">
|
|---|
| 327 | <toolboxes>
|
|---|
| 328 | <toolbox name="MyRaster">
|
|---|
| 329 | <label>My &raster</label>
|
|---|
| 330 | <items>
|
|---|
| 331 | <module-item name="r.buffer">
|
|---|
| 332 | <label>Buffer rasters</label>
|
|---|
| 333 | </module-item>
|
|---|
| 334 | <module-item name="r.mask">
|
|---|
| 335 | <label>Mask</label>
|
|---|
| 336 | </module-item>
|
|---|
| 337 | <separator/>
|
|---|
| 338 | <wxgui-item name="RasterMapCalculator"/>
|
|---|
| 339 | <subtoolbox name="NeighborhoodAnalysis"/>
|
|---|
| 340 | <subtoolbox name="ReportAndStatistics"/>
|
|---|
| 341 | </items>
|
|---|
| 342 | </toolbox>
|
|---|
| 343 | </toolboxes>
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 | main_menu.xml
|
|---|
| 347 | """""""""""""
|
|---|
| 348 |
|
|---|
| 349 | .. code-block:: xml
|
|---|
| 350 |
|
|---|
| 351 | <?xml version="1.0" encoding="UTF-8"?>
|
|---|
| 352 | <!DOCTYPE toolbox SYSTEM "main_menu.dtd">
|
|---|
| 353 | <toolbox name="MyCustomMainMenu">
|
|---|
| 354 | <label>MyCustomMainMenu</label>
|
|---|
| 355 | <items>
|
|---|
| 356 | <subtoolbox name="File"/>
|
|---|
| 357 | <subtoolbox name="Settings"/>
|
|---|
| 358 | <subtoolbox name="MyRaster"/>
|
|---|
| 359 | <subtoolbox name="Imagery"/>
|
|---|
| 360 | <subtoolbox name="Help"/>
|
|---|
| 361 | </items>
|
|---|
| 362 | </toolbox>
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 | Validation
|
|---|
| 366 | ^^^^^^^^^^
|
|---|
| 367 |
|
|---|
| 368 | You should validate your XML before running wxGUI, e.g. using ``xmllint``
|
|---|
| 369 | (no output means that document is valid)::
|
|---|
| 370 |
|
|---|
| 371 | xmllint --noout --dtdvalid toolboxes.dtd toolboxes.xml
|
|---|
| 372 |
|
|---|
| 373 | You can find ``toolboxes.dtd`` and ``main_menu.dtd`` in your GRASS GIS directory,
|
|---|
| 374 | in ``etc/gui/wxpython/xml`` subdirectory. Depending on the validator,
|
|---|
| 375 | you might need to add DTD file to the drectory with the XML file.
|
|---|
| 376 |
|
|---|
| 377 | If you will provide an invalid, not well formed or empty file loading of
|
|---|
| 378 | toolboxes will obviously fail.
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 | Labels
|
|---|
| 382 | ^^^^^^
|
|---|
| 383 |
|
|---|
| 384 | The label shortly describes the toolbox or the action which will happen after
|
|---|
| 385 | running an item. The label can be a command such as *"Create table"*
|
|---|
| 386 | or the general name such as *"Table management"*.
|
|---|
| 387 | You should add label to each toolbox you create and to each item you create.
|
|---|
| 388 | However, if you are just using (and thus referencing) existing items
|
|---|
| 389 | (or toolboxes), you don't need to include labels (so you can use just empty
|
|---|
| 390 | tags only with the name attribute).
|
|---|
| 391 |
|
|---|
| 392 | Important items in menu usually have a automatically assigned shortcut which
|
|---|
| 393 | depends on their label. This shortcut is assigned to ``Alt+Letter``
|
|---|
| 394 | (on most platforms) where letter is a letter after an ampersand (``&``) in the
|
|---|
| 395 | item label and in the user interface the letter is underlined.
|
|---|
| 396 | Note that in XML you cannot write ``&`` but you have to write ``&``.
|
|---|
| 397 | This concept is not related to the standard shortcut assigned to the item
|
|---|
| 398 | according to the shortcut in the XML file.
|
|---|
| 399 |
|
|---|
| 400 | Don't be confused with the label which is set for the module in the source code.
|
|---|
| 401 | These labels play different role, they must be short and usually
|
|---|
| 402 | with the wording of a command.
|
|---|