[Tutor] python connect() function
barthpi at gmail.com
Thu Apr 12 17:42:06 CEST 2012
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)
On Thu, Apr 12, 2012 at 9:21 AM, Peter Otten <__peter__ at 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
> > 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
> > 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():
> data.connect("new_data_point", update_specific_plot)
> A more elegant and more general version of the above would create the
> function on the fly using functools.partial():
> from functools import partial
> partial(analysis_client.update_plot, specific_plot_instance))
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor