/[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 173 by bh, Wed May 15 13:29:34 2002 UTC revision 535 by bh, Fri Mar 14 20:42:18 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 15  from Thuban.Model.table import FIELDTYPE Line 15  from Thuban.Model.table import FIELDTYPE
15       FIELDTYPE_STRING       FIELDTYPE_STRING
16  import view  import view
17  from dialogs import NonModalDialog  from dialogs import NonModalDialog
18  from messages import SELECTED_SHAPE  from messages import SHAPES_SELECTED
19    
20  wx_value_type_map = {FIELDTYPE_INT: wxGRID_VALUE_NUMBER,  wx_value_type_map = {FIELDTYPE_INT: wxGRID_VALUE_NUMBER,
21                       FIELDTYPE_DOUBLE: wxGRID_VALUE_FLOAT,                       FIELDTYPE_DOUBLE: wxGRID_VALUE_FLOAT,
# Line 119  class TableGrid(wxGrid, Publisher): Line 119  class TableGrid(wxGrid, Publisher):
119          #self.AutoSizeColumns(false)          #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 133  class TableGrid(wxGrid, Publisher): Line 133  class TableGrid(wxGrid, Publisher):
133      def OnSelectCell(self, event):      def OnSelectCell(self, event):
134          self.issue(ROW_SELECTED, event.GetRow())          self.issue(ROW_SELECTED, event.GetRow())
135    
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          if layer is not None and layer.table is self.table.table \          if layer is not None and layer.table is self.table.table \
152             and shape is not None:             and shape is not None:
153              self.SelectRow(shape)              self.SelectRow(shape)
# Line 145  class TableFrame(NonModalDialog): Line 159  class TableFrame(NonModalDialog):
159    
160      """Frame that displays a Thuban table in a grid view"""      """Frame that displays a Thuban table in a grid view"""
161    
162      def __init__(self, parent, interactor, name, title, layer = None,      def __init__(self, parent, name, title, table):
163                   table = None):          NonModalDialog.__init__(self, parent, name, title)
         NonModalDialog.__init__(self, parent, interactor, name, title)  
         self.layer = layer  
164          self.table = table          self.table = table
165          self.grid = TableGrid(self, table)          self.grid = self.make_grid(self.table)
166    
167        def make_grid(self, table):
168            """Return the table grid to use in the frame.
169    
170            The default implementation returns a TableGrid instance.
171            Override in derived classes to use different grid classes.
172            """
173            return TableGrid(self, table)
174    
175    
176    class LayerTableFrame(TableFrame):
177    
178        """Frame that displays a layer table in a grid view
179    
180        A LayerTableFrame is TableFrame whose selection is connected to the
181        selected object in a map.
182        """
183    
184        def __init__(self, parent, name, title, layer, table):
185            TableFrame.__init__(self, parent, name, title, table)
186            self.layer = layer
187          self.grid.Subscribe(ROW_SELECTED, self.row_selected)          self.grid.Subscribe(ROW_SELECTED, self.row_selected)
188          self.interactor.Subscribe(SELECTED_SHAPE, self.select_shape)          self.parent.Subscribe(SHAPES_SELECTED, self.select_shape)
189    
190        def make_grid(self, table):
191            """Override the derived method to return a LayerTableGrid.
192            """
193            return LayerTableGrid(self, table)
194    
195      def OnClose(self, event):      def OnClose(self, event):
196          self.interactor.Unsubscribe(SELECTED_SHAPE, self.select_shape)          self.parent.Unsubscribe(SHAPES_SELECTED, self.select_shape)
197          NonModalDialog.OnClose(self, event)          TableFrame.OnClose(self, event)
198    
199      def select_shape(self, layer, shape):      def select_shape(self, layer, shapes):
200            """Subscribed to the SHAPES_SELECTED message.
201    
202            If shapes contains exactly one shape id, select that shape in
203            the grid. Otherwise deselect all.
204            """
205            if len(shapes):
206                shape = shapes[0]
207            else:
208                shape = None
209          self.grid.select_shape(layer, shape)          self.grid.select_shape(layer, shape)
210    
211      def row_selected(self, row):      def row_selected(self, row):
212          if self.layer is not None:          if self.layer is not None:
213              self.interactor.SelectLayerAndShape(self.layer, row)              self.parent.SelectShapes(self.layer, [row])

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26