Thanks for the fast reply. I went a bit deeper into the code and i found where my problem was. The connect function comes from gobject, and the gobject.connect function accepts extra arguments that are passed to the connected function. So i can solve my problem by:
data.connect('new_data_point', analysis_client.update_plot, specific_arguments) Bests, Pierre On Thu, Apr 12, 2012 at 9:21 AM, Peter Otten <__pete...@web.de> wrote: > Pierre Barthelemy wrote: > > > I have a question about event handling and the use of the connect > > function. I have a data object, that contains a series of signals, one > > being "new_data_point" . > > > > When i want to plot the data, i also connect the "new_data_point" event > to > > the function "analysis_client.update_plot". I therefore run the line: > > > > data.connect('new_data_point', analysis_client.update_plot) > > > > In this case, everytime the data object is updated, i also update the > > plot. > > > > > > I would like to adapt this code to allow to have several plots, connected > > to several data objects. I would therefore need to specify, when i > connect > > the "update_plot" function, which plots needs to be updated. > > Is it possible to specify arguments to be used by the connected function > > when the event occurs ? For instance, is there a way to write something > > like: > > > > data.connect('new_data_point', > > analysis_client.update_plot(specific_plot_instance)) > > > > So that when the event occurs, the corresponding plot (and only this one) > > is updated ? > > Like Walter I have no idea what framework or library you are talking about. > The generic answer is yes: Basically you have to make a new function that > calls the method with a specifc plot instance. > > def update_specific_plot(): > analysis_client.update_plot(specific_plot_instance) > data.connect("new_data_point", update_specific_plot) > > A more elegant and more general version of the above would create the > helper > function on the fly using functools.partial(): > > from functools import partial > > data.connect("new_data_point", > partial(analysis_client.update_plot, specific_plot_instance)) > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor