Re: 2 questions regarding a perl daemon with a GTK interface



  Hi,

From: gfricke hushmail com
#  All,
#  I recently used glade to build my first perl program with a GUI
#  interface.  I have come across two problems that I haven't been
#  able to figure out.  My GTK experience is very minimal and my perl
#  expertise is limited to just a few programs.

#  Problem 1 - How do I send GTK to the background so that I can run a
#  daemon loop listening for remote connections, yet having the GTK
#  portion of the program still sending all the actions/signals to
#  thier appropriate functions/handlers?  If i enter my daemon loop
#  after the Gtk->mainl command the loop never executes.  Likewise if
#  I insert the daemon loop before the Gtk->main call the window never
#  appears.

  Maybe that's what you are looking for, taken from the perl-gtk
tutorial (http://personal.riverusers.com/~swilhelm/gtkperl-tutorial):
======================================================================
Monitoring IO

A nifty feature of GDK (the library that underlies GTK), is the
ability to have it check for data on a file descriptor for you (as
returned by open() or socket()). This is especially useful for
networking applications. The function:

$id = Gtk::Gdk->input_add( $source, $condition, \&function, @data );

takes a file descripter you want watched as the first argument, and
the second argument specifies what you want GDK to look for. This may
be one of:

'read' - Call your function when there is data ready for reading on
         your file descriptor.

'write' - Call your function when the file descriptor is ready for
         writing
======================================================================

#  Problem 2 - How can I bind the window manager's destroy button "X" at the 
#  top right corner of the window to my exit function?  My exit button currently 
#  displays an exit dialog window before exiting the application, and I would 
#  like the same dialog when the user clicks on the "X" at the top of the window. 
#     I tried using the delete_event signal handler with a call to my exit 
#  function, however, this method resulted in destroying the main window and 
#  then spawning my exit dialog window.

  Sorry, I don't know for this one ... However, playing with code like : 

======================================================================
$window->signal_connect ("event",  
                         sub {
                           print join ",", @_, "\n";
                           my $a = $_[1];
                           map {print "$_ -> $a->{$_}\n"} keys %$a;
                         });
======================================================================

  Gives information of this kind :

======================================================================
Gtk::Window=HASH(0x81cf25c),Gtk::Gdk::Event=HASH(0x81deaf4),
window -> Gtk::Gdk::Window=HASH(0x81deb0c)
type -> delete
send_event -> 1
_ptr -> 136511304
======================================================================

  Hth,

  Etienne




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