/[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 1549 by jan, Wed Aug 6 11:18:29 2003 UTC revision 1833 by bh, Mon Oct 20 11:00:57 2003 UTC
# Line 13  __version__ = "$Revision$" Line 13  __version__ = "$Revision$"
13  # $Source$  # $Source$
14  # $Id$  # $Id$
15    
16  import os, sys, math  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 get_user_proj_files, get_system_proj_files, \  from Thuban.Model.resource import get_user_proj_file, get_system_proj_file, \
24                                    read_proj_file, write_proj_file                                    read_proj_file, write_proj_file
25  from Thuban.UI.dialogs import NonModalNonParentDialog  from Thuban.UI.dialogs import NonModalNonParentDialog
26    
27    from common import ThubanBeginBusyCursor, ThubanEndBusyCursor
28    from sizers import NotebookLikeSizer
29    
30  ID_PROJ_ADVANCED  = 4001  ID_PROJ_ADVANCED  = 4001
31  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
# Line 49  class ProjFrame(NonModalNonParentDialog) Line 51  class ProjFrame(NonModalNonParentDialog)
51                          SetProjection(projection)                          SetProjection(projection)
52                          GetProjection()                          GetProjection()
53          """          """
54                    NonModalNonParentDialog.__init__(self, parent, name, title)
55    
56            self.projection_panel_defs = [
57                ("tmerc", _("Transverse Mercator"), TMPanel),
58                ("utm", _("Universal Transverse Mercator"), UTMPanel),
59                ("lcc", _("Lambert Conic Conformal"), LCCPanel),
60                ("latlong", _("Geographic"), GeoPanel)]
61          self.receiver = receiver          self.receiver = receiver
62          self.haveTried = False          self.haveTried = False
63          self.curProjPanel = None          self.curProjPanel = None
64    
65          self.projPanels = []          self.build_dialog()
66          self.projPanels.append(          self.Layout()
             ("tmerc", _("Transverse Mercator"), TMPanel))  
         self.projPanels.append(  
             ("utm", _("Universal Transverse Mercator"), UTMPanel))  
         self.projPanels.append(  
             ("lcc", _("Lambert Conic Conformal"), LCCPanel))  
         self.projPanels.append(  
             ("latlong", _("Geographic"), GeoPanel))  
67    
68          NonModalNonParentDialog.__init__(self, parent, name, title)          self.originalProjection = self.receiver.GetProjection()
         # originally generate by wxGlade  
         self.panel_1 = wxPanel(self, -1)  
         self.panel_edit = wxPanel(self, -1)  
         self.label_5 = wxStaticText(self.panel_1, -1,  
                         _("Available Projections:"))  
69    
70          # Projection List specific actions (Import/Export/Remove)          self.__DoOnProjAvail()
71          self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT,          self.button_ok.SetFocus()
72                                        _("Import..."))          self.availprojs.SetFocus()
73          self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT,  
74                                        _("Export..."))      def build_dialog(self):
75          self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE,          """Build the dialog's widgets and set the event handlers"""
76                                        _("Remove"))          self.topBox = top_box = wxBoxSizer(wxVERTICAL)
77    
78            main_box = wxBoxSizer(wxHORIZONTAL)
79            top_box.Add(main_box, 1, wxALL|wxEXPAND)
80    
81            #
82            #    The projection list and associated controls
83            #
84            vbox = wxBoxSizer(wxVERTICAL)
85            main_box.Add(vbox, 0, wxALL|wxEXPAND)
86    
87          # The Projection List          label = wxStaticText(self, -1, _("Available Projections:"))
88          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL,          vbox.Add(label, 0, wxLEFT|wxRIGHT|wxTOP, 4)
89    
90            hbox = wxBoxSizer(wxHORIZONTAL)
91            vbox.Add(hbox, 1, wxALL|wxEXPAND)
92            self.availprojs = wxListBox(self, ID_PROJ_AVAIL,
93                                      style=wxLB_EXTENDED|wxLB_SORT)                                      style=wxLB_EXTENDED|wxLB_SORT)
94          self.projfilepath = wxStaticText(self.panel_1, -1, "")          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
95            hbox.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
96            self.__FillAvailList(selectCurrent = True)
97    
98          # Projection Specific Entries (Name/Projection)          # Projection List specific actions (Import/Export/Remove)
99          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))          buttons = wxBoxSizer(wxVERTICAL)
100          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")          hbox.Add(buttons, 0, wxALL)
101          self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))          self.button_import = wxButton(self, ID_PROJ_IMPORT, _("Import..."))
102          self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)          EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
103            buttons.Add(self.button_import, 1, wxALL|wxEXPAND, 4)
104            self.button_export = wxButton(self, ID_PROJ_EXPORT, _("Export..."))
105            EVT_BUTTON(self, ID_PROJ_EXPORT, self._OnExport)
106            buttons.Add(self.button_export, 1, wxALL|wxEXPAND, 4)
107            buttons.Add(20, 20, 0, wxEXPAND, 0)
108            self.button_remove = wxButton(self, ID_PROJ_REMOVE, _("Remove"))
109            EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)
110            buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4)
111    
112          # Projection Specific actions (New/Save/Add)          # The file path
113          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))          self.projfilepath = wxStaticText(self, -1, "")
114          self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,          vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND)
                                       _("Add to List"))  
         self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Update"))  
115    
116          # Main Action buttons (Try/Revert/OK/Close)          #
117          self.button_try = wxButton(self, wxID_APPLY, _("Try"))          #   The projection editor part
118          self.button_revert = wxButton(self, ID_PROJ_REVERT,          #
119                                        _("Revert"))          self.edit_box = wxStaticBox(self, -1, _("Edit"))
120          self.button_ok = wxButton(self, wxID_OK, _("OK"))          sizer_edit = wxStaticBoxSizer(self.edit_box, wxHORIZONTAL)
121          self.button_ok.SetDefault()          main_box.Add(sizer_edit, 1, wxALL|wxEXPAND)
         self.button_close = wxButton(self, wxID_CANCEL,  
                                      _("Close"))  
122    
123          self.__set_properties()          # Projection Specific Entries (Name/Projection)
124          self.__do_layout()          self.sizer_projctrls = wxBoxSizer(wxVERTICAL)
125            sizer_edit.Add(self.sizer_projctrls, 1, wxALL|wxEXPAND)
126    
127          # wxGlade          hbox = wxBoxSizer(wxHORIZONTAL)
128            self.sizer_projctrls.Add(hbox, 0, wxALL|wxEXPAND)
129            label = wxStaticText(self, -1, _("Name:"))
130            hbox.Add(label, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
131            self.projname = wxTextCtrl(self, ID_PROJ_PROJNAME, "")
132            EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
133            hbox.Add(self.projname, 1, wxALL|wxEXPAND, 4)
134    
135            hbox = wxBoxSizer(wxHORIZONTAL)
136            self.sizer_projctrls.Add(hbox, 0, wxALL|wxEXPAND)
137            label = wxStaticText(self, -1, _("Projection:"))
138            hbox.Add(label, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
139            self.projchoice = wxChoice(self, ID_PROJ_PROJCHOICE)
140            self.projchoice.SetSelection(0)
141            EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
142            hbox.Add(self.projchoice, 1, wxALL|wxEXPAND, 4)
143          # Fill the projection choice list.          # Fill the projection choice list.
144          for proj, name, clazz in self.projPanels:          self.nbsizer = NotebookLikeSizer()
145              self.projchoice.Append(name, [clazz, None])          self.sizer_projctrls.Add(self.nbsizer, 1,
146                                     wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)
147            self.projection_panels = []
148            for proj_type, name, cls in self.projection_panel_defs:
149                self.projchoice.Append(name, proj_type)
150                panel = cls(self, self.receiver)
151                panel.Hide()
152                panel.projection_index = len(self.projection_panels)
153                panel.projection_type = proj_type
154                self.projection_panels.append(panel)
155                self.nbsizer.Add(panel)
156            self.unknown_projection_panel = UnknownProjPanel(self, self.receiver)
157            self.unknown_projection_panel.Hide()
158            self.nbsizer.Add(self.unknown_projection_panel)
159    
160          self.originalProjection = self.receiver.GetProjection()          # Projection Specific actions (New/Save/Add)
161            buttons = wxBoxSizer(wxVERTICAL)
162            sizer_edit.Add(buttons, 0, wxALL)
163            self.button_new = wxButton(self, ID_PROJ_NEW, _("New"))
164            EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
165            buttons.Add(self.button_new, 0, wxEXPAND|wxALL, 4)
166            self.button_add = wxButton(self, ID_PROJ_ADDTOLIST, _("Add to List"))
167            EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)
168            buttons.Add(self.button_add, 0, wxEXPAND|wxALL, 4)
169            buttons.Add(20, 20, 0, wxEXPAND, 0)
170            self.button_save = wxButton(self, ID_PROJ_SAVE,_("Update"))
171            EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
172            buttons.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)
173    
174          self.__DoOnProjAvail()          #
175          self.button_ok.SetFocus()          # Main Action buttons (Try/Revert/OK/Close)
176          self.availprojs.SetFocus()          #
177                    buttons = wxBoxSizer(wxHORIZONTAL)
178            top_box.Add(buttons, 0, wxALL|wxALIGN_RIGHT, 10)
179            self.button_try = wxButton(self, wxID_APPLY, _("Try"))
180          EVT_BUTTON(self, wxID_APPLY, self.OnApply)          EVT_BUTTON(self, wxID_APPLY, self.OnApply)
181            buttons.Add(self.button_try, 0, wxRIGHT, 10)
182            self.button_revert = wxButton(self, ID_PROJ_REVERT, _("Revert"))
183          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)          EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
184            buttons.Add(self.button_revert, 0, wxRIGHT, 10)
185            self.button_ok = wxButton(self, wxID_OK, _("OK"))
186          EVT_BUTTON(self, wxID_OK, self.OnOK)          EVT_BUTTON(self, wxID_OK, self.OnOK)
187            self.button_ok.SetDefault()
188            buttons.Add(self.button_ok, 0, wxRIGHT, 10)
189            self.button_close = wxButton(self, wxID_CANCEL, _("Close"))
190          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)          EVT_BUTTON(self, wxID_CANCEL, self.OnCancel)
191          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          buttons.Add(self.button_close, 0, wxRIGHT, 10)
         EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)  
         EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)  
         EVT_BUTTON(self, ID_PROJ_EXPORT, self._OnExport)  
         EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)  
192    
         EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)  
         EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)  
         EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)  
193    
194          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          #
195            # Automatic Layout
196            #
197            self.SetAutoLayout(1)
198            self.SetSizer(top_box)
199            top_box.Fit(self)
200            top_box.SetSizeHints(self)
201    
202      def OnApply(self, event):      def OnApply(self, event):
203          self.__SetProjection()          self.__SetProjection()
# Line 184  class ProjFrame(NonModalNonParentDialog) Line 247  class ProjFrame(NonModalNonParentDialog)
247    
248          if newproj is not None:          if newproj is not None:
249              projfile.Replace(proj, newproj)              projfile.Replace(proj, newproj)
250              try:              self.write_proj_file(projfile)
                 write_proj_file(projfile)  
             except IOError, (errno, errstr):  
                 self.__ShowError(projfile.GetFilename(), errstr)  
251              self.availprojs.SetClientData(sel[0], [newproj, projfile])              self.availprojs.SetClientData(sel[0], [newproj, projfile])
252    
253              self.__FillAvailList( selectProj = newproj.GetName())              self.__FillAvailList( selectProj = newproj.Label())
254    
255      def _OnAddToList(self, event):      def _OnAddToList(self, event):
256    
257          proj = self.__GetProjection()          proj = self.__GetProjection()
258          if proj is not None:          if proj is not None:
259              self.__usrProjFile.Add(proj)              self.__usrProjFile.Add(proj)
260              try:              self.write_proj_file(self.__usrProjFile)
261                  write_proj_file(self.__usrProjFile)              self.__FillAvailList( selectProj = proj.Label())
             except IOError, (errno, errstr):  
                 self.__ShowError(self.__userProjFile.GetFilename(), errstr)  
   
             self.__FillAvailList( selectProj = proj.GetName())  
262    
263      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
264          self.__DoOnProjAvail()          self.__DoOnProjAvail()
265    
266        def show_warnings(self, title, filename, warnings):
267            """Show the warnings (a list of strings) in a dialog
268    
269            If the list is empty no dialog will be shown.
270            """
271            if warnings:
272                text = (_('Warnings when reading "%s":\n\n%s')
273                        % (filename, "\n\n".join(warnings)))
274                self.parent.RunMessageBox(title, text)
275    
276      def _OnImport(self, event):      def _OnImport(self, event):
277    
278          dlg = wxFileDialog(self, _("Import"), style = wxOPEN)          dlg = wxFileDialog(self, _("Import"), style = wxOPEN)
# Line 214  class ProjFrame(NonModalNonParentDialog) Line 280  class ProjFrame(NonModalNonParentDialog)
280          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
281              path = dlg.GetPath()              path = dlg.GetPath()
282    
283                ThubanBeginBusyCursor()
284              try:              try:
285                  projFile = read_proj_file(path)                  try:
286                  for proj in projFile.GetProjections():                      projFile, warnings = read_proj_file(path)
287                      self.__usrProjFile.Add(proj)                  except IOError, (errno, errstr):
288                  write_proj_file(self.__usrProjFile)                      self.__ShowError(dlg.GetPath(), errstr)
289              except IOError, (errno, errstr):                  else:
290                  self.__ShowError(dlg.GetPath(), errstr)                      self.show_warnings(_("Warnings"), path, warnings)
291                        for proj in projFile.GetProjections():
292                            self.__usrProjFile.Add(proj)
293                        self.write_proj_file(self.__usrProjFile)
294                finally:
295                    ThubanEndBusyCursor()
296    
297              self.__FillAvailList()              self.__FillAvailList()
298    
# Line 244  class ProjFrame(NonModalNonParentDialog) Line 316  class ProjFrame(NonModalNonParentDialog)
316                  if proj is not None:                  if proj is not None:
317                      projFile.Add(proj)                      projFile.Add(proj)
318    
319              try:              self.write_proj_file(projFile)
                 write_proj_file(projFile)  
             except IOError, (errno, errstr):  
                 self.__ShowError(dlg.GetPath(), errstr)  
320    
321          dlg.Destroy()          dlg.Destroy()
322    
# Line 279  class ProjFrame(NonModalNonParentDialog) Line 348  class ProjFrame(NonModalNonParentDialog)
348              if proj is not None and projfile is not None:              if proj is not None and projfile is not None:
349                  projfile.Remove(proj)                  projfile.Remove(proj)
350    
351          try:          self.write_proj_file(projfile)
             write_proj_file(projfile)  
         except IOError, (errno, errstr):  
             self.__ShowError(projfile.GetFilename(), errstr)  
352    
353          self.__FillAvailList()          self.__FillAvailList()
354    
# Line 317  class ProjFrame(NonModalNonParentDialog) Line 383  class ProjFrame(NonModalNonParentDialog)
383          self.button_save.Enable(True)          self.button_save.Enable(True)
384          self.button_remove.Enable(True)          self.button_remove.Enable(True)
385    
386          self.panel_edit.Enable(True)          self.edit_box.Enable(True)
387    
388          for ctrl in [self.button_import,          for ctrl in [self.button_import,
389                       self.button_export,                       self.button_export,
# Line 326  class ProjFrame(NonModalNonParentDialog) Line 392  class ProjFrame(NonModalNonParentDialog)
392                       self.button_add,                       self.button_add,
393                       self.projchoice,                       self.projchoice,
394                       self.projname,                       self.projname,
395                       self.panel_edit]:                       self.edit_box]:
396              ctrl.Enable(True)              ctrl.Enable(True)
397    
398          if self.curProjPanel is not None:          if self.curProjPanel is not None:
# Line 365  class ProjFrame(NonModalNonParentDialog) Line 431  class ProjFrame(NonModalNonParentDialog)
431                  self.button_save.Enable(False)                  self.button_save.Enable(False)
432    
433          else:          else:
434              self.panel_edit.Enable(False)              self.edit_box.Enable(False)
435    
436      def __DoOnProjAvail(self):      def __DoOnProjAvail(self):
437    
# Line 380  class ProjFrame(NonModalNonParentDialog) Line 446  class ProjFrame(NonModalNonParentDialog)
446                  self.projname.Clear()                  self.projname.Clear()
447                  self.projfilepath.SetLabel(_("Projection File: "))                  self.projfilepath.SetLabel(_("Projection File: "))
448              else:              else:
449                
450                  if projfile is not None:                  if projfile is not None:
451                      self.projfilepath.SetLabel(_("Projection File: ") +                      self.projfilepath.SetLabel(_("Projection File: ") +
452                          os.path.basename(projfile.GetFilename()))                          os.path.basename(projfile.GetFilename()))
# Line 388  class ProjFrame(NonModalNonParentDialog) Line 454  class ProjFrame(NonModalNonParentDialog)
454                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
455                      self.projfilepath.SetLabel(_("Projection File: "))                      self.projfilepath.SetLabel(_("Projection File: "))
456    
457                  self.projname.SetValue(proj.GetName())                  self.projname.SetValue(proj.Label())
458    
459                  myProjType = proj.GetParameter("proj")                  myProjType = proj.GetParameter("proj")
460                  i = 0                  i = 0
461                  for projType, name, clazz in self.projPanels:                  for projType, name, cls in self.projection_panel_defs:
462                      if myProjType == projType:                      if myProjType == projType:
463                            self.projchoice.Enable(True)
464                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i)
465                          self.__DoOnProjChoice()                          self.__DoOnProjChoice()
466    
# Line 404  class ProjFrame(NonModalNonParentDialog) Line 471  class ProjFrame(NonModalNonParentDialog)
471                          assert self.curProjPanel is not None                          assert self.curProjPanel is not None
472    
473                          self.curProjPanel.SetProjection(proj)                          self.curProjPanel.SetProjection(proj)
474                            break
475                      i += 1                      i += 1
476                    else:
477                        self.projchoice.Disable()
478                        self._show_proj_panel(UnknownProjPanel)
479    
480          self.__VerifyButtons()          self.__VerifyButtons()
481    
# Line 421  class ProjFrame(NonModalNonParentDialog) Line 492  class ProjFrame(NonModalNonParentDialog)
492          At the end of this method self.curProjPanel will not be None          At the end of this method self.curProjPanel will not be None
493          if there was a item selected.          if there was a item selected.
494          """          """
   
495          choice = self.projchoice          choice = self.projchoice
496    
497          sel = choice.GetSelection()          sel = choice.GetSelection()
498          if sel != -1:          if sel != -1:
499                proj_type = choice.GetClientData(sel)
500              clazz, obj = choice.GetClientData(sel)              for t, name, cls in self.projection_panel_defs:
501                    if t == proj_type:
502              if obj is None:                      self._show_proj_panel(cls)
503                  obj = clazz(self.panel_edit, self.receiver)                      break
504                  choice.SetClientData(sel, [clazz, obj])          # FIXME: what to do if sel == -1?
505    
506              if self.curProjPanel is not None:      def _show_proj_panel(self, panel_class):
507                  self.curProjPanel.Hide()          """Show the panel as the projection panel"""
508                  self.sizer_projctrls.Remove(self.curProjPanel)          if panel_class is UnknownProjPanel:
509                self.edit_box.Disable()
510              self.curProjPanel = obj              self.nbsizer.Activate(self.unknown_projection_panel)
511              self.curProjPanel.Show()              self.curProjPanel = self.unknown_projection_panel
512            else:
513              self.sizer_projctrls.Add(self.curProjPanel, 1,              self.edit_box.Enable(True)
514                  wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)              self.unknown_projection_panel.Hide()
515              self.sizer_projctrls.Layout()              for panel in self.projection_panels:
516              self.Layout()                  if panel.__class__ is panel_class:
517              self.topBox.SetSizeHints(self)                      self.nbsizer.Activate(panel)
518                        self.curProjPanel = panel
519    
520      def __SetProjection(self):      def __SetProjection(self):
521          """Set the receiver's projection."""          """Set the receiver's projection."""
# Line 498  class ProjFrame(NonModalNonParentDialog) Line 569  class ProjFrame(NonModalNonParentDialog)
569          # the list can never be empty. there will always be          # the list can never be empty. there will always be
570          # at least this one item          # at least this one item
571          #          #
572          self.availprojs.Append("<None>", (None, None))          self.availprojs.Append(_("<None>"), (None, None))
573    
574          projfile = get_system_proj_files()          ThubanBeginBusyCursor()
575          projfile = projfile[0]          try:
576          for proj in projfile.GetProjections():              projfile, warnings = get_system_proj_file()
577              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)
578          self.__sysProjFile = projfile              for proj in projfile.GetProjections():
579                    self.availprojs.Append(proj.Label(), [proj, projfile])
580          projfile = get_user_proj_files()              self.__sysProjFile = projfile
581          projfile = projfile[0]  
582          for proj in projfile.GetProjections():              projfile, warnings = get_user_proj_file()
583              self.availprojs.Append(proj.GetName(), [proj, projfile])              self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)
584          self.__usrProjFile = projfile              for proj in projfile.GetProjections():
585                    self.availprojs.Append(proj.Label(), [proj, projfile])
586                self.__usrProjFile = projfile
587            finally:
588                ThubanEndBusyCursor()
589    
590          #          #
591          # We add the current projection to the list at last.          # We add the current projection to the list at last.
# Line 519  class ProjFrame(NonModalNonParentDialog) Line 594  class ProjFrame(NonModalNonParentDialog)
594          #          #
595          proj = self.receiver.GetProjection()          proj = self.receiver.GetProjection()
596          if proj is not None:          if proj is not None:
597              proj_item = _("%s (current)") % proj.GetName()              proj_item = _("%s (current)") % proj.Label()
598              self.availprojs.Append(proj_item, [proj, None])              self.availprojs.Append(proj_item, [proj, None])
599              if selectCurrent:              if selectCurrent:
600                  self.availprojs.SetSelection(                  self.availprojs.SetSelection(
# Line 528  class ProjFrame(NonModalNonParentDialog) Line 603  class ProjFrame(NonModalNonParentDialog)
603          else:          else:
604              if selectCurrent:              if selectCurrent:
605                  self.availprojs.SetSelection(                  self.availprojs.SetSelection(
606                          self.availprojs.FindString("<None>")                          self.availprojs.FindString(_("<None>"))
607                      )                      )
608          if selectProj:          if selectProj:
609              self.availprojs.SetSelection(              self.availprojs.SetSelection(
610                          self.availprojs.FindString(selectProj)                          self.availprojs.FindString(selectProj)
611                      )                      )
612    
613                        def write_proj_file(self, proj_file):
614            """Write the ProjFile object proj_file back to its file
     def __set_properties(self):  
   
         #self.availprojs.SetSelection(0)  
         self.projchoice.SetSelection(0)  
   
         self.__FillAvailList(selectCurrent = True)  
   
         self.projname.SetMaxLength(32)  
615    
616      def __do_layout(self):          Show a busy cursor while writing and if an error occurs show a
617          # originally generated by wxGlade          dialog with the error message.
618            """
619          self.topBox = wxBoxSizer(wxVERTICAL)          try:
620          self.sizer_panel = wxBoxSizer(wxVERTICAL)              ThubanBeginBusyCursor()
621          sizer_6 = wxBoxSizer(wxHORIZONTAL)              try:
622          self.sizer_mainbttns = wxBoxSizer(wxHORIZONTAL)                  write_proj_file(proj_file)
623          self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)              finally:
624          self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)                  ThubanEndBusyCursor()
625          sizer_11 = wxBoxSizer(wxVERTICAL)          except IOError, (errno, errstr):
626          self.sizer_projctrls = wxBoxSizer(wxVERTICAL)              self.__ShowError(proj_file.GetFilename(), errstr)
         sizer_14 = wxBoxSizer(wxHORIZONTAL)  
         sizer_13 = wxBoxSizer(wxHORIZONTAL)  
         sizer_15 = wxBoxSizer(wxVERTICAL)  
         sizer_15.Add(self.button_import, 0, wxALL, 4)  
         sizer_15.Add(self.button_export, 0, wxALL, 4)  
         sizer_15.Add(20, 20, 0, wxEXPAND, 0)  
         sizer_15.Add(self.button_remove, 0, wxALL|wxALIGN_BOTTOM, 4)  
   
         # list controls  
         grid_sizer_1 = wxFlexGridSizer(3, 2, 0, 0)  
         grid_sizer_1.Add(self.label_5, 0, wxLEFT|wxRIGHT|wxTOP, 4)  
         grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)  
         grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)  
         grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)  
         grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4)  
         grid_sizer_1.AddGrowableRow(1)  
         grid_sizer_1.AddGrowableCol(0)  
   
         # edit controls  
         sizer_13.Add(self.label_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)  
         sizer_13.Add(self.projname, 1, wxALL, 4)  
         self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)  
         sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)  
         sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4)  
         self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)  
         self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)  
         sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4)  
         sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4)  
         sizer_11.Add(20, 20, 0, wxEXPAND, 0)  
         sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4)  
         self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)  
   
         sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10)  
         sizer_6.Add(self.button_revert, 0, wxRIGHT| wxEXPAND, 10)  
         sizer_6.Add(self.button_ok, 0, wxRIGHT| wxEXPAND, 10)  
         sizer_6.Add(self.button_close, 0, wxRIGHT| wxEXPAND, 10)  
   
         self.panel_1.SetAutoLayout(1)  
         self.panel_1.SetSizer(grid_sizer_1)  
         grid_sizer_1.Fit(self.panel_1)  
         grid_sizer_1.SetSizeHints(self.panel_1)  
   
         self.panel_edit.SetAutoLayout(1)  
         self.panel_edit.SetSizer(self.sizer_edit)  
         self.sizer_edit.Fit(self.panel_edit)  
         self.sizer_edit.SetSizeHints(self.panel_edit)  
   
         self.sizer_mainctrls.Add(self.panel_1, 0,  
             wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)  
         self.sizer_mainctrls.Add(self.panel_edit, 1,  
             wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)  
   
         self.sizer_mainbttns.Add(sizer_6, 0,  
             wxALL|wxEXPAND|wxADJUST_MINSIZE, 10)  
   
         self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)  
         self.topBox.Add(self.sizer_mainbttns, 0, wxALIGN_RIGHT|wxBOTTOM, 0)  
   
         self.SetAutoLayout(1)  
         self.SetSizer(self.topBox)  
         self.topBox.Fit(self)  
         self.topBox.SetSizeHints(self)  
         self.Layout()  
627    
 # end of class ProjFrame  
628    
629    
630  class ProjPanel(wxPanel):  class ProjPanel(wxPanel):
# Line 690  ID_TMPANEL_FALSE_NORTH = 4004 Line 693  ID_TMPANEL_FALSE_NORTH = 4004
693  ID_TMPANEL_SCALE = 4005  ID_TMPANEL_SCALE = 4005
694    
695  class UnknownProjPanel(ProjPanel):  class UnknownProjPanel(ProjPanel):
696    
697        """Panel for unknown projection types"""
698    
699      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
700          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
701    
# Line 698  class UnknownProjPanel(ProjPanel): Line 704  class UnknownProjPanel(ProjPanel):
704      def _DoLayout(self):      def _DoLayout(self):
705          sizer = wxBoxSizer(wxVERTICAL)          sizer = wxBoxSizer(wxVERTICAL)
706    
707          sizer.Add(wxStaticText(self, -1,          sizer.Add(wxStaticText(self, -1,
708              _("Thuban does not know the parameters for the " +                                 _("Thuban does not know the parameters\n"
709                "current projection and cannot display a " +                                   "for the current projection and cannot\n"
710                "configuration panel.")))                                   "display a configuration panel.")))
711    
712          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
713    
# Line 730  class TMPanel(ProjPanel): Line 736  class TMPanel(ProjPanel):
736    
737      def _DoLayout(self):      def _DoLayout(self):
738    
739          sizer = wxFlexGridSizer(4, 4, 0, 0)          sizer = wxFlexGridSizer(4, 2, 0, 0)
740          sizer.Add(wxStaticText(self, -1, _("Latitude:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Latitude:")), 0, wxALL, 4)
741          sizer.Add(self.__latitude, 0, wxALL, 4)          sizer.Add(self.__latitude, 0, wxALL, 4)
         sizer.Add(wxStaticText(self, -1, _("False Easting:")), 0, wxALL, 4)  
         sizer.Add(self.__falseEast, 0, wxALL, 4)  
742          sizer.Add(wxStaticText(self, -1, _("Longitude:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Longitude:")), 0, wxALL, 4)
743          sizer.Add(self.__longitude, 0, wxALL, 4)          sizer.Add(self.__longitude, 0, wxALL, 4)
744            sizer.Add(wxStaticText(self, -1, _("False Easting:")), 0, wxALL, 4)
745            sizer.Add(self.__falseEast, 0, wxALL, 4)
746          sizer.Add(wxStaticText(self, -1, _("False Northing:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("False Northing:")), 0, wxALL, 4)
747          sizer.Add(self.__falseNorth, 0, wxALL, 4)          sizer.Add(self.__falseNorth, 0, wxALL, 4)
748          sizer.Add(wxStaticText(self, -1, _("Scale Factor:")), 0, wxALL, 4)          sizer.Add(wxStaticText(self, -1, _("Scale Factor:")), 0, wxALL, 4)
# Line 973  class GeoPanel(ProjPanel): Line 979  class GeoPanel(ProjPanel):
979  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001  ID_UTM_PROPOSE_ZONE_DIALOG_TAKE   = 4001
980  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002  ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002
981  class UTMProposeZoneDialog(wxDialog):  class UTMProposeZoneDialog(wxDialog):
982                                                                                    
983      """Propose a sensible Zone considering the current map extent."""      """Propose a sensible Zone considering the current map extent."""
984                                                                                    
985      def __init__(self, parent, (x, y, x2, y2)):      def __init__(self, parent, (x, y, x2, y2)):
986          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),          wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),
987                            wxDefaultPosition, wxSize(200, 100))                            wxDefaultPosition, wxSize(200, 100))
# Line 985  class UTMProposeZoneDialog(wxDialog): Line 991  class UTMProposeZoneDialog(wxDialog):
991          center = (x2 - x) / 2 + x          center = (x2 - x) / 2 + x
992          self.proposedZone = int(center / 6 + 1)          self.proposedZone = int(center / 6 + 1)
993          self.dialogLayout()          self.dialogLayout()
994                                                                                    
995      def dialogLayout(self):      def dialogLayout(self):
996          topBox = wxBoxSizer(wxVERTICAL)          topBox = wxBoxSizer(wxVERTICAL)
997                                                                                    
998          textBox = wxBoxSizer(wxVERTICAL)          textBox = wxBoxSizer(wxVERTICAL)
999          textBox.Add(wxStaticText(self, -1, _("The current map extent center " +          textBox.Add(wxStaticText(self, -1, _("The current map extent center "
1000                                             "lies in UTM Zone")),                                               "lies in UTM Zone")),
1001                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
1002          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),          textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),
1003                      0, wxALIGN_CENTER|wxALL, 4)                      0, wxALIGN_CENTER|wxALL, 4)
1004                                                                                    
1005          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)          topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)
1006                                                                                    
1007          buttonBox = wxBoxSizer(wxHORIZONTAL)          buttonBox = wxBoxSizer(wxHORIZONTAL)
1008          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,          buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,
1009                        _("Take")), 0, wxALL, 4)                        _("Take")), 0, wxALL, 4)
# Line 1006  class UTMProposeZoneDialog(wxDialog): Line 1012  class UTMProposeZoneDialog(wxDialog):
1012          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)          topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
1013          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)
1014          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)          EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)
1015                                                                                    
1016          self.SetAutoLayout(True)          self.SetAutoLayout(True)
1017          self.SetSizer(topBox)          self.SetSizer(topBox)
1018          topBox.Fit(self)          topBox.Fit(self)
1019          topBox.SetSizeHints(self)          topBox.SetSizeHints(self)
1020                                                                                    
1021      def OnTake(self, event):      def OnTake(self, event):
1022          self.EndModal(wxID_OK)          self.EndModal(wxID_OK)
1023                                                                                    
1024      def OnCancel(self, event):      def OnCancel(self, event):
1025          self.EndModal(wxID_CANCEL)          self.EndModal(wxID_CANCEL)
1026    

Legend:
Removed from v.1549  
changed lines
  Added in v.1833

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26