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

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

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

revision 1786 by bh, Wed Oct 8 10:39:11 2003 UTC revision 1806 by bh, Fri Oct 10 10:36:34 2003 UTC
# Line 49  class ProjFrame(NonModalNonParentDialog) Line 49  class ProjFrame(NonModalNonParentDialog)
49                          SetProjection(projection)                          SetProjection(projection)
50                          GetProjection()                          GetProjection()
51          """          """
52                    NonModalNonParentDialog.__init__(self, parent, name, title)
53    
54            self.projection_panels = [
55                ("tmerc", _("Transverse Mercator"), TMPanel),
56                ("utm", _("Universal Transverse Mercator"), UTMPanel),
57                ("lcc", _("Lambert Conic Conformal"), LCCPanel),
58                ("latlong", _("Geographic"), GeoPanel)]
59          self.receiver = receiver          self.receiver = receiver
60          self.haveTried = False          self.haveTried = False
61          self.curProjPanel = None          self.curProjPanel = None
62    
63          self.projPanels = []          self.build_dialog()
64          self.projPanels.append(          self.Layout()
             ("tmerc", _("Transverse Mercator"), TMPanel))  
         self.projPanels.append(  
             ("utm", _("Universal Transverse Mercator"), UTMPanel))  
         self.projPanels.append(  
             ("lcc", _("Lambert Conic Conformal"), LCCPanel))  
         self.projPanels.append(  
             ("latlong", _("Geographic"), GeoPanel))  
65    
66          NonModalNonParentDialog.__init__(self, parent, name, title)          self.originalProjection = self.receiver.GetProjection()
         # originally generate by wxGlade  
         self.panel_1 = wxPanel(self, -1)  
         self.panel_edit = wxPanel(self, -1)  
         self.label_5 = wxStaticText(self.panel_1, -1,  
                         _("Available Projections:"))  
67    
68          # Projection List specific actions (Import/Export/Remove)          self.__DoOnProjAvail()
69          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT,          self.button_ok.SetFocus()
70                                        _("Import..."))          self.availprojs.SetFocus()
71          self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT,  
72                                        _("Export..."))      def build_dialog(self):
73          self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE,          """Build the dialog's widgets and set the event handlers"""
74                                        _("Remove"))          self.topBox = top_box = wxBoxSizer(wxVERTICAL)
75    
76            main_box = wxBoxSizer(wxHORIZONTAL)
77            top_box.Add(main_box, 1, wxALL|wxEXPAND)
78    
79          # The Projection List          #
80          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL,          #    The projection list and associated controls
81            #
82            vbox = wxBoxSizer(wxVERTICAL)
83            main_box.Add(vbox, 0, wxALL|wxEXPAND)
84    
85            label = wxStaticText(self, -1, _("Available Projections:"))
86            vbox.Add(label, 0, wxLEFT|wxRIGHT|wxTOP, 4)
87    
88            hbox = wxBoxSizer(wxHORIZONTAL)
89            vbox.Add(hbox, 1, wxALL|wxEXPAND)
90            self.availprojs = wxListBox(self, ID_PROJ_AVAIL,
91                                      style=wxLB_EXTENDED|wxLB_SORT)                                      style=wxLB_EXTENDED|wxLB_SORT)
92          self.projfilepath = wxStaticText(self.panel_1, -1, "")          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
93            hbox.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
94            self.__FillAvailList(selectCurrent = True)
95    
96          # Projection Specific Entries (Name/Projection)          # Projection List specific actions (Import/Export/Remove)
97          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))          buttons = wxBoxSizer(wxVERTICAL)
98          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")          hbox.Add(buttons, 0, wxALL)
99          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))          self.button_import = wxButton(self, ID_PROJ_IMPORT, _("Import..."))
100          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
101            buttons.Add(self.button_import, 1, wxALL|wxEXPAND, 4)
102            self.button_export = wxButton(self, ID_PROJ_EXPORT, _("Export..."))
103            EVT_BUTTON(self, ID_PROJ_EXPORT, self._OnExport)
104            buttons.Add(self.button_export, 1, wxALL|wxEXPAND, 4)
105            buttons.Add(20, 20, 0, wxEXPAND, 0)
106            self.button_remove = wxButton(self, ID_PROJ_REMOVE, _("Remove"))
107            EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)
108            buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4)
109    
110          # Projection Specific actions (New/Save/Add)          # The file path
111          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))          self.projfilepath = wxStaticText(self, -1, "")
112          self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,          vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND)
                                       _("Add to List"))  
         self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Update"))  
113    
114          # Main Action buttons (Try/Revert/OK/Close)          #
115          self.button_try = wxButton(self, wxID_APPLY, _("Try"))          #   The projection editor part
116          self.button_revert = wxButton(self, ID_PROJ_REVERT,          #
117                                        _("Revert"))          self.edit_box = wxStaticBox(self, -1, _("Edit"))
118          self.button_ok = wxButton(self, wxID_OK, _("OK"))          sizer_edit = wxStaticBoxSizer(self.edit_box, wxHORIZONTAL)
119          self.button_ok.SetDefault()          main_box.Add(sizer_edit, 1, wxALL|wxEXPAND)
         self.button_close = wxButton(self, wxID_CANCEL,  
                                      _("Close"))  
120    
121          self.__set_properties()          # Projection Specific Entries (Name/Projection)
122          self.__do_layout()          self.sizer_projctrls = wxBoxSizer(wxVERTICAL)
123            sizer_edit.Add(self.sizer_projctrls, 1, wxALL|wxEXPAND)
124    
125          # wxGlade          hbox = wxBoxSizer(wxHORIZONTAL)
126            self.sizer_projctrls.Add(hbox, 0, wxALL|wxEXPAND)
127            label = wxStaticText(self, -1, _("Name:"))
128            hbox.Add(label, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
129            self.projname = wxTextCtrl(self, ID_PROJ_PROJNAME, "")
130            EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
131            hbox.Add(self.projname, 1, wxALL|wxEXPAND, 4)
132    
133            hbox = wxBoxSizer(wxHORIZONTAL)
134            self.sizer_projctrls.Add(hbox, 0, wxALL|wxEXPAND)
135            label = wxStaticText(self, -1, _("Projection:"))
136            hbox.Add(label, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
137            self.projchoice = wxChoice(self, ID_PROJ_PROJCHOICE)
138            self.projchoice.SetSelection(0)
139            EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
140            hbox.Add(self.projchoice, 1, wxALL|wxEXPAND, 4)
141          # Fill the projection choice list.          # Fill the projection choice list.
142          for proj, name, clazz in self.projPanels:          for proj, name, clazz in self.projection_panels:
143              self.projchoice.Append(name, [clazz, None])              self.projchoice.Append(name, [clazz, None])
144    
145          self.originalProjection = self.receiver.GetProjection()          # Projection Specific actions (New/Save/Add)
146            buttons = wxBoxSizer(wxVERTICAL)
147            sizer_edit.Add(buttons, 0, wxALL)
148            self.button_new = wxButton(self, ID_PROJ_NEW, _("New"))
149            EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
150            buttons.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
151            self.button_add = wxButton(self, ID_PROJ_ADDTOLIST, _("Add to List"))
152            EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)
153            buttons.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
154            buttons.Add(20, 20, 0, wxEXPAND, 0)
155            self.button_save = wxButton(self, ID_PROJ_SAVE,_("Update"))
156            EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
157            buttons.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)
158    
159          self.__DoOnProjAvail()          #
160          self.button_ok.SetFocus()          # Main Action buttons (Try/Revert/OK/Close)
161          self.availprojs.SetFocus()          #
162                    buttons = wxBoxSizer(wxHORIZONTAL)
163            top_box.Add(buttons, 0, wxALL|wxALIGN_RIGHT, 10)
164            self.button_try = wxButton(self, wxID_APPLY, _("Try"))
165          EVT_BUTTON(self, wxID_APPLY, self.OnApply)          EVT_BUTTON(self, wxID_APPLY, self.OnApply)
166            buttons.Add(self.button_try, 0, wxRIGHT, 10)
167            self.button_revert = wxButton(self, ID_PROJ_REVERT, _("Revert"))
168          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
169            buttons.Add(self.button_revert, 0, wxRIGHT, 10)
170            self.button_ok = wxButton(self, wxID_OK, _("OK"))
171          EVT_BUTTON(self, wxID_OK, self.OnOK)          EVT_BUTTON(self, wxID_OK, self.OnOK)
172            self.button_ok.SetDefault()
173            buttons.Add(self.button_ok, 0, wxRIGHT, 10)
174            self.button_close = wxButton(self, wxID_CANCEL, _("Close"))
175          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
176          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          buttons.Add(self.button_close, 0, wxRIGHT, 10)
         EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)  
         EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)  
         EVT_BUTTON(self, ID_PROJ_EXPORT, self._OnExport)  
         EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)  
177    
         EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)  
         EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)  
         EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)  
178    
179          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          #
180            # Automatic Layout
181            #
182            self.SetAutoLayout(1)
183            self.SetSizer(top_box)
184            top_box.Fit(self)
185            top_box.SetSizeHints(self)
186    
187      def OnApply(self, event):      def OnApply(self, event):
188          self.__SetProjection()          self.__SetProjection()
# Line 328  class ProjFrame(NonModalNonParentDialog) Line 376  class ProjFrame(NonModalNonParentDialog)
376          self.button_save.Enable(True)          self.button_save.Enable(True)
377          self.button_remove.Enable(True)          self.button_remove.Enable(True)
378    
379          self.panel_edit.Enable(True)          self.edit_box.Enable(True)
380    
381          for ctrl in [self.button_import,          for ctrl in [self.button_import,
382                       self.button_export,                       self.button_export,
# Line 337  class ProjFrame(NonModalNonParentDialog) Line 385  class ProjFrame(NonModalNonParentDialog)
385                       self.button_add,                       self.button_add,
386                       self.projchoice,                       self.projchoice,
387                       self.projname,                       self.projname,
388                       self.panel_edit]:                       self.edit_box]:
389              ctrl.Enable(True)              ctrl.Enable(True)
390    
391          if self.curProjPanel is not None:          if self.curProjPanel is not None:
# Line 376  class ProjFrame(NonModalNonParentDialog) Line 424  class ProjFrame(NonModalNonParentDialog)
424                  self.button_save.Enable(False)                  self.button_save.Enable(False)
425    
426          else:          else:
427              self.panel_edit.Enable(False)              self.edit_box.Enable(False)
428    
429      def __DoOnProjAvail(self):      def __DoOnProjAvail(self):
430    
# Line 403  class ProjFrame(NonModalNonParentDialog) Line 451  class ProjFrame(NonModalNonParentDialog)
451    
452                  myProjType = proj.GetParameter("proj")                  myProjType = proj.GetParameter("proj")
453                  i = 0                  i = 0
454                  for projType, name, clazz in self.projPanels:                  for projType, name, clazz in self.projection_panels:
455                      if myProjType == projType:                      if myProjType == projType:
456                            self.projchoice.Enable(True)
457                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i)
458                          self.__DoOnProjChoice()                          self.__DoOnProjChoice()
459    
# Line 415  class ProjFrame(NonModalNonParentDialog) Line 464  class ProjFrame(NonModalNonParentDialog)
464                          assert self.curProjPanel is not None                          assert self.curProjPanel is not None
465    
466                          self.curProjPanel.SetProjection(proj)                          self.curProjPanel.SetProjection(proj)
467                            break
468                      i += 1                      i += 1
469                    else:
470                        self.projchoice.Disable()
471                        self._show_proj_panel(UnknownProjPanel(self,
472                                                               self.receiver))
473    
474          self.__VerifyButtons()          self.__VerifyButtons()
475    
# Line 432  class ProjFrame(NonModalNonParentDialog) Line 486  class ProjFrame(NonModalNonParentDialog)
486          At the end of this method self.curProjPanel will not be None          At the end of this method self.curProjPanel will not be None
487          if there was a item selected.          if there was a item selected.
488          """          """
   
489          choice = self.projchoice          choice = self.projchoice
490    
491          sel = choice.GetSelection()          sel = choice.GetSelection()
492          if sel != -1:          if sel != -1:
   
493              clazz, obj = choice.GetClientData(sel)              clazz, obj = choice.GetClientData(sel)
   
494              if obj is None:              if obj is None:
495                  obj = clazz(self.panel_edit, self.receiver)                  obj = clazz(self, self.receiver)
496                  choice.SetClientData(sel, [clazz, obj])                  choice.SetClientData(sel, [clazz, obj])
497                self._show_proj_panel(obj)
498    
499        def _show_proj_panel(self, panel):
500            """Show the panel as the projection panel"""
501            if self.curProjPanel is not None:
502                self.curProjPanel.Hide()
503                self.sizer_projctrls.Remove(self.curProjPanel)
504    
505              if self.curProjPanel is not None:          self.curProjPanel = panel
506                  self.curProjPanel.Hide()          self.curProjPanel.Show()
507                  self.sizer_projctrls.Remove(self.curProjPanel)  
508            self.sizer_projctrls.Add(self.curProjPanel, 1,
509              self.curProjPanel = obj              wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)
510              self.curProjPanel.Show()          self.sizer_projctrls.Layout()
511            self.Layout()
512              self.sizer_projctrls.Add(self.curProjPanel, 1,          self.topBox.SetSizeHints(self)
                 wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)  
             self.sizer_projctrls.Layout()  
             self.Layout()  
             self.topBox.SetSizeHints(self)  
513    
514      def __SetProjection(self):      def __SetProjection(self):
515          """Set the receiver's projection."""          """Set the receiver's projection."""
# Line 546  class ProjFrame(NonModalNonParentDialog) Line 600  class ProjFrame(NonModalNonParentDialog)
600                          self.availprojs.FindString(selectProj)                          self.availprojs.FindString(selectProj)
601                      )                      )
602    
                   
   
     def __set_properties(self):  
   
         #self.availprojs.SetSelection(0)  
         self.projchoice.SetSelection(0)  
   
         self.__FillAvailList(selectCurrent = True)  
   
         self.projname.SetMaxLength(32)  
   
     def __do_layout(self):  
         # originally generated by wxGlade  
   
         self.topBox = wxBoxSizer(wxVERTICAL)  
         self.sizer_panel = wxBoxSizer(wxVERTICAL)  
         sizer_6 = wxBoxSizer(wxHORIZONTAL)  
         self.sizer_mainbttns = wxBoxSizer(wxHORIZONTAL)  
         self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)  
         self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)  
         sizer_11 = wxBoxSizer(wxVERTICAL)  
         self.sizer_projctrls = wxBoxSizer(wxVERTICAL)  
         sizer_14 = wxBoxSizer(wxHORIZONTAL)  
         sizer_13 = wxBoxSizer(wxHORIZONTAL)  
         sizer_15 = wxBoxSizer(wxVERTICAL)  
         sizer_15.Add(self.button_import, 0, wxALL, 4)  
         sizer_15.Add(self.button_export, 0, wxALL, 4)  
         sizer_15.Add(20, 20, 0, wxEXPAND, 0)  
         sizer_15.Add(self.button_remove, 0, wxALL|wxALIGN_BOTTOM, 4)  
   
         # list controls  
         grid_sizer_1 = wxFlexGridSizer(3, 2, 0, 0)  
         grid_sizer_1.Add(self.label_5, 0, wxLEFT|wxRIGHT|wxTOP, 4)  
         grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)  
         grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)  
         grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)  
         grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4)  
         grid_sizer_1.AddGrowableRow(1)  
         grid_sizer_1.AddGrowableCol(0)  
   
         # edit controls  
         sizer_13.Add(self.label_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)  
         sizer_13.Add(self.projname, 1, wxALL, 4)  
         self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)  
         sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)  
         sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)  
         self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)  
         self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)  
         sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)  
         sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)  
         sizer_11.Add(20, 20, 0, wxEXPAND, 0)  
         sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)  
         self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)  
   
         sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)  
         sizer_6.Add(self.button_revert, 0, wxRIGHT| wxEXPAND, 10)  
         sizer_6.Add(self.button_ok, 0, wxRIGHT| wxEXPAND, 10)  
         sizer_6.Add(self.button_close, 0, wxRIGHT| wxEXPAND, 10)  
   
         self.panel_1.SetAutoLayout(1)  
         self.panel_1.SetSizer(grid_sizer_1)  
         grid_sizer_1.Fit(self.panel_1)  
         grid_sizer_1.SetSizeHints(self.panel_1)  
   
         self.panel_edit.SetAutoLayout(1)  
         self.panel_edit.SetSizer(self.sizer_edit)  
         self.sizer_edit.Fit(self.panel_edit)  
         self.sizer_edit.SetSizeHints(self.panel_edit)  
   
         self.sizer_mainctrls.Add(self.panel_1, 0,  
             wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)  
         self.sizer_mainctrls.Add(self.panel_edit, 1,  
             wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)  
   
         self.sizer_mainbttns.Add(sizer_6, 0,  
             wxALL|wxEXPAND|wxADJUST_MINSIZE, 10)  
   
         self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)  
         self.topBox.Add(self.sizer_mainbttns, 0, wxALIGN_RIGHT|wxBOTTOM, 0)  
   
         self.SetAutoLayout(1)  
         self.SetSizer(self.topBox)  
         self.topBox.Fit(self)  
         self.topBox.SetSizeHints(self)  
         self.Layout()  
   
 # end of class ProjFrame  
   
603    
604  class ProjPanel(wxPanel):  class ProjPanel(wxPanel):
605      """Base class for all projection panels."""      """Base class for all projection panels."""
# Line 701  ID_TMPANEL_FALSE_NORTH = 4004 Line 667  ID_TMPANEL_FALSE_NORTH = 4004
667  ID_TMPANEL_SCALE = 4005  ID_TMPANEL_SCALE = 4005
668    
669  class UnknownProjPanel(ProjPanel):  class UnknownProjPanel(ProjPanel):
670    
671        """Panel for unknown projection types"""
672    
673      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
674          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
675    
# Line 711  class UnknownProjPanel(ProjPanel): Line 680  class UnknownProjPanel(ProjPanel):
680    
681          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
682                                 _("Thuban does not know the parameters for the"                                 _("Thuban does not know the parameters for the"
683                                   " current projection and cannot display a"                                   " current projection\n"
684                                   " configuration panel.")))                                   "and cannot display a configuration panel.")))
685    
686          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
687    

Legend:
Removed from v.1786  
changed lines
  Added in v.1806

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26