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

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

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

revision 29 by bh, Thu Sep 6 13:30:59 2001 UTC revision 1131 by frank, Thu Jun 5 13:27:01 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 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  __version__ = "$Revision$" Line 10  __version__ = "$Revision$"
10  from wxPython.wx import *  from wxPython.wx import *
11  from wxPython.grid import *  from wxPython.grid import *
12    
13  import view  from Thuban import _
14    
15  from dialogs import NonModalDialog  from dialogs import NonModalDialog
16  from messages import SELECTED_SHAPE  from controls import RecordListCtrl, RecordGridCtrl
17    from messages import SHAPES_SELECTED
18    
19  class IdentifyListCtrl(wxListCtrl):  class IdentifyListCtrl(RecordListCtrl):
20    
21      def __init__(self, parent, id):      def selected_shape(self, layer, shape):
22          wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT)          if layer is not None:
23                table = layer.table
24            else:
25                table = None
26            self.fill_list(table, shape)
27    
28          self.InsertColumn(0, "Field")  class IdentifyGridCtrl(RecordGridCtrl):
         self.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)  
         self.InsertColumn(1, "Value")  
         self.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER)  
   
     def fill_list(self, layer, shape):  
         self.DeleteAllItems()  
   
         if shape is not None:  
             table = layer.shapetable  
             num_cols = table.field_count()  
             num_rows = table.record_count()  
               
             names = []  
             for i in range(num_cols):  
                 type, name, length, decc = table.field_info(i)  
                 names.append(name)  
             record = table.read_record(shape)  
             i = 0  
             for name in names:  
                 value = record[name]  
                 i = self.InsertStringItem(i, name)  
                 self.SetStringItem(i, 1, str(value))  
29    
30      def selected_shape(self, layer, shape):      def selected_shape(self, layer, shape):
31          self.fill_list(layer, shape)          if layer is not None:
32                            table = layer.table
33            else:
34                table = None
35            self.SetTableRecord(table, shape)
36    
37  class IdentifyView(NonModalDialog):  class IdentifyView(NonModalDialog):
38    
39      def __init__(self, parent, interactor, name):      def __init__(self, parent, name):
40          NonModalDialog.__init__(self, parent, interactor, name,          NonModalDialog.__init__(self, parent, name, _("Identify Shape"))
41                                  "Identify Shape")          parent.Subscribe(SHAPES_SELECTED, self.selected_shape)
42          self.interactor.Subscribe(SELECTED_SHAPE, self.selected_shape)  
           
43          panel = wxPanel(self, -1, style = wxWANTS_CHARS)          panel = wxPanel(self, -1, style = wxWANTS_CHARS)
44          self.list = IdentifyListCtrl(panel, -1)          self.list = IdentifyListCtrl(panel, -1)
45            #self.list = IdentifyGridCtrl(panel)
46    
47          sizer = wxBoxSizer(wxVERTICAL)          sizer = wxBoxSizer(wxVERTICAL)
48          sizer.Add(self.list, 1, wx.wxEXPAND| wx.wxALL, 0)          sizer.Add(self.list, 1, wx.wxEXPAND| wx.wxALL, 0)
49    
50          panel.SetAutoLayout(true)          self.SetSize(wxSize(300,200))
51            panel.SetAutoLayout(True)
52          panel.SetSizer(sizer)          panel.SetSizer(sizer)
53          sizer.Fit(panel)          sizer.Fit(panel)
54    
55      def OnClose(self, event):      def OnClose(self, event):
56          self.interactor.Unsubscribe(SELECTED_SHAPE, self.selected_shape)          self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape)
57          NonModalDialog.OnClose(self, event)          NonModalDialog.OnClose(self, event)
58    
59      def selected_shape(self, layer, shape):      def selected_shape(self, layer, shapes):
60            """Subscribed to the SHAPES_SELECTED messages.
61    
62            If exatly one shape is selected, pass that shape id to the
63            list's selected_shape method. Otherwise pass None as the shape
64            id.
65            """
66            if len(shapes) == 1:
67                shape = shapes[0]
68            else:
69                shape = None
70          self.list.selected_shape(layer, shape)          self.list.selected_shape(layer, shape)

Legend:
Removed from v.29  
changed lines
  Added in v.1131

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26