wxguitoolboxes.dox 13 KB

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