/[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 730 by jonathan, Thu Apr 24 16:07:41 2003 UTC revision 1181 by jonathan, Thu Jun 12 16:29:06 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  # Frank Koormann <[email protected]>
5    #
6    # This program is free software under the GPL (>=v2)
7    # Read the file COPYING coming with Thuban for details.
8                                                                                    
9    import os, sys, math
10  from wxPython.wx import *  from wxPython.wx import *
11    
12  from Thuban import _  from Thuban import _
13    
14  from Thuban.Model.proj import Projection, ProjFile  from Thuban.Model.proj import Projection, ProjFile
15    
16  from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles, \  from Thuban.Model.resource import get_user_proj_files, get_system_proj_files, \
17                                    ReadProjFile, WriteProjFile                                    read_proj_file, write_proj_file
18  from Thuban.UI.dialogs import NonModalDialog  from Thuban.UI.dialogs import NonModalNonParentDialog
19    
20    
21  ID_PROJ_ADVANCED  = 4001  ID_PROJ_ADVANCED  = 4001
22  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
23  ID_PROJ_SAVEAS    = 4003  ID_PROJ_ADDTOLIST    = 4003
24  ID_PROJ_NEW       = 4004  ID_PROJ_NEW       = 4004
 ID_PROJ_TRY       = 4005  
25  ID_PROJ_REVERT    = 4006  ID_PROJ_REVERT    = 4006
 ID_PROJ_OK        = 4007  
 ID_PROJ_CLOSE     = 4008  
26  ID_PROJ_AVAIL     = 4009  ID_PROJ_AVAIL     = 4009
27  ID_PROJ_SAVE      = 4010  ID_PROJ_SAVE      = 4010
28  ID_PROJ_IMPORT    = 4011  ID_PROJ_IMPORT    = 4011
# Line 31  ID_PROJ_PROJNAME  = 4014 Line 33  ID_PROJ_PROJNAME  = 4014
33  CLIENT_PROJ = 0  CLIENT_PROJ = 0
34  CLIENT_PROJFILE = 1  CLIENT_PROJFILE = 1
35    
36  class ProjFrame(NonModalDialog):  class ProjFrame(NonModalNonParentDialog):
37    
38      def __init__(self, parent, name, receiver, *args, **kwds):      def __init__(self, parent, name, title, receiver):
39          """Initialize the projection dialog.          """Initialize the projection dialog.
40    
41          receiver -- An object that implements the following methods:          receiver -- An object that implements the following methods:
# Line 42  class ProjFrame(NonModalDialog): Line 44  class ProjFrame(NonModalDialog):
44          """          """
45                    
46          self.receiver = receiver          self.receiver = receiver
47          self.originalProjection = -1          self.haveTried = False
48          self.curProjPanel = None          self.curProjPanel = None
49    
50          self.projPanels = []          self.projPanels = []
# Line 55  class ProjFrame(NonModalDialog): Line 57  class ProjFrame(NonModalDialog):
57          self.projPanels.append(          self.projPanels.append(
58              ("latlong", _("Geographic"), GeoPanel))              ("latlong", _("Geographic"), GeoPanel))
59    
60          NonModalDialog.__init__(self, parent, name, "")          NonModalNonParentDialog.__init__(self, parent, name, title)
61          # originally generate by wxGlade          # originally generate by wxGlade
62          self.panel_1 = wxPanel(self, -1)          self.panel_1 = wxPanel(self, -1)
63          self.panel_edit = wxPanel(self, -1)          self.panel_edit = wxPanel(self, -1)
64          self.panel_buttons = wxPanel(self, -1)          self.label_5 = wxStaticText(self.panel_1, -1,
65          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))                          _("Available Projections:"))
66          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED |wxLB_SORT)  
67            # Projection List specific actions (Import/Export/Remove)
68            self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT,
69                                          _("Import..."))
70            self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT,
71                                          _("Export..."))
72            self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE,
73                                          _("Remove"))
74    
75            # The Projection List
76            self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL,
77                                        style=wxLB_EXTENDED|wxLB_SORT)
78          self.projfilepath = wxStaticText(self.panel_1, -1, "")          self.projfilepath = wxStaticText(self.panel_1, -1, "")
79    
80            # Projection Specific Entries (Name/Projection)
81          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))
82          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")
83          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))
84          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)
85          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, _("Import..."))  
86          self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT, _("Export..."))          # Projection Specific actions (New/Save/Add)
         self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove"))  
87          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))
88          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))          self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,
         self.button_add = wxButton(self.panel_edit, ID_PROJ_SAVEAS,  
89                                        _("Add to List"))                                        _("Add to List"))
90          self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Update"))
91          self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))  
92          self.button_ok = wxButton(self.panel_buttons, ID_PROJ_OK, _("OK"))          # Main Action buttons (Try/Revert/OK/Close)
93          self.button_close = wxButton(self.panel_buttons, ID_PROJ_CLOSE, _("Close"))          self.button_try = wxButton(self, wxID_APPLY, _("Try"))
94            self.button_revert = wxButton(self, ID_PROJ_REVERT,
95                                          _("Revert"))
96            self.button_ok = wxButton(self, wxID_OK, _("OK"))
97            self.button_ok.SetDefault()
98            self.button_close = wxButton(self, wxID_CANCEL,
99                                         _("Close"))
100    
101          self.__set_properties()          self.__set_properties()
102          self.__do_layout()          self.__do_layout()
103    
104          # wxGlade          # wxGlade
105    
106            # Fill the projection choice list.
107            for proj, name, clazz in self.projPanels:
108                self.projchoice.Append(name, [clazz, None])
109    
110            self.originalProjection = self.receiver.GetProjection()
111    
112          self.__DoOnProjAvail()          self.__DoOnProjAvail()
113            self.button_ok.SetFocus()
114            self.availprojs.SetFocus()
115                    
116          EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry)          EVT_BUTTON(self, wxID_APPLY, self.OnApply)
117          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
118          EVT_BUTTON(self, ID_PROJ_OK, self._OnOK)          EVT_BUTTON(self, wxID_OK, self.OnOK)
119          EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose)          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
120          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
121          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
122          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
# Line 97  class ProjFrame(NonModalDialog): Line 125  class ProjFrame(NonModalDialog):
125    
126          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
127          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
128          EVT_BUTTON(self, ID_PROJ_SAVEAS, self._OnSaveAs)          EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)
129    
130          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
131    
132      def GetReceiver(self):      def OnApply(self, event):
         return self.receiver  
   
     def _OnTry(self, event):  
133          self.__SetProjection()          self.__SetProjection()
134            self.haveTried = True
135    
136      def _OnRevert(self, event):      def OnOK(self, event):
         if self.originalProjection != -1:  
             self.receiver.SetProjection(self.originalProjection)  
   
     def _OnOK(self, event):  
137          self.__SetProjection()          self.__SetProjection()
138          self.Close()          self.Close()
139    
140      def _OnClose(self, event):      def OnCancel(self, event):
141            """Cancel just closes the dialog, but we call it cancel so we
142            can overload the functionality of wxDialog.
143            """
144          self.Close()          self.Close()
145    
146        def _OnRevert(self, event):
147            if self.haveTried:
148                self.receiver.SetProjection(self.originalProjection)
149                self.haveTried = False
150    
151      def _OnNew(self, event):      def _OnNew(self, event):
152          self.__DoOnNew()  
153            # clear all selections
154            sel = self.availprojs.GetSelections()
155            for index in sel:
156                self.availprojs.SetSelection(index, False)
157    
158            self.projname.Clear()
159    
160            # supply a projection panel if there wasn't one
161            if self.curProjPanel is None:
162                self.projchoice.SetSelection(0)
163                self.__DoOnProjChoice()
164    
165            self.curProjPanel.Clear()
166    
167      def _OnSave(self, event):      def _OnSave(self, event):
168    
# Line 133  class ProjFrame(NonModalDialog): Line 176  class ProjFrame(NonModalDialog):
176          newproj = self.__GetProjection()          newproj = self.__GetProjection()
177    
178          if newproj is not None:          if newproj is not None:
179              projfile.Remove(proj)              projfile.Replace(proj, newproj)
             projfile.Add(newproj)  
180              try:              try:
181                  WriteProjFile(projfile)                  write_proj_file(projfile)
182              except IOError, (errno, errstr):              except IOError, (errno, errstr):
183                  wxMessageDialog(self,                  self.__ShowError(projfile.GetFilename(), errstr)
184                      _("The following error occured:\n") +              self.availprojs.SetClientData(sel[0], [newproj, projfile])
                     projfile.GetFileName() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
             self.__FillAvailList()  
185    
186      def _OnSaveAs(self, event):              self.__FillAvailList( selectProj = newproj.GetName())
187    
188        def _OnAddToList(self, event):
189    
190          proj = self.__GetProjection()          proj = self.__GetProjection()
191          if proj is not None:          if proj is not None:
192              self.__usrProjFile.Add(proj)              self.__usrProjFile.Add(proj)
193              try:              try:
194                  WriteProjFile(self.__usrProjFile)                  write_proj_file(self.__usrProjFile)
195              except IOError, (errno, errstr):              except IOError, (errno, errstr):
196                  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()  
197    
198          return              self.__FillAvailList( selectProj = proj.GetName())
   
         """Save the projection somewhere.  
   
         There are three important cases to consider.  
             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()  
199    
200      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
201          self.__DoOnProjAvail()          self.__DoOnProjAvail()
# Line 248  class ProjFrame(NonModalDialog): Line 208  class ProjFrame(NonModalDialog):
208              path = dlg.GetPath()              path = dlg.GetPath()
209    
210              try:              try:
211                  projFile = ReadProjFile(path)                  projFile = read_proj_file(path)
212                  for proj in projFile.GetProjections():                  for proj in projFile.GetProjections():
213                      self.__usrProjFile.Add(proj)                      self.__usrProjFile.Add(proj)
214                  WriteProjFile(self.__usrProjFile)                  write_proj_file(self.__usrProjFile)
215              except IOError, (errno, errstr):              except IOError, (errno, errstr):
216                  wxMessageDialog(self,                  self.__ShowError(dlg.GetPath(), errstr)
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
217    
218              self.__FillAvailList()              self.__FillAvailList()
219    
220          dlg.Destroy()          dlg.Destroy()
221    
222      def _OnExport(self, event):      def _OnExport(self, event):
         proj = self.__GetProjection()  
223    
224          if proj is None: return          sel = self.availprojs.GetSelections()
225            assert len(sel) != 0, "button should be disabled"
226    
227          dlg = wxFileDialog(self, _("Export"),          dlg = wxFileDialog(self, _("Export"),
228                             style = wxSAVE|wxOVERWRITE_PROMPT)                          style = wxSAVE|wxOVERWRITE_PROMPT)
229    
230          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
231              path = dlg.GetPath()              path = dlg.GetPath()
232    
233              projFile = ProjFile(path)              projFile = ProjFile(path)
234              projFile.Add(proj)  
235                for i in sel:
236                    proj = self.availprojs.GetClientData(i)[CLIENT_PROJ]
237                    if proj is not None:
238                        projFile.Add(proj)
239    
240              try:              try:
241                  WriteProjFile(projFile)                  write_proj_file(projFile)
242              except IOError, (errno, errstr):              except IOError, (errno, errstr):
243                  wxMessageDialog(self,                  self.__ShowError(dlg.GetPath(), errstr)
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
244    
245          dlg.Destroy()          dlg.Destroy()
246    
# Line 314  class ProjFrame(NonModalDialog): Line 273  class ProjFrame(NonModalDialog):
273                  projfile.Remove(proj)                  projfile.Remove(proj)
274    
275          try:          try:
276              WriteProjFile(projfile)              write_proj_file(projfile)
277          except IOError, (errno, errstr):          except IOError, (errno, errstr):
278              wxMessageDialog(self,              self.__ShowError(projfile.GetFilename(), errstr)
                 _("The following error occured:\n") +  
                 projfile.GetFileName() + "\n" + errstr,  
                 _("Error"), wxOK | wxICON_ERROR).ShowModal()  
   
279    
280          self.__FillAvailList()          self.__FillAvailList()
281    
# Line 332  class ProjFrame(NonModalDialog): Line 287  class ProjFrame(NonModalDialog):
287          if newselection != -1 and self.availprojs.GetCount() > 0:          if newselection != -1 and self.availprojs.GetCount() > 0:
288              self.availprojs.SetSelection(newselection)              self.availprojs.SetSelection(newselection)
289    
290            self.__VerifyButtons()
291    
292      def _OnProjName(self, event):      def _OnProjName(self, event):
293          self.__VerifyButtons()          self.__VerifyButtons()
294    
295        def __ShowError(self, filename, errstr):
296            wxMessageDialog(self,
297                _("The following error occured:\n") +
298                filename + "\n" + errstr,
299                _("Error"), wxOK | wxICON_ERROR).ShowModal()
300    
301      def __VerifyButtons(self):      def __VerifyButtons(self):
302            """Enable or disable the appropriate buttons based on the
303            current state of the dialog.
304            """
305    
306          sel = self.availprojs.GetSelections()          sel = self.availprojs.GetSelections()
307    
308          self.button_import.Enable(True)          self.button_import.Enable(True)
# Line 345  class ProjFrame(NonModalDialog): Line 312  class ProjFrame(NonModalDialog):
312    
313          self.panel_edit.Enable(True)          self.panel_edit.Enable(True)
314    
315            for ctrl in [self.button_import,
316                         self.button_export,
317                         self.button_remove,
318                         self.button_save,
319                         self.button_add,
320                         self.projchoice,
321                         self.projname,
322                         self.panel_edit]:
323                ctrl.Enable(True)
324    
325            if self.curProjPanel is not None:
326                self.curProjPanel.Enable(True)
327    
328          if len(sel) == 0:          if len(sel) == 0:
329              self.button_import.Enable(True)              self.button_import.Enable(True)
330              self.button_export.Enable(False)              self.button_export.Enable(False)
331              self.button_remove.Enable(False)              self.button_remove.Enable(False)
332                self.button_save.Enable(False)
333    
334          elif len(sel) == 1:          elif len(sel) == 1:
335    
# Line 358  class ProjFrame(NonModalDialog): Line 339  class ProjFrame(NonModalDialog):
339              self.button_add.Enable(len(self.projname.GetValue()) > 0)              self.button_add.Enable(len(self.projname.GetValue()) > 0)
340    
341              if proj is None:              if proj is None:
342                  self.button_export.Enable(False)                  # <None> is selected
343                    for ctrl in [self.button_export,
344                                 self.button_remove,
345                                 self.button_save,
346                                 self.button_add,
347                                 self.projchoice,
348                                 self.projname]:
349                        ctrl.Enable(False)
350    
351                    if self.curProjPanel is not None:
352                        self.curProjPanel.Enable(False)
353    
354                elif proj is self.originalProjection:
355                  self.button_remove.Enable(False)                  self.button_remove.Enable(False)
356    
357              if projFile is None:              if projFile is None:
# Line 367  class ProjFrame(NonModalDialog): Line 360  class ProjFrame(NonModalDialog):
360          else:          else:
361              self.panel_edit.Enable(False)              self.panel_edit.Enable(False)
362    
     def __DoOnNew(self):  
         sel = self.availprojs.GetSelections()  
         if len(sel) != 0:  
             self.availprojs.SetSelection(sel, False)  
         self.projname.Clear()  
         self.curProjPanel.Clear()  
   
363      def __DoOnProjAvail(self):      def __DoOnProjAvail(self):
364    
365          sel = self.availprojs.GetSelections()          sel = self.availprojs.GetSelections()
# Line 385  class ProjFrame(NonModalDialog): Line 371  class ProjFrame(NonModalDialog):
371              if proj is None:              if proj is None:
372                  # user selected <None>                  # user selected <None>
373                  self.projname.Clear()                  self.projname.Clear()
374                    
375              else:              else:
376                            
377                  if projfile is not None:                  if projfile is not None:
378                      self.projfilepath.SetLabel(projfile.GetFileName())                      self.projfilepath.SetLabel(_("Projection File: ") +
379                            os.path.basename(projfile.GetFilename()))
380                  else:                  else:
381                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
382                      self.projfilepath.SetLabel("")                      self.projfilepath.SetLabel(_("Projection File: "))
383    
384                  self.projname.SetValue(proj.GetName())                  self.projname.SetValue(proj.GetName())
385    
# Line 401  class ProjFrame(NonModalDialog): Line 389  class ProjFrame(NonModalDialog):
389                      if myProjType == projType:                      if myProjType == projType:
390                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i)
391                          self.__DoOnProjChoice()                          self.__DoOnProjChoice()
392    
393                            #
394                            # self.curProjPanel should not be null
395                            # after a call to __DoOnProjChoice
396                            #
397                            assert self.curProjPanel is not None
398    
399                          self.curProjPanel.SetProjection(proj)                          self.curProjPanel.SetProjection(proj)
400                      i += 1                      i += 1
401    
# Line 410  class ProjFrame(NonModalDialog): Line 405  class ProjFrame(NonModalDialog):
405          self.__DoOnProjChoice()          self.__DoOnProjChoice()
406    
407      def __DoOnProjChoice(self):      def __DoOnProjChoice(self):
408            """Create and layout a projection panel based on the selected
409            projection type.
410    
411            This is necessary to have in seperate method since calls to
412            wxChoice.SetSelection() do not trigger an event.
413    
414            At the end of this method self.curProjPanel will not be None
415            if there was a item selected.
416            """
417    
418          choice = self.projchoice          choice = self.projchoice
419    
420          sel = choice.GetSelection()          sel = choice.GetSelection()
# Line 435  class ProjFrame(NonModalDialog): Line 440  class ProjFrame(NonModalDialog):
440              self.topBox.SetSizeHints(self)              self.topBox.SetSizeHints(self)
441    
442      def __SetProjection(self):      def __SetProjection(self):
443            """Set the receiver's projection."""
444    
445          #          #
446          # save the original projection only once in case          # save the original projection only once in case
447          # we try to apply several different projections          # we try to apply several different projections
448          #          #
         if self.originalProjection == -1:  
             self.originalProjection = self.receiver.GetProjection()  
   
449          self.receiver.SetProjection(self.__GetProjection())          self.receiver.SetProjection(self.__GetProjection())
450    
451      def __GetProjection(self):      def __GetProjection(self):
452          """Return the packaged projection.          """Return a suitable Projection object based on the current
453            state of the dialog box selections.
454    
455          Could be None.          Could be None.
456          """          """
457    
458          proj = None          sel = self.availprojs.GetSelections()
459            assert len(sel) < 2, "button should be disabled"
460    
461    
462            if len(sel) == 1:
463                proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ]
464                if proj is None:
465                    # <None> is selected
466                    return None
467    
468            #
469            # self.curProjPanel should always contain the most
470            # relevant data for a projection
471            #
472          if self.curProjPanel is not None:          if self.curProjPanel is not None:
473              proj = Projection(self.curProjPanel.GetParameters())              return Projection(self.curProjPanel.GetParameters(),
474              proj.SetName(self.projname.GetValue())                                self.projname.GetValue())
475    
476          return proj          return None
477    
478        def __FillAvailList(self, selectCurrent = False, selectProj = None):
479            """Populate the list of available projections.
480            
481            selectCurrent -- if True, select the projection used by
482                             the receiver, otherwise select nothing.
483            selectProj    -- if set, select the projection found under the
484                             specified name. This overwrites any other
485                             selection estimate.
486            """
487    
     def __FillAvailList(self):  
488          self.availprojs.Clear()          self.availprojs.Clear()
489    
490          #          #
# Line 468  class ProjFrame(NonModalDialog): Line 493  class ProjFrame(NonModalDialog):
493          #          #
494          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append("<None>", (None, None))
495    
496          self.__sysProjFile = None          projfile = get_system_proj_files()
497          self.__usrProjFile = None          projfile = projfile[0]
498            for proj in projfile.GetProjections():
499          projfile = GetSystemProjFiles()              self.availprojs.Append(proj.GetName(), [proj, projfile])
500          if len(projfile) > 0:          self.__sysProjFile = projfile
501              projfile = projfile[0]  
502              for proj in projfile.GetProjections():          projfile = get_user_proj_files()
503                  self.availprojs.Append(proj.GetName(), [proj, projfile])          projfile = projfile[0]
504              self.__sysProjFile = projfile          for proj in projfile.GetProjections():
505                self.availprojs.Append(proj.GetName(), [proj, projfile])
506          projfile = GetUserProjFiles()          self.__usrProjFile = projfile
         if len(projfile) > 0:  
             projfile = projfile[0]  
             for proj in projfile.GetProjections():  
                 self.availprojs.Append(proj.GetName(), [proj, 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  
507    
508            #
509            # We add the current projection to the list at last.
510            # Since the list is resorted immediately a following FindString()
511            # determines the index correctly.
512            #
513          proj = self.receiver.GetProjection()          proj = self.receiver.GetProjection()
514          if proj is not None:          if proj is not None:
515              self.availprojs.Append(proj.GetName() + _(" (current)"),              proj_item = _("%s (current)") % proj.GetName()
516                                     [proj, None])              self.availprojs.Append(proj_item, [proj, None])
517                if selectCurrent:
518                    self.availprojs.SetSelection(
519                            self.availprojs.FindString(proj_item)
520                        )
521            else:
522                if selectCurrent:
523                    self.availprojs.SetSelection(
524                            self.availprojs.FindString("<None>")
525                        )
526            if selectProj:
527                self.availprojs.SetSelection(
528                            self.availprojs.FindString(selectProj)
529                        )
530    
531          for proj, name, clazz in self.projPanels:                  
             self.projchoice.Append(name, [clazz, None])  
532    
533      def __set_properties(self):      def __set_properties(self):
         self.__FillAvailList()  
534    
535          # begin wxGlade: ProjFrame.__set_properties          #self.availprojs.SetSelection(0)
         self.SetTitle(_("Projections"))  
         self.availprojs.SetSelection(0)  
536          self.projchoice.SetSelection(0)          self.projchoice.SetSelection(0)
537          # end wxGlade  
538            self.__FillAvailList(selectCurrent = True)
539    
540          self.projname.SetMaxLength(32)          self.projname.SetMaxLength(32)
541    
# Line 522  class ProjFrame(NonModalDialog): Line 545  class ProjFrame(NonModalDialog):
545          self.topBox = wxBoxSizer(wxVERTICAL)          self.topBox = wxBoxSizer(wxVERTICAL)
546          self.sizer_panel = wxBoxSizer(wxVERTICAL)          self.sizer_panel = wxBoxSizer(wxVERTICAL)
547          sizer_6 = wxBoxSizer(wxHORIZONTAL)          sizer_6 = wxBoxSizer(wxHORIZONTAL)
548            self.sizer_mainbttns = wxBoxSizer(wxHORIZONTAL)
549          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)
550          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)
551          sizer_11 = wxBoxSizer(wxVERTICAL)          sizer_11 = wxBoxSizer(wxVERTICAL)
# Line 540  class ProjFrame(NonModalDialog): Line 564  class ProjFrame(NonModalDialog):
564          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)
565          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
566          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)
567          grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4)
568          grid_sizer_1.AddGrowableRow(1)          grid_sizer_1.AddGrowableRow(1)
569          grid_sizer_1.AddGrowableCol(0)          grid_sizer_1.AddGrowableCol(0)
570    
# Line 549  class ProjFrame(NonModalDialog): Line 573  class ProjFrame(NonModalDialog):
573          sizer_13.Add(self.projname, 1, wxALL, 4)          sizer_13.Add(self.projname, 1, wxALL, 4)
574          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)
575          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
576          sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
577          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
578          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
579          sizer_11.Add(self.button_new, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
580          sizer_11.Add(self.button_save, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
581          sizer_11.Add(self.button_add, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(20, 20, 0, wxEXPAND, 0)
582            sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)
583          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)
584    
585          sizer_6.Add(20, 20, 1, wxEXPAND, 0)          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)
586          sizer_6.Add(self.button_try, 0, wxALL, 4)          sizer_6.Add(self.button_revert, 0, wxRIGHT| wxEXPAND, 10)
587          sizer_6.Add(20, 20, 1, 0, 0)          sizer_6.Add(self.button_ok, 0, wxRIGHT| wxEXPAND, 10)
588          sizer_6.Add(self.button_revert, 0, wxALL, 4)          sizer_6.Add(self.button_close, 0, wxRIGHT| wxEXPAND, 10)
         sizer_6.Add(20, 20, 1, 0, 0)  
         sizer_6.Add(self.button_ok, 0, wxALL, 4)  
         sizer_6.Add(20, 20, 1, 0, 0)  
         sizer_6.Add(self.button_close, 0, wxALL, 4)  
         sizer_6.Add(20, 20, 1, wxEXPAND, 0)  
589    
590          self.panel_1.SetAutoLayout(1)          self.panel_1.SetAutoLayout(1)
591          self.panel_1.SetSizer(grid_sizer_1)          self.panel_1.SetSizer(grid_sizer_1)
# Line 577  class ProjFrame(NonModalDialog): Line 597  class ProjFrame(NonModalDialog):
597          self.sizer_edit.Fit(self.panel_edit)          self.sizer_edit.Fit(self.panel_edit)
598          self.sizer_edit.SetSizeHints(self.panel_edit)          self.sizer_edit.SetSizeHints(self.panel_edit)
599    
         self.panel_buttons.SetAutoLayout(1)  
         self.panel_buttons.SetSizer(sizer_6)  
         sizer_6.Fit(self.panel_buttons)  
         sizer_6.SetSizeHints(self.panel_buttons)  
   
600          self.sizer_mainctrls.Add(self.panel_1, 0,          self.sizer_mainctrls.Add(self.panel_1, 0,
601              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
602          self.sizer_mainctrls.Add(self.panel_edit, 1,          self.sizer_mainctrls.Add(self.panel_edit, 1,
603              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
604    
605            self.sizer_mainbttns.Add(sizer_6, 0,
606                wxALL|wxEXPAND|wxADJUST_MINSIZE, 10)
607    
608          self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)          self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)
609          self.topBox.Add(self.panel_buttons, 0, wxEXPAND, 0)          self.topBox.Add(self.sizer_mainbttns, 0, wxALIGN_RIGHT|wxBOTTOM, 0)
610    
611          self.SetAutoLayout(1)          self.SetAutoLayout(1)
612          self.SetSizer(self.topBox)          self.SetSizer(self.topBox)
# Line 606  class ProjPanel(wxPanel): Line 624  class ProjPanel(wxPanel):
624          wxPanel.__init__(self, parent, -1)          wxPanel.__init__(self, parent, -1)
625    
626          self.__ellps = wxChoice(self, -1)          self.__ellps = wxChoice(self, -1)
627          self.ellpsData = [("bessel", _("Bessel 1841")),          self.ellpsData = [("airy"  , _("Airy")),
628                              ("bessel", _("Bessel 1841")),
629                            ("clrk66", _("Clarke 1866")),                            ("clrk66", _("Clarke 1866")),
630                            ("clrk80", _("Clarke 1880")),                            ("clrk80", _("Clarke 1880")),
631                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),
# Line 622  class ProjPanel(wxPanel): Line 641  class ProjPanel(wxPanel):
641    
642          panelSizer = wxBoxSizer(wxVERTICAL)          panelSizer = wxBoxSizer(wxVERTICAL)
643    
         if childPanel is not None:  
             panelSizer.Add(childPanel, 0, wxALL|wxEXPAND, 4)  
               
644          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
645          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0,
646          sizer.Add(self.__ellps, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)                                      wxALL|wxALIGN_CENTER_VERTICAL, 4)
647            sizer.Add(self.__ellps, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
648          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)
649    
650            if childPanel is not None:
651                panelSizer.Add(childPanel, 0, wxEXPAND, 0)
652                
653          self.SetAutoLayout(1)          self.SetAutoLayout(1)
654          self.SetSizer(panelSizer)          self.SetSizer(panelSizer)
655          panelSizer.Fit(self)          panelSizer.Fit(self)
# Line 695  class TMPanel(ProjPanel): Line 715  class TMPanel(ProjPanel):
715    
716          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)
717          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)
718            self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)
719          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)
720          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)
         self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)  
721    
722          self._DoLayout()          self._DoLayout()
723    
# Line 763  class UTMPanel(ProjPanel): Line 783  class UTMPanel(ProjPanel):
783          self.receiver = receiver          self.receiver = receiver
784    
785          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)
786            self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))
787          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,
788                                    _("Southern Hemisphere"))                                    _("Southern Hemisphere"))
         self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))  
789    
790          self._DoLayout()          self._DoLayout()
791    
# Line 834  class LCCPanel(ProjPanel): Line 854  class LCCPanel(ProjPanel):
854          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
855              _("Latitude of second standard parallel:")))              _("Latitude of second standard parallel:")))
856          sizer.Add(self.__sspLatitude, 0, wxALL, 4)          sizer.Add(self.__sspLatitude, 0, wxALL, 4)
         sizer.Add(wxStaticText(self, -1, _("Latitude of origin:")))  
         sizer.Add(self.__originLat, 0, wxALL, 4)  
857          sizer.Add(wxStaticText(self, -1, _("Central Meridian:")))          sizer.Add(wxStaticText(self, -1, _("Central Meridian:")))
858          sizer.Add(self.__meridian, 0, wxALL, 4)          sizer.Add(self.__meridian, 0, wxALL, 4)
859            sizer.Add(wxStaticText(self, -1, _("Latitude of origin:")))
860            sizer.Add(self.__originLat, 0, wxALL, 4)
861          sizer.Add(wxStaticText(self, -1, _("False Easting:")))          sizer.Add(wxStaticText(self, -1, _("False Easting:")))
862          sizer.Add(self.__falseEast, 0, wxALL, 4)          sizer.Add(self.__falseEast, 0, wxALL, 4)
863          sizer.Add(wxStaticText(self, -1, _("False Northing:")))          sizer.Add(wxStaticText(self, -1, _("False Northing:")))
# Line 885  class GeoPanel(ProjPanel): Line 905  class GeoPanel(ProjPanel):
905    
906      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
907          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
908          ProjPanel._DoLayout(self, None)  
909            self.__choices = [(_("Degrees"), "0.017453"),
910                              (_("Radians"), "1")]
911    
912            self.__scale = wxChoice(self, -1)
913            for choice, value in self.__choices:
914                self.__scale.Append(choice, value)
915    
916            self._DoLayout()
917    
918      def GetProjName(self):      def GetProjName(self):
919          return _("Geographic")          return _("Geographic")
920                    
921      def SetProjection(self, proj):      def SetProjection(self, proj):
922            value = proj.GetParameter("to_meter")
923            for i in range(len(self.__choices)):
924                choice, data = self.__choices[i]
925                if value == data:
926                    self.__scale.SetSelection(i)
927          ProjPanel.SetProjection(self, proj)          ProjPanel.SetProjection(self, proj)
928    
929      def GetParameters(self):      def GetParameters(self):
930          params = ["proj=latlong"]          params = ["proj=latlong",
931                      "to_meter=%s" % self.__scale.GetClientData(
932                                      self.__scale.GetSelection())]
933    
934          params.extend(ProjPanel.GetParameters(self))          params.extend(ProjPanel.GetParameters(self))
935          return params          return params
936    
937      def Clear(self):      def Clear(self):
938          ProjPanel.Clear(self)          ProjPanel.Clear(self)
939    
940        def _DoLayout(self):
941            sizer = wxBoxSizer(wxHORIZONTAL)
942    
943            sizer.Add(wxStaticText(self, -1, _("Source Data is in: ")),
944                      0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
945            sizer.Add(self.__scale, 1, wxEXPAND|wxALL, 4)
946    
947            self.__scale.SetSelection(0)
948    
949            ProjPanel._DoLayout(self, sizer)
950    
951    
952  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001
953  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002

Legend:
Removed from v.730  
changed lines
  Added in v.1181

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26