Show More
@@ -35,7 +35,7 b' class IGridRenderer(wx.grid.PyGridCellRenderer):' | |||
|
35 | 35 | |
|
36 | 36 | def _getvalue(self, row, col): |
|
37 | 37 | try: |
|
38 | value = self.table.displayattrs[col].value(self.table.items[row]) | |
|
38 | value = self.table._displayattrs[col].value(self.table.items[row]) | |
|
39 | 39 | (align, width, text) = ipipe.xformat(value, "cell", self.maxchars) |
|
40 | 40 | except Exception, exc: |
|
41 | 41 | (align, width, text) = ipipe.xformat(exc, "cell", self.maxchars) |
@@ -123,12 +123,12 b' class IGridTable(wx.grid.PyGridTableBase):' | |||
|
123 | 123 | self.input = input |
|
124 | 124 | self.iterator = ipipe.xiter(input) |
|
125 | 125 | self.items = [] |
|
126 | self.hiddenattrs = [] | |
|
127 | self.attrs = attrs | |
|
128 |
self.displayattrs = |
|
|
129 | self.fetch(1) | |
|
130 | self.sizing = False | |
|
126 | self.attrs = [ipipe.upgradexattr(attr) for attr in attrs] | |
|
127 | self._displayattrs = self.attrs[:] | |
|
128 | self._displayattrset = set(self.attrs) | |
|
129 | self._sizing = False | |
|
131 | 130 | self.fontsize = fontsize |
|
131 | self._fetch(1) | |
|
132 | 132 | |
|
133 | 133 | def GetAttr(self, *args): |
|
134 | 134 | attr = wx.grid.GridCellAttr() |
@@ -139,11 +139,11 b' class IGridTable(wx.grid.PyGridTableBase):' | |||
|
139 | 139 | return len(self.items) |
|
140 | 140 | |
|
141 | 141 | def GetNumberCols(self): |
|
142 | return len(self.displayattrs) | |
|
142 | return len(self._displayattrs) | |
|
143 | 143 | |
|
144 | 144 | def GetColLabelValue(self, col): |
|
145 | if col < len(self.displayattrs): | |
|
146 | return self.displayattrs[col].name() | |
|
145 | if col < len(self._displayattrs): | |
|
146 | return self._displayattrs[col].name() | |
|
147 | 147 | else: |
|
148 | 148 | return "" |
|
149 | 149 | |
@@ -153,10 +153,19 b' class IGridTable(wx.grid.PyGridTableBase):' | |||
|
153 | 153 | def IsEmptyCell(self, row, col): |
|
154 | 154 | return False |
|
155 | 155 | |
|
156 |
def |
|
|
156 | def _append(self, item): | |
|
157 | self.items.append(item) | |
|
158 | # Nothing to do if the set of attributes has been fixed by the user | |
|
159 | if not self.attrs: | |
|
160 | for attr in ipipe.xattrs(item): | |
|
161 | attr = ipipe.upgradexattr(attr) | |
|
162 | if attr not in self._displayattrset: | |
|
163 | self._displayattrs.append(attr) | |
|
164 | self._displayattrset.add(attr) | |
|
165 | ||
|
166 | def _fetch(self, count): | |
|
157 | 167 | # Try to fill ``self.items`` with at least ``count`` objects. |
|
158 | 168 | have = len(self.items) |
|
159 | work = False | |
|
160 | 169 | while self.iterator is not None and have < count: |
|
161 | 170 | try: |
|
162 | 171 | item = self.iterator.next() |
@@ -167,58 +176,32 b' class IGridTable(wx.grid.PyGridTableBase):' | |||
|
167 | 176 | raise |
|
168 | 177 | except Exception, exc: |
|
169 | 178 | have += 1 |
|
170 |
self. |
|
|
171 | work = True | |
|
179 | self._append(item) | |
|
172 | 180 | self.iterator = None |
|
173 | 181 | break |
|
174 | 182 | else: |
|
175 | 183 | have += 1 |
|
176 |
self. |
|
|
177 | work = True | |
|
178 | if work: | |
|
179 | self.calcdisplayattrs() | |
|
180 | ||
|
181 | def calcdisplayattrs(self): | |
|
182 | # Calculate which attributes are available from the objects that are | |
|
183 | # currently visible on screen (and store it in ``self.displayattrs``) | |
|
184 | attrs = set() | |
|
185 | self.displayattrs = [] | |
|
186 | if self.attrs: | |
|
187 | # If the browser object specifies a fixed list of attributes, | |
|
188 | # simply use it (removing hidden attributes). | |
|
189 | for attr in self.attrs: | |
|
190 | attr = ipipe.upgradexattr(attr) | |
|
191 | if attr not in attrs and attr not in self.hiddenattrs: | |
|
192 | self.displayattrs.append(attr) | |
|
193 | attrs.add(attr) | |
|
194 | else: | |
|
195 | endy = len(self.items) | |
|
196 | for i in xrange(endy): | |
|
197 | for attr in ipipe.xattrs(self.items[i]): | |
|
198 | attr = ipipe.upgradexattr(attr) | |
|
199 | if attr not in attrs and attr not in self.hiddenattrs: | |
|
200 | self.displayattrs.append(attr) | |
|
201 | attrs.add(attr) | |
|
184 | self._append(item) | |
|
202 | 185 | |
|
203 | 186 | def GetValue(self, row, col): |
|
204 | 187 | # some kind of dummy-function: does not return anything but ""; |
|
205 | 188 | # (The value isn't use anyway) |
|
206 | 189 | # its main task is to trigger the fetch of new objects |
|
207 | had_cols = self.displayattrs[:] | |
|
190 | had_cols = self._displayattrs[:] | |
|
208 | 191 | had_rows = len(self.items) |
|
209 | if row == had_rows - 1 and self.iterator is not None and not self.sizing: | |
|
210 | self.fetch(row + 20) | |
|
192 | if row == had_rows - 1 and self.iterator is not None and not self._sizing: | |
|
193 | self._fetch(row + 20) | |
|
211 | 194 | have_rows = len(self.items) |
|
212 | have_cols = len(self.displayattrs) | |
|
195 | have_cols = len(self._displayattrs) | |
|
213 | 196 | if have_rows > had_rows: |
|
214 | 197 | msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, have_rows - had_rows) |
|
215 | 198 | self.GetView().ProcessTableMessage(msg) |
|
216 | self.sizing = True | |
|
199 | self._sizing = True | |
|
217 | 200 | self.GetView().AutoSizeColumns(False) |
|
218 | self.sizing = False | |
|
201 | self._sizing = False | |
|
219 | 202 | if row >= have_rows: |
|
220 | 203 | return "" |
|
221 | if self.displayattrs != had_cols: | |
|
204 | if self._displayattrs != had_cols: | |
|
222 | 205 | msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED, have_cols - len(had_cols)) |
|
223 | 206 | self.GetView().ProcessTableMessage(msg) |
|
224 | 207 | return "" |
@@ -300,7 +283,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
300 | 283 | Sort in ascending order; sorting criteria is the current attribute |
|
301 | 284 | """ |
|
302 | 285 | col = self.GetGridCursorCol() |
|
303 | attr = self.table.displayattrs[col] | |
|
286 | attr = self.table._displayattrs[col] | |
|
304 | 287 | frame = self.GetParent().GetParent().GetParent() |
|
305 | 288 | if attr is ipipe.noitem: |
|
306 | 289 | self.error_output("no column under cursor") |
@@ -320,7 +303,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
320 | 303 | Sort in descending order; sorting criteria is the current attribute |
|
321 | 304 | """ |
|
322 | 305 | col = self.GetGridCursorCol() |
|
323 | attr = self.table.displayattrs[col] | |
|
306 | attr = self.table._displayattrs[col] | |
|
324 | 307 | frame = self.GetParent().GetParent().GetParent() |
|
325 | 308 | if attr is ipipe.noitem: |
|
326 | 309 | self.error_output("no column under cursor") |
@@ -346,7 +329,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
346 | 329 | Gets the text which is displayed at ``(row, col)`` |
|
347 | 330 | """ |
|
348 | 331 | try: |
|
349 | value = self.table.displayattrs[col].value(self.table.items[row]) | |
|
332 | value = self.table._displayattrs[col].value(self.table.items[row]) | |
|
350 | 333 | (align, width, text) = ipipe.xformat(value, "cell", self.maxchars) |
|
351 | 334 | except IndexError: |
|
352 | 335 | raise IndexError |
@@ -430,10 +413,10 b' class IGridGrid(wx.grid.Grid):' | |||
|
430 | 413 | self.SetGridCursor(row, 0) |
|
431 | 414 | elif keycode == ord("C") and sh: |
|
432 | 415 | col = self.GetGridCursorCol() |
|
433 | attr = self.table.displayattrs[col] | |
|
416 | attr = self.table._displayattrs[col] | |
|
434 | 417 | returnobj = [] |
|
435 | 418 | for i in xrange(self.GetNumberRows()): |
|
436 | returnobj.append(self.table.displayattrs[col].value(self.table.items[i])) | |
|
419 | returnobj.append(self.table._displayattrs[col].value(self.table.items[i])) | |
|
437 | 420 | self.quit(returnobj) |
|
438 | 421 | elif keycode in (wx.WXK_ESCAPE, ord("Q")) and not (ctrl or sh): |
|
439 | 422 | self.quit() |
@@ -511,7 +494,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
511 | 494 | |
|
512 | 495 | def enterattr(self, row, col): |
|
513 | 496 | try: |
|
514 | attr = self.table.displayattrs[col] | |
|
497 | attr = self.table._displayattrs[col] | |
|
515 | 498 | value = attr.value(self.table.items[row]) |
|
516 | 499 | except Exception, exc: |
|
517 | 500 | self.error_output(str(exc)) |
@@ -531,7 +514,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
531 | 514 | shows a detail-view of the current cell |
|
532 | 515 | """ |
|
533 | 516 | try: |
|
534 | attr = self.table.displayattrs[col] | |
|
517 | attr = self.table._displayattrs[col] | |
|
535 | 518 | item = self.table.items[row] |
|
536 | 519 | except Exception, exc: |
|
537 | 520 | self.error_output(str(exc)) |
@@ -541,7 +524,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
541 | 524 | |
|
542 | 525 | def detail_attr(self, row, col): |
|
543 | 526 | try: |
|
544 | attr = self.table.displayattrs[col] | |
|
527 | attr = self.table._displayattrs[col] | |
|
545 | 528 | item = attr.value(self.table.items[row]) |
|
546 | 529 | except Exception, exc: |
|
547 | 530 | self.error_output(str(exc)) |
@@ -591,7 +574,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
591 | 574 | """ |
|
592 | 575 | values = [] |
|
593 | 576 | try: |
|
594 | attr = self.table.displayattrs[col] | |
|
577 | attr = self.table._displayattrs[col] | |
|
595 | 578 | for row in rows: |
|
596 | 579 | try: |
|
597 | 580 | values.append(attr.value(self.table.items[row])) |
@@ -606,7 +589,7 b' class IGridGrid(wx.grid.Grid):' | |||
|
606 | 589 | |
|
607 | 590 | def pickattr(self, row, col): |
|
608 | 591 | try: |
|
609 | attr = self.table.displayattrs[col] | |
|
592 | attr = self.table._displayattrs[col] | |
|
610 | 593 | value = attr.value(self.table.items[row]) |
|
611 | 594 | except Exception, exc: |
|
612 | 595 | self.error_output(str(exc)) |
@@ -2,6 +2,10 b'' | |||
|
2 | 2 | |
|
3 | 3 | * IPython/Extensions/ipipe.py: Prefer ibrowse over igrid |
|
4 | 4 | as the default browser. |
|
5 | * IPython/Extensions/igrid.py: Make a few igrid attributes private. | |
|
6 | As igrid displays all attributes it ever encounters, fetch() (which has | |
|
7 | been renamed to _fetch()) doesn't have to recalculate the display attributes | |
|
8 | every time a new item is fetched. This should speed up scrolling. | |
|
5 | 9 | |
|
6 | 10 | 2007-03-10 Fernando Perez <Fernando.Perez@colorado.edu> |
|
7 | 11 |
General Comments 0
You need to be logged in to leave comments.
Login now