deadpickle has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; use Gtk2::TrayIcon; #user variables my $icon_file = Gtk2::Gdk::Pixbuf->new_from_file("/home/deadpickle/Des +ktop/Gtk2/test.png"); my $time = 1200000; #global variables my $user = 'uas'; my $server = 'updraft.unl.edu'; my $local_waypoint = '/local'; my $remote_waypoint = '/remote'; my $waytemp = 'waytemp'; my $wayfinal = 'wayfinal'; #icon goes in box, box goes in tray my $icon = Gtk2::Image->new_from_pixbuf($icon_file); my $eventbox = Gtk2::EventBox->new; $eventbox->add($icon); my $tray = Gtk2::TrayIcon->new('Test'); $tray->add($eventbox); #tooltip my $tooltip = Gtk2::Tooltips->new; $tooltip->set_tip($tray, "GRRUVI v1.0"); #events and timeouts $eventbox->signal_connect('button_release_event', \&click); #show tray $tray->show_all; #end event loop Gtk2->main; #handles tray clicks sub click { #left mouse button if ($_[1]->button == 1) { #what should this do? #&open_woot(); } #right mouse button elsif ($_[1]->button == 3) { &menu(); } return 1; } #right click menu sub menu { my $menu = Gtk2::Menu->new(); #configure my $menu_pref = Gtk2::ImageMenuItem->new_with_label("Configure"); $menu_pref->signal_connect(activate => \&configure); $menu_pref->set_image(Gtk2::Image->new_from_stock('gtk-preferences +', 'menu')); $menu->add($menu_pref); #refresh my $menu_refresh = Gtk2::ImageMenuItem->new_with_label("Refresh"); $menu_refresh->signal_connect(activate => \&refresh); $menu_refresh->set_image(Gtk2::Image->new_from_stock('gtk-refresh' +, 'menu')); $menu->add($menu_refresh); #separator my $menu_sep = Gtk2::SeparatorMenuItem->new(); $menu->add($menu_sep); #Quit my $menu_quit = Gtk2::ImageMenuItem->new_with_label("Quit"); $menu_quit->signal_connect(activate => sub { Gtk2->main_quit;} ); $menu_quit->set_image(Gtk2::Image->new_from_stock('gtk-quit', 'men +u')); $menu->add($menu_quit); $menu->show_all; #popup menu, the three is for right mouse button $menu->popup(undef,undef,undef,3,undef,undef); return 1; } #configuration dialog window (not filled) sub configure { #Create the new window my $config_window = Gtk2::Window->new('toplevel'); $config_window->set_title("Configuration"); #VBox container my $table_config = Gtk2::Table->new(3, 5, FALSE); #Create Notebook my $config_notebook = Gtk2::Notebook->new; $config_notebook->set_tab_pos('top'); #the First Page; Connection my $connect_vbox = Gtk2::VBox->new( FALSE, 1); my $label_user = Gtk2::Label->new('Username'); my $entry_user = Gtk2::Entry->new; my $label_server = Gtk2::Label->new('Server'); my $entry_server = Gtk2::Entry->new; $entry_user->set_text($user); $entry_server->set_text($server); $connect_vbox->pack_start($label_user, FALSE, FALSE, 1); $connect_vbox->pack_start($entry_user, FALSE, FALSE, 1); $connect_vbox->pack_start($label_server, FALSE, FALSE, 1); $connect_vbox->pack_start($entry_server, FALSE, FALSE, 1); #the Second Page; Waypoint my $table_waypoint = Gtk2::Table->new(4, 2, FALSE); my $label_temp_waypoint = Gtk2::Label->new('Temp Waypoint Filename +'); my $entry_temp_waypoint = Gtk2::Entry->new; my $label_final_waypoint = Gtk2::Label->new('Final Waypoint Filena +me'); my $entry_final_waypoint = Gtk2::Entry->new; my $label_local_waypoint = Gtk2::Label->new('Local Waypoint Folder +'); my $entry_local_waypoint = Gtk2::Entry->new; my $label_remote_waypoint = Gtk2::Label->new('Remote Waypoint Fold +er'); my $entry_remote_waypoint = Gtk2::Entry->new; $entry_temp_waypoint->set_text($waytemp); $entry_final_waypoint->set_text($wayfinal); $entry_local_waypoint->set_text($local_waypoint); $entry_remote_waypoint->set_text($remote_waypoint); $entry_temp_waypoint->set_editable(0); $entry_final_waypoint->set_editable(0); $table_waypoint->attach_defaults($label_temp_waypoint, 0, 1, 0, 1) +; $table_waypoint->attach_defaults($entry_temp_waypoint, 1, 2, 0, 1) +; $table_waypoint->attach_defaults($label_final_waypoint, 0, 1, 1, 2 +); $table_waypoint->attach_defaults($entry_final_waypoint, 1, 2, 1, 2 +); $table_waypoint->attach_defaults($label_local_waypoint, 0, 1, 2, 3 +); $table_waypoint->attach_defaults($entry_local_waypoint, 1, 2, 2, 3 +); $table_waypoint->attach_defaults($label_remote_waypoint, 0, 1, 3, +4); $table_waypoint->attach_defaults($entry_remote_waypoint, 1, 2, 3, +4); #append pages $config_notebook->append_page($connect_vbox, "Connection"); $config_notebook->append_page($table_waypoint, "Waypoint"); #add button to the main window my $button_accept = Gtk2::Button->new_with_mnemonic("_Accept"); my $button_cancel = Gtk2::Button->new_with_mnemonic("_Cancel"); #pack them into the dialog window $table_config->attach_defaults($config_notebook, 0, 5, 0, 1); $table_config->attach_defaults($button_accept, 1, 2, 2, 3); $table_config->attach_defaults($button_cancel, 3, 4, 2, 3); $config_window->add($table_config); $config_window->show_all; #Button Functions $button_cancel->signal_connect('clicked' => sub {$config_window->d +estroy}); $button_accept->signal_connect('clicked' => sub {$user = $entry_us +er->get_text; $server = $entry_server->get_text; $local_waypoint = $e +ntry_local_waypoint->get_text; $remote_waypoint = $entry_remote_waypo +int->get_text; my @settings = ($user, $server, $local_waypoint, $remo +te_waypoint);save_default(@settings) ; $config_window->destroy}); } sub save_default { open DEFAULT, '<', 'default.cfg' or die "Could not Open file!! $!" +; my $num_setting = @_; for ( my $count = 0; $count <= ($num_setting-1); $count++) { print "$_[$count]\n"; } close DEFAULT; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Gtk2 question(s)
by moritz (Cardinal) on Jul 17, 2007 at 07:37 UTC | |
by zentara (Cardinal) on Jul 17, 2007 at 10:13 UTC | |
by moritz (Cardinal) on Jul 17, 2007 at 11:33 UTC | |
by daxim (Curate) on Jul 17, 2007 at 10:40 UTC | |
by deadpickle (Pilgrim) on Jul 19, 2007 at 17:06 UTC | |
by Anonymous Monk on Jan 28, 2008 at 05:13 UTC |