/[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 535 by bh, Fri Mar 14 20:42:18 2003 UTC revision 838 by bh, Tue May 6 15:53:32 2003 UTC
# Line 38  class DataTable(wxPyGridTableBase): Line 38  class DataTable(wxPyGridTableBase):
38    
39      def SetTable(self, table):      def SetTable(self, table):
40          self.table = table          self.table = table
41          self.num_cols = table.field_count()          self.num_cols = table.NumColumns()
42          self.num_rows = table.record_count()          self.num_rows = table.NumRows()
43    
44          self.columns = []          self.columns = []
45          for i in range(self.num_cols):          for i in range(self.num_cols):
46              type, name, len, decc = table.field_info(i)              col = table.Column(i)
47              self.columns.append((name, wx_value_type_map[type], len, decc))              self.columns.append((col.name, wx_value_type_map[col.type]))
48    
49      #      #
50      # required methods for the wxPyGridTableBase interface      # required methods for the wxPyGridTableBase interface
# Line 64  class DataTable(wxPyGridTableBase): Line 64  class DataTable(wxPyGridTableBase):
64      # Renderer understands the type too,) not just strings as in the      # Renderer understands the type too,) not just strings as in the
65      # C++ version.      # C++ version.
66      def GetValue(self, row, col):      def GetValue(self, row, col):
67          record = self.table.read_record(row)          record = self.table.ReadRowAsDict(row)
68          return record[self.columns[col][0]]          return record[self.columns[col][0]]
69    
70      def SetValue(self, row, col, value):      def SetValue(self, row, col, value):
# Line 97  class DataTable(wxPyGridTableBase): Line 97  class DataTable(wxPyGridTableBase):
97    
98  class TableGrid(wxGrid, Publisher):  class TableGrid(wxGrid, Publisher):
99    
100      """A grid view for a Thuban table"""      """A grid view for a Thuban table
101    
102        When rows are selected by the user the table issues ROW_SELECTED
103        messages. wx sends selection events even when the selection is
104        manipulated by code (instead of by the user) which usually lead to
105        ROW_SELECTED messages being sent in turn. Therefore sending messages
106        can be switched on and off with the allow_messages and
107        disallow_messages methods.
108        """
109    
110      def __init__(self, parent, table = None):      def __init__(self, parent, table = None):
111          wxGrid.__init__(self, parent, -1)          wxGrid.__init__(self, parent, -1)
112    
113            self.allow_messages_count = 0
114    
115          self.table = DataTable(table)          self.table = DataTable(table)
116    
117          # The second parameter means that the grid is to take ownership          # The second parameter means that the grid is to take ownership
# Line 133  class TableGrid(wxGrid, Publisher): Line 143  class TableGrid(wxGrid, Publisher):
143      def OnSelectCell(self, event):      def OnSelectCell(self, event):
144          self.issue(ROW_SELECTED, event.GetRow())          self.issue(ROW_SELECTED, event.GetRow())
145    
146        def disallow_messages(self):
147            """Disallow messages to be send.
148    
149            This method only increases a counter so that calls to
150            disallow_messages and allow_messages can be nested. Only the
151            outermost calls will actually switch message sending on and off.
152            """
153            self.allow_messages_count += 1
154    
155        def allow_messages(self):
156            """Allow messages to be send.
157    
158            This method only decreases a counter so that calls to
159            disallow_messages and allow_messages can be nested. Only the
160            outermost calls will actually switch message sending on and off.
161            """
162            self.allow_messages_count -= 1
163    
164        def issue(self, *args):
165            """Issue a message unless disallowed.
166    
167            See the allow_messages and disallow_messages methods.
168            """
169            if self.allow_messages_count == 0:
170                Publisher.issue(self, *args)
171    
172    
173  class LayerTableGrid(TableGrid):  class LayerTableGrid(TableGrid):
174    
# Line 150  class LayerTableGrid(TableGrid): Line 186  class LayerTableGrid(TableGrid):
186          """          """
187          if layer is not None and layer.table is self.table.table \          if layer is not None and layer.table is self.table.table \
188             and shape is not None:             and shape is not None:
189              self.SelectRow(shape)              self.disallow_messages()
190              self.SetGridCursor(shape, 0)              try:
191              self.MakeCellVisible(shape, 0)                  self.SelectRow(shape)
192                    self.SetGridCursor(shape, 0)
193                    self.MakeCellVisible(shape, 0)
194                finally:
195                    self.allow_messages()
196    
197    
198  class TableFrame(NonModalDialog):  class TableFrame(NonModalDialog):

Legend:
Removed from v.535  
changed lines
  Added in v.838

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26