wxgui_toolboxes.rst 13 KB

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