Menu, Status Bar, Tool Bar¶
Menu Editor¶
wxGlade includes a simple menu editor.
To attach a menu to a frame, go to Properties -> Widget and check Has MenuBar.
This will add a menubar icon to the Tree, just below the frame’s icon.
To open the menu editor, click the “Edit menus…” button.
The following screenshots are from the file wxglade/examples/Allwidgets_28.wxg.
Example:
As an exercise, we will now add a “File” menu with two entries to our calculator window.
- When you hit “Edit menus…” for the first time, the bottom part of the editor window is almost empty. It will just contain a default entry “item”.
- To create the required menu structure, change the label to File.
- To create the first item, hit “Add” and then the “>” button to turn it into a submenu item and then change the label to Reset. Give this item a name i_reset. The item will then be stored with this attribute name, such that it can e.g. enabled and disabled programmatically.
- Create an item Exit with event handler on_menu_File_Exit
As of now, these items would not yet call any code when selected. So the “Event Handler” field needs to be filled with e.g. on_menu_File_Reset and on_menu_File_Exit for the two items.
When done and after hitting the “Start generating source files”, the editor and the created code should look like this:
You can implement the handler either in a derived class or directly in the file that wxGlade has written.
In the latter case, you should have enabled Properties -> Application -> Keep user sources.
- The example menu is part of the example at wxglade/examples/Calculator:
Lambda Event Handlers¶
When creating Python code, you may also specify a lambda function as event handler.
E.g. you may want to have three menu items named Insert A
, Insert B
and Insert C
.
Instead of three separate handlers, you may enter three lambda functions that will call the same method or function
with different arguments each:
Of course you need to implement a method on_menu_insert_abc
.
Status Bar Editor¶
To attach a status bar to a frame, go to Properties -> Widget and check cHas StatusBar`. This will add a statusbar icon to the Tree window, just below the frame’s icon. (Similar to Has MenuBar in the first screenshot on this page.)
To add/remove fields to the status bar, go to Properties -> Widget -> Fields and use the “Add”/”Insert”/”Remove”/”Apply” buttons. If you set the “Size” of a field to a negative value like -1 or -2, it will grow to fill the available space.
Example:
Statusbar: Properties / Field Editor: two growing and two fixed size fields |
|
Toolbar two growing and two fixed size fields |
Tool Bar Editor¶
The logic for creating and editing a toolbar is the same as with menu bars.
Buttons and other controls are not supported yet