source: grass/trunk/gui/wxpython/docs/wxgui_sphinx/src/wxgui_toolboxes.rst

Last change on this file was 66113, checked in by neteler, 9 years ago

svn propset

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id
  • Property svn:mime-type set to text/plain
File size: 13.2 KB
Line 
1WxGUI Toolboxes
2===============
3
4Introduction
5------------
6
7wxGUI toolboxes enables GUI customization and organization of menu (and other
8views) according to user needs.
9
10XML files are used for code generation and in case of toolboxes enables
11wxGUI (menu) customization.
12
13Currently, all the files described here are related to the menus which are
14generated from these files. The most of the files described here are
15the part of implementation of toolboxes in wxGUI.
16
17Each XML file has a DTD file which can by used for validation. XSD files are
18not provided (but this can change in the future). Some file types can occur
19multiple times, some occur only once.
20
21Note that in XML context, the term *tag* partially overlaps with the term
22*element*. Element emphasizes the XML structure, XML object model and
23content of these objects. Tag emphasizes the markup and the name of the element.
24
25
26Files overview
27--------------
28
29Files related to toolboxes
30^^^^^^^^^^^^^^^^^^^^^^^^^^
31
32GRASS 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
39GRASS 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
48GRASS 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
95Other files
96^^^^^^^^^^^
97
98GRASS source code contains these XML files:
99
100* ``gui/wxpython/xml/menudata_gmodeler.xml``
101* ``gui/wxpython/xml/menudata_psmap.xml``
102
103In GRASS distribution these XML files are in the ``etc/gui/wxpython/xml``
104directory.
105
106
107Generation of files and menu
108----------------------------
109
110As noted in the section \ref toolboxesFilesOverview, there are files in the
111GRASS distribution and in the user home directory (particularly in
112``.grass7/tooboxes`` subdirectory).
113
114When user doesn't have any ``toolboxes.xml`` or ``main_menu.xml`` files in the
115home directory, file ``menudata.xml`` included in the distribution is used to
116build a menu.
117
118When ``toolboxes.xml`` or ``main_menu.xml`` file (in user home directory) is newer
119than ``menudata.xml`` in user home directory or ``menudata.xml`` does not exists
120in user home directory, the ``menudata.xml`` is generated when GUI starts.
121
122When ``menudata.xml`` in user home directory is fresh enough,
123it is used to create a menu.
124
125When ``toolboxes.xml`` or ``main_menu.xml`` file is not in user home directory
126but ``menudata.xml`` is, the file is re-generated (each time the GUI starts).
127So, if you just have your own ``main_menu.xml``, it is better to create also
128a ``toolboxes.xml`` file with no toolboxes (note that you still need to create
129a valid XML toolbox file).
130Similarly, if you have only the ``toolboxes.xml`` file it
131is better to copy the ``main_menu.xml`` file from distribution into your home
132directory.
133
134When reading the main_menu file, user toolboxes are expanded first and then
135toolboxes from distribution are expanded.
136
137
138Toolboxes file
139--------------
140
141This file contains definition of toolboxes. A toolbox contains references
142(links) to other items, namely ``<module-items>``, ``<wxgui-items>``
143and other toolboxes using tag ``<subtoolbox>``. Tag ``<separator>`` is
144used when the view supports some kind of visual separators to group parts
145of the toolbox (or menu).
146
147Items are referenced using ``name`` attribute. In case of ``<module-items>``,
148``<wxgui-items>`` also subelements can be added to create new items or to
149replace 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
192Main menu file
193--------------
194
195File has a layout similar to the \ref toolboxesFile but contains only one
196toolbox (``<toolbox>``) which can contain only subtoolboxes
197(``<subtoolbox>`` elements) and one special
198element ``<user-toolboxes-list>`` which will be replaced by a menu with the list
199of toolboxes in the user toolbox file.
200
201
202Modules items file
203------------------
204
205The file contains information obtained from modules' interface descriptions.
206The structure of one ``module-item`` is the same as in the \ref toolboxesFile
207but some subelements are mandatory.
208
209File contained in distribution is generated during compilation from available
210modules using the script ``gui/wxpython/tools/build_modules_xml.py``.
211
212Element ``<module>`` is the name of the executable, e.g. ``r.info``.
213
214Element ``<label>`` is currently not present. It represents the short label in
215menu and it is added in toolboxes.
216
217Element ``<description>`` is created from module's description (or if
218it exists, label concatenated with description).
219
220Element ``<keywords>`` is created from module's keywords.
221
222
223wxGUI items file
224----------------
225
226The file contains definitions of wxGUI actions which can be accessed for
227example, from menu.
228The structure of one ``wxgui-item`` is the same as in \ref toolboxesFile
229but some subelements are mandatory.
230
231
232Menudata file
233-------------
234
235Historically, menudata.xml file was in the source codes and was partially
236maintained by the script ``gui/wxpython/tools/update_menudata.py``
237which updated the description and keywords (based on module's
238label or description, and keywords).
239Other items (menu structure, menu item labels and non-module only items) were
240edited in the menudata.xml file directly.
241
242Currently, the file is generated during compilation or at startup. It serves
243as an intermediate layer between all toolboxes XMLs and GUI menu tree
244generation.
245
246
247How to write a custom toolbox
248-----------------------------
249
250To create a new toolbox use ``<toolbox>`` tag:
251
252.. code-block:: xml
253
254 <toolbox name="MyRaster">
255 <label>My &amp;raster</label>
256 <items>
257 <!-- ... -->
258 </items>
259 </toolbox>
260
261To 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
269This works for modules contained in distribution. For modules from addons or
270some 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
280The name of a module is duplicated in the XML but anyway, try to keep ``name``
281attribute and ``module`` element in sync.
282
283To create a new item which triggers some wxGUI action defined in distribution
284use ``<wxgui-item>`` tag:
285
286.. code-block:: xml
287
288 <wxgui-item name="RasterMapCalculator"/>
289
290Note that now it is not possible to create custom wxGUI items.
291
292To include an existing toolbox use ``<subtoolbox>`` tag:
293
294.. code-block:: xml
295
296 <subtoolbox name="NeighborhoodAnalysis"/>
297
298To create a submenu in your new menu (toolbox), you need to create a new toolbox
299and include this toolbox.
300
301To create your custom main menu create a file main_menu.xml in your user home
302directory, in ``.grass7/toolboxes`` subdirectory. Directory ``.grass7`` may be
303hidden directory on your system. The XML file should contain the definition of
304only one toolbox. The name attribute and label element are not used but should
305be filled for documentation purposes and future compatibility.
306
307If you want to base your toolbox or main menu on existing toolbox or main menu
308copy the part of existing XML file from GRASS GIS distribution (installation)
309directory or GRASS GIS source code. If you want to include some existing
310toolboxes or wxGUI items defined in GRASS GIS you need to look to these files
311too and find the proper ``name`` attributes.
312
313
314Example
315^^^^^^^
316
317Files should be placed in user home directory in ``.grass7/toolboxes``
318subdirectory, e.g. ``/home/john/.grass7/toolboxes``.
319
320toolboxes.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 &amp;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
346main_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
365Validation
366^^^^^^^^^^
367
368You 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
373You can find ``toolboxes.dtd`` and ``main_menu.dtd`` in your GRASS GIS directory,
374in ``etc/gui/wxpython/xml`` subdirectory. Depending on the validator,
375you might need to add DTD file to the drectory with the XML file.
376
377If you will provide an invalid, not well formed or empty file loading of
378toolboxes will obviously fail.
379
380
381Labels
382^^^^^^
383
384The label shortly describes the toolbox or the action which will happen after
385running an item. The label can be a command such as *"Create table"*
386or the general name such as *"Table management"*.
387You should add label to each toolbox you create and to each item you create.
388However, 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
390tags only with the name attribute).
391
392Important items in menu usually have a automatically assigned shortcut which
393depends on their label. This shortcut is assigned to ``Alt+Letter``
394(on most platforms) where letter is a letter after an ampersand (``&``) in the
395item label and in the user interface the letter is underlined.
396Note that in XML you cannot write ``&`` but you have to write ``&amp;``.
397This concept is not related to the standard shortcut assigned to the item
398according to the shortcut in the XML file.
399
400Don't be confused with the label which is set for the module in the source code.
401These labels play different role, they must be short and usually
402with the wording of a command.
Note: See TracBrowser for help on using the repository browser.