/[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 1806 by bh, Fri Oct 10 10:36:34 2003 UTC revision 1833 by bh, Mon Oct 20 11:00:57 2003 UTC
# Line 24  from Thuban.Model.resource import get_us Line 24  from Thuban.Model.resource import get_us
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 51  class ProjFrame(NonModalNonParentDialog) Line 53  class ProjFrame(NonModalNonParentDialog)
53          """          """
54          NonModalNonParentDialog.__init__(self, parent, name, title)          NonModalNonParentDialog.__init__(self, parent, name, title)
55    
56          self.projection_panels = [          self.projection_panel_defs = [
57              ("tmerc", _("Transverse Mercator"), TMPanel),              ("tmerc", _("Transverse Mercator"), TMPanel),
58              ("utm", _("Universal Transverse Mercator"), UTMPanel),              ("utm", _("Universal Transverse Mercator"), UTMPanel),
59              ("lcc", _("Lambert Conic Conformal"), LCCPanel),              ("lcc", _("Lambert Conic Conformal"), LCCPanel),
# Line 139  class ProjFrame(NonModalNonParentDialog) Line 141  class ProjFrame(NonModalNonParentDialog)
141          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)          EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
142          hbox.Add(self.projchoice, 1, wxALL|wxEXPAND, 4)          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.projection_panels:          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          # Projection Specific actions (New/Save/Add)          # Projection Specific actions (New/Save/Add)
161          buttons = wxBoxSizer(wxVERTICAL)          buttons = wxBoxSizer(wxVERTICAL)
# Line 232  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()
# Line 272  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, warnings = read_proj_file(path)                  try:
286                  self.show_warnings(_("Warnings"), path, warnings)                      projFile, warnings = read_proj_file(path)
287                  for proj in projFile.GetProjections():                  except IOError, (errno, errstr):
288                      self.__usrProjFile.Add(proj)                      self.__ShowError(dlg.GetPath(), errstr)
289                  write_proj_file(self.__usrProjFile)                  else:
290              except IOError, (errno, errstr):                      self.show_warnings(_("Warnings"), path, warnings)
291                  self.__ShowError(dlg.GetPath(), errstr)                      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 303  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 338  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 439  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 447  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.projection_panels:                  for projType, name, cls in self.projection_panel_defs:
462                      if myProjType == projType:                      if myProjType == projType:
463                          self.projchoice.Enable(True)                          self.projchoice.Enable(True)
464                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i)
# Line 468  class ProjFrame(NonModalNonParentDialog) Line 475  class ProjFrame(NonModalNonParentDialog)
475                      i += 1                      i += 1
476                  else:                  else:
477                      self.projchoice.Disable()                      self.projchoice.Disable()
478                      self._show_proj_panel(UnknownProjPanel(self,                      self._show_proj_panel(UnknownProjPanel)
                                                            self.receiver))  
479    
480          self.__VerifyButtons()          self.__VerifyButtons()
481    
# Line 490  class ProjFrame(NonModalNonParentDialog) Line 496  class ProjFrame(NonModalNonParentDialog)
496    
497          sel = choice.GetSelection()          sel = choice.GetSelection()
498          if sel != -1:          if sel != -1:
499              clazz, obj = choice.GetClientData(sel)              proj_type = choice.GetClientData(sel)
500              if obj is None:              for t, name, cls in self.projection_panel_defs:
501                  obj = clazz(self, self.receiver)                  if t == proj_type:
502                  choice.SetClientData(sel, [clazz, obj])                      self._show_proj_panel(cls)
503              self._show_proj_panel(obj)                      break
504            # FIXME: what to do if sel == -1?
505    
506      def _show_proj_panel(self, panel):      def _show_proj_panel(self, panel_class):
507          """Show the panel as the projection panel"""          """Show the panel as the projection panel"""
508          if self.curProjPanel is not None:          if panel_class is UnknownProjPanel:
509              self.curProjPanel.Hide()              self.edit_box.Disable()
510              self.sizer_projctrls.Remove(self.curProjPanel)              self.nbsizer.Activate(self.unknown_projection_panel)
511                self.curProjPanel = self.unknown_projection_panel
512          self.curProjPanel = panel          else:
513          self.curProjPanel.Show()              self.edit_box.Enable(True)
514                self.unknown_projection_panel.Hide()
515          self.sizer_projctrls.Add(self.curProjPanel, 1,              for panel in self.projection_panels:
516              wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)                  if panel.__class__ is panel_class:
517          self.sizer_projctrls.Layout()                      self.nbsizer.Activate(panel)
518          self.Layout()                      self.curProjPanel = panel
         self.topBox.SetSizeHints(self)  
519    
520      def __SetProjection(self):      def __SetProjection(self):
521          """Set the receiver's projection."""          """Set the receiver's projection."""
# Line 563  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, warnings = get_system_proj_file()          ThubanBeginBusyCursor()
575          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)          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, warnings = get_user_proj_file()              self.__sysProjFile = projfile
581          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)  
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 584  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 593  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
615    
616            Show a busy cursor while writing and if an error occurs show a
617            dialog with the error message.
618            """
619            try:
620                ThubanBeginBusyCursor()
621                try:
622                    write_proj_file(proj_file)
623                finally:
624                    ThubanEndBusyCursor()
625            except IOError, (errno, errstr):
626                self.__ShowError(proj_file.GetFilename(), errstr)
627    
628    
629    
630  class ProjPanel(wxPanel):  class ProjPanel(wxPanel):
631      """Base class for all projection panels."""      """Base class for all projection panels."""
# Line 679  class UnknownProjPanel(ProjPanel): Line 705  class UnknownProjPanel(ProjPanel):
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\n"                                   "for the current projection and cannot\n"
710                                   "and cannot display a configuration panel.")))                                   "display a configuration panel.")))
711    
712          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
713    
# Line 710  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)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26