/[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 6 by bh, Tue Aug 28 15:41:52 2001 UTC revision 1035 by jan, Mon May 26 17:03:08 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 _
 from messages import SELECTED_SHAPE  
14    
15  class IdentifyListCtrl(wxListCtrl):  from dialogs import NonModalDialog
16    from controls import RecordListCtrl, RecordGridCtrl
17    from messages import SHAPES_SELECTED
18    
19      def __init__(self, parent, id, interactor):  class IdentifyListCtrl(RecordListCtrl):
         wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT)  
         self.interactor = interactor  
         self.interactor.Subscribe(SELECTED_SHAPE, self.selected_shape)  
   
         self.InsertColumn(0, "Field")  
         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))  
20    
21      def selected_shape(self, layer, shape):      def selected_shape(self, layer, shape):
22          self.fill_list(layer, shape)          if layer is not None:
23                            table = layer.table
24            else:
25                table = None
26            self.fill_list(table, shape)
27    
28    class IdentifyGridCtrl(RecordGridCtrl):
29    
30  class IdentifyView(wxFrame):      def selected_shape(self, layer, shape):
31            if layer is not None:
32                table = layer.table
33            else:
34                table = None
35            self.SetTableRecord(table, shape)
36    
37    class IdentifyView(NonModalDialog):
38    
39        def __init__(self, parent, name):
40            NonModalDialog.__init__(self, parent, name, _("Identify Shape"))
41            parent.Subscribe(SHAPES_SELECTED, self.selected_shape)
42    
     def __init__(self, parent, app):  
         # assume parent is Thuban's main window python object  
         wxFrame.__init__(self, parent, -1, "Identify Shape")  
43          panel = wxPanel(self, -1, style = wxWANTS_CHARS)          panel = wxPanel(self, -1, style = wxWANTS_CHARS)
44          self.list = IdentifyListCtrl(panel, -1, app.interactor)          #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):
56            self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape)
57            NonModalDialog.OnClose(self, event)
58    
59        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)

Legend:
Removed from v.6  
changed lines
  Added in v.1035

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26