/[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 1135 by frank, Thu Jun 5 15:05:21 2003 UTC revision 1579 by bh, Tue Aug 12 12:34:07 2003 UTC
# Line 2  Line 2 
2  # Authors:  # Authors:
3  # Jonathan Coles <[email protected]>  # Jonathan Coles <[email protected]>
4  # Frank Koormann <[email protected]>  # Frank Koormann <[email protected]>
5    # Jan-Oliver Wagner <[email protected]>
6  #  #
7  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
8  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
9                                                                                    
10    """Projection dialog"""
11    
12    __version__ = "$Revision$"
13    # $Source$
14    # $Id$
15    
16  import os, sys, math  import os, sys, math
17  from wxPython.wx import *  from wxPython.wx import *
18    
# Line 13  from Thuban import _ Line 20  from Thuban import _
20    
21  from Thuban.Model.proj import Projection, ProjFile  from Thuban.Model.proj import Projection, ProjFile
22    
23  from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles, \  from Thuban.Model.resource import get_user_proj_files, get_system_proj_files, \
24                                    ReadProjFile, WriteProjFile                                    read_proj_file, write_proj_file
25  from Thuban.UI.dialogs import NonModalNonParentDialog  from Thuban.UI.dialogs import NonModalNonParentDialog
26    
27    
# Line 129  class ProjFrame(NonModalNonParentDialog) Line 136  class ProjFrame(NonModalNonParentDialog)
136    
137          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
138    
   
139      def OnApply(self, event):      def OnApply(self, event):
140          self.__SetProjection()          self.__SetProjection()
141          self.haveTried = True          self.haveTried = True
# Line 149  class ProjFrame(NonModalNonParentDialog) Line 155  class ProjFrame(NonModalNonParentDialog)
155              self.receiver.SetProjection(self.originalProjection)              self.receiver.SetProjection(self.originalProjection)
156              self.haveTried = False              self.haveTried = False
157    
   
158      def _OnNew(self, event):      def _OnNew(self, event):
159    
160          # clear all selections          # clear all selections
# Line 180  class ProjFrame(NonModalNonParentDialog) Line 185  class ProjFrame(NonModalNonParentDialog)
185          if newproj is not None:          if newproj is not None:
186              projfile.Replace(proj, newproj)              projfile.Replace(proj, newproj)
187              try:              try:
188                  WriteProjFile(projfile)                  write_proj_file(projfile)
189              except IOError, (errno, errstr):              except IOError, (errno, errstr):
190                  self.__ShowError(projfile.GetFilename(), errstr)                  self.__ShowError(projfile.GetFilename(), errstr)
191              self.availprojs.SetClientData(sel[0], [newproj, projfile])              self.availprojs.SetClientData(sel[0], [newproj, projfile])
# Line 193  class ProjFrame(NonModalNonParentDialog) Line 198  class ProjFrame(NonModalNonParentDialog)
198          if proj is not None:          if proj is not None:
199              self.__usrProjFile.Add(proj)              self.__usrProjFile.Add(proj)
200              try:              try:
201                  WriteProjFile(self.__usrProjFile)                  write_proj_file(self.__usrProjFile)
202              except IOError, (errno, errstr):              except IOError, (errno, errstr):
203                  self.__ShowError(self.__userProjFile.GetFilename(), errstr)                  self.__ShowError(self.__userProjFile.GetFilename(), errstr)
204    
# Line 210  class ProjFrame(NonModalNonParentDialog) Line 215  class ProjFrame(NonModalNonParentDialog)
215              path = dlg.GetPath()              path = dlg.GetPath()
216    
217              try:              try:
218                  projFile = ReadProjFile(path)                  projFile = read_proj_file(path)
219                  for proj in projFile.GetProjections():                  for proj in projFile.GetProjections():
220                      self.__usrProjFile.Add(proj)                      self.__usrProjFile.Add(proj)
221                  WriteProjFile(self.__usrProjFile)                  write_proj_file(self.__usrProjFile)
222              except IOError, (errno, errstr):              except IOError, (errno, errstr):
223                  self.__ShowError(dlg.GetPath(), errstr)                  self.__ShowError(dlg.GetPath(), errstr)
224    
# Line 240  class ProjFrame(NonModalNonParentDialog) Line 245  class ProjFrame(NonModalNonParentDialog)
245                      projFile.Add(proj)                      projFile.Add(proj)
246    
247              try:              try:
248                  WriteProjFile(projFile)                  write_proj_file(projFile)
249              except IOError, (errno, errstr):              except IOError, (errno, errstr):
250                  self.__ShowError(dlg.GetPath(), errstr)                  self.__ShowError(dlg.GetPath(), errstr)
251    
# Line 275  class ProjFrame(NonModalNonParentDialog) Line 280  class ProjFrame(NonModalNonParentDialog)
280                  projfile.Remove(proj)                  projfile.Remove(proj)
281    
282          try:          try:
283              WriteProjFile(projfile)              write_proj_file(projfile)
284          except IOError, (errno, errstr):          except IOError, (errno, errstr):
285              self.__ShowError(projfile.GetFilename(), errstr)              self.__ShowError(projfile.GetFilename(), errstr)
286    
# Line 373  class ProjFrame(NonModalNonParentDialog) Line 378  class ProjFrame(NonModalNonParentDialog)
378              if proj is None:              if proj is None:
379                  # user selected <None>                  # user selected <None>
380                  self.projname.Clear()                  self.projname.Clear()
381                                    self.projfilepath.SetLabel(_("Projection File: "))
382              else:              else:
383                            
384                  if projfile is not None:                  if projfile is not None:
385                      self.projfilepath.SetLabel(projfile.GetFilename())                      self.projfilepath.SetLabel(_("Projection File: ") +
386                            os.path.basename(projfile.GetFilename()))
387                  else:                  else:
388                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
389                      self.projfilepath.SetLabel("")                      self.projfilepath.SetLabel(_("Projection File: "))
390    
391                  self.projname.SetValue(proj.GetName())                  self.projname.SetValue(proj.GetName())
392    
# Line 494  class ProjFrame(NonModalNonParentDialog) Line 500  class ProjFrame(NonModalNonParentDialog)
500          #          #
501          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append("<None>", (None, None))
502    
503          projfile = GetSystemProjFiles()          projfile = get_system_proj_files()
504          projfile = projfile[0]          projfile = projfile[0]
505          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
506              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
507          self.__sysProjFile = projfile          self.__sysProjFile = projfile
508    
509          projfile = GetUserProjFiles()          projfile = get_user_proj_files()
510          projfile = projfile[0]          projfile = projfile[0]
511          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
512              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
# Line 565  class ProjFrame(NonModalNonParentDialog) Line 571  class ProjFrame(NonModalNonParentDialog)
571          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)
572          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
573          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)
574          grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4)
575          grid_sizer_1.AddGrowableRow(1)          grid_sizer_1.AddGrowableRow(1)
576          grid_sizer_1.AddGrowableCol(0)          grid_sizer_1.AddGrowableCol(0)
577    
# Line 577  class ProjFrame(NonModalNonParentDialog) Line 583  class ProjFrame(NonModalNonParentDialog)
583          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
584          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
585          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
586          sizer_11.Add(self.button_new, 0, wxALL, 4)          sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
587          sizer_11.Add(self.button_add, 0, wxALL, 4)          sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
588          sizer_11.Add(20, 20, 0, wxEXPAND, 0)          sizer_11.Add(20, 20, 0, wxEXPAND, 0)
589          sizer_11.Add(self.button_save, 0, wxALL|wxALIGN_BOTTOM, 4)          sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)
590          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)
591    
592          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)
# Line 692  class UnknownProjPanel(ProjPanel): Line 698  class UnknownProjPanel(ProjPanel):
698      def _DoLayout(self):      def _DoLayout(self):
699          sizer = wxBoxSizer(wxVERTICAL)          sizer = wxBoxSizer(wxVERTICAL)
700    
701          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
702              _("Thuban does not know the parameters for the " +                                 _("Thuban does not know the parameters for the"
703                "current projection and cannot display a " +                                   " current projection and cannot display a"
704                "configuration panel.")))                                   " configuration panel.")))
705    
706          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
707    
# Line 826  class UTMPanel(ProjPanel): Line 832  class UTMPanel(ProjPanel):
832          ProjPanel.Clear(self)          ProjPanel.Clear(self)
833    
834      def _OnPropose(self, event):      def _OnPropose(self, event):
835          UTMProposeZoneDialog          """Call the propose dialog.
836            If the receiver (e.g. the current map) has no bounding box,
837            inform the user accordingly.
838            """
839            bb = self.receiver.BoundingBox()
840            if bb is None:
841                dlg = wxMessageDialog(self,
842                        _("Can not propose: No bounding box found."),
843                        _("Projection: Propose UTM Zone"),
844                        wxOK | wxICON_INFORMATION)
845                dlg.CenterOnParent()
846                result = dlg.ShowModal()
847                dlg.Destroy()
848                return
849    
850          dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())          dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())
851          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
852              self.__zone.SetValue(dlg.GetProposedZone())              self.__zone.SetValue(dlg.GetProposedZone())
# Line 953  class GeoPanel(ProjPanel): Line 973  class GeoPanel(ProjPanel):
973  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001
974  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002
975  class UTMProposeZoneDialog(wxDialog):  class UTMProposeZoneDialog(wxDialog):
976                                                                                    
977      """Propose a sensible Zone considering the current map extent."""      """Propose a sensible Zone considering the current map extent."""
978                                                                                    
979      def __init__(self, parent, (x, y, x2, y2)):      def __init__(self, parent, (x, y, x2, y2)):
980          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),
981                            wxDefaultPosition, wxSize(200, 100))                            wxDefaultPosition, wxSize(200, 100))
982          self.parent = parent          self.parent = parent
         #x, y, x2, y2 = elf.parent.parent.map_bounding_box  
983          x = x + 180          x = x + 180
984          x2 = x2 + 180          x2 = x2 + 180
985          center = (x2 - x) / 2 + x          center = (x2 - x) / 2 + x
986          self.proposedZone = int(center / 6 + 1)          self.proposedZone = int(center / 6 + 1)
987          self.dialogLayout()          self.dialogLayout()
988                                                                                    
989      def dialogLayout(self):      def dialogLayout(self):
990          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
991                                                                                    
992          textBox = wxBoxSizer(wxVERTICAL)          textBox = wxBoxSizer(wxVERTICAL)
993          textBox.Add(wxStaticText(self, -1, _("The current map extent center " +          textBox.Add(wxStaticText(self, -1, _("The current map extent center "
994                                             "lies in UTM Zone")),                                               "lies in UTM Zone")),
995                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
996          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),
997                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
998                                                                                    
999          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)
1000                                                                                    
1001          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
1002          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,
1003                        _("Take")), 0, wxALL, 4)                        _("Take")), 0, wxALL, 4)
# Line 987  class UTMProposeZoneDialog(wxDialog): Line 1006  class UTMProposeZoneDialog(wxDialog):
1006          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
1007          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)
1008          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)
1009                                                                                    
1010          self.SetAutoLayout(True)          self.SetAutoLayout(True)
1011          self.SetSizer(topBox)          self.SetSizer(topBox)
1012          topBox.Fit(self)          topBox.Fit(self)
1013          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
1014                                                                                    
1015      def OnTake(self, event):      def OnTake(self, event):
1016          self.EndModal(wxID_OK)          self.EndModal(wxID_OK)
1017                                                                                    
1018      def OnCancel(self, event):      def OnCancel(self, event):
1019          self.EndModal(wxID_CANCEL)          self.EndModal(wxID_CANCEL)
1020    

Legend:
Removed from v.1135  
changed lines
  Added in v.1579

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26