/[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 1968 by bh, Fri Nov 21 14:33:27 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    # Frank Koormann <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 10  __version__ = "$Revision$" Line 11  __version__ = "$Revision$"
11  from wxPython.wx import *  from wxPython.wx import *
12  from wxPython.grid import *  from wxPython.grid import *
13    
14  import view  from Thuban import _
15    
16  from dialogs import NonModalDialog  from dialogs import NonModalDialog
17  from messages import SELECTED_SHAPE  from controls import RecordListCtrl, RecordGridCtrl
18    from messages import SHAPES_SELECTED
19    import main
20    
21  class IdentifyListCtrl(wxListCtrl):  class IdentifyListCtrl(RecordListCtrl):
22    
23      def __init__(self, parent, id):      def selected_shape(self, layer, shape):
24          wxListCtrl.__init__(self, parent, id, style = wxLC_REPORT)          if layer is not None:
25                table = layer.ShapeStore().Table()
26            else:
27                table = None
28            self.fill_list(table, shape)
29    
30          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))  
31    
32      def selected_shape(self, layer, shape):      def selected_shape(self, layer, shape):
33          self.fill_list(layer, shape)          if layer is not None:
34                            table = layer.ShapeStore().Table()
35            else:
36                table = None
37            self.SetTableRecord(table, shape)
38    
39  class IdentifyView(NonModalDialog):  class IdentifyView(NonModalDialog):
40    
41      def __init__(self, parent, interactor, name):      ID_STOP = 100
42          NonModalDialog.__init__(self, parent, interactor, name,  
43                                  "Identify Shape")      def __init__(self, parent, name):
44          self.interactor.Subscribe(SELECTED_SHAPE, self.selected_shape)          NonModalDialog.__init__(self, parent, name, _("Identify Shape"))
45                    parent.Subscribe(SHAPES_SELECTED, self.selected_shape)
46          panel = wxPanel(self, -1, style = wxWANTS_CHARS)  
47          self.list = IdentifyListCtrl(panel, -1)          top_box = wxBoxSizer(wxVERTICAL)
48            if main.options.attribute_editing_enabled:
49          sizer = wxBoxSizer(wxVERTICAL)              self.list = IdentifyGridCtrl(self)
50          sizer.Add(self.list, 1, wx.wxEXPAND| wx.wxALL, 0)          else:
51                self.list = IdentifyListCtrl(self, -1)
52          panel.SetAutoLayout(true)          self.list.SetSize(wxSize(305,200))
53          panel.SetSizer(sizer)          top_box.Add(self.list, 1, wxEXPAND|wxALL, 4)
54          sizer.Fit(panel)  
55            box = wxBoxSizer(wxHORIZONTAL)
56            box.Add(wxButton(self, wxID_CLOSE, _("Close Window")), 0, wxALL, 4)
57            box.Add(wxButton(self, self.ID_STOP, _("Stop Identify Mode")),
58                             0, wxALL, 4)
59            top_box.Add(box, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 4)
60    
61            EVT_BUTTON(self, wxID_CLOSE, self.OnClose)
62            EVT_BUTTON(self, self.ID_STOP, self.OnStop)
63    
64            self.SetAutoLayout(True)
65            self.SetSizer(top_box)
66            top_box.Fit(self)
67            top_box.SetSizeHints(self)
68    
69            # Make sure to reflect the current selection.
70            self.selected_shape(parent.SelectedLayer(), parent.SelectedShapes())
71    
72      def OnClose(self, event):      def OnClose(self, event):
73          self.interactor.Unsubscribe(SELECTED_SHAPE, self.selected_shape)          self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape)
74          NonModalDialog.OnClose(self, event)          NonModalDialog.OnClose(self, event)
75    
76      def selected_shape(self, layer, shape):      def OnStop(self, event):
77            self.parent.Unsubscribe(SHAPES_SELECTED, self.selected_shape)
78            self.parent.canvas.SelectTool(None)
79            NonModalDialog.OnClose(self, event)
80    
81        def selected_shape(self, layer, shapes):
82            """Subscribed to the SHAPES_SELECTED messages.
83    
84            If exactly one shape is selected, pass that shape id to the
85            list's selected_shape method. Otherwise pass None as the shape
86            id.
87            """
88            if len(shapes) == 1:
89                shape = shapes[0]
90            else:
91                shape = None
92          self.list.selected_shape(layer, shape)          self.list.selected_shape(layer, shape)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26