/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/tableview.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/tableview.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1394 by jonathan, Thu Jul 10 14:54:58 2003 UTC revision 2700 by dpinte, Mon Sep 18 14:27:02 2006 UTC
# Line 11  import os.path Line 11  import os.path
11    
12  from Thuban import _  from Thuban import _
13    
14  from wxPython.wx import *  import wx
15  from wxPython.grid import *  from wx import grid
16    
17  from Thuban.Lib.connector import Publisher  from Thuban.Lib.connector import Publisher
18  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \
# Line 23  from messages import SHAPES_SELECTED, SE Line 23  from messages import SHAPES_SELECTED, SE
23  from Thuban.Model.messages import TABLE_REMOVED, MAP_LAYERS_REMOVED  from Thuban.Model.messages import TABLE_REMOVED, MAP_LAYERS_REMOVED
24  from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor  from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
25    
26  wx_value_type_map = {FIELDTYPE_INT: wxGRID_VALUE_NUMBER,  wx_value_type_map = {FIELDTYPE_INT: grid.GRID_VALUE_NUMBER,
27                       FIELDTYPE_DOUBLE: wxGRID_VALUE_FLOAT,                       FIELDTYPE_DOUBLE: grid.GRID_VALUE_FLOAT,
28                       FIELDTYPE_STRING: wxGRID_VALUE_STRING}                       FIELDTYPE_STRING: grid.GRID_VALUE_STRING}
29    
30  ROW_SELECTED = "ROW_SELECTED"  ROW_SELECTED = "ROW_SELECTED"
31    
32  QUERY_KEY = 'S'  QUERY_KEY = 'S'
33    
34  class DataTable(wxPyGridTableBase):  class DataTable(grid.PyGridTableBase):
35    
36      """Wrapper around a Thuban table object suitable for a wxGrid"""      """Wrapper around a Thuban table object suitable for a wxGrid"""
37    
38      def __init__(self, table = None):      def __init__(self, table = None):
39          wxPyGridTableBase.__init__(self)          grid.PyGridTableBase.__init__(self)
40          self.num_cols = 0          self.num_cols = 0
41          self.num_rows = 0          self.num_rows = 0
42          self.columns = []          self.columns = []
# Line 71  class DataTable(wxPyGridTableBase): Line 71  class DataTable(wxPyGridTableBase):
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):
# Line 102  class DataTable(wxPyGridTableBase): Line 102  class DataTable(wxPyGridTableBase):
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  class NullRenderer(wxPyGridCellRenderer):  
115    class NullRenderer(grid.PyGridCellRenderer):
116    
117      """Renderer that draws NULL as a gray rectangle      """Renderer that draws NULL as a gray rectangle
118    
# Line 112  class NullRenderer(wxPyGridCellRenderer) Line 121  class NullRenderer(wxPyGridCellRenderer)
121      """      """
122    
123      def __init__(self, non_null_renderer):      def __init__(self, non_null_renderer):
124          wxPyGridCellRenderer.__init__(self)          grid.PyGridCellRenderer.__init__(self)
125          self.non_null_renderer = non_null_renderer          self.non_null_renderer = non_null_renderer
126    
127      def Draw(self, grid, attr, dc, rect, row, col, isSelected):      def Draw(self, grid, attr, dc, rect, row, col, isSelected):
128          value = grid.table.GetValue(row, col)          value = grid.table.GetValue(row, col)
129          if value is None:          if value is None:
130              dc.SetBackgroundMode(wxSOLID)              dc.SetBackgroundMode(wx.SOLID)
131              dc.SetBrush(wxBrush(wxColour(192, 192, 192), wxSOLID))              dc.SetBrush(wx.Brush(wx.Colour(192, 192, 192), wx.SOLID))
132              dc.SetPen(wxTRANSPARENT_PEN)              dc.SetPen(wx.TRANSPARENT_PEN)
133              dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)              dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
134          else:          else:
135              self.non_null_renderer.Draw(grid, attr, dc, rect, row, col,              self.non_null_renderer.Draw(grid, attr, dc, rect, row, col,
# Line 133  class NullRenderer(wxPyGridCellRenderer) Line 142  class NullRenderer(wxPyGridCellRenderer)
142          return NullRenderer(self.non_null_renderer)          return NullRenderer(self.non_null_renderer)
143    
144    
145  class TableGrid(wxGrid, Publisher):  class TableGrid(grid.Grid, Publisher):
146    
147      """A grid view for a Thuban table      """A grid view for a Thuban table
148    
# Line 146  class TableGrid(wxGrid, Publisher): Line 155  class TableGrid(wxGrid, Publisher):
155      """      """
156    
157      def __init__(self, parent, table = None):      def __init__(self, parent, table = None):
158          wxGrid.__init__(self, parent, -1)          grid.Grid.__init__(self, parent, -1)
159    
160          self.allow_messages_count = 0          self.allow_messages_count = 0
161    
# Line 169  class TableGrid(wxGrid, Publisher): Line 178  class TableGrid(wxGrid, Publisher):
178          # long time.          # long time.
179          #self.AutoSizeColumns(False)          #self.AutoSizeColumns(False)
180    
181          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(grid.Grid.wxGridSelectRows)
182    
183          self.ToggleEventListeners(True)          self.ToggleEventListeners(True)
184          EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)          self.Bind(grid.EVT_GRID_RANGE_SELECT, self.OnRangeSelect)
185          EVT_GRID_SELECT_CELL(self, self.OnSelectCell)          self.Bind(grid.EVT_GRID_SELECT_CELL, self.OnSelectCell)
186    
187          # Replace the normal renderers with our own versions which          # Replace the normal renderers with our own versions which
188          # render NULL/None values specially          # render NULL/None values specially
189          self.RegisterDataType(wxGRID_VALUE_STRING,          self.RegisterDataType(grid.GRID_VALUE_STRING,
190                                NullRenderer(wxGridCellStringRenderer()), None)                                NullRenderer(grid.GridCellStringRenderer()), None)
191          self.RegisterDataType(wxGRID_VALUE_NUMBER,          self.RegisterDataType(grid.GRID_VALUE_NUMBER,
192                                NullRenderer(wxGridCellNumberRenderer()), None)                                NullRenderer(grid.GridCellNumberRenderer()), None)
193          self.RegisterDataType(wxGRID_VALUE_FLOAT,          self.RegisterDataType(grid.GRID_VALUE_FLOAT,
194                                NullRenderer(wxGridCellFloatRenderer()), None)                                NullRenderer(grid.GridCellFloatRenderer()), None)
195    
196            self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
197    
198        def OnDestroy(self, event):
199            Publisher.Destroy(self)
200    
201      def SetTableObject(self, table):      def SetTableObject(self, table):
202          self.table.SetTable(table)          self.table.SetTable(table)
203    
204      def OnRangeSelect(self, event):      def OnRangeSelect(self, event):
205            to_id = self.table.RowOrdinalToId
206          if self.handleSelectEvents:          if self.handleSelectEvents:
207              self.rows = dict([(i, 0) for i in self.GetSelectedRows()])              self.rows = dict([(to_id(i), 0) for i in self.GetSelectedRows()])
208    
209              # if we're selecting we need to include the selected range and              # if we're selecting we need to include the selected range and
210              # make sure that the current row is also included, which may              # make sure that the current row is also included, which may
211              # not be the case if you just click on a single row!              # not be the case if you just click on a single row!
212              if event.Selecting():              if event.Selecting():
213                  for i in range(event.GetTopRow(), event.GetBottomRow() + 1):                  for i in range(event.GetTopRow(), event.GetBottomRow() + 1):
214                      self.rows[i] = 0                      self.rows[to_id(i)] = 0
215                  self.rows[event.GetTopLeftCoords().GetRow()] = 0                  self.rows[to_id(event.GetTopLeftCoords().GetRow())] = 0
216        
217              self.issue(ROW_SELECTED, self.rows.keys())              self.issue(ROW_SELECTED, self.rows.keys())
218    
219          event.Skip()          event.Skip()
220    
221      def OnSelectCell(self, event):      def OnSelectCell(self, event):
222            to_id = self.table.RowOrdinalToId
223          if self.handleSelectEvents:          if self.handleSelectEvents:
224              self.issue(ROW_SELECTED, self.GetSelectedRows())              self.issue(ROW_SELECTED,
225                           [to_id(i) for i in self.GetSelectedRows()])
226          event.Skip()          event.Skip()
227    
228      def ToggleEventListeners(self, on):      def ToggleEventListeners(self, on):
229          self.handleSelectEvents = on          self.handleSelectEvents = on
230                
231      def GetNumberSelected(self):      def GetNumberSelected(self):
232          return len(self.rows)          return len(self.rows)
233    
# Line 240  class TableGrid(wxGrid, Publisher): Line 257  class TableGrid(wxGrid, Publisher):
257          if self.allow_messages_count == 0:          if self.allow_messages_count == 0:
258              Publisher.issue(self, *args)              Publisher.issue(self, *args)
259    
260        def SelectRowById(self, rowid, do_select):
261            """Select row with the id rowid"""
262            self.SelectRow(self.table.RowIdToOrdinal(rowid), do_select)
263    
264    
265  class LayerTableGrid(TableGrid):  class LayerTableGrid(TableGrid):
266    
# Line 262  class LayerTableGrid(TableGrid): Line 283  class LayerTableGrid(TableGrid):
283              try:              try:
284                  self.ClearSelection()                  self.ClearSelection()
285                  if len(shapes) > 0:                  if len(shapes) > 0:
286                      #                      # keep track of the lowest id so we can make it the
287                      # keep track of the lowest id so we can make it                      # first visible item
288                      # the first visible item                      first = -1
                     #  
                     first = shapes[0]  
289    
290                        to_ordinal = self.table.RowIdToOrdinal
291                      for shape in shapes:                      for shape in shapes:
292                          self.SelectRow(shape, True)                          row = to_ordinal(shape)
293                          if shape < first:                          self.SelectRow(row, True)
294                              first = shape                          if row < first:
295                                first = row
296    
297                      self.SetGridCursor(first, 0)                      self.SetGridCursor(first, 0)
298                      self.MakeCellVisible(first, 0)                      self.MakeCellVisible(first, 0)
# Line 285  class TableFrame(ThubanFrame): Line 306  class TableFrame(ThubanFrame):
306    
307      def __init__(self, parent, name, title, table):      def __init__(self, parent, name, title, table):
308          ThubanFrame.__init__(self, parent, name, title)          ThubanFrame.__init__(self, parent, name, title)
309          self.panel = wxPanel(self, -1)          self.panel = wx.Panel(self, -1)
310    
311          self.table = table          self.table = table
312          self.grid = self.make_grid(self.table)          self.grid = self.make_grid(self.table)
# Line 294  class TableFrame(ThubanFrame): Line 315  class TableFrame(ThubanFrame):
315          self.session = self.app.Session()          self.session = self.app.Session()
316          self.session.Subscribe(TABLE_REMOVED, self.close_on_table_removed)          self.session.Subscribe(TABLE_REMOVED, self.close_on_table_removed)
317    
318        def OnDestroy(self, event):
319            """Extend inherited method to unsubscribe messages"""
320            self.app.Unsubscribe(SESSION_REPLACED, self.close_on_session_replaced)
321            self.session.Unsubscribe(TABLE_REMOVED, self.close_on_table_removed)
322            ThubanFrame.OnDestroy(self, event)
323    
324      def make_grid(self, table):      def make_grid(self, table):
325          """Return the table grid to use in the frame.          """Return the table grid to use in the frame.
# Line 303  class TableFrame(ThubanFrame): Line 329  class TableFrame(ThubanFrame):
329          """          """
330          return TableGrid(self, table)          return TableGrid(self, table)
331    
     def OnClose(self, event):  
         self.app.Unsubscribe(SESSION_REPLACED, self.close_on_session_replaced)  
         self.session.Unsubscribe(TABLE_REMOVED, self.close_on_table_removed)  
         ThubanFrame.OnClose(self, event)  
   
332      def close_on_session_replaced(self, *args):      def close_on_session_replaced(self, *args):
333          """Subscriber for the SESSION_REPLACED messages.          """Subscriber for the SESSION_REPLACED messages.
334    
# Line 343  class QueryTableFrame(TableFrame): Line 364  class QueryTableFrame(TableFrame):
364      def __init__(self, parent, name, title, table):      def __init__(self, parent, name, title, table):
365          TableFrame.__init__(self, parent, name, title, table)          TableFrame.__init__(self, parent, name, title, table)
366    
367          self.combo_fields = wxComboBox(self.panel, -1, style=wxCB_READONLY)          self.combo_fields = wx.ComboBox(self.panel, -1, style=wx.CB_READONLY)
368          self.choice_comp = wxChoice(self.panel, -1,          self.choice_comp = wx.Choice(self.panel, -1,
369                                choices=["<", "<=", "==", "!=", ">=", ">"])                                choices=["<", "<=", "==", "!=", ">=", ">"])
370          self.combo_value = wxComboBox(self.panel, ID_COMBOVALUE)          self.combo_value = wx.ComboBox(self.panel, ID_COMBOVALUE)
371          self.choice_action = wxChoice(self.panel, -1,          self.choice_action = wx.Choice(self.panel, -1,
372                                  choices=[_("Replace Selection"),                                  choices=[_("Replace Selection"),
373                                          _("Refine Selection"),                                          _("Refine Selection"),
374                                          _("Add to Selection")])                                          _("Add to Selection")])
375    
376          button_query = wxButton(self.panel, ID_QUERY, _("Query"))          button_query = wx.Button(self.panel, ID_QUERY, _("Query"))
377          button_export = wxButton(self.panel, ID_EXPORT, _("Export"))          button_export = wx.Button(self.panel, ID_EXPORT, _("Export"))
378          button_exportSel = wxButton(self.panel, ID_EXPORTSEL, _("Export Selection"))          button_exportSel = wx.Button(self.panel, ID_EXPORTSEL, _("Export Selection"))
379          button_close = wxButton(self.panel, wxID_CLOSE, _("Close"))          button_close = wx.Button(self.panel, wx.ID_CLOSE, _("Close"))
380    
381          self.CreateStatusBar()          self.CreateStatusBar()
382    
# Line 377  class QueryTableFrame(TableFrame): Line 398  class QueryTableFrame(TableFrame):
398    
399          self.UpdateStatusText()          self.UpdateStatusText()
400    
401          topBox = wxBoxSizer(wxVERTICAL)          topBox = wx.BoxSizer(wx.VERTICAL)
402    
403          sizer = wxStaticBoxSizer(wxStaticBox(self.panel, -1,          sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, -1,
404                                    _("Selection")),                                    _("Selection")),
405                                    wxHORIZONTAL)                                    wx.HORIZONTAL)
406          sizer.Add(self.combo_fields, 1, wxEXPAND|wxALL, 4)          sizer.Add(self.combo_fields, 1, wx.EXPAND|wx.ALL, 4)
407          sizer.Add(self.choice_comp, 0, wxALL, 4)          sizer.Add(self.choice_comp, 0, wx.ALL, 4)
408          sizer.Add(self.combo_value, 1, wxEXPAND|wxALL, 4)          sizer.Add(self.combo_value, 1, wx.EXPAND|wx.ALL, 4)
409          sizer.Add(self.choice_action, 0, wxALL, 4)          sizer.Add(self.choice_action, 0, wx.ALL, 4)
410          sizer.Add(button_query, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)          sizer.Add(button_query, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 4)
411          sizer.Add(40, 20, 0, wxALL, 4)          sizer.Add( (40, 20), 0, wx.ALL, 4)
412    
413          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)          topBox.Add(sizer, 0, wx.EXPAND|wx.ALL, 4)
414          topBox.Add(self.grid, 1, wxEXPAND|wxALL, 0)          topBox.Add(self.grid, 1, wx.EXPAND|wx.ALL, 0)
415    
416          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wx.BoxSizer(wx.HORIZONTAL)
417          sizer.Add(button_export, 0, wxALL, 4)          sizer.Add(button_export, 0, wx.ALL, 4)
418          sizer.Add(button_exportSel, 0, wxALL, 4)          sizer.Add(button_exportSel, 0, wx.ALL, 4)
419          sizer.Add(60, 20, 1, wxALL|wxEXPAND, 4)          sizer.Add( (60, 20), 1, wx.ALL|wx.EXPAND, 4)
420          sizer.Add(button_close, 0, wxALL|wxALIGN_RIGHT, 4)          sizer.Add(button_close, 0, wx.ALL|wx.ALIGN_RIGHT, 4)
421          topBox.Add(sizer, 0, wxALL | wxEXPAND, 4)          topBox.Add(sizer, 0, wx.ALL | wx.EXPAND, 4)
422    
423          self.panel.SetAutoLayout(True)          self.panel.SetAutoLayout(True)
424          self.panel.SetSizer(topBox)          self.panel.SetSizer(topBox)
425          topBox.Fit(self.panel)          topBox.Fit(self.panel)
426          topBox.SetSizeHints(self.panel)          topBox.SetSizeHints(self.panel)
427    
428          panelSizer = wxBoxSizer(wxVERTICAL)          panelSizer = wx.BoxSizer(wx.VERTICAL)
429          panelSizer.Add(self.panel, 1, wxEXPAND, 0)          panelSizer.Add(self.panel, 1, wx.EXPAND, 0)
430          self.SetAutoLayout(True)          self.SetAutoLayout(True)
431          self.SetSizer(panelSizer)          self.SetSizer(panelSizer)
432          panelSizer.Fit(self)          panelSizer.Fit(self)
# Line 413  class QueryTableFrame(TableFrame): Line 434  class QueryTableFrame(TableFrame):
434    
435          self.grid.SetFocus()          self.grid.SetFocus()
436    
437          EVT_BUTTON(self, ID_QUERY, self.OnQuery)          self.Bind(wx.EVT_BUTTON, self.OnQuery, id=ID_QUERY)
438          EVT_BUTTON(self, ID_EXPORT, self.OnExport)          self.Bind(wx.EVT_BUTTON, self.OnExport, id=ID_EXPORT)
439          EVT_BUTTON(self, ID_EXPORTSEL, self.OnExportSel)          self.Bind(wx.EVT_BUTTON, self.OnExportSel, id=ID_EXPORTSEL)
440          EVT_BUTTON(self, wxID_CLOSE, self.OnClose)          self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
441          EVT_KEY_DOWN(self.grid, self.OnKeyDown)          self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown, self.grid)
442    
443          self.grid.Subscribe(ROW_SELECTED, self.UpdateStatusText)          self.grid.Subscribe(ROW_SELECTED, self.UpdateStatusText)
444    
445      def UpdateStatusText(self, rows=None):      def UpdateStatusText(self, rows=None):
446          self.SetStatusText(_("%i rows (%i selected), %i columns")          self.SetStatusText(_("%i rows (%i selected), %i columns")
447              % (self.grid.GetNumberRows(),              % (self.grid.GetNumberRows(),
448                 self.grid.GetNumberSelected(),                 self.grid.GetNumberSelected(),
449                 self.grid.GetNumberCols()))                 self.grid.GetNumberCols()))
450    
# Line 447  class QueryTableFrame(TableFrame): Line 468  class QueryTableFrame(TableFrame):
468                  value = self.table.Column(text)                  value = self.table.Column(text)
469    
470              ids = self.table.SimpleQuery(              ids = self.table.SimpleQuery(
471                      self.table.Column(self.combo_fields.GetStringSelection()),                      self.table.Column(self.combo_fields.GetStringSelection()),
472                      self.choice_comp.GetStringSelection(),                      self.choice_comp.GetStringSelection(),
473                      value)                      value)
474    
475              choice = self.choice_action.GetSelection()              choice = self.choice_action.GetSelection()
476                
477              #              #
478              # what used to be nice code got became a bit ugly because              # what used to be nice code got became a bit ugly because
479              # each time we select a row a message is sent to the grid              # each time we select a row a message is sent to the grid
# Line 487  class QueryTableFrame(TableFrame): Line 508  class QueryTableFrame(TableFrame):
508                  if firsttime:                  if firsttime:
509                      firsttime = False                      firsttime = False
510                  else:                  else:
511                      self.grid.SelectRow(id, True)                      self.grid.SelectRowById(id, True)
512    
513              self.grid.ToggleEventListeners(True)              self.grid.ToggleEventListeners(True)
514    
# Line 495  class QueryTableFrame(TableFrame): Line 516  class QueryTableFrame(TableFrame):
516              # select the first row              # select the first row
517              #              #
518              if ids:              if ids:
519                  self.grid.SelectRow(ids[0], True)                  self.grid.SelectRowById(ids[0], True)
520    
521          finally:          finally:
522              ThubanEndBusyCursor()              ThubanEndBusyCursor()
523            
524      def doExport(self, onlySelected):      def doExport(self, onlySelected):
525            
526          dlg = wxFileDialog(self, _("Export Table To"), ".", "",          dlg = wx.FileDialog(self, _("Export Table To"), ".", "",
527                             _("DBF Files (*.dbf)|*.dbf|") +                             _("DBF Files (*.dbf)|*.dbf|") +
528                             _("CSV Files (*.csv)|*.csv|") +                             _("CSV Files (*.csv)|*.csv|") +
529                             _("All Files (*.*)|*.*"),                             _("All Files (*.*)|*.*"),
530                             wxSAVE|wxOVERWRITE_PROMPT)                             wx.SAVE|wx.OVERWRITE_PROMPT)
531          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wx.ID_OK:
532              filename = dlg.GetPath()              filename = dlg.GetPath()
533              type = os.path.basename(filename).split('.')[-1:][0]              type = os.path.basename(filename).split('.')[-1:][0]
534              dlg.Destroy()              dlg.Destroy()
# Line 522  class QueryTableFrame(TableFrame): Line 543  class QueryTableFrame(TableFrame):
543              elif type.upper() == 'CSV':              elif type.upper() == 'CSV':
544                  table_to_csv(self.table, filename, records)                  table_to_csv(self.table, filename, records)
545              else:              else:
546                  dlg = wxMessageDialog(None, "Unsupported format: %s" % type,                  dlg = wx.MessageDialog(None, "Unsupported format: %s" % type,
547                                        "Table Export", wxOK|wxICON_WARNING)                                        "Table Export", wx.OK|wx.ICON_WARNING)
548                  dlg.ShowModal()                  dlg.ShowModal()
549                  dlg.Destroy()                  dlg.Destroy()
550          else:          else:
# Line 540  class QueryTableFrame(TableFrame): Line 561  class QueryTableFrame(TableFrame):
561    
562      def get_selected(self):      def get_selected(self):
563          """Return a dictionary of the selected rows.          """Return a dictionary of the selected rows.
564            
565          The dictionary has the indexes as keys."""          The dictionary has the indexes as keys."""
566          return dict([(i, 0) for i in self.grid.GetSelectedRows()])          to_id = self.table.RowOrdinalToId
567            return dict([(to_id(i), 0) for i in self.grid.GetSelectedRows()])
568    
569    
570  class LayerTableFrame(QueryTableFrame):  class LayerTableFrame(QueryTableFrame):
571    
# Line 564  class LayerTableFrame(QueryTableFrame): Line 587  class LayerTableFrame(QueryTableFrame):
587          # accordingly          # accordingly
588          sel = self.get_selected().keys()          sel = self.get_selected().keys()
589          for i in sel:          for i in sel:
590              self.grid.SelectRow(i, True)              self.grid.SelectRowById(i, True)
591    
592        def OnDestroy(self, event):
593            """Extend inherited method to unsubscribe messages"""
594            # There's no need to unsubscribe from self.grid's messages
595            # because it will get a DESTROY event too (since destroying the
596            # frame basically means that all child windows are also
597            # destroyed) and this it will clear all subscriptions
598            # automatically.  It may even have been destroyed already (this
599            # does happen on w2000 for instance) so calling any of its
600            # methods here would be an error.
601            self.parent.Unsubscribe(SHAPES_SELECTED, self.select_shapes)
602            self.map.Unsubscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
603            QueryTableFrame.OnDestroy(self, event)
604    
605      def make_grid(self, table):      def make_grid(self, table):
606          """Override the derived method to return a LayerTableGrid.          """Override the derived method to return a LayerTableGrid.
# Line 577  class LayerTableFrame(QueryTableFrame): Line 613  class LayerTableFrame(QueryTableFrame):
613          """          """
614          return dict([(i, 0) for i in self.parent.SelectedShapes()])          return dict([(i, 0) for i in self.parent.SelectedShapes()])
615    
     def OnClose(self, event):  
         """Override the derived method to first unsubscribed."""  
         self.parent.Unsubscribe(SHAPES_SELECTED, self.select_shapes)  
         self.grid.Unsubscribe(ROW_SELECTED, self.rows_selected)  
         self.map.Unsubscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)  
         QueryTableFrame.OnClose(self, event)  
   
616      def select_shapes(self, layer, shapes):      def select_shapes(self, layer, shapes):
617          """Subscribed to the SHAPES_SELECTED message.          """Subscribed to the SHAPES_SELECTED message.
618    

Legend:
Removed from v.1394  
changed lines
  Added in v.2700

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26