/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/controls.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/controls.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/thuban/Thuban/UI/controls.py revision 274 by bh, Thu Aug 22 16:25:46 2002 UTC branches/WIP-pyshapelib-bramz/Thuban/UI/controls.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 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 10  Line 10 
10    
11  __version__ = "$Revision$"  __version__ = "$Revision$"
12    
13  from wxPython.wx import wxListCtrl, wxLC_REPORT, wxLIST_AUTOSIZE_USEHEADER, \  import wx
14       EVT_LIST_ITEM_SELECTED, true, false  from wx import grid
15  from wxPython.grid import wxPyGridTableBase, wxGrid, wxGRID_VALUE_STRING, \  
16       wxGridTableMessage, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, \  from Thuban import _
      wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES  
17    
18  # FIXME: the wx_value_type_map should be moved from tableview to a  # FIXME: the wx_value_type_map should be moved from tableview to a
19  # separate module  # separate module
# Line 22  from tableview import wx_value_type_map Line 21  from tableview import wx_value_type_map
21    
22    
23    
24  class RecordListCtrl(wxListCtrl):  class RecordListCtrl(wx.ListCtrl):
25    
26      """List Control showing a single record from a thuban table"""      """List Control showing a single record from a thuban table"""
27    
28      def __init__(self, parent, id):      def __init__(self, parent, id):
29          wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT)          wx.ListCtrl.__init__(self, parent, id, style = wx.LC_REPORT)
30    
31          self.InsertColumn(0, "Field")          self.InsertColumn(0, _("Field"))
32          self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)          self.SetColumnWidth(0, 200)
33          self.InsertColumn(1, "Value")          self.InsertColumn(1, _("Value"))
34          self.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER)          self.SetColumnWidth(1, 100)
35    
36          # vaues maps row numbers to the corresponding python values          # vaues maps row numbers to the corresponding python values
37          self.values = {}          self.values = {}
# Line 43  class RecordListCtrl(wxListCtrl): Line 42  class RecordListCtrl(wxListCtrl):
42          values = {}          values = {}
43    
44          if shape is not None:          if shape is not None:
             num_cols = table.field_count()  
   
45              names = []              names = []
46              for i in range(num_cols):              for col in table.Columns():
47                  type, name, length, decc = table.field_info(i)                  names.append(col.name)
48                  names.append(name)              record = table.ReadRowAsDict(shape)
             record = table.read_record(shape)  
49    
50              for i in range(len(names)):              for i in range(len(names)):
51                  name = names[i]                  name = names[i]
52                  value = record[name]                  value = record[name]
53                  self.InsertStringItem(i, name)                  self.InsertStringItem(i, name)
54                  self.SetStringItem(i, 1, str(value))                  self.SetStringItem(i, 1, str(value).decode('iso-8859-1'))
55                  values[i] = value                  values[i] = value
56    
57          self.values = values          self.values = values
# Line 68  class SelectableRecordListCtrl(RecordLis Line 64  class SelectableRecordListCtrl(RecordLis
64          # selected is the index of the selected record or -1 if none is          # selected is the index of the selected record or -1 if none is
65          # selected          # selected
66          self.selected = -1          self.selected = -1
67          EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected)          self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, id=self.GetId())
68    
69      def OnItemSelected(self, event):      def OnItemSelected(self, event):
70          """Event handler. Update the selected instvar"""          """Event handler. Update the selected instvar"""
# Line 82  class SelectableRecordListCtrl(RecordLis Line 78  class SelectableRecordListCtrl(RecordLis
78              return None              return None
79    
80    
81  class RecordTable(wxPyGridTableBase):  class RecordTable(grid.PyGridTableBase):
82    
83      """Wrapper that makes a Thuban table record look like a table for a      """Wrapper that makes a Thuban table record look like a table for a
84         wxGrid         wxGrid
85      """      """
86    
87      def __init__(self, table = None, record = None):      def __init__(self, table = None, record = None):
88          wxPyGridTableBase.__init__(self)          grid.PyGridTableBase.__init__(self)
89          self.num_cols = 1          self.num_cols = 1
90          self.num_rows = 0          self.num_rows = 0
91          self.table = None          self.table = None
# Line 102  class RecordTable(wxPyGridTableBase): Line 98  class RecordTable(wxPyGridTableBase):
98          if record_index is not None:          if record_index is not None:
99              self.table = table              self.table = table
100              self.record_index = record_index              self.record_index = record_index
101              self.record = table.read_record(record_index)              self.record = table.ReadRowAsDict(record_index)
102    
103              # we have one row for each field in the table              # we have one row for each field in the table
104              self.num_rows = table.field_count()              self.num_rows = table.NumColumns()
105    
106              # extract the field types and names of the row we're showing.              # extract the field types and names of the row we're showing.
107              self.rows = []              self.rows = []
108              for i in range(self.num_rows):              for i in range(self.num_rows):
109                  type, name, len, decc = table.field_info(i)                  col = table.Column(i)
110                  self.rows.append((name, wx_value_type_map[type], len, decc))                  self.rows.append((col.name, wx_value_type_map[col.type]))
111              self.notify_get_values()              self.notify_get_values()
112          else:          else:
113              # make the grid empty              # make the grid empty
# Line 126  class RecordTable(wxPyGridTableBase): Line 122  class RecordTable(wxPyGridTableBase):
122    
123      def notify_append_rows(self, num):      def notify_append_rows(self, num):
124          """Tell the view that num rows were appended"""          """Tell the view that num rows were appended"""
125          self.send_view_message(wxGRIDTABLE_NOTIFY_ROWS_APPENDED, num)          self.send_view_message(grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, num)
126    
127      def notify_delete_rows(self, start, num):      def notify_delete_rows(self, start, num):
128          """Tell the view that num rows were deleted starting at start"""          """Tell the view that num rows were deleted starting at start"""
129          self.send_view_message(wxGRIDTABLE_NOTIFY_ROWS_DELETED, start, num)          self.send_view_message(grid.GRIDTABLE_NOTIFY_ROWS_DELETED, start, num)
130    
131      def notify_get_values(self):      def notify_get_values(self):
132          """Tell the view that the grid's values have to be updated"""          """Tell the view that the grid's values have to be updated"""
133          self.send_view_message(wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)          self.send_view_message(grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
134    
135      def send_view_message(self, msgid, *args):      def send_view_message(self, msgid, *args):
136          """Send the message msgid to the view with arguments args"""          """Send the message msgid to the view with arguments args"""
137          view = self.GetView()          view = self.GetView()
138          if view:          if view:
139              #print "send_view_message", msgid, args              #print "send_view_message", msgid, args
140              msg = apply(wxGridTableMessage, (self, msgid) + args)              msg = apply(grid.GridTableMessage, (self, msgid) + args)
141              view.ProcessTableMessage(msg)              view.ProcessTableMessage(msg)
142    
143      #      #
# Line 178  class RecordTable(wxPyGridTableBase): Line 174  class RecordTable(wxPyGridTableBase):
174    
175      # Called when the grid needs to display labels      # Called when the grid needs to display labels
176      def GetColLabelValue(self, col):      def GetColLabelValue(self, col):
177          return "Value"          return _("Value")
178    
179      def GetRowLabelValue(self, row):      def GetRowLabelValue(self, row):
180          if row < self.num_rows:          if row < self.num_rows:
# Line 193  class RecordTable(wxPyGridTableBase): Line 189  class RecordTable(wxPyGridTableBase):
189          # it's probably a wx bug (filed as #593189 on sourceforge)          # it's probably a wx bug (filed as #593189 on sourceforge)
190          if 0 <= row < self.num_rows:          if 0 <= row < self.num_rows:
191              return self.rows[row][1]              return self.rows[row][1]
192          return wxGRID_VALUE_STRING          return grid.GRID_VALUE_STRING
193    
194      # Called to determine how the data can be fetched and stored by the      # Called to determine how the data can be fetched and stored by the
195      # editor and renderer.  This allows you to enforce some type-safety      # editor and renderer.  This allows you to enforce some type-safety
# Line 207  class RecordTable(wxPyGridTableBase): Line 203  class RecordTable(wxPyGridTableBase):
203    
204    
205    
206  class RecordGridCtrl(wxGrid):  class RecordGridCtrl(grid.Grid):
207    
208      """Grid view for a RecordTable"""      """Grid view for a RecordTable"""
209    
210      def __init__(self, parent, table = None, record = None):      def __init__(self, parent, table = None, record = None):
211          wxGrid.__init__(self, parent, -1)          grid.Grid.__init__(self, parent, -1)
212    
213          self.table = RecordTable(table, record)          self.table = RecordTable(table, record)
214    
# Line 220  class RecordGridCtrl(wxGrid): Line 216  class RecordGridCtrl(wxGrid):
216          # of the table and will destroy it when done. Otherwise you          # of the table and will destroy it when done. Otherwise you
217          # would need to keep a reference to it and call it's Destroy          # would need to keep a reference to it and call it's Destroy
218          # method later.          # method later.
219          self.SetTable(self.table, true)          self.SetTable(self.table, True)
220    
221          #self.SetMargins(0,0)          #self.SetMargins(0,0)
222          self.AutoSizeColumn(0, true)          self.AutoSizeColumn(0, True)
223    
224          #self.SetSelectionMode(wxGrid.wxGridSelectRows)          #self.SetSelectionMode(wxGrid.wxGridSelectRows)
225    

Legend:
Removed from v.274  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26