To anyone who read this post, thanks for having a look. I found the
problem. It turned out the real bottleneck was the event handler
self.on_combo_column_changed; I fixed it by not connecting that event
handler to the signal until after the combo column is first set.

John

On 12/18/2010 09:32 AM, John Haiducek wrote:
> I have a function that draws a bunch of widgets and takes longer than
> expected to run; when I profile it I find the bottleneck is in
> gtk.ComboBox.set_active(). The set_active() method takes 0.364 seconds
> to run, while the rest of the function takes 0.012 seconds. I don't
> see why set_active should take so long; it doesn't take that long to
> pick an item from the list in the GUI. Incidentally, there are 28
> items in the ComboBox's model. Is there something I can do to make the
> set_active() call go faster?
>
> Here's my cProfile output:
>
>         191413 function calls (188937 primitive calls) in 0.769 CPU
> seconds
>
>    Ordered by: cumulative time
>    List reduced from 622 to 10 due to restriction <10>
>
>    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>         1    0.000    0.000    0.769    0.769 <string>:1(<module>)
>         1    0.000    0.000    0.769    0.769 sqlvis.py:316(switch_figure)
>         1    0.012    0.012    0.745    0.745
> /home/jhaiduce/sqlvis/general2/plot.py:195(show_settings_widgets)
>         2    0.000    0.000    0.729    0.364 {method 'set_active' of
> 'gtk.ComboBox' objects}
>         2    0.000    0.000    0.728    0.364
> /home/jhaiduce/sqlvis/general2/plot.py:257(on_column_combo_changed)
>         2    0.000    0.000    0.728    0.364
> /home/jhaiduce/sqlvis/general2/eventManager.py:56(Post)
>         4    0.000    0.000    0.673    0.168
> /home/jhaiduce/sqlvis/general2/plot.py:58(Notify)
>         2    0.001    0.001    0.672    0.336
> /home/jhaiduce/sqlvis/general2/plot.py:70(refresh)
>         2    0.000    0.000    0.262    0.131
> /usr/lib/pymodules/python2.6/matplotlib/backends/backend_gtk.py:280(draw)
>         2    0.000    0.000    0.261    0.131 {method
> 'process_updates' of 'gtk.gdk.Window' objects}
>
>
> And a portion of the code from the function:
>        
>         for i in range(2):
>             label=gtk.Label(labels[i])
>            
> table.attach(label,0,1,i,i+1,xoptions=gtk.FILL,yoptions=gtk.FILL)
>             label.show()
>            
>             field=gtk.ComboBox(liststore)
>             cell = gtk.CellRendererText()
>             field.pack_start(cell, True)
>             field.add_attribute(cell, 'text', 0)
>             field.connect('changed',self.on_column_combo_changed,axes[i])
>             if i==0:
>                 field.set_active(self.xcolumn)
>             if i==1:
>                 field.set_active(self.ycolumn)
>
>             table.attach(field,1,2,i,i+1,yoptions=gtk.FILL)
>             field.show()
>
>

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to