[pygtk] Signal handling by inherited classes

2011-01-19 Thread Ben Shomer
Hello everyone,

I'm writing an application which displays a series of parallel graphs,
all packed in one window.
There is a main graph drawn by a gtk.DrawingArea inheriting class.
There are several other graphs, each of them, inheriting the main graph
class, overriding the
data feed and draw methods.

I created a graphic cursor which tracks the mouse movement when it is on
any of the graphs.
What I want to achieve is a situation where the cursor is updated to the
same position in all
the graphs (all cursors follow the mouse position, no matter where the
mouse is hovering).

My idea was to connect with the mouse movement event and emit a signal
which will update
the cursor movement.
Eventually - it works, but only in the graph in which the mouse is in.
It does not propagate to
the other graphs.

Here are the relevant parts of the code:


class priceGraph(gtk.DrawingArea):
# Define a new signal - 'data_cursor_moved'
__gsignals__ = {'data_cursor_moved' :(gobject.SIGNAL_ACTION,
   gobject.TYPE_NONE,
   (gobject.TYPE_PYOBJECT,))
}
   
def __init__(self, caller, graphtype = FULL):
gtk.DrawingArea.__init__(self)
self.connect(expose_event, self.expose)
self.add_events(gtk.gdk.POINTER_MOTION_MASK|
gtk.gdk.POINTER_MOTION_HINT_MASK)
self.connect(motion_notify_event, self.detectMove)
self.connect(data_cursor_moved, self.handleMove)
rest of init stuff and other methods...


def detectMove(self, widget, event):
self.emit(data_cursor_moved,  event)


def handleMove(self, widget, event):
 Redraw the cursor in the event location 
context = self.window.cairo_create()
widget.queue_draw_area(*self.cursorRect)
context.set_source_rgba(1,0.2,0.3,0.5)
context.set_dash([2,3,2],2)
context.set_line_width(1)
context.move_to(event.x, self.mapY(self.Ymin))
context.line_to(event.x, self.mapY(self.Ymax))
context.stroke()
self.cursorRect =
(int(event.x-2),int(self.mapY(self.Ymax)),4,int(self.mapY(self.Ymin)))
return False

 Rest of class methods... lots of stuff...

gobject.type_register(priceGraph)


class stochastics(priceGraph):
Class inheriting main graph, overriding loadData and draw
methods
.class stuff
gobject.type_register(stochastics)



Same goes for 4 other similar inheriting classes.

My initial understanding was, that the signal catching of the
data_cursor_moved signal
should be inherited by all classes, hence the signal will be caught by
all of them.
This doesn't happen - where am I wrong here?

In the pygtk FAQ 3.11 I read:
A single signal emission will only call handlers attached to the object
it was emitted on. The propagation of events up the heirachy is acheived
by emitting the signal a number of times.

So isn't an inheriting class instance considered the same object? 
I could not properly understand the second sentence about emitting the
signal a number of times.
Is this what should be done? Can anyone give me an example code for
this?

How would you suggest I do that?



Thanks very much in advance,

Ben.




___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] signal handling

2004-06-21 Thread Alex Roitman
Hi all,

I'm trying to figure out the proper signal handling for the following
situation. I have gnome.canvas object, with some
gnome.canvas.CanvasGroup things added to it. I would like to have two
handlers for the events: one when e.g. the click is made over
CanvasGroup and another one when e.g. click is made elsewhere in the
parent canvas.

If I just define two handlers then, when I right-click over the
CanvasGroup I get two handlers kick in one after another. 

I read FAQ and tried stopping the signal emission after the first
handler is done, to no avail. The thing seems to be that stop_emission()
and emit_stop_by_name() only apply to the same object (CanvasGroup).

How do I prevent parent canvas from handling a signal already handled by
the CanvasGroup? Should I just watch the coordinates of the event, or is
there a way to communicate between the two objects?

Thanks in advance,
Alex

-- 
Alexander Roitman   http://ebner.neuroscience.umn.edu/people/alex.html
Dept. of Neuroscience, Lions Research Building
2001 6th Street SE, Minneapolis, MN  55455
Tel (612) 625-7566   FAX (612) 626-9201


signature.asc
Description: This is a digitally signed message part
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Signal handling

2000-06-05 Thread Luca Minuti

I have a problem trying to install a new signal handler.
I try this program:


#!/usr/bin/env python

from signal import *
from gtk import *

def signal_handler(sig, frame):
 print "Received signal %s" % (sig)

signal(10, signal_handler)

win = GtkWindow()
win.set_usize(100,100)
win.show()
win.connect("destroy", mainquit)
mainloop()

but if I write:

$ kill -s 10 pid

the program answer only after the mainquit.
If I don't import gtk and I write a simple console application it works. And
the same program translate in C works.

Someone can help me?

Thanks.



___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Signal handling

2000-06-05 Thread Hrvoje Niksic

"Luca Minuti" [EMAIL PROTECTED] writes:

 #!/usr/bin/env python
 
 from signal import *
 from gtk import *
 
 def signal_handler(sig, frame):
  print "Received signal %s" % (sig)
 
 signal(10, signal_handler)
 
 win = GtkWindow()
 win.set_usize(100,100)
 win.show()
 win.connect("destroy", mainquit)
 mainloop()
 
 but if I write:
 
 $ kill -s 10 pid
 
 the program answer only after the mainquit.

I've hit this problem before[1], and it boiled down to a problem with
Gtk/Python interaction.  You should know that in Python signals are
never really asynchronous.  When the OS/C-level signal handler is
invoked, Python merely enqueues the Python handler to a special queue,
to be executed by the Python interpreter as soon as possible.

The problem with Gtk is that when the signal handler returns, it gives
back control to the Gtk main loop, not to Python, so the code that is
supposed to check for the signal-handler queue gets run only when the
interpreter exits.

The solution here is for pygtk to hook into the main loop with a
routine that gets run after the loop has been interrupted by a signal.
This routine would manually call the Python signal-handling
incantation.  Alas, last time I looked, GDK main loop didn't have that
kind of hook.  I asked about it on the Gtk list, but got no response.

James, have you looked into the features of GDK main loop recently?
Can you now specify a "post-signal" handler nowadays?


[1]
Before someone jumps with "don't use UNIX signals in a GUI
application", let me assure you that it was hard to do otherwise.  My
Gtk program spawned off a bunch of child processes, and was interested
in their exit statuses.  Apparently the only wait to find out when a
process has died is to handle SIGCHLD.  I haven't found the solution
to the problem, and gave up the application entirely.

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Signal handling

2000-06-05 Thread Matt Wilson

On Mon, Jun 05, 2000 at 03:17:02PM +0200, Luca Minuti wrote:
 
 My program must do this: if someone make some change to the data that the
 program
 manipulate other instance of the same program must update their own view.

Have your program set up a named pipe and add an input hander on that
file descriptor.  When other programs want your program to update its
view, write to the pipe.

Just an idea.

Matt


___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Signal handling

2000-06-05 Thread Hrvoje Niksic

"Luca Minuti" [EMAIL PROTECTED] writes:

 I think that the use of the signal is not the only possible solution
 for me.  But I don't know others inter process comunication
 tecnique.
 
 My program must do this: if someone make some change to the data
 that the program manipulate other instance of the same program must
 update their own view.

How do you know the PID's of the other instances?

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk