/[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 30 by bh, Thu Sep 6 13:31:57 2001 UTC revision 278 by bh, Mon Aug 26 12:50:23 2002 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2002 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 10  __version__ = "$Revision$" Line 10  __version__ = "$Revision$"
10  from wxPython.wx import *  from wxPython.wx import *
11  from wxPython.grid import *  from wxPython.grid import *
12    
13    from Thuban.Lib.connector import Publisher
14  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \
15       FIELDTYPE_STRING       FIELDTYPE_STRING
16  import view  import view
# Line 20  wx_value_type_map = {FIELDTYPE_INT: wxGR Line 21  wx_value_type_map = {FIELDTYPE_INT: wxGR
21                       FIELDTYPE_DOUBLE: wxGRID_VALUE_FLOAT,                       FIELDTYPE_DOUBLE: wxGRID_VALUE_FLOAT,
22                       FIELDTYPE_STRING: wxGRID_VALUE_STRING}                       FIELDTYPE_STRING: wxGRID_VALUE_STRING}
23    
24    ROW_SELECTED = "ROW_SELECTED"
25    
26    
27  class DataTable(wxPyGridTableBase):  class DataTable(wxPyGridTableBase):
28    
29        """Wrapper around a Thuban table object suitable for a wxGrid"""
30    
31      def __init__(self, table = None):      def __init__(self, table = None):
32          wxPyGridTableBase.__init__(self)          wxPyGridTableBase.__init__(self)
33          self.num_cols = 0          self.num_cols = 0
# Line 89  class DataTable(wxPyGridTableBase): Line 95  class DataTable(wxPyGridTableBase):
95          return self.CanGetValueAs(row, col, typeName)          return self.CanGetValueAs(row, col, typeName)
96    
97    
98      # Thuban stuff  class TableGrid(wxGrid, Publisher):
     def SelectRow(self, row):  
         import main  
         interactor = main.app.interactor  
         return interactor.SelectShape(self.table, row)  
99    
100        """A grid view for a Thuban table"""
 class TableGrid(wxGrid):  
101    
102      def __init__(self, parent, table = None):      def __init__(self, parent, table = None):
103          wxGrid.__init__(self, parent, -1)          wxGrid.__init__(self, parent, -1)
# Line 105  class TableGrid(wxGrid): Line 106  class TableGrid(wxGrid):
106    
107          # The second parameter means that the grid is to take ownership          # The second parameter means that the grid is to take ownership
108          # of the table and will destroy it when done. Otherwise you          # of the table and will destroy it when done. Otherwise you
109          # would need to keep a reference to it and call it's Destroy          # would need to keep a reference to it and call its Destroy
110          # method later.          # method later.
111          self.SetTable(self.table, true)          self.SetTable(self.table, true)
112    
113          #self.SetMargins(0,0)          #self.SetMargins(0,0)
114          self.AutoSizeColumns(false)  
115            # AutoSizeColumns would allow us to make the grid have optimal
116            # column widths automatically but it would cause a traversal of
117            # the entire table which for large .dbf files can take a very
118            # long time.
119            #self.AutoSizeColumns(false)
120    
121          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
122            
123          EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)          EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
124          EVT_GRID_SELECT_CELL(self, self.OnSelectCell)          EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
125    
# Line 122  class TableGrid(wxGrid): Line 128  class TableGrid(wxGrid):
128    
129      def OnRangeSelect(self, event):      def OnRangeSelect(self, event):
130          if event.Selecting():          if event.Selecting():
131              if not self.table.SelectRow(event.GetTopLeftCoords().GetRow()):              self.issue(ROW_SELECTED, event.GetTopLeftCoords().GetRow())
                 event.Skip()  
132    
133      def OnSelectCell(self, event):      def OnSelectCell(self, event):
134          if not self.table.SelectRow(event.GetRow()):          self.issue(ROW_SELECTED, event.GetRow())
135              event.Skip()  
136    
137    class LayerTableGrid(TableGrid):
138    
139        """Table grid for the layer tables.
140    
141        The LayerTableGrid is basically the same as a TableGrid but it's
142        selection is usually coupled to the selected object in the map.
143        """
144    
145      def select_shape(self, layer, shape):      def select_shape(self, layer, shape):
146            """Select the row corresponding to the specified shape and layer
147    
148            If layer is not the layer the table is associated with do
149            nothing. If shape or layer is None also do nothing.
150            """
151            print "LayerTableGrid.select_shape", layer, shape
152          if layer is not None and layer.table is self.table.table \          if layer is not None and layer.table is self.table.table \
153             and shape is not None:             and shape is not None:
154              self.SelectRow(shape)              self.SelectRow(shape)
# Line 139  class TableGrid(wxGrid): Line 158  class TableGrid(wxGrid):
158    
159  class TableFrame(NonModalDialog):  class TableFrame(NonModalDialog):
160    
161      def __init__(self, parent, interactor, name, title, table = None):      """Frame that displays a Thuban table in a grid view"""
162    
163        def __init__(self, parent, interactor, name, title, table):
164          NonModalDialog.__init__(self, parent, interactor, name, title)          NonModalDialog.__init__(self, parent, interactor, name, title)
165          self.grid = TableGrid(self, table)          self.table = table
166            self.grid = self.make_grid(self.table)
167    
168        def make_grid(self, table):
169            """Return the table grid to use in the frame.
170    
171            The default implementation returns a TableGrid instance.
172            Override in derived classes to use different grid classes.
173            """
174            return TableGrid(self, table)
175    
176    
177    class LayerTableFrame(TableFrame):
178    
179        """Frame that displays a layer table in a grid view
180    
181        A LayerTableFrame is TableFrame whose selection is connected to the
182        selected object in a map.
183        """
184    
185        def __init__(self, parent, interactor, name, title, layer, table):
186            TableFrame.__init__(self, parent, interactor, name, title, table)
187            self.layer = layer
188            self.grid.Subscribe(ROW_SELECTED, self.row_selected)
189          self.interactor.Subscribe(SELECTED_SHAPE, self.select_shape)          self.interactor.Subscribe(SELECTED_SHAPE, self.select_shape)
190    
191        def make_grid(self, table):
192            """Override the derived method to return a LayerTableGrid.
193            """
194            return LayerTableGrid(self, table)
195    
196      def OnClose(self, event):      def OnClose(self, event):
197          self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape)          self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape)
198          NonModalDialog.OnClose(self, event)          TableFrame.OnClose(self, event)
199    
200      def select_shape(self, layer, shape):      def select_shape(self, layer, shape):
201          self.grid.select_shape(layer, shape)          self.grid.select_shape(layer, shape)
202    
203        def row_selected(self, row):
204            if self.layer is not None:
205                self.interactor.SelectLayerAndShape(self.layer, row)

Legend:
Removed from v.30  
changed lines
  Added in v.278

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26