WxPerl::MenuMaker - create and manage linked menus and toolbars
This is not a wxMenu, only a way to hold and manage named references to the menu items and toolbar items.
my $mm = WxPerl::MenuMaker->new( handler => $self, nomethod => sub {warn "$_[1] cannot '$_[0]()'"}, ); $mm->create_menubar(\@menu); # the toolbar takes a few more parameters $mm->create_toolbar(\@toolbar, parent => $frame, # all you really need id => -1, position => wxDefaultPosition, size => wxDefaultSize, style => wxTB_HORIZONTAL|wxTB_FLAT|wxTB_DOCKABLE, bitmap_size => [32, 32], ); # and you can get them back my $menu = $mm->menubar; my $menu_item = $mm->menu_items->file_open; my $toolbar = $mm->toolbar; my $toolbar_item = $mm->toolbar_items->that_button; # and my $associate = $mm->associated_menu->that_button;
my $mm = WxPerl::MenuMaker->new( handler => $self, nomethod => sub {warn "$_[1] cannot '$_[0]()'"}, );
Should typically be called before create_toolbar().
my @menu = ( { name => 'file', menu => [...], # see create_menu() label => '&File', } ); $mm->create_menubar(\@menu);
In the above example, the submenu [...] will have its entries prefixed by file_. Thus, you will be able to access the open submenu item via $mm->menu_items->file_open.
file_
open
$mm->menu_items->file_open
This is called for you by create_menubar().
Using this for standalone menus is untested.
my @menu = ( { name => 'open', action => 'file_open', label => '&Open }, { separator => 1 }, { auto_action => 1, name => 'quit', label => 'Quit' } ); my $menu = $mm->create_menu(\@menu, prefix => 'file_');
The hash reference items in the array are treated as follows:
Set the separator property to true to get a separator.
separator
If action is defined, the event will be connected to a menu_action() method.
action
If auto_action is not present and false, your menu events will be connected to 'menu_' . $name (where $name starts with the prefix.)
auto_action
In the above example, the resultant events are menu_file_open() and menu_file_quit().
$name = $self->_name_check($item->{name});
my @toolbar = ( { tooltip => 'File Manager', icon => 'file-manager.png', auto_action => 0, name => 'file_manager' }, { tooltip => 'Notes', icon => 'tb_button_notes.png', name => 'notes' }, { separator => '1' }, { tooltip => 'Open File', icon => 'kedit.png', associate => 'file_open', name => 'file_open' }, { tooltip => 'Browse', icon => 'tb_button_browse.png', action => 'do_something', name => 'browse' }, { tooltip => 'Foo', icon => 'tb_button_foo.png', action => sub {warn "this is foo"}, name => 'foo' } ); $mm->create_toolbar(\@toolbar, parent => $frame, # all you really need id => -1, position => wxDefaultPosition, size => wxDefaultSize, style => wxTB_HORIZONTAL|wxTB_FLAT|wxTB_DOCKABLE, bitmap_size => [32, 32], );
If you set a handler in the constructor, you will not need to pass the parent argument to this method.
The toolbar items are connected much like in create_menu(), except that the default method is menu_tb_name().
name
The associate property will cause the tool to be associated to that menu entry. This means they will have the same ID (and thus the same events.)
associate
$mm->append_toolbar(%args);
my $tool = $self->_add_toolbar_item(%args);
$class->_mk_accessor($package, $method, $value);
$self->_mk_event($item, $name, $menu_item);
Eric Wilhelm <ewilhelm at cpan dot org>
http://scratchcomputing.com/
If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
If you pulled this development version from my /svn/, please contact me directly.
Copyright (C) 2006 Eric L. Wilhelm, All Rights Reserved.
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install dtRdr, copy and paste the appropriate command in to your terminal.
cpanm
cpanm dtRdr
CPAN shell
perl -MCPAN -e shell install dtRdr
For more information on module installation, please visit the detailed CPAN module installation guide.