/[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 1795 by bh, Wed Oct 8 17:35:52 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  import os, sys, math  """Projection dialog"""
11    
12    __version__ = "$Revision$"
13    # $Source$
14    # $Id$
15    
16    import os
17  from wxPython.wx import *  from wxPython.wx import *
18    
19  from Thuban import _  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_file, get_system_proj_file, \
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 202  class ProjFrame(NonModalNonParentDialog) Line 207  class ProjFrame(NonModalNonParentDialog)
207      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
208          self.__DoOnProjAvail()          self.__DoOnProjAvail()
209    
210        def show_warnings(self, title, filename, warnings):
211            """Show the warnings (a list of strings) in a dialog
212    
213            If the list is empty no dialog will be shown.
214            """
215            if warnings:
216                text = (_('Warnings when reading "%s":\n\n%s')
217                        % (filename, "\n\n".join(warnings)))
218                self.parent.RunMessageBox(title, text)
219    
220      def _OnImport(self, event):      def _OnImport(self, event):
221    
222          dlg = wxFileDialog(self, _("Import"), style = wxOPEN)          dlg = wxFileDialog(self, _("Import"), style = wxOPEN)
# Line 210  class ProjFrame(NonModalNonParentDialog) Line 225  class ProjFrame(NonModalNonParentDialog)
225              path = dlg.GetPath()              path = dlg.GetPath()
226    
227              try:              try:
228                  projFile = ReadProjFile(path)                  projFile, warnings = read_proj_file(path)
229                    self.show_warnings(_("Warnings"), path, warnings)
230                  for proj in projFile.GetProjections():                  for proj in projFile.GetProjections():
231                      self.__usrProjFile.Add(proj)                      self.__usrProjFile.Add(proj)
232                  WriteProjFile(self.__usrProjFile)                  write_proj_file(self.__usrProjFile)
233              except IOError, (errno, errstr):              except IOError, (errno, errstr):
234                  self.__ShowError(dlg.GetPath(), errstr)                  self.__ShowError(dlg.GetPath(), errstr)
235    
# Line 240  class ProjFrame(NonModalNonParentDialog) Line 256  class ProjFrame(NonModalNonParentDialog)
256                      projFile.Add(proj)                      projFile.Add(proj)
257    
258              try:              try:
259                  WriteProjFile(projFile)                  write_proj_file(projFile)
260              except IOError, (errno, errstr):              except IOError, (errno, errstr):
261                  self.__ShowError(dlg.GetPath(), errstr)                  self.__ShowError(dlg.GetPath(), errstr)
262    
# Line 275  class ProjFrame(NonModalNonParentDialog) Line 291  class ProjFrame(NonModalNonParentDialog)
291                  projfile.Remove(proj)                  projfile.Remove(proj)
292    
293          try:          try:
294              WriteProjFile(projfile)              write_proj_file(projfile)
295          except IOError, (errno, errstr):          except IOError, (errno, errstr):
296              self.__ShowError(projfile.GetFilename(), errstr)              self.__ShowError(projfile.GetFilename(), errstr)
297    
# Line 373  class ProjFrame(NonModalNonParentDialog) Line 389  class ProjFrame(NonModalNonParentDialog)
389              if proj is None:              if proj is None:
390                  # user selected <None>                  # user selected <None>
391                  self.projname.Clear()                  self.projname.Clear()
392                                    self.projfilepath.SetLabel(_("Projection File: "))
393              else:              else:
394                            
395                  if projfile is not None:                  if projfile is not None:
396                      self.projfilepath.SetLabel(projfile.GetFilename())                      self.projfilepath.SetLabel(_("Projection File: ") +
397                            os.path.basename(projfile.GetFilename()))
398                  else:                  else:
399                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
400                      self.projfilepath.SetLabel("")                      self.projfilepath.SetLabel(_("Projection File: "))
401    
402                  self.projname.SetValue(proj.GetName())                  self.projname.SetValue(proj.GetName())
403    
# Line 388  class ProjFrame(NonModalNonParentDialog) Line 405  class ProjFrame(NonModalNonParentDialog)
405                  i = 0                  i = 0
406                  for projType, name, clazz in self.projPanels:                  for projType, name, clazz in self.projPanels:
407                      if myProjType == projType:                      if myProjType == projType:
408                            self.projchoice.Enable(True)
409                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i)
410                          self.__DoOnProjChoice()                          self.__DoOnProjChoice()
411    
# Line 398  class ProjFrame(NonModalNonParentDialog) Line 416  class ProjFrame(NonModalNonParentDialog)
416                          assert self.curProjPanel is not None                          assert self.curProjPanel is not None
417    
418                          self.curProjPanel.SetProjection(proj)                          self.curProjPanel.SetProjection(proj)
419                            break
420                      i += 1                      i += 1
421                    else:
422                        self.projchoice.Disable()
423                        self._show_proj_panel(UnknownProjPanel(self.panel_edit,
424                                                               self.receiver))
425    
426          self.__VerifyButtons()          self.__VerifyButtons()
427    
# Line 420  class ProjFrame(NonModalNonParentDialog) Line 443  class ProjFrame(NonModalNonParentDialog)
443    
444          sel = choice.GetSelection()          sel = choice.GetSelection()
445          if sel != -1:          if sel != -1:
   
446              clazz, obj = choice.GetClientData(sel)              clazz, obj = choice.GetClientData(sel)
   
447              if obj is None:              if obj is None:
448                  obj = clazz(self.panel_edit, self.receiver)                  obj = clazz(self.panel_edit, self.receiver)
449                  choice.SetClientData(sel, [clazz, obj])                  choice.SetClientData(sel, [clazz, obj])
450                self._show_proj_panel(obj)
451    
452        def _show_proj_panel(self, panel):
453            """Show the panel as the projection panel"""
454            if self.curProjPanel is not None:
455                self.curProjPanel.Hide()
456                self.sizer_projctrls.Remove(self.curProjPanel)
457    
458            self.curProjPanel = panel
459            self.curProjPanel.Show()
460    
461              if self.curProjPanel is not None:          self.sizer_projctrls.Add(self.curProjPanel, 1,
462                  self.curProjPanel.Hide()              wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)
463                  self.sizer_projctrls.Remove(self.curProjPanel)          self.sizer_projctrls.Layout()
464            self.Layout()
465              self.curProjPanel = obj          self.topBox.SetSizeHints(self)
             self.curProjPanel.Show()  
   
             self.sizer_projctrls.Add(self.curProjPanel, 1,  
                 wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)  
             self.sizer_projctrls.Layout()  
             self.Layout()  
             self.topBox.SetSizeHints(self)  
466    
467      def __SetProjection(self):      def __SetProjection(self):
468          """Set the receiver's projection."""          """Set the receiver's projection."""
# Line 494  class ProjFrame(NonModalNonParentDialog) Line 518  class ProjFrame(NonModalNonParentDialog)
518          #          #
519          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append("<None>", (None, None))
520    
521          projfile = GetSystemProjFiles()          projfile, warnings = get_system_proj_file()
522          projfile = projfile[0]          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)
523          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
524              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
525          self.__sysProjFile = projfile          self.__sysProjFile = projfile
526    
527          projfile = GetUserProjFiles()          projfile, warnings = get_user_proj_file()
528          projfile = projfile[0]          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)
529          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
530              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
531          self.__usrProjFile = projfile          self.__usrProjFile = projfile
# Line 538  class ProjFrame(NonModalNonParentDialog) Line 562  class ProjFrame(NonModalNonParentDialog)
562    
563          self.__FillAvailList(selectCurrent = True)          self.__FillAvailList(selectCurrent = True)
564    
         self.projname.SetMaxLength(32)  
   
565      def __do_layout(self):      def __do_layout(self):
566          # originally generated by wxGlade          # originally generated by wxGlade
567    
# Line 565  class ProjFrame(NonModalNonParentDialog) Line 587  class ProjFrame(NonModalNonParentDialog)
587          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)
588          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
589          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)
590          grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4)
591          grid_sizer_1.AddGrowableRow(1)          grid_sizer_1.AddGrowableRow(1)
592          grid_sizer_1.AddGrowableCol(0)          grid_sizer_1.AddGrowableCol(0)
593    
# Line 577  class ProjFrame(NonModalNonParentDialog) Line 599  class ProjFrame(NonModalNonParentDialog)
599          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
600          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
601          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
602          sizer_11.Add(self.button_new, 0, wxALL, 4)          sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
603          sizer_11.Add(self.button_add, 0, wxALL, 4)          sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
604          sizer_11.Add(20, 20, 0, wxEXPAND, 0)          sizer_11.Add(20, 20, 0, wxEXPAND, 0)
605          sizer_11.Add(self.button_save, 0, wxALL|wxALIGN_BOTTOM, 4)          sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)
606          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)
607    
608          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)
# Line 684  ID_TMPANEL_FALSE_NORTH = 4004 Line 706  ID_TMPANEL_FALSE_NORTH = 4004
706  ID_TMPANEL_SCALE = 4005  ID_TMPANEL_SCALE = 4005
707    
708  class UnknownProjPanel(ProjPanel):  class UnknownProjPanel(ProjPanel):
709    
710        """Panel for unknown projection types"""
711    
712      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
713          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
714    
# Line 692  class UnknownProjPanel(ProjPanel): Line 717  class UnknownProjPanel(ProjPanel):
717      def _DoLayout(self):      def _DoLayout(self):
718          sizer = wxBoxSizer(wxVERTICAL)          sizer = wxBoxSizer(wxVERTICAL)
719    
720          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
721              _("Thuban does not know the parameters for the " +                                 _("Thuban does not know the parameters for the"
722                "current projection and cannot display a " +                                   " current projection\n"
723                "configuration panel.")))                                   "and cannot display a configuration panel.")))
724    
725          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
726    
# Line 826  class UTMPanel(ProjPanel): Line 851  class UTMPanel(ProjPanel):
851          ProjPanel.Clear(self)          ProjPanel.Clear(self)
852    
853      def _OnPropose(self, event):      def _OnPropose(self, event):
854          UTMProposeZoneDialog          """Call the propose dialog.
855            If the receiver (e.g. the current map) has no bounding box,
856            inform the user accordingly.
857            """
858            bb = self.receiver.BoundingBox()
859            if bb is None:
860                dlg = wxMessageDialog(self,
861                        _("Can not propose: No bounding box found."),
862                        _("Projection: Propose UTM Zone"),
863                        wxOK | wxICON_INFORMATION)
864                dlg.CenterOnParent()
865                result = dlg.ShowModal()
866                dlg.Destroy()
867                return
868    
869          dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())          dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())
870          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
871              self.__zone.SetValue(dlg.GetProposedZone())              self.__zone.SetValue(dlg.GetProposedZone())
# Line 953  class GeoPanel(ProjPanel): Line 992  class GeoPanel(ProjPanel):
992  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001
993  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002
994  class UTMProposeZoneDialog(wxDialog):  class UTMProposeZoneDialog(wxDialog):
995                                                                                    
996      """Propose a sensible Zone considering the current map extent."""      """Propose a sensible Zone considering the current map extent."""
997                                                                                    
998      def __init__(self, parent, (x, y, x2, y2)):      def __init__(self, parent, (x, y, x2, y2)):
999          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),
1000                            wxDefaultPosition, wxSize(200, 100))                            wxDefaultPosition, wxSize(200, 100))
1001          self.parent = parent          self.parent = parent
         #x, y, x2, y2 = elf.parent.parent.map_bounding_box  
1002          x = x + 180          x = x + 180
1003          x2 = x2 + 180          x2 = x2 + 180
1004          center = (x2 - x) / 2 + x          center = (x2 - x) / 2 + x
1005          self.proposedZone = int(center / 6 + 1)          self.proposedZone = int(center / 6 + 1)
1006          self.dialogLayout()          self.dialogLayout()
1007                                                                                    
1008      def dialogLayout(self):      def dialogLayout(self):
1009          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
1010                                                                                    
1011          textBox = wxBoxSizer(wxVERTICAL)          textBox = wxBoxSizer(wxVERTICAL)
1012          textBox.Add(wxStaticText(self, -1, _("The current map extent center " +          textBox.Add(wxStaticText(self, -1, _("The current map extent center "
1013                                             "lies in UTM Zone")),                                               "lies in UTM Zone")),
1014                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
1015          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),
1016                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
1017                                                                                    
1018          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)
1019                                                                                    
1020          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
1021          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,
1022                        _("Take")), 0, wxALL, 4)                        _("Take")), 0, wxALL, 4)
# Line 987  class UTMProposeZoneDialog(wxDialog): Line 1025  class UTMProposeZoneDialog(wxDialog):
1025          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
1026          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)
1027          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)
1028                                                                                    
1029          self.SetAutoLayout(True)          self.SetAutoLayout(True)
1030          self.SetSizer(topBox)          self.SetSizer(topBox)
1031          topBox.Fit(self)          topBox.Fit(self)
1032          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
1033                                                                                    
1034      def OnTake(self, event):      def OnTake(self, event):
1035          self.EndModal(wxID_OK)          self.EndModal(wxID_OK)
1036                                                                                    
1037      def OnCancel(self, event):      def OnCancel(self, event):
1038          self.EndModal(wxID_CANCEL)          self.EndModal(wxID_CANCEL)
1039    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26