Gtk2 and placing widgets in Gtk2::Menu



I am using Gtk2-perl. What I am trying to do is use the Gtk2::Menu to add a Gtk2::Progressbar to the Menu widget. The idea is to have a window that pops up only when the user left clicks the system tray icon. Is this possible to do? If not is there another way I can do this? Below is a code snippet of the program I am writing. the Gtk2::Progressbar widget will be located in the interface subroutine.

#!/usr/bin/perl -w
use strict;
use warnings;
use threads;
use threads::shared;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
use Gtk2::TrayIcon;

#user variables
my $icon_main = Gtk2::Gdk::Pixbuf->new_from_file("/home/deadpickle/Desktop/Gtk2/test.png");
my $icon_nav = Gtk2::Gdk::Pixbuf->new_from_file("/home/deadpickle/Desktop/Gtk2/uvnav.png");
my $icon_vci = Gtk2::Gdk::Pixbuf->new_from_file("/home/deadpickle/Desktop/Gtk2/vci.png");
my $time = 1200000;

#icon goes in box, box goes in tray
my $icon = Gtk2::Image->new_from_pixbuf($icon_main);
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) {
        &interface;
    }
   
    #right mouse button
    elsif ($_[1]->button == 3) {
        &menu;
    }
    return 1;
}


#right click menu
sub menu {
    my $menu = Gtk2::Menu->new();

    #VCI
    my $menu_VCI = Gtk2::ImageMenuItem->new_with_label("VCI");
    $menu_VCI->set_image(Gtk2::Image->new_from_stock('gtk-refresh', 'menu'));
    $menu->add($menu_VCI);

    #configure
    my $menu_pref = Gtk2::ImageMenuItem->new_with_label("Configure");
    $menu_pref->set_image(Gtk2::Image->new_from_stock('gtk-preferences', 'menu'));
    $menu->add($menu_pref);

    #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', 'menu'));
    $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;
}

#Program interfaces
sub interface {
    my $interface = Gtk2::Menu->new;
   
    #menu items for VCI
    #Progress bar for number of downloads; just a countng bar
   
    #Add the correct controls to menu
    my $menu_vci_connect = Gtk2::ImageMenuItem->new_with_label("Connect");
    $interface->add($menu_vci_connect);
    my $menu_vci_stop = Gtk2::ImageMenuItem->new_with_label("Stop");
    $interface->add($menu_vci_stop);

    $interface->show_all;
   
    $interface->popup(undef,undef,undef,1,undef,undef);
}

--
Jamie Lahowetz
Software Developer
GRRUVI Project


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]