/[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 757 by jonathan, Fri Apr 25 17:37:44 2003 UTC revision 1786 by bh, Wed Oct 8 10:39:11 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2003 by Intevation GmbH  # Copyright (c) 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jonathan Coles <[email protected]>  # Jonathan Coles <[email protected]>
4    # 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  """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 NonModalDialog  from Thuban.UI.dialogs import NonModalNonParentDialog
26    
27    
28  ID_PROJ_ADVANCED  = 4001  ID_PROJ_ADVANCED  = 4001
29  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
30  ID_PROJ_ADDTOLIST    = 4003  ID_PROJ_ADDTOLIST    = 4003
31  ID_PROJ_NEW       = 4004  ID_PROJ_NEW       = 4004
 ID_PROJ_TRY       = 4005  
32  ID_PROJ_REVERT    = 4006  ID_PROJ_REVERT    = 4006
 ID_PROJ_OK        = 4007  
 ID_PROJ_CLOSE     = 4008  
33  ID_PROJ_AVAIL     = 4009  ID_PROJ_AVAIL     = 4009
34  ID_PROJ_SAVE      = 4010  ID_PROJ_SAVE      = 4010
35  ID_PROJ_IMPORT    = 4011  ID_PROJ_IMPORT    = 4011
# Line 35  ID_PROJ_PROJNAME  = 4014 Line 40  ID_PROJ_PROJNAME  = 4014
40  CLIENT_PROJ = 0  CLIENT_PROJ = 0
41  CLIENT_PROJFILE = 1  CLIENT_PROJFILE = 1
42    
43  class ProjFrame(NonModalDialog):  class ProjFrame(NonModalNonParentDialog):
44    
45      def __init__(self, parent, name, title, receiver):      def __init__(self, parent, name, title, receiver):
46          """Initialize the projection dialog.          """Initialize the projection dialog.
# Line 59  class ProjFrame(NonModalDialog): Line 64  class ProjFrame(NonModalDialog):
64          self.projPanels.append(          self.projPanels.append(
65              ("latlong", _("Geographic"), GeoPanel))              ("latlong", _("Geographic"), GeoPanel))
66    
67          NonModalDialog.__init__(self, parent, name, title)          NonModalNonParentDialog.__init__(self, parent, name, title)
68          # originally generate by wxGlade          # originally generate by wxGlade
69          self.panel_1 = wxPanel(self, -1)          self.panel_1 = wxPanel(self, -1)
70          self.panel_edit = wxPanel(self, -1)          self.panel_edit = wxPanel(self, -1)
71          self.panel_buttons = wxPanel(self, -1)          self.label_5 = wxStaticText(self.panel_1, -1,
72          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))                          _("Available Projections:"))
73          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED|wxLB_SORT)  
74            # Projection List specific actions (Import/Export/Remove)
75            self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT,
76                                          _("Import..."))
77            self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT,
78                                          _("Export..."))
79            self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE,
80                                          _("Remove"))
81    
82            # The Projection List
83            self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL,
84                                        style=wxLB_EXTENDED|wxLB_SORT)
85          self.projfilepath = wxStaticText(self.panel_1, -1, "")          self.projfilepath = wxStaticText(self.panel_1, -1, "")
86    
87            # Projection Specific Entries (Name/Projection)
88          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))
89          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")
90          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))
91          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)
92          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, _("Import..."))  
93          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"))  
94          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))
         self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))  
95          self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,          self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,
96                                        _("Add to List"))                                        _("Add to List"))
97          self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Update"))
98          self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))  
99          self.button_ok = wxButton(self.panel_buttons, ID_PROJ_OK, _("OK"))          # Main Action buttons (Try/Revert/OK/Close)
100          self.button_close = wxButton(self.panel_buttons, ID_PROJ_CLOSE, _("Close"))          self.button_try = wxButton(self, wxID_APPLY, _("Try"))
101            self.button_revert = wxButton(self, ID_PROJ_REVERT,
102                                          _("Revert"))
103            self.button_ok = wxButton(self, wxID_OK, _("OK"))
104            self.button_ok.SetDefault()
105            self.button_close = wxButton(self, wxID_CANCEL,
106                                         _("Close"))
107    
108          self.__set_properties()          self.__set_properties()
109          self.__do_layout()          self.__do_layout()
110    
111          # wxGlade          # wxGlade
112    
113            # Fill the projection choice list.
114            for proj, name, clazz in self.projPanels:
115                self.projchoice.Append(name, [clazz, None])
116    
117          self.originalProjection = self.receiver.GetProjection()          self.originalProjection = self.receiver.GetProjection()
118    
119          self.__DoOnProjAvail()          self.__DoOnProjAvail()
120            self.button_ok.SetFocus()
121            self.availprojs.SetFocus()
122                    
123          EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry)          EVT_BUTTON(self, wxID_APPLY, self.OnApply)
124          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
125          EVT_BUTTON(self, ID_PROJ_OK, self._OnOK)          EVT_BUTTON(self, wxID_OK, self.OnOK)
126          EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose)          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
127          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
128          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
129          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
# Line 107  class ProjFrame(NonModalDialog): Line 136  class ProjFrame(NonModalDialog):
136    
137          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
138    
139      def _OnTry(self, event):      def OnApply(self, event):
140          self.__SetProjection()          self.__SetProjection()
141          self.haveTried = True          self.haveTried = True
142    
143      def _OnRevert(self, event):      def OnOK(self, event):
         if self.haveTried:  
             self.receiver.SetProjection(self.originalProjection)  
             self.haveTried = False  
   
     def _OnOK(self, event):  
144          self.__SetProjection()          self.__SetProjection()
145          self.Close()          self.Close()
146    
147      def _OnClose(self, event):      def OnCancel(self, event):
148            """Cancel just closes the dialog, but we call it cancel so we
149            can overload the functionality of wxDialog.
150            """
151          self.Close()          self.Close()
152    
153        def _OnRevert(self, event):
154            if self.haveTried:
155                self.receiver.SetProjection(self.originalProjection)
156                self.haveTried = False
157    
158      def _OnNew(self, event):      def _OnNew(self, event):
159    
160          # clear all selections          # clear all selections
# Line 151  class ProjFrame(NonModalDialog): Line 183  class ProjFrame(NonModalDialog):
183          newproj = self.__GetProjection()          newproj = self.__GetProjection()
184    
185          if newproj is not None:          if newproj is not None:
186              proj.SetProjection(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])
192    
193                self.__FillAvailList( selectProj = newproj.GetName())
194    
195      def _OnAddToList(self, event):      def _OnAddToList(self, event):
196    
# Line 163  class ProjFrame(NonModalDialog): Line 198  class ProjFrame(NonModalDialog):
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    
205              self.__FillAvailList()              self.__FillAvailList( selectProj = proj.GetName())
206    
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 180  class ProjFrame(NonModalDialog): Line 225  class ProjFrame(NonModalDialog):
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 210  class ProjFrame(NonModalDialog): Line 256  class ProjFrame(NonModalDialog):
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 245  class ProjFrame(NonModalDialog): Line 291  class ProjFrame(NonModalDialog):
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 301  class ProjFrame(NonModalDialog): Line 347  class ProjFrame(NonModalDialog):
347              self.button_import.Enable(True)              self.button_import.Enable(True)
348              self.button_export.Enable(False)              self.button_export.Enable(False)
349              self.button_remove.Enable(False)              self.button_remove.Enable(False)
350                self.button_save.Enable(False)
351    
352          elif len(sel) == 1:          elif len(sel) == 1:
353    
# Line 342  class ProjFrame(NonModalDialog): Line 389  class ProjFrame(NonModalDialog):
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 445  class ProjFrame(NonModalDialog): Line 493  class ProjFrame(NonModalDialog):
493    
494          return None          return None
495    
496      def __FillAvailList(self, selectCurrent = False):      def __FillAvailList(self, selectCurrent = False, selectProj = None):
497          """Populate the list of available projections.          """Populate the list of available projections.
498                    
499          selectCurrent -- if True, select the projection used by          selectCurrent -- if True, select the projection used by
500                           the receiver, otherwise select nothing.                           the receiver, otherwise select nothing.
501            selectProj    -- if set, select the projection found under the
502                             specified name. This overwrites any other
503                             selection estimate.
504          """          """
505    
506          self.availprojs.Clear()          self.availprojs.Clear()
507    
508          #          #
         # We add the current projection to the list first so that  
         # we are sure that it's at index 0. That way we can  
         # set the selection with confidence. The problem is the  
         # the list is automatically sorted when an item is appended  
         # and the index of where it was inserted is not returned.  
         #  
         proj = self.receiver.GetProjection()  
         if proj is not None:  
             self.availprojs.Append(_("%s (current)") % proj.GetName(),  
                                    [proj, None])  
             if selectCurrent:  
                 self.availprojs.SetSelection(0)  
                 self.availprojs.SetFirstItem(0)  
   
         #  
509          # the list can never be empty. there will always be          # the list can never be empty. there will always be
510          # at least this one item          # at least this one item
511          #          #
512          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append("<None>", (None, None))
513    
514          # proj is only None when <None> should be selected          projfile, warnings = get_system_proj_file()
515          if proj is None and selectCurrent:          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)
             self.availprojs.SetSelection(0)  
             self.availprojs.SetFirstItem(0)  
   
         projfile = GetSystemProjFiles()  
         projfile = projfile[0]  
516          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
517              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
518          self.__sysProjFile = projfile          self.__sysProjFile = projfile
519    
520          projfile = GetUserProjFiles()          projfile, warnings = get_user_proj_file()
521          projfile = projfile[0]          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)
522          for proj in projfile.GetProjections():          for proj in projfile.GetProjections():
523              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.availprojs.Append(proj.GetName(), [proj, projfile])
524          self.__usrProjFile = projfile          self.__usrProjFile = projfile
525    
526          for proj, name, clazz in self.projPanels:          #
527              self.projchoice.Append(name, [clazz, None])          # We add the current projection to the list at last.
528            # Since the list is resorted immediately a following FindString()
529            # determines the index correctly.
530            #
531            proj = self.receiver.GetProjection()
532            if proj is not None:
533                proj_item = _("%s (current)") % proj.GetName()
534                self.availprojs.Append(proj_item, [proj, None])
535                if selectCurrent:
536                    self.availprojs.SetSelection(
537                            self.availprojs.FindString(proj_item)
538                        )
539            else:
540                if selectCurrent:
541                    self.availprojs.SetSelection(
542                            self.availprojs.FindString("<None>")
543                        )
544            if selectProj:
545                self.availprojs.SetSelection(
546                            self.availprojs.FindString(selectProj)
547                        )
548    
549                    
550    
551      def __set_properties(self):      def __set_properties(self):
552    
# Line 510  class ProjFrame(NonModalDialog): Line 563  class ProjFrame(NonModalDialog):
563          self.topBox = wxBoxSizer(wxVERTICAL)          self.topBox = wxBoxSizer(wxVERTICAL)
564          self.sizer_panel = wxBoxSizer(wxVERTICAL)          self.sizer_panel = wxBoxSizer(wxVERTICAL)
565          sizer_6 = wxBoxSizer(wxHORIZONTAL)          sizer_6 = wxBoxSizer(wxHORIZONTAL)
566            self.sizer_mainbttns = wxBoxSizer(wxHORIZONTAL)
567          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)
568          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)
569          sizer_11 = wxBoxSizer(wxVERTICAL)          sizer_11 = wxBoxSizer(wxVERTICAL)
# Line 528  class ProjFrame(NonModalDialog): Line 582  class ProjFrame(NonModalDialog):
582          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)          grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)
583          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
584          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)          grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)
585          grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4)          grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4)
586          grid_sizer_1.AddGrowableRow(1)          grid_sizer_1.AddGrowableRow(1)
587          grid_sizer_1.AddGrowableCol(0)          grid_sizer_1.AddGrowableCol(0)
588    
# Line 537  class ProjFrame(NonModalDialog): Line 591  class ProjFrame(NonModalDialog):
591          sizer_13.Add(self.projname, 1, wxALL, 4)          sizer_13.Add(self.projname, 1, wxALL, 4)
592          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)
593          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)          sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
594          sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
595          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)          self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
596          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)          self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
597          sizer_11.Add(self.button_new, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
598          sizer_11.Add(self.button_save, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
599          sizer_11.Add(self.button_add, 0, wxALL|wxEXPAND, 4)          sizer_11.Add(20, 20, 0, wxEXPAND, 0)
600            sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)
601          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)          self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)
602    
603          sizer_6.Add(20, 20, 1, wxEXPAND, 0)          sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)
604          sizer_6.Add(self.button_try, 0, wxALL, 4)          sizer_6.Add(self.button_revert, 0, wxRIGHT| wxEXPAND, 10)
605          sizer_6.Add(20, 20, 1, 0, 0)          sizer_6.Add(self.button_ok, 0, wxRIGHT| wxEXPAND, 10)
606          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)  
607    
608          self.panel_1.SetAutoLayout(1)          self.panel_1.SetAutoLayout(1)
609          self.panel_1.SetSizer(grid_sizer_1)          self.panel_1.SetSizer(grid_sizer_1)
# Line 565  class ProjFrame(NonModalDialog): Line 615  class ProjFrame(NonModalDialog):
615          self.sizer_edit.Fit(self.panel_edit)          self.sizer_edit.Fit(self.panel_edit)
616          self.sizer_edit.SetSizeHints(self.panel_edit)          self.sizer_edit.SetSizeHints(self.panel_edit)
617    
         self.panel_buttons.SetAutoLayout(1)  
         self.panel_buttons.SetSizer(sizer_6)  
         sizer_6.Fit(self.panel_buttons)  
         sizer_6.SetSizeHints(self.panel_buttons)  
   
618          self.sizer_mainctrls.Add(self.panel_1, 0,          self.sizer_mainctrls.Add(self.panel_1, 0,
619              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
620          self.sizer_mainctrls.Add(self.panel_edit, 1,          self.sizer_mainctrls.Add(self.panel_edit, 1,
621              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)              wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
622    
623            self.sizer_mainbttns.Add(sizer_6, 0,
624                wxALL|wxEXPAND|wxADJUST_MINSIZE, 10)
625    
626          self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)          self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)
627          self.topBox.Add(self.panel_buttons, 0, wxEXPAND, 0)          self.topBox.Add(self.sizer_mainbttns, 0, wxALIGN_RIGHT|wxBOTTOM, 0)
628    
629          self.SetAutoLayout(1)          self.SetAutoLayout(1)
630          self.SetSizer(self.topBox)          self.SetSizer(self.topBox)
# Line 594  class ProjPanel(wxPanel): Line 642  class ProjPanel(wxPanel):
642          wxPanel.__init__(self, parent, -1)          wxPanel.__init__(self, parent, -1)
643    
644          self.__ellps = wxChoice(self, -1)          self.__ellps = wxChoice(self, -1)
645          self.ellpsData = [("bessel", _("Bessel 1841")),          self.ellpsData = [("airy"  , _("Airy")),
646                              ("bessel", _("Bessel 1841")),
647                            ("clrk66", _("Clarke 1866")),                            ("clrk66", _("Clarke 1866")),
648                            ("clrk80", _("Clarke 1880")),                            ("clrk80", _("Clarke 1880")),
649                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),
# Line 610  class ProjPanel(wxPanel): Line 659  class ProjPanel(wxPanel):
659    
660          panelSizer = wxBoxSizer(wxVERTICAL)          panelSizer = wxBoxSizer(wxVERTICAL)
661    
         if childPanel is not None:  
             panelSizer.Add(childPanel, 0, wxALL|wxEXPAND, 4)  
               
662          sizer = wxBoxSizer(wxHORIZONTAL)          sizer = wxBoxSizer(wxHORIZONTAL)
663          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0,
664          sizer.Add(self.__ellps, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)                                      wxALL|wxALIGN_CENTER_VERTICAL, 4)
665            sizer.Add(self.__ellps, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)
666          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)          panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)
667    
668            if childPanel is not None:
669                panelSizer.Add(childPanel, 0, wxEXPAND, 0)
670                
671          self.SetAutoLayout(1)          self.SetAutoLayout(1)
672          self.SetSizer(panelSizer)          self.SetSizer(panelSizer)
673          panelSizer.Fit(self)          panelSizer.Fit(self)
# Line 659  class UnknownProjPanel(ProjPanel): Line 709  class UnknownProjPanel(ProjPanel):
709      def _DoLayout(self):      def _DoLayout(self):
710          sizer = wxBoxSizer(wxVERTICAL)          sizer = wxBoxSizer(wxVERTICAL)
711    
712          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
713              _("Thuban does not know the parameters for the " +                                 _("Thuban does not know the parameters for the"
714                "current projection and cannot display a " +                                   " current projection and cannot display a"
715                "configuration panel.")))                                   " configuration panel.")))
716    
717          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
718    
# Line 683  class TMPanel(ProjPanel): Line 733  class TMPanel(ProjPanel):
733    
734          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)
735          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)
736            self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)
737          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)
738          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)
         self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)  
739    
740          self._DoLayout()          self._DoLayout()
741    
# Line 751  class UTMPanel(ProjPanel): Line 801  class UTMPanel(ProjPanel):
801          self.receiver = receiver          self.receiver = receiver
802    
803          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)          self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)
804            self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))
805          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,          self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,
806                                    _("Southern Hemisphere"))                                    _("Southern Hemisphere"))
         self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))  
807    
808          self._DoLayout()          self._DoLayout()
809    
# Line 793  class UTMPanel(ProjPanel): Line 843  class UTMPanel(ProjPanel):
843          ProjPanel.Clear(self)          ProjPanel.Clear(self)
844    
845      def _OnPropose(self, event):      def _OnPropose(self, event):
846          UTMProposeZoneDialog          """Call the propose dialog.
847            If the receiver (e.g. the current map) has no bounding box,
848            inform the user accordingly.
849            """
850            bb = self.receiver.BoundingBox()
851            if bb is None:
852                dlg = wxMessageDialog(self,
853                        _("Can not propose: No bounding box found."),
854                        _("Projection: Propose UTM Zone"),
855                        wxOK | wxICON_INFORMATION)
856                dlg.CenterOnParent()
857                result = dlg.ShowModal()
858                dlg.Destroy()
859                return
860    
861          dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())          dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())
862          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
863              self.__zone.SetValue(dlg.GetProposedZone())              self.__zone.SetValue(dlg.GetProposedZone())
# Line 822  class LCCPanel(ProjPanel): Line 886  class LCCPanel(ProjPanel):
886          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
887              _("Latitude of second standard parallel:")))              _("Latitude of second standard parallel:")))
888          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)  
889          sizer.Add(wxStaticText(self, -1, _("Central Meridian:")))          sizer.Add(wxStaticText(self, -1, _("Central Meridian:")))
890          sizer.Add(self.__meridian, 0, wxALL, 4)          sizer.Add(self.__meridian, 0, wxALL, 4)
891            sizer.Add(wxStaticText(self, -1, _("Latitude of origin:")))
892            sizer.Add(self.__originLat, 0, wxALL, 4)
893          sizer.Add(wxStaticText(self, -1, _("False Easting:")))          sizer.Add(wxStaticText(self, -1, _("False Easting:")))
894          sizer.Add(self.__falseEast, 0, wxALL, 4)          sizer.Add(self.__falseEast, 0, wxALL, 4)
895          sizer.Add(wxStaticText(self, -1, _("False Northing:")))          sizer.Add(wxStaticText(self, -1, _("False Northing:")))
# Line 873  class GeoPanel(ProjPanel): Line 937  class GeoPanel(ProjPanel):
937    
938      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
939          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
940          ProjPanel._DoLayout(self, None)  
941            self.__choices = [(_("Degrees"), "0.017453"),
942                              (_("Radians"), "1")]
943    
944            self.__scale = wxChoice(self, -1)
945            for choice, value in self.__choices:
946                self.__scale.Append(choice, value)
947    
948            self._DoLayout()
949    
950      def GetProjName(self):      def GetProjName(self):
951          return _("Geographic")          return _("Geographic")
952                    
953      def SetProjection(self, proj):      def SetProjection(self, proj):
954            value = proj.GetParameter("to_meter")
955            for i in range(len(self.__choices)):
956                choice, data = self.__choices[i]
957                if value == data:
958                    self.__scale.SetSelection(i)
959          ProjPanel.SetProjection(self, proj)          ProjPanel.SetProjection(self, proj)
960    
961      def GetParameters(self):      def GetParameters(self):
962          params = ["proj=latlong"]          params = ["proj=latlong",
963                      "to_meter=%s" % self.__scale.GetClientData(
964                                      self.__scale.GetSelection())]
965    
966          params.extend(ProjPanel.GetParameters(self))          params.extend(ProjPanel.GetParameters(self))
967          return params          return params
968    
969      def Clear(self):      def Clear(self):
970          ProjPanel.Clear(self)          ProjPanel.Clear(self)
971    
972        def _DoLayout(self):
973            sizer = wxBoxSizer(wxHORIZONTAL)
974    
975            sizer.Add(wxStaticText(self, -1, _("Source Data is in: ")),
976                      0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
977            sizer.Add(self.__scale, 1, wxEXPAND|wxALL, 4)
978    
979            self.__scale.SetSelection(0)
980    
981            ProjPanel._DoLayout(self, sizer)
982    
983    
984  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001
985  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002
986  class UTMProposeZoneDialog(wxDialog):  class UTMProposeZoneDialog(wxDialog):
987                                                                                    
988      """Propose a sensible Zone considering the current map extent."""      """Propose a sensible Zone considering the current map extent."""
989                                                                                    
990      def __init__(self, parent, (x, y, x2, y2)):      def __init__(self, parent, (x, y, x2, y2)):
991          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),
992                            wxDefaultPosition, wxSize(200, 100))                            wxDefaultPosition, wxSize(200, 100))
993          self.parent = parent          self.parent = parent
         #x, y, x2, y2 = elf.parent.parent.map_bounding_box  
994          x = x + 180          x = x + 180
995          x2 = x2 + 180          x2 = x2 + 180
996          center = (x2 - x) / 2 + x          center = (x2 - x) / 2 + x
997          self.proposedZone = int(center / 6 + 1)          self.proposedZone = int(center / 6 + 1)
998          self.dialogLayout()          self.dialogLayout()
999                                                                                    
1000      def dialogLayout(self):      def dialogLayout(self):
1001          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
1002                                                                                    
1003          textBox = wxBoxSizer(wxVERTICAL)          textBox = wxBoxSizer(wxVERTICAL)
1004          textBox.Add(wxStaticText(self, -1, _("The current map extent center " +          textBox.Add(wxStaticText(self, -1, _("The current map extent center "
1005                                             "lies in UTM Zone")),                                               "lies in UTM Zone")),
1006                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
1007          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),
1008                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
1009                                                                                    
1010          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)
1011                                                                                    
1012          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
1013          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,
1014                        _("Take")), 0, wxALL, 4)                        _("Take")), 0, wxALL, 4)
# Line 927  class UTMProposeZoneDialog(wxDialog): Line 1017  class UTMProposeZoneDialog(wxDialog):
1017          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
1018          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)
1019          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)
1020                                                                                    
1021          self.SetAutoLayout(True)          self.SetAutoLayout(True)
1022          self.SetSizer(topBox)          self.SetSizer(topBox)
1023          topBox.Fit(self)          topBox.Fit(self)
1024          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
1025                                                                                    
1026      def OnTake(self, event):      def OnTake(self, event):
1027          self.EndModal(wxID_OK)          self.EndModal(wxID_OK)
1028                                                                                    
1029      def OnCancel(self, event):      def OnCancel(self, event):
1030          self.EndModal(wxID_CANCEL)          self.EndModal(wxID_CANCEL)
1031    

Legend:
Removed from v.757  
changed lines
  Added in v.1786

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26