/[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 2561 by bh, Tue Feb 8 20:34:29 2005 UTC
# 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    
115  class NullRenderer(wxPyGridCellRenderer):  class NullRenderer(wxPyGridCellRenderer):
116    
# Line 184  class TableGrid(wxGrid, Publisher): Line 193  class TableGrid(wxGrid, Publisher):
193          self.RegisterDataType(wxGRID_VALUE_FLOAT,          self.RegisterDataType(wxGRID_VALUE_FLOAT,
194                                NullRenderer(wxGridCellFloatRenderer()), None)                                NullRenderer(wxGridCellFloatRenderer()), None)
195    
196            EVT_WINDOW_DESTROY(self, 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 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 387  class QueryTableFrame(TableFrame): Line 408  class QueryTableFrame(TableFrame):
408          sizer.Add(self.combo_value, 1, wxEXPAND|wxALL, 4)          sizer.Add(self.combo_value, 1, wxEXPAND|wxALL, 4)
409          sizer.Add(self.choice_action, 0, wxALL, 4)          sizer.Add(self.choice_action, 0, wxALL, 4)
410          sizer.Add(button_query, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)          sizer.Add(button_query, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)
411          sizer.Add(40, 20, 0, wxALL, 4)          sizer.Add( (40, 20), 0, wxALL, 4)
412    
413          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)
414          topBox.Add(self.grid, 1, wxEXPAND|wxALL, 0)          topBox.Add(self.grid, 1, wxEXPAND|wxALL, 0)
# Line 395  class QueryTableFrame(TableFrame): Line 416  class QueryTableFrame(TableFrame):
416          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
417          sizer.Add(button_export, 0, wxALL, 4)          sizer.Add(button_export, 0, wxALL, 4)
418          sizer.Add(button_exportSel, 0, wxALL, 4)          sizer.Add(button_exportSel, 0, wxALL, 4)
419          sizer.Add(60, 20, 1, wxALL|wxEXPAND, 4)          sizer.Add( (60, 20), 1, wxALL|wxEXPAND, 4)
420          sizer.Add(button_close, 0, wxALL|wxALIGN_RIGHT, 4)          sizer.Add(button_close, 0, wxALL|wxALIGN_RIGHT, 4)
421          topBox.Add(sizer, 0, wxALL | wxEXPAND, 4)          topBox.Add(sizer, 0, wxALL | wxEXPAND, 4)
422    
# 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()
# 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.2561

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26