/[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 1851 by bh, Tue Oct 21 14:17:24 2003 UTC revision 1933 by bh, Tue Nov 11 16:37:53 2003 UTC
# Line 21  from Thuban import _ Line 21  from Thuban import _
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_file, get_system_proj_file, \  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                                      DEFAULT_PROJ_FILE, EPSG_PROJ_FILE
26  from Thuban.UI.dialogs import NonModalNonParentDialog  from Thuban.UI.dialogs import NonModalNonParentDialog
27    
28  from common import ThubanBeginBusyCursor, ThubanEndBusyCursor  from common import ThubanBeginBusyCursor, ThubanEndBusyCursor
# Line 60  class ProjFrame(NonModalNonParentDialog) Line 61  class ProjFrame(NonModalNonParentDialog)
61              ("tmerc", _("Transverse Mercator"), TMPanel),              ("tmerc", _("Transverse Mercator"), TMPanel),
62              ("utm", _("Universal Transverse Mercator"), UTMPanel),              ("utm", _("Universal Transverse Mercator"), UTMPanel),
63              ("lcc", _("Lambert Conic Conformal"), LCCPanel),              ("lcc", _("Lambert Conic Conformal"), LCCPanel),
64              ("latlong", _("Geographic"), GeoPanel)]              ("latlong", _("Geographic"), GeoPanel),
65                ("longlat", _("Geographic"), GeoPanel)]#longlat is an alias of proj
66          self.receiver = receiver          self.receiver = receiver
67          self.haveTried = False          self.haveTried = False
68          self.curProjPanel = None          self.curProjPanel = None
69          self.__usrProjFile = None          self.__usrProjFile = None
70          self.__sysProjFile = None          self._sys_proj_files = {}
71    
72          self.build_dialog()          self.build_dialog()
73          self.Layout()          self.Layout()
# Line 73  class ProjFrame(NonModalNonParentDialog) Line 75  class ProjFrame(NonModalNonParentDialog)
75          self.originalProjection = self.receiver.GetProjection()          self.originalProjection = self.receiver.GetProjection()
76    
77          self.projection_list.SelectProjection(self.originalProjection)          self.projection_list.SelectProjection(self.originalProjection)
         self.button_ok.SetFocus()  
78          self.projection_list.SetFocus()          self.projection_list.SetFocus()
79    
80      def build_dialog(self):      def build_dialog(self):
# Line 94  class ProjFrame(NonModalNonParentDialog) Line 95  class ProjFrame(NonModalNonParentDialog)
95    
96          hbox = wxBoxSizer(wxHORIZONTAL)          hbox = wxBoxSizer(wxHORIZONTAL)
97          vbox.Add(hbox, 1, wxALL|wxEXPAND)          vbox.Add(hbox, 1, wxALL|wxEXPAND)
98          self.projection_list = ProjectionList(self, self.load_system_proj(),          proj_files = [self.load_user_proj(),
99                                                self.load_user_proj(),                        self.load_system_proj(DEFAULT_PROJ_FILE)]
100            self.projection_list = ProjectionList(self, proj_files,
101                                                self.receiver.GetProjection())                                                self.receiver.GetProjection())
102          hbox.Add(self.projection_list, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          hbox.Add(self.projection_list, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
103          self.projection_list.Subscribe(PROJ_SELECTION_CHANGED,          self.projection_list.Subscribe(PROJ_SELECTION_CHANGED,
# Line 115  class ProjFrame(NonModalNonParentDialog) Line 117  class ProjFrame(NonModalNonParentDialog)
117          EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)
118          buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4)          buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4)
119    
120            self.check_epsg = wxCheckBox(self, -1, _("Show EPSG"))
121            EVT_CHECKBOX(self, self.check_epsg.GetId(), self._OnShowEPSG)
122            buttons.Add(self.check_epsg, 1, wxALL|wxEXPAND, 4)
123    
124          # The file path          # The file path
125          self.projfilepath = wxStaticText(self, -1, "")          self.projfilepath = wxStaticText(self, -1, "")
126          vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND)          vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND)
# Line 209  class ProjFrame(NonModalNonParentDialog) Line 215  class ProjFrame(NonModalNonParentDialog)
215      def OnClose(self, event):      def OnClose(self, event):
216          self.projection_list.Unsubscribe(PROJ_SELECTION_CHANGED,          self.projection_list.Unsubscribe(PROJ_SELECTION_CHANGED,
217                                           self.proj_selection_changed)                                           self.proj_selection_changed)
218            # Destroy the projection list explicitly so that it properly
219            # unsubscribes everything. It would be cleaner if the projection
220            # could do this by itself but wx doesn't always send destroy
221            # events for non-top-level widgets
222            self.projection_list.Destroy()
223          NonModalNonParentDialog.OnClose(self, event)          NonModalNonParentDialog.OnClose(self, event)
224    
225      def OnApply(self, event):      def OnApply(self, event):
# Line 344  class ProjFrame(NonModalNonParentDialog) Line 355  class ProjFrame(NonModalNonParentDialog)
355          if modified:          if modified:
356              self.write_proj_file(self.__usrProjFile)              self.write_proj_file(self.__usrProjFile)
357    
358        def _OnShowEPSG(self, event):
359            """Handler for the EVT_CHECKBOX events from the EPSG check button
360    
361            If the button is checked add the EPSG_PROJ_FILE to the list of
362            projfiles shown by the projection list. Otherwise remove it
363            """
364            if self.check_epsg.IsChecked():
365                proj_files = [self.load_user_proj(),
366                              self.load_system_proj(DEFAULT_PROJ_FILE),
367                              self.load_system_proj(EPSG_PROJ_FILE)]
368            else:
369                proj_files = [self.load_user_proj(),
370                              self.load_system_proj(DEFAULT_PROJ_FILE)]
371            self.projection_list.SetProjFiles(proj_files)
372    
373      def _OnProjName(self, event):      def _OnProjName(self, event):
374          self.__VerifyButtons()          self.__VerifyButtons()
375    
# Line 459  class ProjFrame(NonModalNonParentDialog) Line 485  class ProjFrame(NonModalNonParentDialog)
485                      self.projchoice.Select(0)                      self.projchoice.Select(0)
486                      self.projchoice.Disable()                      self.projchoice.Disable()
487                      self._show_proj_panel(UnknownProjPanel)                      self._show_proj_panel(UnknownProjPanel)
488                        assert self.curProjPanel is not None
489                        self.curProjPanel.SetProjection(proj)
490          else:          else:
491              self.projfilepath.SetLabel(_("Multiple Projections selected"))              self.projfilepath.SetLabel(_("Multiple Projections selected"))
492    
# Line 536  class ProjFrame(NonModalNonParentDialog) Line 564  class ProjFrame(NonModalNonParentDialog)
564          return None          return None
565    
566      def load_user_proj(self):      def load_user_proj(self):
567          ThubanBeginBusyCursor()          """Return the user's ProjFile
568          try:  
569              if self.__usrProjFile is None:          If the file has not yet been loaded by the dialog, load it first
570            with get_user_proj_file and cache it in self.__usrProjFile.
571    
572            Show a busy cursor while loading the file.
573            """
574            if self.__usrProjFile is None:
575                ThubanBeginBusyCursor()
576                try:
577                  projfile, warnings = get_user_proj_file()                  projfile, warnings = get_user_proj_file()
578                  self.show_warnings(_("Warnings"), projfile.GetFilename(),                  self.show_warnings(_("Warnings"), projfile.GetFilename(),
579                                     warnings)                                     warnings)
580                  self.__usrProjFile = projfile                  self.__usrProjFile = projfile
581              return self.__usrProjFile              finally:
582          finally:                  ThubanEndBusyCursor()
583              ThubanEndBusyCursor()          return self.__usrProjFile
584    
585      def load_system_proj(self):      def load_system_proj(self, name):
586          ThubanBeginBusyCursor()          """Load the system ProjFile with the given name.
587          try:  
588              if self.__sysProjFile is None:          If the file has not been loaded yet, load it first with
589                  projfile, warnings = get_system_proj_file()          get_system_proj_file and put it into the cache. The name is
590            simply forwarded to get_system_proj_file.
591    
592            Show a busy cursor while loading the file.
593            """
594            if name not in self._sys_proj_files:
595                ThubanBeginBusyCursor()
596                try:
597                    projfile, warnings = get_system_proj_file(name)
598                  self.show_warnings(_("Warnings"), projfile.GetFilename(),                  self.show_warnings(_("Warnings"), projfile.GetFilename(),
599                                     warnings)                                     warnings)
600                  self.__sysProjFile = projfile                  self._sys_proj_files[name] = projfile
601              return self.__sysProjFile              finally:
602          finally:                  ThubanEndBusyCursor()
603              ThubanEndBusyCursor()          return self._sys_proj_files[name]
604    
605      def write_proj_file(self, proj_file):      def write_proj_file(self, proj_file):
606          """Write the ProjFile object proj_file back to its file          """Write the ProjFile object proj_file back to its file
# Line 651  class UnknownProjPanel(ProjPanel): Line 694  class UnknownProjPanel(ProjPanel):
694      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
695          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
696    
697            self.__text = _("Thuban does not know the parameters\n"
698                            "for the current projection and cannot\n"
699                            "display a configuration panel.\n\n"
700                            "The unidentified set of parameters is:\n\n")
701    
702            self.__textbox = wxTextCtrl(self, -1, self.__text, size=(100,200),
703                                style=wxTE_READONLY|wxTE_MULTILINE|wxTE_LINEWRAP)
704          self._DoLayout()          self._DoLayout()
705    
706      def _DoLayout(self):      def _DoLayout(self):
707          sizer = wxBoxSizer(wxVERTICAL)          sizer = wxBoxSizer(wxVERTICAL)
708    
709          sizer.Add(wxStaticText(self, -1,          sizer.Add(self.__textbox, 0, wxALL|wxEXPAND, 4)
                                _("Thuban does not know the parameters\n"  
                                  "for the current projection and cannot\n"  
                                  "display a configuration panel.")))  
710    
711          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
712    
# Line 667  class UnknownProjPanel(ProjPanel): Line 714  class UnknownProjPanel(ProjPanel):
714          return "Unknown"          return "Unknown"
715    
716      def SetProjection(self, proj):      def SetProjection(self, proj):
717          pass          """Append the available parameters to the info text."""
718            text = self.__text
719            for param in proj.GetAllParameters():
720                text = text + '%s\n' % param
721            self.__textbox.SetValue(text)
722    
723      def GetParameters(self):      def GetParameters(self):
724          return None          return None

Legend:
Removed from v.1851  
changed lines
  Added in v.1933

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26