/[thuban]/trunk/thuban/Thuban/UI/projlist.py
ViewVC logotype

Diff of /trunk/thuban/Thuban/UI/projlist.py

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

revision 1932 by bh, Wed Oct 22 09:38:20 2003 UTC revision 1933 by bh, Tue Nov 11 16:37:53 2003 UTC
# Line 28  class ProjectionList(wxListCtrl, Publish Line 28  class ProjectionList(wxListCtrl, Publish
28    
29      """A ListCtrl that shows a list of projections      """A ListCtrl that shows a list of projections
30    
31      The list control is effectively a view on two ProjFile instances and      The list control is effectively a view on several ProjFile instances
32      a specific 'original' projection (e.g. the projection of the current      and a specific 'original' projection (e.g. the projection of the
33      map). The list control subscribes to the change messages of the      current map). The list control subscribes to the change messages of
34      ProjFile instances to update the list whenever they change.      the ProjFile instances to update the list whenever they change.
35    
36      When the selection changes the instance sends a      When the selection changes the instance sends a
37      PROJ_SELECTION_CHANGED message.      PROJ_SELECTION_CHANGED message.
38      """      """
39    
40      def __init__(self, parent, system_projs, user_projs, orig_proj, ID = -1):      def __init__(self, parent, proj_files, orig_proj, ID = -1):
41          """Initialize the ProjectionList          """Initialize the ProjectionList
42    
43          Parameters:          Parameters:
44    
45          parent -- The parent widget          parent -- The parent widget
46          system_projs, user_projs -- the system and user ProjFiles          proj_files -- a sequence of ProjFile objects
47          orig_proj -- The projection originally selected in the map/layer          orig_proj -- The projection originally selected in the map/layer
48          """          """
49          wxListCtrl.__init__(self, parent, ID, style=wxLC_REPORT|wxLC_VIRTUAL)          wxListCtrl.__init__(self, parent, ID, style=wxLC_REPORT|wxLC_VIRTUAL)
50    
51          self.InsertColumn(0, _("Available Projections"))          self.InsertColumn(0, _("Available Projections"))
52          self.system_projs = system_projs          self.proj_files = proj_files
53          self.user_projs = user_projs          self._subscribe_proj_files()
54          self.orig_proj = orig_proj          self.orig_proj = orig_proj
55          self.projections = []          self.projections = []
56          self.proj_map = {}          self.proj_map = {}
# Line 61  class ProjectionList(wxListCtrl, Publish Line 61  class ProjectionList(wxListCtrl, Publish
61          EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.item_selected)          EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.item_selected)
62          EVT_LIST_ITEM_DESELECTED(self, self.GetId(), self.item_deselected)          EVT_LIST_ITEM_DESELECTED(self, self.GetId(), self.item_deselected)
63          EVT_IDLE(self, self.OnIdle)          EVT_IDLE(self, self.OnIdle)
         for pf in (self.system_projs, self.user_projs):  
             pf.Subscribe(PROJECTION_ADDED, self.pf_projection_added)  
             pf.Subscribe(PROJECTION_REMOVED, self.pf_projection_removed)  
             pf.Subscribe(PROJECTION_REPLACED, self.pf_projection_replaced)  
64    
65      def __del__(self):      def __del__(self):
66          wxListCtrl.__del__()          wxListCtrl.__del__()
67          Publisher.__del__()          Publisher.__del__()
68    
69      def Destroy(self):      def _subscribe_proj_files(self):
70          for pf in (self.system_projs, self.user_projs):          """Subscribe to the messages of self.proj_files"""
71            for pf in self.proj_files:
72                pf.Subscribe(PROJECTION_ADDED, self.pf_projection_added)
73                pf.Subscribe(PROJECTION_REMOVED, self.pf_projection_removed)
74                pf.Subscribe(PROJECTION_REPLACED, self.pf_projection_replaced)
75    
76        def _unsubscribe_proj_files(self):
77            """Unsubscribe from the messages subscribed to in _subscribe_proj_files
78            """
79            for pf in self.proj_files:
80              pf.Unsubscribe(PROJECTION_ADDED, self.pf_projection_added)              pf.Unsubscribe(PROJECTION_ADDED, self.pf_projection_added)
81              pf.Unsubscribe(PROJECTION_REMOVED, self.pf_projection_removed)              pf.Unsubscribe(PROJECTION_REMOVED, self.pf_projection_removed)
82              pf.Unsubscribe(PROJECTION_REPLACED, self.pf_projection_replaced)              pf.Unsubscribe(PROJECTION_REPLACED, self.pf_projection_replaced)
83    
84        def Destroy(self):
85            self._unsubscribe_proj_files()
86          # Call wxListCtrl's method last because afterwards self is not          # Call wxListCtrl's method last because afterwards self is not
87          # an instance of ProjectionList anymore as wxPython replaces          # an instance of ProjectionList anymore as wxPython replaces
88          # self.__class__ with its dead object class          # self.__class__ with its dead object class
# Line 103  class ProjectionList(wxListCtrl, Publish Line 110  class ProjectionList(wxListCtrl, Publish
110    
111          # Build the new projection list          # Build the new projection list
112          projections = [(_("<None>"), None, None)]          projections = [(_("<None>"), None, None)]
113          for pf in (self.user_projs, self.system_projs):          for pf in self.proj_files:
114              for p in pf.GetProjections():              for p in pf.GetProjections():
115                  projections.append((p.Label(), p, pf))                  projections.append((p.Label(), p, pf))
116          if self.orig_proj is not None:          if self.orig_proj is not None:
# Line 181  class ProjectionList(wxListCtrl, Publish Line 188  class ProjectionList(wxListCtrl, Publish
188          for i in range(len(self.projections)):          for i in range(len(self.projections)):
189              self.SetItemState(i, 0, wxLIST_STATE_SELECTED)              self.SetItemState(i, 0, wxLIST_STATE_SELECTED)
190    
191        def SetProjFiles(self, proj_files):
192            """Set the projfile objects whose projections are shown in the list"""
193            self._unsubscribe_proj_files()
194            self.proj_files = proj_files
195            self._subscribe_proj_files()
196            self.update_projections()
197    
198      def OnGetItemText(self, item, col):      def OnGetItemText(self, item, col):
199          """Callback for the virtual ListCtrl mode"""          """Callback for the virtual ListCtrl mode"""
200          return self.projections[item][0]          return self.projections[item][0]

Legend:
Removed from v.1932  
changed lines
  Added in v.1933

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26