/[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 734 by bh, Thu Apr 24 19:14:16 2003 UTC revision 903 by jonathan, Wed May 14 11:16:28 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/env python  # Copyright (c) 2003 by Intevation GmbH
2  # generated by wxGlade 0.2.1 on Thu Apr 17 11:51:39 2003  # Authors:
3    # Jonathan Coles <[email protected]>
4  import os, sys  #
5    # This program is free software under the GPL (>=v2)
6    # Read the file COPYING coming with Thuban for details.
7                                                                                    
8    import os, sys, math
9  from wxPython.wx import *  from wxPython.wx import *
10    
11  from Thuban import _  from Thuban import _
# Line 15  from Thuban.UI.dialogs import NonModalDi Line 19  from Thuban.UI.dialogs import NonModalDi
19    
20  ID_PROJ_ADVANCED  = 4001  ID_PROJ_ADVANCED  = 4001
21  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
22  ID_PROJ_SAVEAS    = 4003  ID_PROJ_ADDTOLIST    = 4003
23  ID_PROJ_NEW       = 4004  ID_PROJ_NEW       = 4004
 ID_PROJ_TRY       = 4005  
24  ID_PROJ_REVERT    = 4006  ID_PROJ_REVERT    = 4006
 ID_PROJ_OK        = 4007  
 ID_PROJ_CLOSE     = 4008  
25  ID_PROJ_AVAIL     = 4009  ID_PROJ_AVAIL     = 4009
26  ID_PROJ_SAVE      = 4010  ID_PROJ_SAVE      = 4010
27  ID_PROJ_IMPORT    = 4011  ID_PROJ_IMPORT    = 4011
# Line 33  CLIENT_PROJFILE = 1 Line 34  CLIENT_PROJFILE = 1
34    
35  class ProjFrame(NonModalDialog):  class ProjFrame(NonModalDialog):
36    
37      def __init__(self, parent, name, receiver, *args, **kwds):      def __init__(self, parent, name, title, receiver):
38          """Initialize the projection dialog.          """Initialize the projection dialog.
39    
40          receiver -- An object that implements the following methods:          receiver -- An object that implements the following methods:
# Line 42  class ProjFrame(NonModalDialog): Line 43  class ProjFrame(NonModalDialog):
43          """          """
44                    
45          self.receiver = receiver          self.receiver = receiver
46          self.originalProjection = -1          self.haveTried = False
47          self.curProjPanel = None          self.curProjPanel = None
48    
49          self.projPanels = []          self.projPanels = []
# Line 55  class ProjFrame(NonModalDialog): Line 56  class ProjFrame(NonModalDialog):
56          self.projPanels.append(          self.projPanels.append(
57              ("latlong", _("Geographic"), GeoPanel))              ("latlong", _("Geographic"), GeoPanel))
58    
59          NonModalDialog.__init__(self, parent, name, "")          NonModalDialog.__init__(self, parent, name, title)
60          # originally generate by wxGlade          # originally generate by wxGlade
61          self.panel_1 = wxPanel(self, -1)          self.panel_1 = wxPanel(self, -1)
62          self.panel_edit = wxPanel(self, -1)          self.panel_edit = wxPanel(self, -1)
63          self.panel_buttons = wxPanel(self, -1)          self.panel_buttons = wxPanel(self, -1)
64          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))          self.label_5 = wxStaticText(self.panel_1, -1,
65          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED |wxLB_SORT)                          _("Available Projections:"))
66            self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL,
67                                        style=wxLB_EXTENDED|wxLB_SORT)
68          self.projfilepath = wxStaticText(self.panel_1, -1, "")          self.projfilepath = wxStaticText(self.panel_1, -1, "")
69          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))
70          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")
71          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))
72          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)
73          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, _("Import..."))          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT,
74          self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT, _("Export..."))                                        _("Import..."))
75            self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT,
76                                          _("Export..."))
77          self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove"))          self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove"))
78          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))
79          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))
80          self.button_add = wxButton(self.panel_edit, ID_PROJ_SAVEAS,          self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,
81                                        _("Add to List"))                                        _("Add to List"))
82          self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))          self.button_try = wxButton(self.panel_buttons, wxID_APPLY, _("Try"))
83          self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))          self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT,
84          self.button_ok = wxButton(self.panel_buttons, ID_PROJ_OK, _("OK"))                                        _("Revert"))
85          self.button_close = wxButton(self.panel_buttons, ID_PROJ_CLOSE, _("Close"))          self.button_ok = wxButton(self.panel_buttons, wxID_OK, _("OK"))
86            self.button_ok.SetDefault()
87            self.button_close = wxButton(self.panel_buttons, wxID_CANCEL,
88                                         _("Close"))
89    
90          self.__set_properties()          self.__set_properties()
91          self.__do_layout()          self.__do_layout()
92          # wxGlade          # wxGlade
93    
94            self.originalProjection = self.receiver.GetProjection()
95    
96          self.__DoOnProjAvail()          self.__DoOnProjAvail()
97            self.button_ok.SetFocus()
98            self.availprojs.SetFocus()
99                    
100          EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry)          EVT_BUTTON(self, wxID_APPLY, self.OnApply)
101          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
102          EVT_BUTTON(self, ID_PROJ_OK, self._OnOK)          EVT_BUTTON(self, wxID_OK, self.OnOK)
103          EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose)          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
104          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
105          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
106          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
# Line 97  class ProjFrame(NonModalDialog): Line 109  class ProjFrame(NonModalDialog):
109    
110          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
111          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
112          EVT_BUTTON(self, ID_PROJ_SAVEAS, self._OnSaveAs)          EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)
113    
114          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
115    
     def GetReceiver(self):  
         return self.receiver  
116    
117      def _OnTry(self, event):      def OnApply(self, event):
118          self.__SetProjection()          self.__SetProjection()
119            self.haveTried = True
120    
121      def _OnRevert(self, event):      def OnOK(self, event):
         if self.originalProjection != -1:  
             self.receiver.SetProjection(self.originalProjection)  
   
     def _OnOK(self, event):  
122          self.__SetProjection()          self.__SetProjection()
123          self.Close()          self.Close()
124    
125      def _OnClose(self, event):      def OnCancel(self, event):
126            """Cancel just closes the dialog, but we call it cancel so we
127            can overload the functionality of wxDialog.
128            """
129          self.Close()          self.Close()
130    
131        def _OnRevert(self, event):
132            if self.haveTried:
133                self.receiver.SetProjection(self.originalProjection)
134                self.haveTried = False
135    
136    
137      def _OnNew(self, event):      def _OnNew(self, event):
138          self.__DoOnNew()  
139            # clear all selections
140            sel = self.availprojs.GetSelections()
141            for index in sel:
142                self.availprojs.SetSelection(index, False)
143    
144            self.projname.Clear()
145    
146            # supply a projection panel if there wasn't one
147            if self.curProjPanel is None:
148                self.projchoice.SetSelection(0)
149                self.__DoOnProjChoice()
150    
151            self.curProjPanel.Clear()
152    
153      def _OnSave(self, event):      def _OnSave(self, event):
154    
# Line 133  class ProjFrame(NonModalDialog): Line 162  class ProjFrame(NonModalDialog):
162          newproj = self.__GetProjection()          newproj = self.__GetProjection()
163    
164          if newproj is not None:          if newproj is not None:
165              projfile.Remove(proj)              projfile.Replace(proj, newproj)
             projfile.Add(newproj)  
166              try:              try:
167                  WriteProjFile(projfile)                  WriteProjFile(projfile)
168              except IOError, (errno, errstr):              except IOError, (errno, errstr):
169                  wxMessageDialog(self,                  self.__ShowError(projfile.GetFilename(), errstr)
170                      _("The following error occured:\n") +              self.availprojs.SetClientData(sel[0], [newproj, projfile])
                     projfile.GetFileName() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
             self.__FillAvailList()  
171    
172      def _OnSaveAs(self, event):      def _OnAddToList(self, event):
173    
174          proj = self.__GetProjection()          proj = self.__GetProjection()
175          if proj is not None:          if proj is not None:
# Line 152  class ProjFrame(NonModalDialog): Line 177  class ProjFrame(NonModalDialog):
177              try:              try:
178                  WriteProjFile(self.__usrProjFile)                  WriteProjFile(self.__usrProjFile)
179              except IOError, (errno, errstr):              except IOError, (errno, errstr):
180                  wxMessageDialog(self,                  self.__ShowError(self.__userProjFile.GetFilename(), errstr)
                     _("The following error occured:\n") +  
                     self.__usrProjFile.GetFileName() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
             self.__FillAvailList()  
   
         return  
   
         """Save the projection somewhere.  
181    
182          There are three important cases to consider.              self.__FillAvailList()
             1. the file already exists and the user wants to overwrite it.  
             2. the file already exists and the user wants to append the  
                current projection to the end of the file  
             3. the file doesn't exist and the user wants to create it  
   
         The list of available projections is then updated.  
         """  
   
         proj = Projection(self.curProjPanel.GetParameters())  
         if self.projname.GetValue() != "":  
             proj.SetName(self.projname.GetValue())  
   
         dlg = wxFileDialog(self, _("Save As"), style = wxSAVE)  
         if dlg.ShowModal() == wxID_OK:  
             path = dlg.GetPath()  
   
             if os.access(path, os.F_OK):  
                 # file already exists.  
                 if os.access(path, os.W_OK | os.R_OK):  
                   
                     # is it a .proj file?  
                     try:  
                         projFile = ReadProjFile(path)  
                     except:  
                         # obviously not.  
                         dlg = wxMessageDialog(self,  
                             path + _(" already exists. Overwrite?"),  
                             "",  
                             wxYES | wxNO)  
   
                         if dlg.ShowModal() == wxID_YES:  
                             projFile = ProjFile(path)  
                         else:  
                             return # returning early  
                     else:  
                         # ask the user to overwrite or append  
                         dlg = wxMessageDialog(self,  
                             _("The selected projection file already exists.\n"+  
                               "The current projection can be added to the " +  
                               "file, or it can completely replace the " +  
                               "selected file.\n\nShould the current " +  
                               "projection be added to the file?"),  
                             _("Question"),  
                             wxYES | wxNO | wxICON_QUESTION)  
   
                         if dlg.ShowModal() == wxID_NO:  
                             projFile = ProjFile(path)  
                 else:  
                     # can't access the file  
                     dlg = wxMessageDialog(self,  
                         _("Couldn't access ") + path,  
                         "",  
                         wxOK | wxICON | wxICON_EXCLAMATION)  
                     return  
   
             else:  
                 # file doesn't exist. make a new one.  
                 projFile = ProjFile(path)  
                   
             #  
             # if we get this far we have a valid projFile and  
             # can just write the file  
             #  
             projFile.Add(proj)  
             try:  
                 WriteProjFile(projFile)  
                 self.__FillAvailList()  
             except IOError, (errno, errstr):  
                 wxMessageDialog(self,  
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
         dlg.Destroy()  
183    
184      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
185          self.__DoOnProjAvail()          self.__DoOnProjAvail()
# Line 253  class ProjFrame(NonModalDialog): Line 197  class ProjFrame(NonModalDialog):
197                      self.__usrProjFile.Add(proj)                      self.__usrProjFile.Add(proj)
198                  WriteProjFile(self.__usrProjFile)                  WriteProjFile(self.__usrProjFile)
199              except IOError, (errno, errstr):              except IOError, (errno, errstr):
200                  wxMessageDialog(self,                  self.__ShowError(dlg.GetPath(), errstr)
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
201    
202              self.__FillAvailList()              self.__FillAvailList()
203    
204          dlg.Destroy()          dlg.Destroy()
205    
206      def _OnExport(self, event):      def _OnExport(self, event):
         proj = self.__GetProjection()  
207    
208          if proj is None: return          sel = self.availprojs.GetSelections()
209            assert len(sel) != 0, "button should be disabled"
210    
211          dlg = wxFileDialog(self, _("Export"),          dlg = wxFileDialog(self, _("Export"),
212                             style = wxSAVE|wxOVERWRITE_PROMPT)                          style = wxSAVE|wxOVERWRITE_PROMPT)
213    
214          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
215              path = dlg.GetPath()              path = dlg.GetPath()
216    
217              projFile = ProjFile(path)              projFile = ProjFile(path)
218              projFile.Add(proj)  
219                for i in sel:
220                    proj = self.availprojs.GetClientData(i)[CLIENT_PROJ]
221                    if proj is not None:
222                        projFile.Add(proj)
223    
224              try:              try:
225                  WriteProjFile(projFile)                  WriteProjFile(projFile)
226              except IOError, (errno, errstr):              except IOError, (errno, errstr):
227                  wxMessageDialog(self,                  self.__ShowError(dlg.GetPath(), errstr)
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
228    
229          dlg.Destroy()          dlg.Destroy()
230    
# Line 316  class ProjFrame(NonModalDialog): Line 259  class ProjFrame(NonModalDialog):
259          try:          try:
260              WriteProjFile(projfile)              WriteProjFile(projfile)
261          except IOError, (errno, errstr):          except IOError, (errno, errstr):
262              wxMessageDialog(self,              self.__ShowError(projfile.GetFilename(), errstr)
                 _("The following error occured:\n") +  
                 projfile.GetFileName() + "\n" + errstr,  
                 _("Error"), wxOK | wxICON_ERROR).ShowModal()  
   
263    
264          self.__FillAvailList()          self.__FillAvailList()
265    
# Line 332  class ProjFrame(NonModalDialog): Line 271  class ProjFrame(NonModalDialog):
271          if newselection != -1 and self.availprojs.GetCount() > 0:          if newselection != -1 and self.availprojs.GetCount() > 0:
272              self.availprojs.SetSelection(newselection)              self.availprojs.SetSelection(newselection)
273    
274            self.__VerifyButtons()
275    
276      def _OnProjName(self, event):      def _OnProjName(self, event):
277          self.__VerifyButtons()          self.__VerifyButtons()
278    
279        def __ShowError(self, filename, errstr):
280            wxMessageDialog(self,
281                _("The following error occured:\n") +
282                filename + "\n" + errstr,
283                _("Error"), wxOK | wxICON_ERROR).ShowModal()
284    
285      def __VerifyButtons(self):      def __VerifyButtons(self):
286            """Enable or disable the appropriate buttons based on the
287            current state of the dialog.
288            """
289    
290          sel = self.availprojs.GetSelections()          sel = self.availprojs.GetSelections()
291    
292          self.button_import.Enable(True)          self.button_import.Enable(True)
# Line 345  class ProjFrame(NonModalDialog): Line 296  class ProjFrame(NonModalDialog):
296    
297          self.panel_edit.Enable(True)          self.panel_edit.Enable(True)
298    
299            for ctrl in [self.button_import,
300                         self.button_export,
301                         self.button_remove,
302                         self.button_save,
303                         self.button_add,
304                         self.projchoice,
305                         self.projname,
306                         self.panel_edit]:
307                ctrl.Enable(True)
308    
309            if self.curProjPanel is not None:
310                self.curProjPanel.Enable(True)
311    
312          if len(sel) == 0:          if len(sel) == 0:
313              self.button_import.Enable(True)              self.button_import.Enable(True)
314              self.button_export.Enable(False)              self.button_export.Enable(False)
315              self.button_remove.Enable(False)              self.button_remove.Enable(False)
316                self.button_save.Enable(False)
317    
318          elif len(sel) == 1:          elif len(sel) == 1:
319    
# Line 358  class ProjFrame(NonModalDialog): Line 323  class ProjFrame(NonModalDialog):
323              self.button_add.Enable(len(self.projname.GetValue()) > 0)              self.button_add.Enable(len(self.projname.GetValue()) > 0)
324    
325              if proj is None:              if proj is None:
326                  self.button_export.Enable(False)                  # <None> is selected
327                    for ctrl in [self.button_export,
328                                 self.button_remove,
329                                 self.button_save,
330                                 self.button_add,
331                                 self.projchoice,
332                                 self.projname]:
333                        ctrl.Enable(False)
334    
335                    if self.curProjPanel is not None:
336                        self.curProjPanel.Enable(False)
337    
338                elif proj is self.originalProjection:
339                  self.button_remove.Enable(False)                  self.button_remove.Enable(False)
340    
341              if projFile is None:              if projFile is None:
# Line 367  class ProjFrame(NonModalDialog): Line 344  class ProjFrame(NonModalDialog):
344          else:          else:
345              self.panel_edit.Enable(False)              self.panel_edit.Enable(False)
346    
     def __DoOnNew(self):  
         sel = self.availprojs.GetSelections()  
         if len(sel) != 0:  
             self.availprojs.SetSelection(sel, False)  
         self.projname.Clear()  
         self.curProjPanel.Clear()  
   
347      def __DoOnProjAvail(self):      def __DoOnProjAvail(self):
348    
349          sel = self.availprojs.GetSelections()          sel = self.availprojs.GetSelections()
# Line 385  class ProjFrame(NonModalDialog): Line 355  class ProjFrame(NonModalDialog):
355              if proj is None:              if proj is None:
356                  # user selected <None>                  # user selected <None>
357                  self.projname.Clear()                  self.projname.Clear()
358                    
359              else:              else:
360                            
361                  if projfile is not None:                  if projfile is not None:
362                      self.projfilepath.SetLabel(projfile.GetFileName())                      self.projfilepath.SetLabel(projfile.GetFilename())
363                  else:                  else:
364                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
365                      self.projfilepath.SetLabel("")                      self.projfilepath.SetLabel("")
# Line 401  class ProjFrame(NonModalDialog): Line 372  class ProjFrame(NonModalDialog):
372                      if myProjType == projType:                      if myProjType == projType:
373                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i)
374                          self.__DoOnProjChoice()                          self.__DoOnProjChoice()
375    
376                            #
377                            # self.curProjPanel should not be null
378                            # after a call to __DoOnProjChoice
379                            #
380                            assert self.curProjPanel is not None
381    
382                          self.curProjPanel.SetProjection(proj)                          self.curProjPanel.SetProjection(proj)
383                      i += 1                      i += 1
384    
# Line 410  class ProjFrame(NonModalDialog): Line 388  class ProjFrame(NonModalDialog):
388          self.__DoOnProjChoice()          self.__DoOnProjChoice()
389    
390      def __DoOnProjChoice(self):      def __DoOnProjChoice(self):
391            """Create and layout a projection panel based on the selected
392            projection type.
393    
394            This is necessary to have in seperate method since calls to
395            wxChoice.SetSelection() do not trigger an event.
396    
397            At the end of this method self.curProjPanel will not be None
398            if there was a item selected.
399            """
400    
401          choice = self.projchoice          choice = self.projchoice
402    
403          sel = choice.GetSelection()          sel = choice.GetSelection()
# Line 435  class ProjFrame(NonModalDialog): Line 423  class ProjFrame(NonModalDialog):
423              self.topBox.SetSizeHints(self)              self.topBox.SetSizeHints(self)
424    
425      def __SetProjection(self):      def __SetProjection(self):
426            """Set the receiver's projection."""
427    
428          #          #
429          # save the original projection only once in case          # save the original projection only once in case
430          # we try to apply several different projections          # we try to apply several different projections
431          #          #
         if self.originalProjection == -1:  
             self.originalProjection = self.receiver.GetProjection()  
   
432          self.receiver.SetProjection(self.__GetProjection())          self.receiver.SetProjection(self.__GetProjection())
433    
434      def __GetProjection(self):      def __GetProjection(self):
435          """Return the packaged projection.          """Return a suitable Projection object based on the current
436            state of the dialog box selections.
437    
438          Could be None.          Could be None.
439          """          """
440    
441          proj = None          sel = self.availprojs.GetSelections()
442            assert len(sel) < 2, "button should be disabled"
443    
444    
445            if len(sel) == 1:
446                proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ]
447                if proj is None:
448                    # <None> is selected
449                    return None
450    
451            #
452            # self.curProjPanel should always contain the most
453            # relevant data for a projection
454            #
455          if self.curProjPanel is not None:          if self.curProjPanel is not None:
456              proj = Projection(self.curProjPanel.GetParameters())              return Projection(self.curProjPanel.GetParameters(),
457              proj.SetName(self.projname.GetValue())                                self.projname.GetValue())
458    
459            return None
460    
461          return proj      def __FillAvailList(self, selectCurrent = False):
462            """Populate the list of available projections.
463            
464            selectCurrent -- if True, select the projection used by
465                             the receiver, otherwise select nothing.
466            """
467    
     def __FillAvailList(self):  
468          self.availprojs.Clear()          self.availprojs.Clear()
469    
470          #          #
471            # We add the current projection to the list first so that
472            # we are sure that it's at index 0. That way we can
473            # set the selection with confidence. The problem is the
474            # the list is automatically sorted when an item is appended
475            # and the index of where it was inserted is not returned.
476            #
477            proj = self.receiver.GetProjection()
478            if proj is not None:
479                self.availprojs.Append(_("%s (current)") % proj.GetName(),
480                                       [proj, None])
481                if selectCurrent:
482                    self.availprojs.SetSelection(0)
483                    self.availprojs.SetFirstItem(0)
484    
485            #
486          # the list can never be empty. there will always be          # the list can never be empty. there will always be
487          # at least this one item          # at least this one item
488          #          #
489          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append("<None>", (None, None))
490    
491          self.__sysProjFile = None          # proj is only None when <None> should be selected
492          self.__usrProjFile = None          if proj is None and selectCurrent:
493                self.availprojs.SetSelection(0)
494                self.availprojs.SetFirstItem(0)
495    
496          projfile = GetSystemProjFiles()          projfile = GetSystemProjFiles()
497          if len(projfile) > 0:          projfile = projfile[0]
498              projfile = projfile[0]          for proj in projfile.GetProjections():
499              for proj in projfile.GetProjections():              self.availprojs.Append(proj.GetName(), [proj, projfile])
500                  self.availprojs.Append(proj.GetName(), [proj, projfile])          self.__sysProjFile = projfile
             self.__sysProjFile = projfile  
501    
502          projfile = GetUserProjFiles()          projfile = GetUserProjFiles()
503          if len(projfile) > 0:          projfile = projfile[0]
504              projfile = projfile[0]          for proj in projfile.GetProjections():
505              for proj in projfile.GetProjections():              self.availprojs.Append(proj.GetName(), [proj, projfile])
506                  self.availprojs.Append(proj.GetName(), [proj, projfile])          self.__usrProjFile = projfile
             self.__usrProjFile = projfile  
   
 #       projfiles = GetSystemProjFiles()  
 #       for projfile in projfiles:  
 #           for proj in projfile.GetProjections():  
 #               self.availprojs.Append(proj.GetName(), [proj, projfile])  
 #       self.__sysProjFiles = projfiles  
   
 #       projfiles = GetUserProjFiles()  
 #       for projfile in projfiles:  
 #           for proj in projfile.GetProjections():  
 #               self.availprojs.Append(proj.GetName(), [proj, projfile])  
 #       self.__usrProjFiles = projfiles  
   
         proj = self.receiver.GetProjection()  
         if proj is not None:  
             self.availprojs.Append(proj.GetName() + _(" (current)"),  
                                    [proj, None])  
507    
508          for proj, name, clazz in self.projPanels:          for proj, name, clazz in self.projPanels:
509              self.projchoice.Append(name, [clazz, None])              self.projchoice.Append(name, [clazz, None])
510    
511      def __set_properties(self):      def __set_properties(self):
         self.__FillAvailList()  
512    
513          # begin wxGlade: ProjFrame.__set_properties          #self.availprojs.SetSelection(0)
         self.SetTitle(_("Projections"))  
         self.availprojs.SetSelection(0)  
514          self.projchoice.SetSelection(0)          self.projchoice.SetSelection(0)
515          # end wxGlade  
516            self.__FillAvailList(selectCurrent = True)
517    
518          self.projname.SetMaxLength(32)          self.projname.SetMaxLength(32)
519    
# Line 548  class ProjFrame(NonModalDialog): Line 549  class ProjFrame(NonModalDialog):
549          sizer_13.Add(self.label_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_13.Add(self.label_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
550          sizer_13.Add(self.projname, 1, wxALL, 4)          sizer_13.Add(self.projname, 1, wxALL, 4)
551          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)
552          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_14.Add(self.label_3, 0, wxALL, 4)
553          sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
554          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
555          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
# Line 606  class ProjPanel(wxPanel): Line 607  class ProjPanel(wxPanel):
607          wxPanel.__init__(self, parent, -1)          wxPanel.__init__(self, parent, -1)
608    
609          self.__ellps = wxChoice(self, -1)          self.__ellps = wxChoice(self, -1)
610          self.ellpsData = [("bessel", _("Bessel 1841")),          self.ellpsData = [("airy"  , _("Airy")),
611                              ("bessel", _("Bessel 1841")),
612                            ("clrk66", _("Clarke 1866")),                            ("clrk66", _("Clarke 1866")),
613                            ("clrk80", _("Clarke 1880")),                            ("clrk80", _("Clarke 1880")),
614                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),
# Line 623  class ProjPanel(wxPanel): Line 625  class ProjPanel(wxPanel):
625          panelSizer = wxBoxSizer(wxVERTICAL)          panelSizer = wxBoxSizer(wxVERTICAL)
626    
627          if childPanel is not None:          if childPanel is not None:
628              panelSizer.Add(childPanel, 0, wxALL|wxEXPAND, 4)              panelSizer.Add(childPanel, 0, wxEXPAND, 0)
629                            
630          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
631          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)
# Line 763  class UTMPanel(ProjPanel): Line 765  class UTMPanel(ProjPanel):
765          self.receiver = receiver          self.receiver = receiver
766    
767          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)
768            self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))
769          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,
770                                    _("Southern Hemisphere"))                                    _("Southern Hemisphere"))
         self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))  
771    
772          self._DoLayout()          self._DoLayout()
773    
# Line 885  class GeoPanel(ProjPanel): Line 887  class GeoPanel(ProjPanel):
887    
888      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
889          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
890          ProjPanel._DoLayout(self, None)  
891            self.__choices = [(_("Radians"), "1"),
892                              (_("Degrees"), "0.017453")]
893    
894            self.__scale = wxChoice(self, -1)
895            for choice, value in self.__choices:
896                self.__scale.Append(choice, value)
897    
898            self._DoLayout()
899    
900      def GetProjName(self):      def GetProjName(self):
901          return _("Geographic")          return _("Geographic")
902                    
903      def SetProjection(self, proj):      def SetProjection(self, proj):
904            value = proj.GetParameter("to_meter")
905            for i in range(len(self.__choices)):
906                choice, data = self.__choices[i]
907                if value == data:
908                    self.__scale.SetSelection(i)
909          ProjPanel.SetProjection(self, proj)          ProjPanel.SetProjection(self, proj)
910    
911      def GetParameters(self):      def GetParameters(self):
912          params = ["proj=latlong"]          params = ["proj=latlong",
913                      "to_meter=%s" % self.__scale.GetClientData(
914                                      self.__scale.GetSelection())]
915    
916          params.extend(ProjPanel.GetParameters(self))          params.extend(ProjPanel.GetParameters(self))
917          return params          return params
918    
919      def Clear(self):      def Clear(self):
920          ProjPanel.Clear(self)          ProjPanel.Clear(self)
921    
922        def _DoLayout(self):
923            sizer = wxBoxSizer(wxHORIZONTAL)
924    
925            sizer.Add(wxStaticText(self, -1, _("Source Data is in: ")),
926                      0, wxALL, 4)
927            sizer.Add(self.__scale, 1, wxEXPAND|wxALL, 4)
928    
929            self.__scale.SetSelection(0)
930    
931            ProjPanel._DoLayout(self, sizer)
932    
933    
934  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001
935  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002

Legend:
Removed from v.734  
changed lines
  Added in v.903

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26