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