/[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 881 by jonathan, Fri May 9 16:34:15 2003 UTC revision 979 by frank, Thu May 22 11:40:59 2003 UTC
# Line 25  wx_value_type_map = {FIELDTYPE_INT: wxGR Line 25  wx_value_type_map = {FIELDTYPE_INT: wxGR
25    
26  ROW_SELECTED = "ROW_SELECTED"  ROW_SELECTED = "ROW_SELECTED"
27    
28    QUERY_KEY = 'S'
29    
30  class DataTable(wxPyGridTableBase):  class DataTable(wxPyGridTableBase):
31    
# Line 132  class TableGrid(wxGrid, Publisher): Line 133  class TableGrid(wxGrid, Publisher):
133    
134          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
135    
136          EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)          #EVT_GRID_RANGE_SELECT(self, None)
137          EVT_GRID_SELECT_CELL(self, self.OnSelectCell)          #EVT_GRID_SELECT_CELL(self, None)
138            #EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
139            #EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
140    
141            self.ToggleEventListeners(True)
142    
143      def SetTableObject(self, table):      def SetTableObject(self, table):
144          self.table.SetTable(table)          self.table.SetTable(table)
# Line 156  class TableGrid(wxGrid, Publisher): Line 161  class TableGrid(wxGrid, Publisher):
161          self.issue(ROW_SELECTED, self.GetSelectedRows())          self.issue(ROW_SELECTED, self.GetSelectedRows())
162          event.Skip()          event.Skip()
163    
164        def ToggleEventListeners(self, on):
165            if on:
166                EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
167                EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
168            else:
169                EVT_GRID_RANGE_SELECT(self, None)
170                EVT_GRID_SELECT_CELL(self, None)
171                
172      def disallow_messages(self):      def disallow_messages(self):
173          """Disallow messages to be send.          """Disallow messages to be send.
174    
# Line 258  class LayerTableFrame(TableFrame): Line 271  class LayerTableFrame(TableFrame):
271    
272          self.combo_fields = wxComboBox(self, -1, style=wxCB_READONLY)          self.combo_fields = wxComboBox(self, -1, style=wxCB_READONLY)
273          self.choice_comp = wxChoice(self, -1,          self.choice_comp = wxChoice(self, -1,
274                                choices=["<", "<=", "=", "<>", ">=", ">"])                                choices=["<", "<=", "==", "!=", ">=", ">"])
275          self.combo_value = wxComboBox(self, -1)          self.combo_value = wxComboBox(self, -1)
276          self.choice_action = wxChoice(self, -1,          self.choice_action = wxChoice(self, -1,
277                                  choices=[_("Replace Selection"),                                  choices=[_("Replace Selection"),
# Line 266  class LayerTableFrame(TableFrame): Line 279  class LayerTableFrame(TableFrame):
279                                          _("Add to Selection")])                                          _("Add to Selection")])
280    
281          button_query = wxButton(self, ID_QUERY, _("Query"))          button_query = wxButton(self, ID_QUERY, _("Query"))
282          button_saveas = wxButton(self, ID_SAVEAS, _("Save As..."))          button_saveas = wxButton(self, ID_SAVEAS, _("Export"))
283    
284          self.grid.SetSize((400, 200))          self.grid.SetSize((400, 200))
285    
286          self.combo_value.Append("")          self.combo_value.Append("")
287          for i in range(table.field_count()):          for i in range(table.NumColumns()):
288              type, name, len, decc = layer.table.field_info(i)              name = table.Column(i).name
289              self.combo_fields.Append(name)              self.combo_fields.Append(name)
290              self.combo_value.Append(name)              self.combo_value.Append(name)
291                                                                                    
292          # assume at least one field?          # assume at least one field?
293          self.combo_fields.SetSelection(0)          self.combo_fields.SetSelection(0)
294          self.combo_value.SetSelection(0)          self.combo_value.SetSelection(0)
# Line 288  class LayerTableFrame(TableFrame): Line 301  class LayerTableFrame(TableFrame):
301          sizer.Add(self.choice_comp, 0, wxALL, 4)          sizer.Add(self.choice_comp, 0, wxALL, 4)
302          sizer.Add(self.combo_value, 1, wxEXPAND|wxALL, 4)          sizer.Add(self.combo_value, 1, wxEXPAND|wxALL, 4)
303          sizer.Add(self.choice_action, 0, wxALL, 4)          sizer.Add(self.choice_action, 0, wxALL, 4)
304          sizer.Add(button_query, 0, wxALL, 4)          sizer.Add(button_query, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)
305          sizer.Add(40, 20, 0, wxALL, 4)          sizer.Add(40, 20, 0, wxALL, 4)
306          sizer.Add(button_saveas, 0, wxALL, 4)          sizer.Add(button_saveas, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)
307    
308          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)
309          topBox.Add(self.grid, 1, wxEXPAND|wxALL, 0)          topBox.Add(self.grid, 1, wxEXPAND|wxALL, 0)
# Line 300  class LayerTableFrame(TableFrame): Line 313  class LayerTableFrame(TableFrame):
313          topBox.Fit(self)          topBox.Fit(self)
314          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
315    
316            self.grid.SetFocus()
317          EVT_BUTTON(self, ID_QUERY, self.OnQuery)          EVT_BUTTON(self, ID_QUERY, self.OnQuery)
318          EVT_BUTTON(self, ID_SAVEAS, self.OnSaveAs)          EVT_BUTTON(self, ID_SAVEAS, self.OnSaveAs)
319            EVT_KEY_DOWN(self.grid, self.OnKeyDown)
320    
321        def OnKeyDown(self, event):
322            """Catch query key from grid"""
323            print "In OnKeyDown"
324            if event.AltDown() and event.GetKeyCode() == ord(QUERY_KEY):
325                print "Got the Key!"
326                self.combo_fields.SetFocus()
327                self.combo_fields.refocus = True
328            else:
329                event.Skip()
330    
331    
332      def OnQuery(self, event):      def OnQuery(self, event):
333          wxBeginBusyCursor()          wxBeginBusyCursor()
334    
335          if self.combo_value.GetSelection() < 1:          if self.combo_value.GetSelection() < 1:
336              value = self.combo_value.GetValue()              value = self.combo_value.GetValue()
             print value  
337          else:          else:
338              value = self.table.Column(self.combo_value.GetValue())              value = self.table.Column(self.combo_value.GetValue())
339    
340          #ids = self.table.Query(          ids = self.table.SimpleQuery(
341                  #self.table.Column(self.combo_fields.GetStringSelection()),                  self.table.Column(self.combo_fields.GetStringSelection()),
342                  #self.choice_comp.GetStringSelection(),                  self.choice_comp.GetStringSelection(),
343                  #value)                  value)
344    
345          choice = self.choice_action.GetSelection()          choice = self.choice_action.GetSelection()
346                            
347            #
348            # what used to be nice code got became a bit ugly because
349            # each time we select a row a message is sent to the grid
350            # which we are listening for and then we send further
351            # messages.
352            #
353            # now, we disable those listeners select everything but
354            # the first item, reenable the listeners, and select
355            # the first element, which causes everything to be
356            # updated properly.
357            #
358            self.grid.ToggleEventListeners(False)
359    
360          if choice == 0:          if choice == 0:
             ids = [1, 2, 3, 4, 5]  
361              # Replace Selection              # Replace Selection
362              self.grid.ClearSelection()              self.grid.ClearSelection()
             for id in ids:  
                 self.grid.SelectRow(id, True)  
363          elif choice == 1:          elif choice == 1:
             ids = [1, 3, 5]  
364              # Refine Selection              # Refine Selection
365              sel = dict([(i, 0) for i in self.parent.SelectedShapes()])              sel = dict([(i, 0) for i in self.parent.SelectedShapes()])
366              self.grid.ClearSelection()              self.grid.ClearSelection()
367              for id in filter(sel.has_key, ids):              ids = filter(sel.has_key, ids)
                 self.grid.SelectRow(id, True)  
368          elif choice == 2:          elif choice == 2:
             ids = [2, 4]  
369              # Add to Selection              # Add to Selection
370              for id in ids:              pass
371    
372            #
373            # select the rows (all but the first)
374            #
375            firsttime = True
376            for id in ids:
377                if firsttime:
378                    firsttime = False
379                else:
380                  self.grid.SelectRow(id, True)                  self.grid.SelectRow(id, True)
381    
382            self.grid.ToggleEventListeners(True)
383    
384            #
385            # select the first row
386            #
387            if ids:
388                self.grid.SelectRow(ids[0], True)
389    
390          wxEndBusyCursor()          wxEndBusyCursor()
391                    
392      def OnSaveAs(self, event):      def OnSaveAs(self, event):

Legend:
Removed from v.881  
changed lines
  Added in v.979

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26