I am having a problem when inserting a large amount of data into a tree with a sorted column. It seems that when the data is inserted in random order, the inserts get exponentially slower. I suspect this is because the entire tree is getting resorted upon every insert.

However, if the data is inserted in sorted order, the inserts are significantly faster. When I put all of the random data into a list, sort the list, then insert the data in sorted order it seems to take about 1/10th of the time to do 10,000 inserts compared to inserting it unsorted (see attached sample). The only problem is that this is not a reasonable solution for what I need to do.

Is it possible to keep the tree from sorting on each insert and just do it once when I am done inserting? Or is there a better way to do this all together? Any help would be appreciated!

--
Jon Ellis <[EMAIL PROTECTED]>
import gtk, time


#------------------------------------------------------------------------------
class TableTest:
    #--------------------------------------------------------------------------
    def __init__(self):
        window = gtk.Window()
        window.connect('destroy', self._onWindowDestroy)
        window.set_default_size(400, 100)

        self.table = gtk.Table(rows=2, columns=1)
        self.table.set_border_width(10)

        self.entry = gtk.HBox()
        entry = gtk.Entry()
        self.entry.pack_start(entry)
        entry.show()
        self.table.attach(self.entry, 0, 1, 0, 1, yoptions=gtk.SHRINK)
        self.entry.show()

        self.Testing = self.entry

        button = gtk.Button(label="Click Me!")
        button.connect('clicked', self._onButtonClicked)
        self.table.attach(button, 0, 1, 1, 2, yoptions=gtk.SHRINK)
        button.show()

        window.add(self.table)
        self.table.show()


        window.show()

    #--------------------------------------------------------------------------
    def _onButtonClicked(self, *args):
        self.entry.hide()
        #self.entry.destroy()

        self.entry = gtk.HBox()
        button = gtk.Button()
        image = gtk.image_new_from_stock(gtk.STOCK_SAVE, 
gtk.ICON_SIZE_LARGE_TOOLBAR)
        button.add(image)
        image.show()
        button.show()
        self.entry.pack_start(button)
        self.entry.set_border_width(10)
        self.table.attach(self.entry, 0, 1, 0, 1, yoptions=gtk.SHRINK, 
xoptions=gtk.SHRINK)
        self.entry.show()
        while gtk.events_pending():
            gtk.main_iteration()
        time.sleep(3)

        self.entry.hide()
        #self.entry.destroy()

        self.entry = gtk.Entry()
        self.table.attach(self.entry, 0, 1, 0, 1, yoptions=gtk.SHRINK, 
xoptions=gtk.SHRINK)

        self.entry.show()
        
        

    #--------------------------------------------------------------------------
    def _onWindowDestroy(self, *args):
        gtk.main_quit()

#------------------------------------------------------------------------------

if __name__ == '__main__':
    test = TableTest()
    gtk.main()
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to