/[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 1013 by jan, Fri May 23 09:18:28 2003 UTC revision 1068 by bh, Tue May 27 15:02:37 2003 UTC
# Line 7  Line 7 
7    
8  __version__ = "$Revision$"  __version__ = "$Revision$"
9    
10    import os.path
11    
12  from Thuban import _  from Thuban import _
13    
14  from wxPython.wx import *  from wxPython.wx import *
# Line 14  from wxPython.grid import * Line 16  from wxPython.grid import *
16    
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       FIELDTYPE_STRING, table_to_dbf, table_to_csv
20  import view  import view
21  from dialogs import NonModalDialog  from dialogs import NonModalNonParentDialog
22  from messages import SHAPES_SELECTED  
23    from messages import SHAPES_SELECTED, SESSION_REPLACED
24    from Thuban.Model.messages import TABLE_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 121  class TableGrid(wxGrid, Publisher): Line 125  class TableGrid(wxGrid, Publisher):
125          # of the table and will destroy it when done. Otherwise you          # of the table and will destroy it when done. Otherwise you
126          # would need to keep a reference to it and call its Destroy          # would need to keep a reference to it and call its Destroy
127          # method later.          # method later.
128          self.SetTable(self.table, true)          self.SetTable(self.table, True)
129    
130          #self.SetMargins(0,0)          #self.SetMargins(0,0)
131    
# Line 129  class TableGrid(wxGrid, Publisher): Line 133  class TableGrid(wxGrid, Publisher):
133          # column widths automatically but it would cause a traversal of          # column widths automatically but it would cause a traversal of
134          # the entire table which for large .dbf files can take a very          # the entire table which for large .dbf files can take a very
135          # long time.          # long time.
136          #self.AutoSizeColumns(false)          #self.AutoSizeColumns(False)
137    
138          self.SetSelectionMode(wxGrid.wxGridSelectRows)          self.SetSelectionMode(wxGrid.wxGridSelectRows)
139    
# Line 234  class LayerTableGrid(TableGrid): Line 238  class LayerTableGrid(TableGrid):
238                  self.allow_messages()                  self.allow_messages()
239    
240    
241  class TableFrame(NonModalDialog):  class TableFrame(NonModalNonParentDialog):
242    
243      """Frame that displays a Thuban table in a grid view"""      """Frame that displays a Thuban table in a grid view"""
244    
245      def __init__(self, parent, name, title, table):      def __init__(self, parent, name, title, table):
246          NonModalDialog.__init__(self, parent, name, title)          NonModalNonParentDialog.__init__(self, parent, name, title)
247          self.table = table          self.table = table
248          self.grid = self.make_grid(self.table)          self.grid = self.make_grid(self.table)
249            self.app = self.parent.application
250            self.app.Subscribe(SESSION_REPLACED, self.close_on_session_replaced)
251            self.session = self.app.Session()
252            self.session.Subscribe(TABLE_REMOVED, self.close_on_table_removed)
253    
254      def make_grid(self, table):      def make_grid(self, table):
255          """Return the table grid to use in the frame.          """Return the table grid to use in the frame.
# Line 251  class TableFrame(NonModalDialog): Line 259  class TableFrame(NonModalDialog):
259          """          """
260          return TableGrid(self, table)          return TableGrid(self, table)
261    
262        def OnClose(self, event):
263            self.app.Unsubscribe(SESSION_REPLACED, self.close_on_session_replaced)
264            self.session.Unsubscribe(TABLE_REMOVED, self.close_on_table_removed)
265            NonModalNonParentDialog.OnClose(self, event)
266    
267        def close_on_session_replaced(self, *args):
268            """Subscriber for the SESSION_REPLACED messages.
269    
270            The table frame is tied to a session so close the window when
271            the session changes.
272            """
273            self.Close()
274    
275        def close_on_table_removed(self, table):
276            """Subscriber for the TABLE_REMOVED messages.
277    
278            The table frame is tied to a particular table so close the
279            window when the table is removed.
280            """
281            if table is self.table:
282                self.Close()
283    
284    
285  ID_QUERY = 4001  ID_QUERY = 4001
286  ID_EXPORT = 4002  ID_EXPORT = 4002
# Line 293  class QueryTableFrame(TableFrame): Line 323  class QueryTableFrame(TableFrame):
323    
324          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
325    
326          sizer = wxStaticBoxSizer(wxStaticBox(self, -1, _("Selection")),          sizer = wxStaticBoxSizer(wxStaticBox(self, -1,
327                                      _("Selection")),
328                                    wxHORIZONTAL)                                    wxHORIZONTAL)
329          sizer.Add(self.combo_fields, 1, wxEXPAND|wxALL, 4)          sizer.Add(self.combo_fields, 1, wxEXPAND|wxALL, 4)
330          sizer.Add(self.choice_comp, 0, wxALL, 4)          sizer.Add(self.choice_comp, 0, wxALL, 4)
# Line 392  class QueryTableFrame(TableFrame): Line 423  class QueryTableFrame(TableFrame):
423                             _("All Files (*.*)|*.*"),                             _("All Files (*.*)|*.*"),
424                             wxSAVE|wxOVERWRITE_PROMPT)                             wxSAVE|wxOVERWRITE_PROMPT)
425          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
426              pass              filename = dlg.GetPath()
427                                                                                                type = os.path.basename(filename).split('.')[-1:][0]
428          dlg.Destroy()              dlg.Destroy()
429                if type.upper() == "DBF":
430                    table_to_dbf(self.table, filename)
431                elif type.upper() == 'CSV':
432                    table_to_csv(self.table, filename)
433                else:
434                    dlg = wxMessageDialog(None, "Unsupported format: %s" % type,
435                                          "Table Export", wxOK|wxICON_WARNING)
436                    dlg.ShowModal()
437                    dlg.Destroy()
438            else:
439                dlg.Destroy()
440    
441      def OnClose(self, event):      def OnClose(self, event):
442          TableFrame.OnClose(self, event)          TableFrame.OnClose(self, event)
# Line 419  class LayerTableFrame(QueryTableFrame): Line 461  class LayerTableFrame(QueryTableFrame):
461          self.grid.Subscribe(ROW_SELECTED, self.rows_selected)          self.grid.Subscribe(ROW_SELECTED, self.rows_selected)
462          self.parent.Subscribe(SHAPES_SELECTED, self.select_shapes)          self.parent.Subscribe(SHAPES_SELECTED, self.select_shapes)
463    
464            # if there is already a selection present, update the grid
465            # accordingly
466            sel = self.get_selected().keys()
467            for i in sel:
468                self.grid.SelectRow(i, True)
469    
470      def make_grid(self, table):      def make_grid(self, table):
471          """Override the derived method to return a LayerTableGrid.          """Override the derived method to return a LayerTableGrid.
472          """          """

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26