In this section we will see how to extend the folder GUI. We will describe specifically:
How to extend the menubar of the main window.
How to add items to existing menus on the main window menubar.
How to extend the context menus
How to use the folder browser in your own dialogs.
Before getting down to the topics above, let's look at the mechanics of incorporating your changes into the GUI when SpecTcl starts. As we already know, the script SpecTclRC.tcl is sourced by SpecTcl as it starts. The initial version of this script comes with the skeleton files you copied when you started developing your Spectcl.
The folder GUI is started by this script via the following script command:
source $SpecTclHome/Script/newGui.tcl
Simply add your code to extend the GUI anywhere after this line of code in SpecTclRC.tcl. I recommend encapsulating that code into a separate script file, testing your extensions by sourcing them by hand, and then, when you are ready to go to production, adding source to your SpecTclRC.tcl to source your extension script.
The main window of the folder GUI features a menubar. The menu bar is stocked with a set of menus that allow access to most of the GUI commands. The menubar is named .topmenu The menus it contains are named:
Contains the menu contents.
Contains the menu contents.
Contains the menu contents.
Contains the menu contents>
Contains the menu contents.
Contains the menu contents.
Contains the menu contents.
Menus can be added to the menubar between the
and the menus. Menus are added to the menubar
by creating a menu that is a child of .topmenu
and by adding a cascade element to .topmenu that
has the menu as it's -menu.
The sample code below adds a new menu named that contains an item that clears a selected set of spectra using the code developed in the previous section:
Example 8-27. Adding a menu to the folder GUI menubar
menu .toplevel.application
.toplevel.application add command -label {Clear selected spectra ...} \
-command clearSelectedSpectra
.toplevel add cascade -label Application -menu .toplevel.application
Similarly, knowing the names of the menus the folder GUI creates allows us to add commands to the bottom of them. Adding a menu entry to the menu to clear a selection of spectra is done as follows:
Context menus are the menus in the folder gui that pop up when you hold the right mouse button down over an item in the folder GUI's main window. The context menus are created by the folder GUI the first time they are needed, if they have not yet been built. Therefore, in order to extend a context menu, you will first have to create the context menu you want to extend and then add elements to it.
The following procedures create context menus in the folder gui:
createSpectrumFolderContextMenuCreates the context menu for the spectrum folder. The menu is named: .spectrumfoldercontextmenu
createParameterFolderContextMenuCreates the context menu that for the parameters folder. The menu is named: .parameterfoldercontextmenu
createGateFolderContextMenuCreates the context menu for the Gates folder. The menu is named: .gatefoldercontextmenu
createVariableFolderContextMenuCreates the context menu for the Variables folder. This menu is named: .variablefoldercontextmenu
createSpectrumContextMenuCreates the context menu for individual spectra in the spectrum folder. This context menu is named: .parametercontextmenu