18 |
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
19 |
FIELDTYPE_STRING, table_to_dbf, table_to_csv |
FIELDTYPE_STRING, table_to_dbf, table_to_csv |
20 |
import view |
import view |
21 |
from dialogs import NonModalNonParentDialog |
from dialogs import ThubanFrame |
22 |
|
|
23 |
from messages import SHAPES_SELECTED, SESSION_REPLACED |
from messages import SHAPES_SELECTED, SESSION_REPLACED |
24 |
from Thuban.Model.messages import TABLE_REMOVED, MAP_LAYERS_REMOVED |
from Thuban.Model.messages import TABLE_REMOVED, MAP_LAYERS_REMOVED |
150 |
|
|
151 |
self.allow_messages_count = 0 |
self.allow_messages_count = 0 |
152 |
|
|
153 |
|
# keep track of which rows are selected. |
154 |
|
self.rows = {} |
155 |
|
|
156 |
self.table = DataTable(table) |
self.table = DataTable(table) |
157 |
|
|
158 |
# The second parameter means that the grid is to take ownership |
# The second parameter means that the grid is to take ownership |
172 |
self.SetSelectionMode(wxGrid.wxGridSelectRows) |
self.SetSelectionMode(wxGrid.wxGridSelectRows) |
173 |
|
|
174 |
self.ToggleEventListeners(True) |
self.ToggleEventListeners(True) |
175 |
|
EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect) |
176 |
|
EVT_GRID_SELECT_CELL(self, self.OnSelectCell) |
177 |
|
|
178 |
# Replace the normal renderers with our own versions which |
# Replace the normal renderers with our own versions which |
179 |
# render NULL/None values specially |
# render NULL/None values specially |
188 |
self.table.SetTable(table) |
self.table.SetTable(table) |
189 |
|
|
190 |
def OnRangeSelect(self, event): |
def OnRangeSelect(self, event): |
191 |
rows = dict([(i, 0) for i in self.GetSelectedRows()]) |
if self.handleSelectEvents: |
192 |
|
self.rows = dict([(i, 0) for i in self.GetSelectedRows()]) |
193 |
|
|
194 |
# if we're selecting we need to include the selected range and |
# if we're selecting we need to include the selected range and |
195 |
# make sure that the current row is also included, which may |
# make sure that the current row is also included, which may |
196 |
# not be the case if you just click on a single row! |
# not be the case if you just click on a single row! |
197 |
if event.Selecting(): |
if event.Selecting(): |
198 |
for i in range(event.GetTopRow(), event.GetBottomRow() + 1): |
for i in range(event.GetTopRow(), event.GetBottomRow() + 1): |
199 |
rows[i] = 0 |
self.rows[i] = 0 |
200 |
rows[event.GetTopLeftCoords().GetRow()] = 0 |
self.rows[event.GetTopLeftCoords().GetRow()] = 0 |
201 |
|
|
202 |
|
self.issue(ROW_SELECTED, self.rows.keys()) |
203 |
|
|
|
self.issue(ROW_SELECTED, rows.keys()) |
|
204 |
event.Skip() |
event.Skip() |
205 |
|
|
206 |
def OnSelectCell(self, event): |
def OnSelectCell(self, event): |
207 |
self.issue(ROW_SELECTED, self.GetSelectedRows()) |
if self.handleSelectEvents: |
208 |
|
self.issue(ROW_SELECTED, self.GetSelectedRows()) |
209 |
event.Skip() |
event.Skip() |
210 |
|
|
211 |
def ToggleEventListeners(self, on): |
def ToggleEventListeners(self, on): |
212 |
if on: |
self.handleSelectEvents = on |
|
EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect) |
|
|
EVT_GRID_SELECT_CELL(self, self.OnSelectCell) |
|
|
else: |
|
|
EVT_GRID_RANGE_SELECT(self, None) |
|
|
EVT_GRID_SELECT_CELL(self, None) |
|
213 |
|
|
214 |
|
def GetNumberSelected(self): |
215 |
|
return len(self.rows) |
216 |
|
|
217 |
def disallow_messages(self): |
def disallow_messages(self): |
218 |
"""Disallow messages to be send. |
"""Disallow messages to be send. |
219 |
|
|
279 |
self.allow_messages() |
self.allow_messages() |
280 |
|
|
281 |
|
|
282 |
class TableFrame(NonModalNonParentDialog): |
class TableFrame(ThubanFrame): |
283 |
|
|
284 |
"""Frame that displays a Thuban table in a grid view""" |
"""Frame that displays a Thuban table in a grid view""" |
285 |
|
|
286 |
def __init__(self, parent, name, title, table): |
def __init__(self, parent, name, title, table): |
287 |
NonModalNonParentDialog.__init__(self, parent, name, title) |
ThubanFrame.__init__(self, parent, name, title) |
288 |
self.table = table |
self.table = table |
289 |
self.grid = self.make_grid(self.table) |
self.grid = self.make_grid(self.table) |
290 |
self.app = self.parent.application |
self.app = self.parent.application |
303 |
def OnClose(self, event): |
def OnClose(self, event): |
304 |
self.app.Unsubscribe(SESSION_REPLACED, self.close_on_session_replaced) |
self.app.Unsubscribe(SESSION_REPLACED, self.close_on_session_replaced) |
305 |
self.session.Unsubscribe(TABLE_REMOVED, self.close_on_table_removed) |
self.session.Unsubscribe(TABLE_REMOVED, self.close_on_table_removed) |
306 |
NonModalNonParentDialog.OnClose(self, event) |
ThubanFrame.OnClose(self, event) |
307 |
|
|
308 |
def close_on_session_replaced(self, *args): |
def close_on_session_replaced(self, *args): |
309 |
"""Subscriber for the SESSION_REPLACED messages. |
"""Subscriber for the SESSION_REPLACED messages. |
325 |
|
|
326 |
ID_QUERY = 4001 |
ID_QUERY = 4001 |
327 |
ID_EXPORT = 4002 |
ID_EXPORT = 4002 |
328 |
|
ID_COMBOVALUE = 4003 |
329 |
|
|
330 |
class QueryTableFrame(TableFrame): |
class QueryTableFrame(TableFrame): |
331 |
|
|
342 |
self.combo_fields = wxComboBox(self, -1, style=wxCB_READONLY) |
self.combo_fields = wxComboBox(self, -1, style=wxCB_READONLY) |
343 |
self.choice_comp = wxChoice(self, -1, |
self.choice_comp = wxChoice(self, -1, |
344 |
choices=["<", "<=", "==", "!=", ">=", ">"]) |
choices=["<", "<=", "==", "!=", ">=", ">"]) |
345 |
self.combo_value = wxComboBox(self, -1) |
self.combo_value = wxComboBox(self, ID_COMBOVALUE) |
346 |
self.choice_action = wxChoice(self, -1, |
self.choice_action = wxChoice(self, -1, |
347 |
choices=[_("Replace Selection"), |
choices=[_("Replace Selection"), |
348 |
_("Refine Selection"), |
_("Refine Selection"), |
351 |
button_query = wxButton(self, ID_QUERY, _("Query")) |
button_query = wxButton(self, ID_QUERY, _("Query")) |
352 |
button_saveas = wxButton(self, ID_EXPORT, _("Export")) |
button_saveas = wxButton(self, ID_EXPORT, _("Export")) |
353 |
|
|
354 |
|
self.CreateStatusBar() |
355 |
|
self.SetStatusText(_("0 rows (0 selected), 0 columns")) |
356 |
|
|
357 |
self.grid.SetSize((400, 200)) |
self.grid.SetSize((400, 200)) |
358 |
|
|
359 |
self.combo_value.Append("") |
self.combo_value.Append("") |
365 |
# assume at least one field? |
# assume at least one field? |
366 |
self.combo_fields.SetSelection(0) |
self.combo_fields.SetSelection(0) |
367 |
self.combo_value.SetSelection(0) |
self.combo_value.SetSelection(0) |
368 |
|
self.choice_action.SetSelection(0) |
369 |
|
self.choice_comp.SetSelection(0) |
370 |
|
|
371 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
372 |
|
|
393 |
EVT_BUTTON(self, ID_QUERY, self.OnQuery) |
EVT_BUTTON(self, ID_QUERY, self.OnQuery) |
394 |
EVT_BUTTON(self, ID_EXPORT, self.OnSaveAs) |
EVT_BUTTON(self, ID_EXPORT, self.OnSaveAs) |
395 |
EVT_KEY_DOWN(self.grid, self.OnKeyDown) |
EVT_KEY_DOWN(self.grid, self.OnKeyDown) |
396 |
|
EVT_GRID_RANGE_SELECT(self.grid, self.OnGridSelectRange) |
397 |
|
EVT_GRID_SELECT_CELL(self.grid, self.OnGridSelectCell) |
398 |
|
|
399 |
|
def UpdateStatusText(self): |
400 |
|
self.SetStatusText(_("%i rows (%i selected), %i columns") |
401 |
|
% (self.grid.GetNumberRows(), |
402 |
|
self.grid.GetNumberSelected(), |
403 |
|
self.grid.GetNumberCols())) |
404 |
|
|
405 |
|
def OnGridSelectRange(self, event): |
406 |
|
self.UpdateStatusText() |
407 |
|
event.Skip() |
408 |
|
|
409 |
|
def OnGridSelectCell(self, event): |
410 |
|
self.UpdateStatusText() |
411 |
|
event.Skip() |
412 |
|
|
413 |
def OnKeyDown(self, event): |
def OnKeyDown(self, event): |
414 |
"""Catch query key from grid""" |
"""Catch query key from grid""" |
415 |
if event.AltDown() and event.GetKeyCode() == ord(QUERY_KEY): |
if event.AltDown() and event.GetKeyCode() == ord(QUERY_KEY): |
418 |
else: |
else: |
419 |
event.Skip() |
event.Skip() |
420 |
|
|
|
|
|
421 |
def OnQuery(self, event): |
def OnQuery(self, event): |
422 |
wxBeginBusyCursor() |
wxBeginBusyCursor() |
423 |
try: |
try: |
424 |
|
|
425 |
if self.combo_value.GetSelection() < 1: |
text = self.combo_value.GetValue() |
426 |
value = self.combo_value.GetValue() |
if self.combo_value.GetSelection() < 1 \ |
427 |
|
or self.combo_value.FindString(text) == -1: |
428 |
|
value = text |
429 |
else: |
else: |
430 |
value = self.table.Column(self.combo_value.GetValue()) |
value = self.table.Column(text) |
431 |
|
|
432 |
ids = self.table.SimpleQuery( |
ids = self.table.SimpleQuery( |
433 |
self.table.Column(self.combo_fields.GetStringSelection()), |
self.table.Column(self.combo_fields.GetStringSelection()), |
447 |
# the first element, which causes everything to be |
# the first element, which causes everything to be |
448 |
# updated properly. |
# updated properly. |
449 |
# |
# |
450 |
self.grid.ToggleEventListeners(False) |
if ids: |
451 |
|
self.grid.ToggleEventListeners(False) |
452 |
|
|
453 |
if choice == 0: |
if choice == 0: |
454 |
# Replace Selection |
# Replace Selection |
479 |
# |
# |
480 |
if ids: |
if ids: |
481 |
self.grid.SelectRow(ids[0], True) |
self.grid.SelectRow(ids[0], True) |
482 |
|
|
483 |
finally: |
finally: |
484 |
wxEndBusyCursor() |
wxEndBusyCursor() |
485 |
|
|