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



Thank you to all those who responded to my initial post.  I have since successfully 
implemented the "delete_event" signal to spawn my exit dialog window, so 
problem 2 is solved :)  However, I'm note sure the solutions given for my 
first problem work in my case (I could be wrong, it may be exactly what 
I need but I have goten it to work yet).  What I need is the ability to 
start and stop the daemon dependant on what buttons are clicked.  I have 
tried to implement this by way of a variable "$daemonStarted" equal to 1 
for true and 0 for false.  I used the fork command and wrote a condition 
that basically says, if $daemonStarted then listen for request else do nothing. 
 Unfortunately, I discovered that when I click the start daemon button, 
the gui child process changes the value of its copy of $daemonStarted but 
the parent process' variable remained unchanged.  I guess what I really 
need is a way to have the child process and the parent process access/modify 
the same variables, or for Gtk to somehow sit in the background, avoid the 
use of fork and allow a daemon loop to execute at the same time.  Any suggestions/links/examples 
would be greatly appreciated.  Thanks in advance.

Greg  

At Thu, 10 May 2001 09:02:07 +0100, Etienne Grossmann <etienne anonimo isr ist utl pt> 
wrote:



 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

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

Free, encrypted, secure Web-based email at www.hushmail.com


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