Gtk2: making a popup window on mouse click

2007-07-28 Thread Jamie Lahowetz
What I want to do is to have a the program run in a system tray. when the
user left clicks the system tray icon the window ('popup') is set to show.
Also, when the user left clicks on the system tray the window is hidden
again. How can I get this to work? I have a small snippet of code that I a
have started with: (Note: this is only simplified version of code used to
help out the question, I'm not sure if this code works)
#!/usr/bin/perl -w
use strict;
use warnings;
use threads;
use threads::shared;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
use Gtk2::TrayIcon;
use Net::SFTP::Foreign;

#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 = 120;

#global variables
my $user : shared = 'uas';
my $server : shared = 'updraft.unl.edu';
my $local_waypoint : shared = '/local';
my $remote_waypoint : shared = '/remote';
my $waytemp : shared = 'waytemp';
my $wayfinal : shared = 'wayfinal';
my $file = 'default.cfg';
my $local_uaspos : shared = '/local';
my $remote_uaspos : shared = '/remote';
my $local_uas : shared = '/local';
my $remote_uas : shared = '/remote';
my $die : shared = 0;
my $sftp_connect : shared = 0;
my $current_controls = 0;

#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);

#threads
my $thread_1 = threads->new( \&sftp);

#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) {

#Window show/hide controls

}

#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 => \&exit_threads);
$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::Window->new('popup');
$interface->set_position('center');

#Eventbox for capturing the mouse click
my $eventbox_interface = Gtk2::EventBox->new;

#table to contain the widgets
my $table_interface = Gtk2::Table->new( 8, 2, FALSE);

#menu items for VCI
if ( $current_controls == 1) {

#Labels
my $label_vci_downloading = Gtk2::Label->new( 'Downloading');
my $label_vci_uploading = Gtk2::Label->new( 'Uploading');

#Bold text for the Main Labels
my $fontdescription = Gtk2::Pango::FontDescription->new;
$fontdescription->set_weight( 'bold');
$label_vci_uploading->modify_font( $fontdescription);
$label_vci_downloading->modify_font( $fontdescription);

#labels for the progressbars
my $label_vci_uasposition = Gtk2::Label->new( 'uasposition');
my $label_vci_waytemp1 = Gtk2::Label->new( 'waytemp');
my $label_vci_waytemp2 = Gtk2::Label->new( 'waytemp');
my $label_vci_wayfinal = Gtk2::Label->new( 'wayfinal');

#Horizontal Separator
my $hseparator_vci = Gtk2::HSeparator->new;

#Connect button-> will switch to stop after press
my $menu_vci_connect = Gtk2::Button->new("Connect");

#Attach the widgets to the table
$table_interface->attach_defaults( $label_vci_uploading, 0, 2, 0,
1);
$table_interface->attach_defaults( $label_vci_uasposition, 0, 1, 1,
2);
$table_interface->attach_defaults( $label_vci_waytemp1, 0, 1, 2, 3);
$table_interface->attach_defaults( $label_vci_wayfinal, 0, 1, 3, 4);
$table_interface->attach_defaults( $label_vci_downloading, 0, 2, 4,
5);
$table_interface->attach_defaults( $label_vci_waytemp2, 0, 1, 5, 6);
$table_interface->attach_defaults( $hseparator_vci, 0, 2, 6, 7);
$table_interface->attach_defaults( $menu_vci_connect, 1, 2, 7, 8);
}


How to construct a tree that every nodes has an icon

2007-07-28 Thread Ye Wenbin
Hi,
How can I construct a tree which nodes have an icon? I have read the
source code of podbrowser. He used two column: Gtk2::Gdk::Pixbuf
Glib::String
for every node. But when the level of the tree is deeper, the tree will be
ugly.
The Nautilus of gnome can show the tree what I mean to.
Is there a way in gtk2-perl?

-- 
Best regards,
Ye Wenbin
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: forked process exiting before output read

2007-07-28 Thread Jeffrey Ratcliffe
On 27/07/07, zentara <[EMAIL PROTECTED]> wrote:
> If you use a thread, you can avoid this by placing the results in a shared 
> variable.

Thanks for the tip. I have always avoided threads as I had the
impression that they don't play well with Gtk2-Perl. I have reworked
my original example with threads. Are there any obvious pitfalls with
this approach?

Jeff

#!/usr/bin/perl

use warnings;
use strict;
use threads;
use threads::shared;
use Thread::Semaphore;
use Gtk2 qw/-init -threads-init/;
use Glib qw(TRUE FALSE); # To get TRUE and FALSE

my $semaphore = Thread::Semaphore->new(0);
my @queue:shared;
my $thread = threads->new(\&worker);

# Create the windows
my $window = Gtk2::Window->new('toplevel');
my $box = Gtk2::VBox->new;
my $pbar = Gtk2::ProgressBar->new;
my $buttonQuit = Gtk2::Button->new('Quit');
my $buttonStart = Gtk2::Button->new('Start');

$window->add ($box);
$box->add ($pbar);
$box->add($buttonQuit);
$box->add($buttonStart);

my %helperTag;

# We should also link this to the destroy message on the main window,
# this is just quick and dirty
$buttonQuit->signal_connect(clicked => sub{Gtk2->main_quit});
$buttonStart->signal_connect(clicked => sub{
 $semaphore->up;
 Glib::Timeout->add (200, sub{
  if (@queue) {
   my $fraction = shift @queue;
   my $text = shift @queue;
   $pbar->set_fraction($fraction);
   $pbar->set_text($text);
   if ($fraction == 1) {
$thread->join;
$semaphore->down;
return FALSE;
   }
  }
  return TRUE;
 });
});
$window->show_all;
Gtk2->main;

sub worker {
 $semaphore->down;
 my $n = 4;
 for (my $i = 0; $i <= $n; $i++) {
  sleep(1);
  push @queue, $i/$n;
  push @queue, "Running $i of $n";
 }
 $semaphore->up;
}
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Is there an interactive shell for gtk-perl

2007-07-28 Thread Sergei Steshenko

--- Ye Wenbin <[EMAIL PROTECTED]> wrote:

> Hi, Sergei,
> There are many thing that glade can't do. Glade only can show what  
> property, signals
> and other static things. But if I want to see the function of some method  
> of widget
> or debug some variable when the program is running, it can't help me.
> 
> On Sat, 28 Jul 2007 05:01:43 +0800, Sergei Steshenko <[EMAIL PROTECTED]>  
> wrote:
> > If the main issue is learning, then why not use 'glade' or 'glade3' - you
> > can build a GUI using several clicks choosing widgets from menus on the  
> > way.
> 
> 
> -- 
> Best regards,
> Ye Wenbin
> ___
> gtk-perl-list mailing list
> gtk-perl-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-perl-list
> 

Well, I once found "zoidberg" Perl shell to be interesting.

It is now

http://search.cpan.org/~pardus/Zoidberg-0.95/lib/Zoidberg.pm
http://search.cpan.org/~pardus/Zoidberg-0.95/lib/Zoidberg/Shell.pm
.

It is not gtk-specific, but since it is both Perl and shell, it
should be pretty easy to call from it gtk-specific stuff.

Regards,
  Sergei.

Applications From Scratch: http://appsfromscratch.berlios.de/


   

Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Stamp doesn't match in iterator in sort method of a tree model

2007-07-28 Thread Torsten Schoenfeld
On Sat, 2007-07-28 at 13:12 +0200, Tian wrote:

> But there should be another condition. As I tried to create a minimal program
> doing this and it worked perfectly, without any of the workarounds. I'll try
> to perform other tests. But maybe with these hints, one of the developers may
> have an idea about what the real problem could be.

In rings no bells for me, sorry.  I don't think anyone on this list is
intimate with the internals of GtkTreeModel, -Filter, or -Sort.

Your chances might be higher on gtk-app-devel-list or gtk-devel-list:

http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
http://mail.gnome.org/mailman/listinfo/gtk-devel-list

-- 
Bye,
-Torsten

___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Stamp doesn't match in iterator in sort method of a tree model

2007-07-28 Thread Tian
Hello,

> Sometimes, in my sort method, I get an assertion telling me the stamp
> found in the iterator doesn't match the one in the model.

I did a lot a test and find a workaround (but not a real solution).

The problem occurs when I filter my list where there are items with children
and all of them hidden. If the 1st child of the 1st item need to be displayed,
it will crash. It works when it should not.

If I only toggle one of the items (not necessarily the 1st one) to show its
children, then there won't be any problem when filtering.

There is also no more problem when I swith my 2 models. i.e. if the filter
contains the sorter which contains the real model. But then my application
doesn't work because the model that is added to the list is not a sorter and
then clicking on column headers generate some errors about this.

So my workaround is to display the list of children in the 1st item on
startup. Then everything works.

It still looks like there is a problem. It seems the TreeModelFilter doesn't
initialize something internal until it has to check for some children. Then
when the TreeModelSorter loops on all items, it gives to my callback the
TreeModelFilter in a bad state.

But there should be another condition. As I tried to create a minimal program
doing this and it worked perfectly, without any of the workarounds. I'll try
to perform other tests. But maybe with these hints, one of the developers may
have an idea about what the real problem could be.

Cheers,

Tian.
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list