/[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 1068 by bh, Tue May 27 15:02:37 2003 UTC revision 1146 by bh, Tue Jun 10 12:00:16 2003 UTC
# Line 21  import view Line 21  import view
21  from dialogs import NonModalNonParentDialog  from dialogs import NonModalNonParentDialog
22    
23  from messages import SHAPES_SELECTED, SESSION_REPLACED  from messages import SHAPES_SELECTED, SESSION_REPLACED
24  from Thuban.Model.messages import TABLE_REMOVED  from Thuban.Model.messages import TABLE_REMOVED, MAP_LAYERS_REMOVED
25    
26  wx_value_type_map = {FIELDTYPE_INT: wxGRID_VALUE_NUMBER,  wx_value_type_map = {FIELDTYPE_INT: wxGRID_VALUE_NUMBER,
27                       FIELDTYPE_DOUBLE: wxGRID_VALUE_FLOAT,                       FIELDTYPE_DOUBLE: wxGRID_VALUE_FLOAT,
# 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    class NullRenderer(wxPyGridCellRenderer):
107    
108        """Renderer that draws NULL as a gray rectangle
109    
110        Other values are delegated to a normal renderer which is given as
111        the parameter to the constructor.
112        """
113    
114        def __init__(self, non_null_renderer):
115            wxPyGridCellRenderer.__init__(self)
116            self.non_null_renderer = non_null_renderer
117    
118        def Draw(self, grid, attr, dc, rect, row, col, isSelected):
119            value = grid.table.GetValue(row, col)
120            if value is None:
121                dc.SetBackgroundMode(wxSOLID)
122                dc.SetBrush(wxBrush(wxColour(192, 192, 192), wxSOLID))
123                dc.SetPen(wxTRANSPARENT_PEN)
124                dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
125            else:
126                self.non_null_renderer.Draw(grid, attr, dc, rect, row, col,
127                                            isSelected)
128    
129        def GetBestSize(self, grid, attr, dc, row, col):
130            self.non_null_renderer.GetBestSize(grid, attr, dc, row, col)
131    
132        def Clone(self):
133            return NullRenderer(self.non_null_renderer)
134    
135    
136  class TableGrid(wxGrid, Publisher):  class TableGrid(wxGrid, Publisher):
137    
138      """A grid view for a Thuban table      """A grid view for a Thuban table
# Line 137  class TableGrid(wxGrid, Publisher): Line 168  class TableGrid(wxGrid, Publisher):
168    
169          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
170    
         #EVT_GRID_RANGE_SELECT(self, None)  
         #EVT_GRID_SELECT_CELL(self, None)  
         #EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)  
         #EVT_GRID_SELECT_CELL(self, self.OnSelectCell)  
   
171          self.ToggleEventListeners(True)          self.ToggleEventListeners(True)
172    
173            # Replace the normal renderers with our own versions which
174            # render NULL/None values specially
175            self.RegisterDataType(wxGRID_VALUE_STRING,
176                                  NullRenderer(wxGridCellStringRenderer()), None)
177            self.RegisterDataType(wxGRID_VALUE_NUMBER,
178                                  NullRenderer(wxGridCellNumberRenderer()), None)
179            self.RegisterDataType(wxGRID_VALUE_FLOAT,
180                                  NullRenderer(wxGridCellFloatRenderer()), None)
181    
182      def SetTableObject(self, table):      def SetTableObject(self, table):
183          self.table.SetTable(table)          self.table.SetTable(table)
184    
# Line 290  class QueryTableFrame(TableFrame): Line 325  class QueryTableFrame(TableFrame):
325      """Frame that displays a table in a grid view and offers user actions      """Frame that displays a table in a grid view and offers user actions
326      selection and export      selection and export
327    
328      A LayerTableFrame is TableFrame whose selection is connected to the      A QueryTableFrame is TableFrame whose selection is connected to the
329      selected object in a map.      selected object in a map.
330      """      """
331    
# Line 358  class QueryTableFrame(TableFrame): Line 393  class QueryTableFrame(TableFrame):
393    
394      def OnQuery(self, event):      def OnQuery(self, event):
395          wxBeginBusyCursor()          wxBeginBusyCursor()
396            try:
397    
398          if self.combo_value.GetSelection() < 1:              if self.combo_value.GetSelection() < 1:
399              value = self.combo_value.GetValue()                  value = self.combo_value.GetValue()
         else:  
             value = self.table.Column(self.combo_value.GetValue())  
   
         ids = self.table.SimpleQuery(  
                 self.table.Column(self.combo_fields.GetStringSelection()),  
                 self.choice_comp.GetStringSelection(),  
                 value)  
   
         choice = self.choice_action.GetSelection()  
               
         #  
         # what used to be nice code got became a bit ugly because  
         # each time we select a row a message is sent to the grid  
         # which we are listening for and then we send further  
         # messages.  
         #  
         # now, we disable those listeners select everything but  
         # the first item, reenable the listeners, and select  
         # the first element, which causes everything to be  
         # updated properly.  
         #  
         self.grid.ToggleEventListeners(False)  
   
         if choice == 0:  
             # Replace Selection  
             self.grid.ClearSelection()  
         elif choice == 1:  
             # Refine Selection  
             sel = self.get_selected()  
             self.grid.ClearSelection()  
             ids = filter(sel.has_key, ids)  
         elif choice == 2:  
             # Add to Selection  
             pass  
   
         #  
         # select the rows (all but the first)  
         #  
         firsttime = True  
         for id in ids:  
             if firsttime:  
                 firsttime = False  
400              else:              else:
401                  self.grid.SelectRow(id, True)                  value = self.table.Column(self.combo_value.GetValue())
   
         self.grid.ToggleEventListeners(True)  
402    
403          #              ids = self.table.SimpleQuery(
404          # select the first row                      self.table.Column(self.combo_fields.GetStringSelection()),
405          #                      self.choice_comp.GetStringSelection(),
406          if ids:                      value)
             self.grid.SelectRow(ids[0], True)  
407    
408          wxEndBusyCursor()              choice = self.choice_action.GetSelection()
409                
410                #
411                # what used to be nice code got became a bit ugly because
412                # each time we select a row a message is sent to the grid
413                # which we are listening for and then we send further
414                # messages.
415                #
416                # now, we disable those listeners select everything but
417                # the first item, reenable the listeners, and select
418                # the first element, which causes everything to be
419                # updated properly.
420                #
421                self.grid.ToggleEventListeners(False)
422    
423                if choice == 0:
424                    # Replace Selection
425                    self.grid.ClearSelection()
426                elif choice == 1:
427                    # Refine Selection
428                    sel = self.get_selected()
429                    self.grid.ClearSelection()
430                    ids = filter(sel.has_key, ids)
431                elif choice == 2:
432                    # Add to Selection
433                    pass
434    
435                #
436                # select the rows (all but the first)
437                #
438                firsttime = True
439                for id in ids:
440                    if firsttime:
441                        firsttime = False
442                    else:
443                        self.grid.SelectRow(id, True)
444    
445                self.grid.ToggleEventListeners(True)
446    
447                #
448                # select the first row
449                #
450                if ids:
451                    self.grid.SelectRow(ids[0], True)
452            finally:
453                wxEndBusyCursor()
454                    
455      def OnSaveAs(self, event):      def OnSaveAs(self, event):
456          dlg = wxFileDialog(self, _("Export Table To"), ".", "",          dlg = wxFileDialog(self, _("Export Table To"), ".", "",
# Line 460  class LayerTableFrame(QueryTableFrame): Line 496  class LayerTableFrame(QueryTableFrame):
496          self.layer = layer          self.layer = layer
497          self.grid.Subscribe(ROW_SELECTED, self.rows_selected)          self.grid.Subscribe(ROW_SELECTED, self.rows_selected)
498          self.parent.Subscribe(SHAPES_SELECTED, self.select_shapes)          self.parent.Subscribe(SHAPES_SELECTED, self.select_shapes)
499            self.map = self.parent.Map()
500            self.map.Subscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
501    
502          # if there is already a selection present, update the grid          # if there is already a selection present, update the grid
503          # accordingly          # accordingly
# Line 481  class LayerTableFrame(QueryTableFrame): Line 519  class LayerTableFrame(QueryTableFrame):
519      def OnClose(self, event):      def OnClose(self, event):
520          """Override the derived method to first unsubscribed."""          """Override the derived method to first unsubscribed."""
521          self.parent.Unsubscribe(SHAPES_SELECTED, self.select_shapes)          self.parent.Unsubscribe(SHAPES_SELECTED, self.select_shapes)
522            self.grid.Unsubscribe(ROW_SELECTED, self.rows_selected)
523            self.map.Unsubscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
524          QueryTableFrame.OnClose(self, event)          QueryTableFrame.OnClose(self, event)
525    
526      def select_shapes(self, layer, shapes):      def select_shapes(self, layer, shapes):
# Line 497  class LayerTableFrame(QueryTableFrame): Line 537  class LayerTableFrame(QueryTableFrame):
537          """          """
538          if self.layer is not None:          if self.layer is not None:
539              self.parent.SelectShapes(self.layer, rows)              self.parent.SelectShapes(self.layer, rows)
540    
541        def map_layers_removed(self, *args):
542            """Receiver for the map's MAP_LAYERS_REMOVED message
543    
544            Close the dialog if the layer whose table we're showing is not
545            in the map anymore.
546            """
547            if self.layer not in self.map.Layers():
548                self.Close()
549    

Legend:
Removed from v.1068  
changed lines
  Added in v.1146

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26