Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

dannoura's scratchpad

by dannoura (Pilgrim)
on Jun 01, 2004 at 19:48 UTC ( #358477=scratchpad: print w/replies, xml ) Need Help??

I have a module which builds all of the GUI for a script I have. My problem is that when I run the script some of the subs which are bound to events are run without being invoked. For example, the sub _save_defaults, is run. This didn't happen when the subs were in the script. What am I doing wrong?

Relevant parts of the code are below.

# This is the script my $gui=FP_GUI->new(); # Create main window $gui->menubar(); # Create menu bar MainLoop(); ########## # And this is the module sub new { # Create main window my $class=shift; my $mw=MainWindow->new(-title => 'Get Patents'); $mw->minsize(qw(500 300)); $mw->configure(-bg=>'ivory'); $mw->fontCreate('lbl', -family=>'arial', -size=>'10', -weight=>'bold' ); my $self={mw=>$mw, # Main window status=>'Ready', # Status of program search_entry=>'', # Pointer to search entry field pat_or_sub=>'Both - Pending and Issued', # search for pa +tents or submissions or both strict=>0, # Search based on exact string match class_search=>0, # Include class in results pat=>'All are retrieved regardless of year', # Search ba +sed on specific years, or all years years=>'', # Pointer to years to search field percent_done=>0 # Percent done in progress bar }; return bless $self, $class; } sub menubar { # Create menubar my $self=shift; my $mw=$self->{mw}; my $menubar = $mw->Menu(-menuitems => &_menubar_menuitems($self) ) +; $mw->configure(-menu => $menubar); $mw->bind( "<Control-q>" => \&_quit); $mw->bind( "<Control-s>" => \&_save_defaults($self)); $mw->bind( "<Control-h>" => \&_show_help); } sub _quit { exit 0; } sub _save_defaults { # Save all search parameters my $self=shift; open FH, ">pto search defaults.txt" or die($!); my $search_terms=$self->{search_entry}->get; print FH "Terms\t$search_terms\n"; print FH "Get\t$self->{pat_or_sub}\n"; print FH "Strict\t$self->{strict}\n"; print FH "Class\t$self->{class_search}\n"; print FH "Search by\t$self->{pat}\n"; my $year_string=$self->{years}->get; print FH "Years\t"; print FH "$year_string\n" if ($year_string); close FH; $self->{status}="Search values saved"; } sub _show_help { system('help.html'); } sub _menubar_menuitems { # Menubar items my $self=shift; return [ map ['cascade', $_->[0], -tearoff=> 0, -menuitems => $_->[1]], ['~File', &_file_menuitems($self)], ['~Help', &_help_menuitems()], ]; } sub _file_menuitems { # File menu items my $self=shift; return [ [("command", "~Save Search Parameters", "-accelerator", "Ctrl-s" +), -command=>[\&_save_defaults($self)]], '', [qw/command ~Quit -accelerator Ctrl-q/, -command=>[\&_quit]], ]; } sub _help_menuitems { # Help menu items return [ ['command', 'Help', -command => [\&_show_help]] ]; }
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2017-03-27 09:37 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (319 votes). Check out past polls.