/[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 1034 by frank, Mon May 26 16:28:33 2003 UTC revision 1542 by bh, Fri Aug 1 16:13:49 2003 UTC
# Line 5  Line 5 
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # 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, math  import os, sys, math
16  from wxPython.wx import *  from wxPython.wx import *
17    
# Line 13  from Thuban import _ Line 19  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
# Line 33  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, title, receiver):      def __init__(self, parent, name, title, receiver):
45          """Initialize the projection dialog.          """Initialize the projection dialog.
# Line 57  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, title)          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)
# Line 100  class ProjFrame(NonModalDialog): Line 106  class ProjFrame(NonModalDialog):
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()          self.originalProjection = self.receiver.GetProjection()
117    
118          self.__DoOnProjAvail()          self.__DoOnProjAvail()
# Line 124  class ProjFrame(NonModalDialog): Line 135  class ProjFrame(NonModalDialog):
135    
136          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
137    
   
138      def OnApply(self, event):      def OnApply(self, event):
139          self.__SetProjection()          self.__SetProjection()
140          self.haveTried = True          self.haveTried = True
# Line 144  class ProjFrame(NonModalDialog): Line 154  class ProjFrame(NonModalDialog):
154              self.receiver.SetProjection(self.originalProjection)              self.receiver.SetProjection(self.originalProjection)
155              self.haveTried = False              self.haveTried = False
156    
   
157      def _OnNew(self, event):      def _OnNew(self, event):
158    
159          # clear all selections          # clear all selections
# Line 175  class ProjFrame(NonModalDialog): Line 184  class ProjFrame(NonModalDialog):
184          if newproj is not None:          if newproj is not None:
185              projfile.Replace(proj, newproj)              projfile.Replace(proj, newproj)
186              try:              try:
187                  WriteProjFile(projfile)                  write_proj_file(projfile)
188              except IOError, (errno, errstr):              except IOError, (errno, errstr):
189                  self.__ShowError(projfile.GetFilename(), errstr)                  self.__ShowError(projfile.GetFilename(), errstr)
190              self.availprojs.SetClientData(sel[0], [newproj, projfile])              self.availprojs.SetClientData(sel[0], [newproj, projfile])
191    
192                self.__FillAvailList( selectProj = newproj.GetName())
193    
194      def _OnAddToList(self, event):      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                  self.__ShowError(self.__userProjFile.GetFilename(), errstr)                  self.__ShowError(self.__userProjFile.GetFilename(), errstr)
203    
204              self.__FillAvailList()              self.__FillAvailList( selectProj = proj.GetName())
205    
206      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
207          self.__DoOnProjAvail()          self.__DoOnProjAvail()
# Line 203  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                  self.__ShowError(dlg.GetPath(), errstr)                  self.__ShowError(dlg.GetPath(), errstr)
223    
# Line 233  class ProjFrame(NonModalDialog): Line 244  class ProjFrame(NonModalDialog):
244                      projFile.Add(proj)                      projFile.Add(proj)
245    
246              try:              try:
247                  WriteProjFile(projFile)                  write_proj_file(projFile)
248              except IOError, (errno, errstr):              except IOError, (errno, errstr):
249                  self.__ShowError(dlg.GetPath(), errstr)                  self.__ShowError(dlg.GetPath(), errstr)
250    
# Line 268  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              self.__ShowError(projfile.GetFilename(), errstr)              self.__ShowError(projfile.GetFilename(), errstr)
285    
# Line 366  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 469  class ProjFrame(NonModalDialog): Line 481  class ProjFrame(NonModalDialog):
481    
482          return None          return None
483    
484      def __FillAvailList(self, selectCurrent = False):      def __FillAvailList(self, selectCurrent = False, selectProj = None):
485          """Populate the list of available projections.          """Populate the list of available projections.
486                    
487          selectCurrent -- if True, select the projection used by          selectCurrent -- if True, select the projection used by
488                           the receiver, otherwise select nothing.                           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    
494          self.availprojs.Clear()          self.availprojs.Clear()
# Line 484  class ProjFrame(NonModalDialog): Line 499  class ProjFrame(NonModalDialog):
499          #          #
500          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append("<None>", (None, None))
501    
502          projfile = GetSystemProjFiles()          projfile = get_system_proj_files()
503          projfile = projfile[0]          projfile = projfile[0]
504          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
505              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
506          self.__sysProjFile = projfile          self.__sysProjFile = projfile
507    
508          projfile = GetUserProjFiles()          projfile = get_user_proj_files()
509          projfile = projfile[0]          projfile = projfile[0]
510          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
511              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
512          self.__usrProjFile = projfile          self.__usrProjFile = projfile
513    
         for proj, name, clazz in self.projPanels:  
             self.projchoice.Append(name, [clazz, None])  
   
514          #          #
515          # We add the current projection to the list at last.          # We add the current projection to the list at last.
516          # Since the list is resorted immediately a following FindString()          # Since the list is resorted immediately a following FindString()
# Line 517  class ProjFrame(NonModalDialog): Line 529  class ProjFrame(NonModalDialog):
529                  self.availprojs.SetSelection(                  self.availprojs.SetSelection(
530                          self.availprojs.FindString("<None>")                          self.availprojs.FindString("<None>")
531                      )                      )
532            if selectProj:
533                self.availprojs.SetSelection(
534                            self.availprojs.FindString(selectProj)
535                        )
536    
537                                    
538    
539      def __set_properties(self):      def __set_properties(self):
# Line 553  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 565  class ProjFrame(NonModalDialog): Line 582  class ProjFrame(NonModalDialog):
582          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 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, 4)          sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
586          sizer_11.Add(self.button_add, 0, wxALL, 4)          sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
587          sizer_11.Add(20, 20, 0, wxEXPAND, 0)          sizer_11.Add(20, 20, 0, wxEXPAND, 0)
588          sizer_11.Add(self.button_save, 0, wxALL|wxALIGN_BOTTOM, 4)          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(self.button_try, 0, wxRIGHT| wxEXPAND, 10)          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)
# Line 843  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:")))

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26