From: Alex T. <al...@tw...> - 2005-07-19 15:09:28
|
Schollnick, Benjamin wrote: > Now regarding the reset of the selected item on a multicolumn list... > > def gather_data ( self ): > current_item = self.last_picked[0] > highlited = -1 > for x in xrange(0, len(self.components.MultiColumnList1.items)): > if current_item == >self.components.MultiColumnList1.items[x][0]: > highlited = x > break > > vsoftware = None > self.components.MultiColumnList1.items = [] > self.components.MultiColumnList1.columnHeadings = [] > headings = [] > > vsoftware, structure = self.odbc_database.select_statement ( >fetch="*", > table=self.database_name, >orderby=self.orderbys) > for x in structure: > headings.append ( x[0].replace("_", " ") ) > self.components.MultiColumnList1.columnHeadings = headings > > data = [] > line = [] > for x in vsoftware: > for y in x: > line.append ( str(y) ) > data.append ( line ) > line = [] > > self.components.MultiColumnList1.items = data > print dir(self.components.MultiColumnList1) > self.components.MultiColumnList1.SetFocus ( highlited ) > >The penalty is too high..... > >Here's some background. The multicolumn list is a representation of >what data is in a database (accessed via ODBC)... The gather_data >function is used to refresh the data in the database view... > >After any changes (Editting, Adding, Removing) I need to refresh, but >the table could be 400+ entries. > > > Do you need to re-retrieve the whole table ? Can you not remember which row you were editing and deal only with that ? (I'm naive about DBs - can you tell ? :-) >It would be rather annoying for a user to make a change at the end of >the table, and then have the table refreshed, and have to scroll all the >way down to the end (again)..... > > >SetSelection works to highlight the text. But it doesn't change the >visible portion of the table to be in the viewing area.... > >The verified Software table is only roughly 100+ items, but if I use the >for loop... > > for x in xrange(0, len(self.components.MultiColumnList1.items)): > if current_item == >self.components.MultiColumnList1.items[x][0]: > highlited = x > break > >It adds roughly a 1-2 seconds to the load process.... > >Any suggestions? > > I'm surprised that the time to load the whole table from the DB, then load that whole thing into the multicolumnlist is small enough for the extra 1-2 seconds to matter. But .... it looks to me as though what you're doing in the loop for x in xrange(0, len(self.components.MultiColumnList1.items)): if current_item == self.components.MultiColumnList1.items[x][0]: highlited = x break is getting the row number where the current_item was *before* any edit to the db. I'd have thought that once you'd edited (or deleted or added), it could be in a different row number - no ? Can't you remove that loop entirely, and get the line number while loading the table from the DB : data = [] line = [] highlited = -1 count = 0 for x in vsoftware: for y in x: line.append ( str(y) ) data.append ( line ) if line[0] == current_item: highlighted = count count += 1 line = [] self.components.MultiColumnList1.items = data print dir(self.components.MultiColumnList1) self.components.MultiColumnList1.SetFocus ( highlited ) If you can't use that, then the other possibility is to retrieve the entire table, and scan that. This saves a significant overhead for accessing each item within the multicolumnlist - but obviously can't be done if your table is too large - i.e. 400 x ?? columns (if it is too large, you may still be able to retrieve the datamap dictionary, and access that - but if you can do this it is easier) What I tried in my copy of the sample/multicolumnlist was > def on_which_mouseClick(self, event): > # current_item = "Yes" > current_item = "Not to be found" > tstart = time.time() > highlited = -1 > for j in range(20): # 20 time just to make it measurable > for x in xrange(0, len(self.components.theList.items)): > if current_item == self.components.theList.items[x][0]: > highlited = x > break > print highlited, time.time()-tstart > > tstart = time.time() > them = self.components.theList.items > highlited = -1 > for j in range(20): # 20 time just to make it measurable > for x in xrange(0, len(them)): > if current_item == them[x][0]: > highlited = x > break > print highlited, time.time()-tstart and this gave times of ~ 6 seconds for the first loop, versus no measurable time for the second. -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.323 / Virus Database: 267.9.0/50 - Release Date: 16/07/2005 |