71 |
# Renderer understands the type too,) not just strings as in the |
# Renderer understands the type too,) not just strings as in the |
72 |
# C++ version. |
# C++ version. |
73 |
def GetValue(self, row, col): |
def GetValue(self, row, col): |
74 |
record = self.table.ReadRowAsDict(row) |
record = self.table.ReadRowAsDict(row, row_is_ordinal = 1) |
75 |
return record[self.columns[col][0]] |
return record[self.columns[col][0]] |
76 |
|
|
77 |
def SetValue(self, row, col, value): |
def SetValue(self, row, col, value): |
102 |
return self.CanGetValueAs(row, col, typeName) |
return self.CanGetValueAs(row, col, typeName) |
103 |
|
|
104 |
|
|
105 |
|
# |
106 |
|
def RowIdToOrdinal(self, rowid): |
107 |
|
"""Return the ordinal of the row given by its id""" |
108 |
|
return self.table.RowIdToOrdinal(rowid) |
109 |
|
|
110 |
|
def RowOrdinalToId(self, ordinal): |
111 |
|
"""Return the id of the row given by its ordinal""" |
112 |
|
return self.table.RowOrdinalToId(ordinal) |
113 |
|
|
114 |
|
|
115 |
class NullRenderer(wxPyGridCellRenderer): |
class NullRenderer(wxPyGridCellRenderer): |
116 |
|
|
197 |
self.table.SetTable(table) |
self.table.SetTable(table) |
198 |
|
|
199 |
def OnRangeSelect(self, event): |
def OnRangeSelect(self, event): |
200 |
|
to_id = self.table.RowOrdinalToId |
201 |
if self.handleSelectEvents: |
if self.handleSelectEvents: |
202 |
self.rows = dict([(i, 0) for i in self.GetSelectedRows()]) |
self.rows = dict([(to_id(i), 0) for i in self.GetSelectedRows()]) |
203 |
|
|
204 |
# if we're selecting we need to include the selected range and |
# if we're selecting we need to include the selected range and |
205 |
# make sure that the current row is also included, which may |
# make sure that the current row is also included, which may |
206 |
# not be the case if you just click on a single row! |
# not be the case if you just click on a single row! |
207 |
if event.Selecting(): |
if event.Selecting(): |
208 |
for i in range(event.GetTopRow(), event.GetBottomRow() + 1): |
for i in range(event.GetTopRow(), event.GetBottomRow() + 1): |
209 |
self.rows[i] = 0 |
self.rows[to_id(i)] = 0 |
210 |
self.rows[event.GetTopLeftCoords().GetRow()] = 0 |
self.rows[to_id(event.GetTopLeftCoords().GetRow())] = 0 |
211 |
|
|
212 |
self.issue(ROW_SELECTED, self.rows.keys()) |
self.issue(ROW_SELECTED, self.rows.keys()) |
213 |
|
|
214 |
event.Skip() |
event.Skip() |
215 |
|
|
216 |
def OnSelectCell(self, event): |
def OnSelectCell(self, event): |
217 |
|
to_id = self.table.RowOrdinalToId |
218 |
if self.handleSelectEvents: |
if self.handleSelectEvents: |
219 |
self.issue(ROW_SELECTED, self.GetSelectedRows()) |
self.issue(ROW_SELECTED, |
220 |
|
[to_id(i) for i in self.GetSelectedRows()]) |
221 |
event.Skip() |
event.Skip() |
222 |
|
|
223 |
def ToggleEventListeners(self, on): |
def ToggleEventListeners(self, on): |
224 |
self.handleSelectEvents = on |
self.handleSelectEvents = on |
225 |
|
|
226 |
def GetNumberSelected(self): |
def GetNumberSelected(self): |
227 |
return len(self.rows) |
return len(self.rows) |
228 |
|
|
252 |
if self.allow_messages_count == 0: |
if self.allow_messages_count == 0: |
253 |
Publisher.issue(self, *args) |
Publisher.issue(self, *args) |
254 |
|
|
255 |
|
def SelectRowById(self, rowid, do_select): |
256 |
|
"""Select row with the id rowid""" |
257 |
|
self.SelectRow(self.table.RowIdToOrdinal(rowid), do_select) |
258 |
|
|
259 |
|
|
260 |
class LayerTableGrid(TableGrid): |
class LayerTableGrid(TableGrid): |
261 |
|
|
278 |
try: |
try: |
279 |
self.ClearSelection() |
self.ClearSelection() |
280 |
if len(shapes) > 0: |
if len(shapes) > 0: |
281 |
# |
# keep track of the lowest id so we can make it the |
282 |
# keep track of the lowest id so we can make it |
# first visible item |
283 |
# the first visible item |
first = -1 |
|
# |
|
|
first = shapes[0] |
|
284 |
|
|
285 |
|
to_ordinal = self.table.RowIdToOrdinal |
286 |
for shape in shapes: |
for shape in shapes: |
287 |
self.SelectRow(shape, True) |
row = to_ordinal(shape) |
288 |
if shape < first: |
self.SelectRow(row, True) |
289 |
first = shape |
if row < first: |
290 |
|
first = row |
291 |
|
|
292 |
self.SetGridCursor(first, 0) |
self.SetGridCursor(first, 0) |
293 |
self.MakeCellVisible(first, 0) |
self.MakeCellVisible(first, 0) |
503 |
if firsttime: |
if firsttime: |
504 |
firsttime = False |
firsttime = False |
505 |
else: |
else: |
506 |
self.grid.SelectRow(id, True) |
self.grid.SelectRowById(id, True) |
507 |
|
|
508 |
self.grid.ToggleEventListeners(True) |
self.grid.ToggleEventListeners(True) |
509 |
|
|
511 |
# select the first row |
# select the first row |
512 |
# |
# |
513 |
if ids: |
if ids: |
514 |
self.grid.SelectRow(ids[0], True) |
self.grid.SelectRowById(ids[0], True) |
515 |
|
|
516 |
finally: |
finally: |
517 |
ThubanEndBusyCursor() |
ThubanEndBusyCursor() |
556 |
|
|
557 |
def get_selected(self): |
def get_selected(self): |
558 |
"""Return a dictionary of the selected rows. |
"""Return a dictionary of the selected rows. |
559 |
|
|
560 |
The dictionary has the indexes as keys.""" |
The dictionary has the indexes as keys.""" |
561 |
return dict([(i, 0) for i in self.grid.GetSelectedRows()]) |
to_id = self.table.RowOrdinalToId |
562 |
|
return dict([(to_id(i), 0) for i in self.grid.GetSelectedRows()]) |
563 |
|
|
564 |
|
|
565 |
class LayerTableFrame(QueryTableFrame): |
class LayerTableFrame(QueryTableFrame): |
566 |
|
|
582 |
# accordingly |
# accordingly |
583 |
sel = self.get_selected().keys() |
sel = self.get_selected().keys() |
584 |
for i in sel: |
for i in sel: |
585 |
self.grid.SelectRow(i, True) |
self.grid.SelectRowById(i, True) |
586 |
|
|
587 |
def make_grid(self, table): |
def make_grid(self, table): |
588 |
"""Override the derived method to return a LayerTableGrid. |
"""Override the derived method to return a LayerTableGrid. |