/[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 1276 by jonathan, Fri Jun 20 17:46:34 2003 UTC revision 1394 by jonathan, Thu Jul 10 14:54:58 2003 UTC
# Line 17  from wxPython.grid import * Line 17  from wxPython.grid import *
17  from Thuban.Lib.connector import Publisher  from Thuban.Lib.connector import Publisher
18  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \  from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \
19       FIELDTYPE_STRING, table_to_dbf, table_to_csv       FIELDTYPE_STRING, table_to_dbf, table_to_csv
 import view  
20  from dialogs import ThubanFrame  from dialogs import ThubanFrame
21    
22  from messages import SHAPES_SELECTED, SESSION_REPLACED  from messages import SHAPES_SELECTED, SESSION_REPLACED
# Line 330  class TableFrame(ThubanFrame): Line 329  class TableFrame(ThubanFrame):
329  ID_QUERY = 4001  ID_QUERY = 4001
330  ID_EXPORT = 4002  ID_EXPORT = 4002
331  ID_COMBOVALUE = 4003  ID_COMBOVALUE = 4003
332    ID_EXPORTSEL = 4004
333    
334  class QueryTableFrame(TableFrame):  class QueryTableFrame(TableFrame):
335    
# Line 353  class QueryTableFrame(TableFrame): Line 353  class QueryTableFrame(TableFrame):
353                                          _("Add to Selection")])                                          _("Add to Selection")])
354    
355          button_query = wxButton(self.panel, ID_QUERY, _("Query"))          button_query = wxButton(self.panel, ID_QUERY, _("Query"))
356          button_saveas = wxButton(self.panel, ID_EXPORT, _("Export"))          button_export = wxButton(self.panel, ID_EXPORT, _("Export"))
357            button_exportSel = wxButton(self.panel, ID_EXPORTSEL, _("Export Selection"))
358            button_close = wxButton(self.panel, wxID_CLOSE, _("Close"))
359    
360          self.CreateStatusBar()          self.CreateStatusBar()
361    
# Line 386  class QueryTableFrame(TableFrame): Line 388  class QueryTableFrame(TableFrame):
388          sizer.Add(self.choice_action, 0, wxALL, 4)          sizer.Add(self.choice_action, 0, wxALL, 4)
389          sizer.Add(button_query, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)          sizer.Add(button_query, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)
390          sizer.Add(40, 20, 0, wxALL, 4)          sizer.Add(40, 20, 0, wxALL, 4)
         sizer.Add(button_saveas, 0, wxALL | wxALIGN_CENTER_VERTICAL, 4)  
391    
392          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)          topBox.Add(sizer, 0, wxEXPAND|wxALL, 4)
393          topBox.Add(self.grid, 1, wxEXPAND|wxALL, 0)          topBox.Add(self.grid, 1, wxEXPAND|wxALL, 0)
394    
395            sizer = wxBoxSizer(wxHORIZONTAL)
396            sizer.Add(button_export, 0, wxALL, 4)
397            sizer.Add(button_exportSel, 0, wxALL, 4)
398            sizer.Add(60, 20, 1, wxALL|wxEXPAND, 4)
399            sizer.Add(button_close, 0, wxALL|wxALIGN_RIGHT, 4)
400            topBox.Add(sizer, 0, wxALL | wxEXPAND, 4)
401    
402          self.panel.SetAutoLayout(True)          self.panel.SetAutoLayout(True)
403          self.panel.SetSizer(topBox)          self.panel.SetSizer(topBox)
404          topBox.Fit(self.panel)          topBox.Fit(self.panel)
# Line 406  class QueryTableFrame(TableFrame): Line 414  class QueryTableFrame(TableFrame):
414          self.grid.SetFocus()          self.grid.SetFocus()
415    
416          EVT_BUTTON(self, ID_QUERY, self.OnQuery)          EVT_BUTTON(self, ID_QUERY, self.OnQuery)
417          EVT_BUTTON(self, ID_EXPORT, self.OnSaveAs)          EVT_BUTTON(self, ID_EXPORT, self.OnExport)
418            EVT_BUTTON(self, ID_EXPORTSEL, self.OnExportSel)
419            EVT_BUTTON(self, wxID_CLOSE, self.OnClose)
420          EVT_KEY_DOWN(self.grid, self.OnKeyDown)          EVT_KEY_DOWN(self.grid, self.OnKeyDown)
         EVT_GRID_RANGE_SELECT(self.grid, self.OnGridSelectRange)  
         EVT_GRID_SELECT_CELL(self.grid, self.OnGridSelectCell)  
421    
422      def UpdateStatusText(self):          self.grid.Subscribe(ROW_SELECTED, self.UpdateStatusText)
423    
424        def UpdateStatusText(self, rows=None):
425          self.SetStatusText(_("%i rows (%i selected), %i columns")          self.SetStatusText(_("%i rows (%i selected), %i columns")
426              % (self.grid.GetNumberRows(),              % (self.grid.GetNumberRows(),
427                 self.grid.GetNumberSelected(),                 self.grid.GetNumberSelected(),
428                 self.grid.GetNumberCols()))                 self.grid.GetNumberCols()))
429    
     def OnGridSelectRange(self, event):  
         self.UpdateStatusText()  
         event.Skip()  
   
     def OnGridSelectCell(self, event):  
         self.UpdateStatusText()  
         event.Skip()  
           
430      def OnKeyDown(self, event):      def OnKeyDown(self, event):
431          """Catch query key from grid"""          """Catch query key from grid"""
432          if event.AltDown() and event.GetKeyCode() == ord(QUERY_KEY):          if event.AltDown() and event.GetKeyCode() == ord(QUERY_KEY):
# Line 498  class QueryTableFrame(TableFrame): Line 500  class QueryTableFrame(TableFrame):
500          finally:          finally:
501              ThubanEndBusyCursor()              ThubanEndBusyCursor()
502                    
503      def OnSaveAs(self, event):      def doExport(self, onlySelected):
504            
505          dlg = wxFileDialog(self, _("Export Table To"), ".", "",          dlg = wxFileDialog(self, _("Export Table To"), ".", "",
506                             _("DBF Files (*.dbf)|*.dbf|") +                             _("DBF Files (*.dbf)|*.dbf|") +
507                             _("CSV Files (*.csv)|*.csv|") +                             _("CSV Files (*.csv)|*.csv|") +
# Line 508  class QueryTableFrame(TableFrame): Line 511  class QueryTableFrame(TableFrame):
511              filename = dlg.GetPath()              filename = dlg.GetPath()
512              type = os.path.basename(filename).split('.')[-1:][0]              type = os.path.basename(filename).split('.')[-1:][0]
513              dlg.Destroy()              dlg.Destroy()
514    
515                if onlySelected:
516                    records = self.grid.GetSelectedRows()
517                else:
518                    records = None
519    
520              if type.upper() == "DBF":              if type.upper() == "DBF":
521                  table_to_dbf(self.table, filename)                  table_to_dbf(self.table, filename, records)
522              elif type.upper() == 'CSV':              elif type.upper() == 'CSV':
523                  table_to_csv(self.table, filename)                  table_to_csv(self.table, filename, records)
524              else:              else:
525                  dlg = wxMessageDialog(None, "Unsupported format: %s" % type,                  dlg = wxMessageDialog(None, "Unsupported format: %s" % type,
526                                        "Table Export", wxOK|wxICON_WARNING)                                        "Table Export", wxOK|wxICON_WARNING)
# Line 520  class QueryTableFrame(TableFrame): Line 529  class QueryTableFrame(TableFrame):
529          else:          else:
530              dlg.Destroy()              dlg.Destroy()
531    
532        def OnExport(self, event):
533            self.doExport(False)
534    
535        def OnExportSel(self, event):
536            self.doExport(True)
537    
538      def OnClose(self, event):      def OnClose(self, event):
539          TableFrame.OnClose(self, event)          TableFrame.OnClose(self, event)
540    
541      def get_selected(self):      def get_selected(self):
542          """Return a dictionary of the selected rows.          """Return a dictionary of the selected rows.
543                    
544          The dictionary has sthe indexes as keys."""          The dictionary has the indexes as keys."""
545          return dict([(i, 0) for i in self.grid.GetSelectedRows()])          return dict([(i, 0) for i in self.grid.GetSelectedRows()])
546    
547  class LayerTableFrame(QueryTableFrame):  class LayerTableFrame(QueryTableFrame):

Legend:
Removed from v.1276  
changed lines
  Added in v.1394

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26