/[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 1542 by bh, Fri Aug 1 16:13:49 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    # 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    """Projection dialog"""
10    
11    __version__ = "$Revision$"
12    # $Source$
13    # $Id$
14    
15  import os, sys  import os, sys, math
16  from wxPython.wx import *  from wxPython.wx import *
17    
18  from Thuban import _  from Thuban import _
19    
20  from Thuban.Model.proj import Projection, ProjFile  from Thuban.Model.proj import Projection, ProjFile
21    
22  from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles, \  from Thuban.Model.resource import get_user_proj_files, get_system_proj_files, \
23                                    ReadProjFile, WriteProjFile                                    read_proj_file, write_proj_file
24  from Thuban.UI.dialogs import NonModalDialog  from Thuban.UI.dialogs import NonModalNonParentDialog
25    
26    
27  ID_PROJ_ADVANCED  = 4001  ID_PROJ_ADVANCED  = 4001
28  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
29  ID_PROJ_SAVEAS    = 4003  ID_PROJ_ADDTOLIST    = 4003
30  ID_PROJ_NEW       = 4004  ID_PROJ_NEW       = 4004
 ID_PROJ_TRY       = 4005  
31  ID_PROJ_REVERT    = 4006  ID_PROJ_REVERT    = 4006
 ID_PROJ_OK        = 4007  
 ID_PROJ_CLOSE     = 4008  
32  ID_PROJ_AVAIL     = 4009  ID_PROJ_AVAIL     = 4009
33  ID_PROJ_SAVE      = 4010  ID_PROJ_SAVE      = 4010
34  ID_PROJ_IMPORT    = 4011  ID_PROJ_IMPORT    = 4011
# Line 31  ID_PROJ_PROJNAME  = 4014 Line 39  ID_PROJ_PROJNAME  = 4014
39  CLIENT_PROJ = 0  CLIENT_PROJ = 0
40  CLIENT_PROJFILE = 1  CLIENT_PROJFILE = 1
41    
42  class ProjFrame(NonModalDialog):  class ProjFrame(NonModalNonParentDialog):
43    
44      def __init__(self, parent, name, receiver, *args, **kwds):      def __init__(self, parent, name, title, receiver):
45          """Initialize the projection dialog.          """Initialize the projection dialog.
46    
47          receiver -- An object that implements the following methods:          receiver -- An object that implements the following methods:
# Line 42  class ProjFrame(NonModalDialog): Line 50  class ProjFrame(NonModalDialog):
50          """          """
51                    
52          self.receiver = receiver          self.receiver = receiver
53          self.originalProjection = -1          self.haveTried = False
54          self.curProjPanel = None          self.curProjPanel = None
55    
56          self.projPanels = []          self.projPanels = []
# Line 55  class ProjFrame(NonModalDialog): Line 63  class ProjFrame(NonModalDialog):
63          self.projPanels.append(          self.projPanels.append(
64              ("latlong", _("Geographic"), GeoPanel))              ("latlong", _("Geographic"), GeoPanel))
65    
66          NonModalDialog.__init__(self, parent, name, "")          NonModalNonParentDialog.__init__(self, parent, name, title)
67          # originally generate by wxGlade          # originally generate by wxGlade
68          self.panel_1 = wxPanel(self, -1)          self.panel_1 = wxPanel(self, -1)
69          self.panel_edit = wxPanel(self, -1)          self.panel_edit = wxPanel(self, -1)
70          self.panel_buttons = wxPanel(self, -1)          self.label_5 = wxStaticText(self.panel_1, -1,
71          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))                          _("Available Projections:"))
72          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED |wxLB_SORT)  
73            # Projection List specific actions (Import/Export/Remove)
74            self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT,
75                                          _("Import..."))
76            self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT,
77                                          _("Export..."))
78            self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE,
79                                          _("Remove"))
80    
81            # The Projection List
82            self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL,
83                                        style=wxLB_EXTENDED|wxLB_SORT)
84          self.projfilepath = wxStaticText(self.panel_1, -1, "")          self.projfilepath = wxStaticText(self.panel_1, -1, "")
85    
86            # Projection Specific Entries (Name/Projection)
87          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))
88          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")
89          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))
90          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)
91          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, _("Import..."))  
92          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"))  
93          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))
94          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,  
95                                        _("Add to List"))                                        _("Add to List"))
96          self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Update"))
97          self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))  
98          self.button_ok = wxButton(self.panel_buttons, ID_PROJ_OK, _("OK"))          # Main Action buttons (Try/Revert/OK/Close)
99          self.button_close = wxButton(self.panel_buttons, ID_PROJ_CLOSE, _("Close"))          self.button_try = wxButton(self, wxID_APPLY, _("Try"))
100            self.button_revert = wxButton(self, ID_PROJ_REVERT,
101                                          _("Revert"))
102            self.button_ok = wxButton(self, wxID_OK, _("OK"))
103            self.button_ok.SetDefault()
104            self.button_close = wxButton(self, wxID_CANCEL,
105                                         _("Close"))
106    
107          self.__set_properties()          self.__set_properties()
108          self.__do_layout()          self.__do_layout()
109    
110          # wxGlade          # wxGlade
111    
112            # Fill the projection choice list.
113            for proj, name, clazz in self.projPanels:
114                self.projchoice.Append(name, [clazz, None])
115    
116            self.originalProjection = self.receiver.GetProjection()
117    
118          self.__DoOnProjAvail()          self.__DoOnProjAvail()
119            self.button_ok.SetFocus()
120            self.availprojs.SetFocus()
121                    
122          EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry)          EVT_BUTTON(self, wxID_APPLY, self.OnApply)
123          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
124          EVT_BUTTON(self, ID_PROJ_OK, self._OnOK)          EVT_BUTTON(self, wxID_OK, self.OnOK)
125          EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose)          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
126          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
127          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
128          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
# Line 97  class ProjFrame(NonModalDialog): Line 131  class ProjFrame(NonModalDialog):
131    
132          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
133          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
134          EVT_BUTTON(self, ID_PROJ_SAVEAS, self._OnSaveAs)          EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)
135    
136          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
137    
138      def GetReceiver(self):      def OnApply(self, event):
         return self.receiver  
   
     def _OnTry(self, event):  
139          self.__SetProjection()          self.__SetProjection()
140            self.haveTried = True
141    
142      def _OnRevert(self, event):      def OnOK(self, event):
         if self.originalProjection != -1:  
             self.receiver.SetProjection(self.originalProjection)  
   
     def _OnOK(self, event):  
143          self.__SetProjection()          self.__SetProjection()
144          self.Close()          self.Close()
145    
146      def _OnClose(self, event):      def OnCancel(self, event):
147            """Cancel just closes the dialog, but we call it cancel so we
148            can overload the functionality of wxDialog.
149            """
150          self.Close()          self.Close()
151    
152        def _OnRevert(self, event):
153            if self.haveTried:
154                self.receiver.SetProjection(self.originalProjection)
155                self.haveTried = False
156    
157      def _OnNew(self, event):      def _OnNew(self, event):
158          self.__DoOnNew()  
159            # clear all selections
160            sel = self.availprojs.GetSelections()
161            for index in sel:
162                self.availprojs.SetSelection(index, False)
163    
164            self.projname.Clear()
165    
166            # supply a projection panel if there wasn't one
167            if self.curProjPanel is None:
168                self.projchoice.SetSelection(0)
169                self.__DoOnProjChoice()
170    
171            self.curProjPanel.Clear()
172    
173      def _OnSave(self, event):      def _OnSave(self, event):
174    
# Line 133  class ProjFrame(NonModalDialog): Line 182  class ProjFrame(NonModalDialog):
182          newproj = self.__GetProjection()          newproj = self.__GetProjection()
183    
184          if newproj is not None:          if newproj is not None:
185              projfile.Remove(proj)              projfile.Replace(proj, newproj)
             projfile.Add(newproj)  
186              try:              try:
187                  WriteProjFile(projfile)                  write_proj_file(projfile)
188              except IOError, (errno, errstr):              except IOError, (errno, errstr):
189                  wxMessageDialog(self,                  self.__ShowError(projfile.GetFilename(), errstr)
190                      _("The following error occured:\n") +              self.availprojs.SetClientData(sel[0], [newproj, projfile])
                     projfile.GetFileName() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
             self.__FillAvailList()  
191    
192      def _OnSaveAs(self, event):              self.__FillAvailList( selectProj = newproj.GetName())
193    
194        def _OnAddToList(self, event):
195    
196          proj = self.__GetProjection()          proj = self.__GetProjection()
197          if proj is not None:          if proj is not None:
198              self.__usrProjFile.Add(proj)              self.__usrProjFile.Add(proj)
199              try:              try:
200                  WriteProjFile(self.__usrProjFile)                  write_proj_file(self.__usrProjFile)
201              except IOError, (errno, errstr):              except IOError, (errno, errstr):
202                  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.  
   
         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  
203    
204          The list of available projections is then updated.              self.__FillAvailList( selectProj = proj.GetName())
         """  
   
         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()  
205    
206      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
207          self.__DoOnProjAvail()          self.__DoOnProjAvail()
# Line 248  class ProjFrame(NonModalDialog): Line 214  class ProjFrame(NonModalDialog):
214              path = dlg.GetPath()              path = dlg.GetPath()
215    
216              try:              try:
217                  projFile = ReadProjFile(path)                  projFile = read_proj_file(path)
218                  for proj in projFile.GetProjections():                  for proj in projFile.GetProjections():
219                      self.__usrProjFile.Add(proj)                      self.__usrProjFile.Add(proj)
220                  WriteProjFile(self.__usrProjFile)                  write_proj_file(self.__usrProjFile)
221              except IOError, (errno, errstr):              except IOError, (errno, errstr):
222                  wxMessageDialog(self,                  self.__ShowError(dlg.GetPath(), errstr)
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
223    
224              self.__FillAvailList()              self.__FillAvailList()
225    
226          dlg.Destroy()          dlg.Destroy()
227    
228      def _OnExport(self, event):      def _OnExport(self, event):
         proj = self.__GetProjection()  
229    
230          if proj is None: return          sel = self.availprojs.GetSelections()
231            assert len(sel) != 0, "button should be disabled"
232    
233          dlg = wxFileDialog(self, _("Export"),          dlg = wxFileDialog(self, _("Export"),
234                             style = wxSAVE|wxOVERWRITE_PROMPT)                          style = wxSAVE|wxOVERWRITE_PROMPT)
235    
236          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
237              path = dlg.GetPath()              path = dlg.GetPath()
238    
239              projFile = ProjFile(path)              projFile = ProjFile(path)
240              projFile.Add(proj)  
241                for i in sel:
242                    proj = self.availprojs.GetClientData(i)[CLIENT_PROJ]
243                    if proj is not None:
244                        projFile.Add(proj)
245    
246              try:              try:
247                  WriteProjFile(projFile)                  write_proj_file(projFile)
248              except IOError, (errno, errstr):              except IOError, (errno, errstr):
249                  wxMessageDialog(self,                  self.__ShowError(dlg.GetPath(), errstr)
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
250    
251          dlg.Destroy()          dlg.Destroy()
252    
# Line 314  class ProjFrame(NonModalDialog): Line 279  class ProjFrame(NonModalDialog):
279                  projfile.Remove(proj)                  projfile.Remove(proj)
280    
281          try:          try:
282              WriteProjFile(projfile)              write_proj_file(projfile)
283          except IOError, (errno, errstr):          except IOError, (errno, errstr):
284              wxMessageDialog(self,              self.__ShowError(projfile.GetFilename(), errstr)
                 _("The following error occured:\n") +  
                 projfile.GetFileName() + "\n" + errstr,  
                 _("Error"), wxOK | wxICON_ERROR).ShowModal()  
   
285    
286          self.__FillAvailList()          self.__FillAvailList()
287    
# Line 332  class ProjFrame(NonModalDialog): Line 293  class ProjFrame(NonModalDialog):
293          if newselection != -1 and self.availprojs.GetCount() > 0:          if newselection != -1 and self.availprojs.GetCount() > 0:
294              self.availprojs.SetSelection(newselection)              self.availprojs.SetSelection(newselection)
295    
296            self.__VerifyButtons()
297    
298      def _OnProjName(self, event):      def _OnProjName(self, event):
299          self.__VerifyButtons()          self.__VerifyButtons()
300    
301        def __ShowError(self, filename, errstr):
302            wxMessageDialog(self,
303                _("The following error occured:\n") +
304                filename + "\n" + errstr,
305                _("Error"), wxOK | wxICON_ERROR).ShowModal()
306    
307      def __VerifyButtons(self):      def __VerifyButtons(self):
308            """Enable or disable the appropriate buttons based on the
309            current state of the dialog.
310            """
311    
312          sel = self.availprojs.GetSelections()          sel = self.availprojs.GetSelections()
313    
314          self.button_import.Enable(True)          self.button_import.Enable(True)
# Line 345  class ProjFrame(NonModalDialog): Line 318  class ProjFrame(NonModalDialog):
318    
319          self.panel_edit.Enable(True)          self.panel_edit.Enable(True)
320    
321            for ctrl in [self.button_import,
322                         self.button_export,
323                         self.button_remove,
324                         self.button_save,
325                         self.button_add,
326                         self.projchoice,
327                         self.projname,
328                         self.panel_edit]:
329                ctrl.Enable(True)
330    
331            if self.curProjPanel is not None:
332                self.curProjPanel.Enable(True)
333    
334          if len(sel) == 0:          if len(sel) == 0:
335              self.button_import.Enable(True)              self.button_import.Enable(True)
336              self.button_export.Enable(False)              self.button_export.Enable(False)
337              self.button_remove.Enable(False)              self.button_remove.Enable(False)
338                self.button_save.Enable(False)
339    
340          elif len(sel) == 1:          elif len(sel) == 1:
341    
# Line 358  class ProjFrame(NonModalDialog): Line 345  class ProjFrame(NonModalDialog):
345              self.button_add.Enable(len(self.projname.GetValue()) > 0)              self.button_add.Enable(len(self.projname.GetValue()) > 0)
346    
347              if proj is None:              if proj is None:
348                  self.button_export.Enable(False)                  # <None> is selected
349                    for ctrl in [self.button_export,
350                                 self.button_remove,
351                                 self.button_save,
352                                 self.button_add,
353                                 self.projchoice,
354                                 self.projname]:
355                        ctrl.Enable(False)
356    
357                    if self.curProjPanel is not None:
358                        self.curProjPanel.Enable(False)
359    
360                elif proj is self.originalProjection:
361                  self.button_remove.Enable(False)                  self.button_remove.Enable(False)
362    
363              if projFile is None:              if projFile is None:
# Line 367  class ProjFrame(NonModalDialog): Line 366  class ProjFrame(NonModalDialog):
366          else:          else:
367              self.panel_edit.Enable(False)              self.panel_edit.Enable(False)
368    
     def __DoOnNew(self):  
         sel = self.availprojs.GetSelections()  
         if len(sel) != 0:  
             self.availprojs.SetSelection(sel, False)  
         self.projname.Clear()  
         self.curProjPanel.Clear()  
   
369      def __DoOnProjAvail(self):      def __DoOnProjAvail(self):
370    
371          sel = self.availprojs.GetSelections()          sel = self.availprojs.GetSelections()
# Line 385  class ProjFrame(NonModalDialog): Line 377  class ProjFrame(NonModalDialog):
377              if proj is None:              if proj is None:
378                  # user selected <None>                  # user selected <None>
379                  self.projname.Clear()                  self.projname.Clear()
380                    self.projfilepath.SetLabel(_("Projection File: "))
381              else:              else:
382                            
383                  if projfile is not None:                  if projfile is not None:
384                      self.projfilepath.SetLabel(projfile.GetFileName())                      self.projfilepath.SetLabel(_("Projection File: ") +
385                            os.path.basename(projfile.GetFilename()))
386                  else:                  else:
387                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
388                      self.projfilepath.SetLabel("")                      self.projfilepath.SetLabel(_("Projection File: "))
389    
390                  self.projname.SetValue(proj.GetName())                  self.projname.SetValue(proj.GetName())
391    
# Line 401  class ProjFrame(NonModalDialog): Line 395  class ProjFrame(NonModalDialog):
395                      if myProjType == projType:                      if myProjType == projType:
396                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i)
397                          self.__DoOnProjChoice()                          self.__DoOnProjChoice()
398    
399                            #
400                            # self.curProjPanel should not be null
401                            # after a call to __DoOnProjChoice
402                            #
403                            assert self.curProjPanel is not None
404    
405                          self.curProjPanel.SetProjection(proj)                          self.curProjPanel.SetProjection(proj)
406                      i += 1                      i += 1
407    
# Line 410  class ProjFrame(NonModalDialog): Line 411  class ProjFrame(NonModalDialog):
411          self.__DoOnProjChoice()          self.__DoOnProjChoice()
412    
413      def __DoOnProjChoice(self):      def __DoOnProjChoice(self):
414            """Create and layout a projection panel based on the selected
415            projection type.
416    
417            This is necessary to have in seperate method since calls to
418            wxChoice.SetSelection() do not trigger an event.
419    
420            At the end of this method self.curProjPanel will not be None
421            if there was a item selected.
422            """
423    
424          choice = self.projchoice          choice = self.projchoice
425    
426          sel = choice.GetSelection()          sel = choice.GetSelection()
# Line 435  class ProjFrame(NonModalDialog): Line 446  class ProjFrame(NonModalDialog):
446              self.topBox.SetSizeHints(self)              self.topBox.SetSizeHints(self)
447    
448      def __SetProjection(self):      def __SetProjection(self):
449            """Set the receiver's projection."""
450    
451          #          #
452          # save the original projection only once in case          # save the original projection only once in case
453          # we try to apply several different projections          # we try to apply several different projections
454          #          #
         if self.originalProjection == -1:  
             self.originalProjection = self.receiver.GetProjection()  
   
455          self.receiver.SetProjection(self.__GetProjection())          self.receiver.SetProjection(self.__GetProjection())
456    
457      def __GetProjection(self):      def __GetProjection(self):
458          """Return the packaged projection.          """Return a suitable Projection object based on the current
459            state of the dialog box selections.
460    
461          Could be None.          Could be None.
462          """          """
463    
464          proj = None          sel = self.availprojs.GetSelections()
465            assert len(sel) < 2, "button should be disabled"
466    
467    
468            if len(sel) == 1:
469                proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ]
470                if proj is None:
471                    # <None> is selected
472                    return None
473    
474            #
475            # self.curProjPanel should always contain the most
476            # relevant data for a projection
477            #
478          if self.curProjPanel is not None:          if self.curProjPanel is not None:
479              proj = Projection(self.curProjPanel.GetParameters())              return Projection(self.curProjPanel.GetParameters(),
480              proj.SetName(self.projname.GetValue())                                self.projname.GetValue())
481    
482          return proj          return None
483    
484        def __FillAvailList(self, selectCurrent = False, selectProj = None):
485            """Populate the list of available projections.
486            
487            selectCurrent -- if True, select the projection used by
488                             the receiver, otherwise select nothing.
489            selectProj    -- if set, select the projection found under the
490                             specified name. This overwrites any other
491                             selection estimate.
492            """
493    
     def __FillAvailList(self):  
494          self.availprojs.Clear()          self.availprojs.Clear()
495    
496          #          #
# Line 468  class ProjFrame(NonModalDialog): Line 499  class ProjFrame(NonModalDialog):
499          #          #
500          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append("<None>", (None, None))
501    
502          self.__sysProjFile = None          projfile = get_system_proj_files()
503          self.__usrProjFile = None          projfile = projfile[0]
504            for proj in projfile.GetProjections():
505          projfile = GetSystemProjFiles()              self.availprojs.Append(proj.GetName(), [proj, projfile])
506          if len(projfile) > 0:          self.__sysProjFile = projfile
507              projfile = projfile[0]  
508              for proj in projfile.GetProjections():          projfile = get_user_proj_files()
509                  self.availprojs.Append(proj.GetName(), [proj, projfile])          projfile = projfile[0]
510              self.__sysProjFile = projfile          for proj in projfile.GetProjections():
511                self.availprojs.Append(proj.GetName(), [proj, projfile])
512          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  
513    
514            #
515            # We add the current projection to the list at last.
516            # Since the list is resorted immediately a following FindString()
517            # determines the index correctly.
518            #
519          proj = self.receiver.GetProjection()          proj = self.receiver.GetProjection()
520          if proj is not None:          if proj is not None:
521              self.availprojs.Append(proj.GetName() + _(" (current)"),              proj_item = _("%s (current)") % proj.GetName()
522                                     [proj, None])              self.availprojs.Append(proj_item, [proj, None])
523                if selectCurrent:
524                    self.availprojs.SetSelection(
525                            self.availprojs.FindString(proj_item)
526                        )
527            else:
528                if selectCurrent:
529                    self.availprojs.SetSelection(
530                            self.availprojs.FindString("<None>")
531                        )
532            if selectProj:
533                self.availprojs.SetSelection(
534                            self.availprojs.FindString(selectProj)
535                        )
536    
537          for proj, name, clazz in self.projPanels:                  
             self.projchoice.Append(name, [clazz, None])  
538    
539      def __set_properties(self):      def __set_properties(self):
         self.__FillAvailList()  
540    
541          # begin wxGlade: ProjFrame.__set_properties          #self.availprojs.SetSelection(0)
         self.SetTitle(_("Projections"))  
         self.availprojs.SetSelection(0)  
542          self.projchoice.SetSelection(0)          self.projchoice.SetSelection(0)
543          # end wxGlade  
544            self.__FillAvailList(selectCurrent = True)
545    
546          self.projname.SetMaxLength(32)          self.projname.SetMaxLength(32)
547    
# Line 522  class ProjFrame(NonModalDialog): Line 551  class ProjFrame(NonModalDialog):
551          self.topBox = wxBoxSizer(wxVERTICAL)          self.topBox = wxBoxSizer(wxVERTICAL)
552          self.sizer_panel = wxBoxSizer(wxVERTICAL)          self.sizer_panel = wxBoxSizer(wxVERTICAL)
553          sizer_6 = wxBoxSizer(wxHORIZONTAL)          sizer_6 = wxBoxSizer(wxHORIZONTAL)
554            self.sizer_mainbttns = wxBoxSizer(wxHORIZONTAL)
555          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)
556          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)
557          sizer_11 = wxBoxSizer(wxVERTICAL)          sizer_11 = wxBoxSizer(wxVERTICAL)
# Line 540  class ProjFrame(NonModalDialog): Line 570  class ProjFrame(NonModalDialog):
570          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)
571          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
572          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)
573          grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4)
574          grid_sizer_1.AddGrowableRow(1)          grid_sizer_1.AddGrowableRow(1)
575          grid_sizer_1.AddGrowableCol(0)          grid_sizer_1.AddGrowableCol(0)
576    
# Line 549  class ProjFrame(NonModalDialog): Line 579  class ProjFrame(NonModalDialog):
579          sizer_13.Add(self.projname, 1, wxALL, 4)          sizer_13.Add(self.projname, 1, wxALL, 4)
580          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)
581          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
582          sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
583          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
584          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
585          sizer_11.Add(self.button_new, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
586          sizer_11.Add(self.button_save, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
587          sizer_11.Add(self.button_add, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(20, 20, 0, wxEXPAND, 0)
588            sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)
589          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)
590    
591          sizer_6.Add(20, 20, 1, wxEXPAND, 0)          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)
592          sizer_6.Add(self.button_try, 0, wxALL, 4)          sizer_6.Add(self.button_revert, 0, wxRIGHT| wxEXPAND, 10)
593          sizer_6.Add(20, 20, 1, 0, 0)          sizer_6.Add(self.button_ok, 0, wxRIGHT| wxEXPAND, 10)
594          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)  
595    
596          self.panel_1.SetAutoLayout(1)          self.panel_1.SetAutoLayout(1)
597          self.panel_1.SetSizer(grid_sizer_1)          self.panel_1.SetSizer(grid_sizer_1)
# Line 577  class ProjFrame(NonModalDialog): Line 603  class ProjFrame(NonModalDialog):
603          self.sizer_edit.Fit(self.panel_edit)          self.sizer_edit.Fit(self.panel_edit)
604          self.sizer_edit.SetSizeHints(self.panel_edit)          self.sizer_edit.SetSizeHints(self.panel_edit)
605    
         self.panel_buttons.SetAutoLayout(1)  
         self.panel_buttons.SetSizer(sizer_6)  
         sizer_6.Fit(self.panel_buttons)  
         sizer_6.SetSizeHints(self.panel_buttons)  
   
606          self.sizer_mainctrls.Add(self.panel_1, 0,          self.sizer_mainctrls.Add(self.panel_1, 0,
607              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
608          self.sizer_mainctrls.Add(self.panel_edit, 1,          self.sizer_mainctrls.Add(self.panel_edit, 1,
609              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
610    
611            self.sizer_mainbttns.Add(sizer_6, 0,
612                wxALL|wxEXPAND|wxADJUST_MINSIZE, 10)
613    
614          self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)          self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)
615          self.topBox.Add(self.panel_buttons, 0, wxEXPAND, 0)          self.topBox.Add(self.sizer_mainbttns, 0, wxALIGN_RIGHT|wxBOTTOM, 0)
616    
617          self.SetAutoLayout(1)          self.SetAutoLayout(1)
618          self.SetSizer(self.topBox)          self.SetSizer(self.topBox)
# Line 606  class ProjPanel(wxPanel): Line 630  class ProjPanel(wxPanel):
630          wxPanel.__init__(self, parent, -1)          wxPanel.__init__(self, parent, -1)
631    
632          self.__ellps = wxChoice(self, -1)          self.__ellps = wxChoice(self, -1)
633          self.ellpsData = [("bessel", _("Bessel 1841")),          self.ellpsData = [("airy"  , _("Airy")),
634                              ("bessel", _("Bessel 1841")),
635                            ("clrk66", _("Clarke 1866")),                            ("clrk66", _("Clarke 1866")),
636                            ("clrk80", _("Clarke 1880")),                            ("clrk80", _("Clarke 1880")),
637                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),
# Line 622  class ProjPanel(wxPanel): Line 647  class ProjPanel(wxPanel):
647    
648          panelSizer = wxBoxSizer(wxVERTICAL)          panelSizer = wxBoxSizer(wxVERTICAL)
649    
         if childPanel is not None:  
             panelSizer.Add(childPanel, 0, wxALL|wxEXPAND, 4)  
               
650          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
651          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0,
652          sizer.Add(self.__ellps, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)                                      wxALL|wxALIGN_CENTER_VERTICAL, 4)
653            sizer.Add(self.__ellps, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
654          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)
655    
656            if childPanel is not None:
657                panelSizer.Add(childPanel, 0, wxEXPAND, 0)
658                
659          self.SetAutoLayout(1)          self.SetAutoLayout(1)
660          self.SetSizer(panelSizer)          self.SetSizer(panelSizer)
661          panelSizer.Fit(self)          panelSizer.Fit(self)
# Line 695  class TMPanel(ProjPanel): Line 721  class TMPanel(ProjPanel):
721    
722          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)
723          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)
724            self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)
725          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)
726          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)
         self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)  
727    
728          self._DoLayout()          self._DoLayout()
729    
# Line 763  class UTMPanel(ProjPanel): Line 789  class UTMPanel(ProjPanel):
789          self.receiver = receiver          self.receiver = receiver
790    
791          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)
792            self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))
793          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,
794                                    _("Southern Hemisphere"))                                    _("Southern Hemisphere"))
         self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))  
795    
796          self._DoLayout()          self._DoLayout()
797    
# Line 834  class LCCPanel(ProjPanel): Line 860  class LCCPanel(ProjPanel):
860          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
861              _("Latitude of second standard parallel:")))              _("Latitude of second standard parallel:")))
862          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)  
863          sizer.Add(wxStaticText(self, -1, _("Central Meridian:")))          sizer.Add(wxStaticText(self, -1, _("Central Meridian:")))
864          sizer.Add(self.__meridian, 0, wxALL, 4)          sizer.Add(self.__meridian, 0, wxALL, 4)
865            sizer.Add(wxStaticText(self, -1, _("Latitude of origin:")))
866            sizer.Add(self.__originLat, 0, wxALL, 4)
867          sizer.Add(wxStaticText(self, -1, _("False Easting:")))          sizer.Add(wxStaticText(self, -1, _("False Easting:")))
868          sizer.Add(self.__falseEast, 0, wxALL, 4)          sizer.Add(self.__falseEast, 0, wxALL, 4)
869          sizer.Add(wxStaticText(self, -1, _("False Northing:")))          sizer.Add(wxStaticText(self, -1, _("False Northing:")))
# Line 885  class GeoPanel(ProjPanel): Line 911  class GeoPanel(ProjPanel):
911    
912      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
913          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
914          ProjPanel._DoLayout(self, None)  
915            self.__choices = [(_("Degrees"), "0.017453"),
916                              (_("Radians"), "1")]
917    
918            self.__scale = wxChoice(self, -1)
919            for choice, value in self.__choices:
920                self.__scale.Append(choice, value)
921    
922            self._DoLayout()
923    
924      def GetProjName(self):      def GetProjName(self):
925          return _("Geographic")          return _("Geographic")
926                    
927      def SetProjection(self, proj):      def SetProjection(self, proj):
928            value = proj.GetParameter("to_meter")
929            for i in range(len(self.__choices)):
930                choice, data = self.__choices[i]
931                if value == data:
932                    self.__scale.SetSelection(i)
933          ProjPanel.SetProjection(self, proj)          ProjPanel.SetProjection(self, proj)
934    
935      def GetParameters(self):      def GetParameters(self):
936          params = ["proj=latlong"]          params = ["proj=latlong",
937                      "to_meter=%s" % self.__scale.GetClientData(
938                                      self.__scale.GetSelection())]
939    
940          params.extend(ProjPanel.GetParameters(self))          params.extend(ProjPanel.GetParameters(self))
941          return params          return params
942    
943      def Clear(self):      def Clear(self):
944          ProjPanel.Clear(self)          ProjPanel.Clear(self)
945    
946        def _DoLayout(self):
947            sizer = wxBoxSizer(wxHORIZONTAL)
948    
949            sizer.Add(wxStaticText(self, -1, _("Source Data is in: ")),
950                      0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
951            sizer.Add(self.__scale, 1, wxEXPAND|wxALL, 4)
952    
953            self.__scale.SetSelection(0)
954    
955            ProjPanel._DoLayout(self, sizer)
956    
957    
958  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001
959  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26