/[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 1941 by bh, Tue Nov 11 18:27:48 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                                      EPSG_DEPRECATED_PROJ_FILE
27  from Thuban.UI.dialogs import NonModalNonParentDialog  from Thuban.UI.dialogs import NonModalNonParentDialog
28    
29  from common import ThubanBeginBusyCursor, ThubanEndBusyCursor  from common import ThubanBeginBusyCursor, ThubanEndBusyCursor
# Line 60  class ProjFrame(NonModalNonParentDialog) Line 62  class ProjFrame(NonModalNonParentDialog)
62              ("tmerc", _("Transverse Mercator"), TMPanel),              ("tmerc", _("Transverse Mercator"), TMPanel),
63              ("utm", _("Universal Transverse Mercator"), UTMPanel),              ("utm", _("Universal Transverse Mercator"), UTMPanel),
64              ("lcc", _("Lambert Conic Conformal"), LCCPanel),              ("lcc", _("Lambert Conic Conformal"), LCCPanel),
65              ("latlong", _("Geographic"), GeoPanel)]              ("latlong", _("Geographic"), GeoPanel),
66                ("longlat", _("Geographic"), GeoPanel)]#longlat is an alias of proj
67          self.receiver = receiver          self.receiver = receiver
68          self.haveTried = False          self.haveTried = False
69          self.curProjPanel = None          self.curProjPanel = None
70          self.__usrProjFile = None          self.__usrProjFile = None
71          self.__sysProjFile = None          self._sys_proj_files = {}
72    
73          self.build_dialog()          self.build_dialog()
74          self.Layout()          self.Layout()
# Line 73  class ProjFrame(NonModalNonParentDialog) Line 76  class ProjFrame(NonModalNonParentDialog)
76          self.originalProjection = self.receiver.GetProjection()          self.originalProjection = self.receiver.GetProjection()
77    
78          self.projection_list.SelectProjection(self.originalProjection)          self.projection_list.SelectProjection(self.originalProjection)
         self.button_ok.SetFocus()  
79          self.projection_list.SetFocus()          self.projection_list.SetFocus()
80    
81      def build_dialog(self):      def build_dialog(self):
# Line 94  class ProjFrame(NonModalNonParentDialog) Line 96  class ProjFrame(NonModalNonParentDialog)
96    
97          hbox = wxBoxSizer(wxHORIZONTAL)          hbox = wxBoxSizer(wxHORIZONTAL)
98          vbox.Add(hbox, 1, wxALL|wxEXPAND)          vbox.Add(hbox, 1, wxALL|wxEXPAND)
99          self.projection_list = ProjectionList(self, self.load_system_proj(),          proj_files = [self.load_user_proj(),
100                                                self.load_user_proj(),                        self.load_system_proj(DEFAULT_PROJ_FILE)]
101            self.projection_list = ProjectionList(self, proj_files,
102                                                self.receiver.GetProjection())                                                self.receiver.GetProjection())
103          hbox.Add(self.projection_list, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)          hbox.Add(self.projection_list, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
104          self.projection_list.Subscribe(PROJ_SELECTION_CHANGED,          self.projection_list.Subscribe(PROJ_SELECTION_CHANGED,
# Line 115  class ProjFrame(NonModalNonParentDialog) Line 118  class ProjFrame(NonModalNonParentDialog)
118          EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)          EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)
119          buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4)          buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4)
120    
121            buttons.Add(20, 20, 0, wxEXPAND, 0)
122            label = wxStaticText(self, -1, _("Show EPSG:"))
123            buttons.Add(label, 0, wxLEFT|wxRIGHT|wxTOP, 4)
124            self.check_epsg = wxCheckBox(self, -1, _("Normal"))
125            EVT_CHECKBOX(self, self.check_epsg.GetId(), self._OnShowEPSG)
126            buttons.Add(self.check_epsg, 1, wxALL|wxEXPAND, 4)
127            self.check_epsg_depr = wxCheckBox(self, -1, _("Deprecated"))
128            EVT_CHECKBOX(self, self.check_epsg_depr.GetId(), self._OnShowEPSG)
129            buttons.Add(self.check_epsg_depr, 1, wxALL|wxEXPAND, 4)
130    
131          # The file path          # The file path
132          self.projfilepath = wxStaticText(self, -1, "")          self.projfilepath = wxStaticText(self, -1, "")
133          vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND)          vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND)
# Line 209  class ProjFrame(NonModalNonParentDialog) Line 222  class ProjFrame(NonModalNonParentDialog)
222      def OnClose(self, event):      def OnClose(self, event):
223          self.projection_list.Unsubscribe(PROJ_SELECTION_CHANGED,          self.projection_list.Unsubscribe(PROJ_SELECTION_CHANGED,
224                                           self.proj_selection_changed)                                           self.proj_selection_changed)
225            # Destroy the projection list explicitly so that it properly
226            # unsubscribes everything. It would be cleaner if the projection
227            # could do this by itself but wx doesn't always send destroy
228            # events for non-top-level widgets
229            self.projection_list.Destroy()
230          NonModalNonParentDialog.OnClose(self, event)          NonModalNonParentDialog.OnClose(self, event)
231    
232      def OnApply(self, event):      def OnApply(self, event):
# Line 344  class ProjFrame(NonModalNonParentDialog) Line 362  class ProjFrame(NonModalNonParentDialog)
362          if modified:          if modified:
363              self.write_proj_file(self.__usrProjFile)              self.write_proj_file(self.__usrProjFile)
364    
365        def _OnShowEPSG(self, event):
366            """Handler for the EVT_CHECKBOX events from the EPSG check button
367    
368            If the button is checked add the EPSG_PROJ_FILE to the list of
369            projfiles shown by the projection list. Otherwise remove it
370            """
371            proj_files = [self.load_user_proj(),
372                          self.load_system_proj(DEFAULT_PROJ_FILE)]
373            if self.check_epsg.IsChecked():
374                proj_files.append(self.load_system_proj(EPSG_PROJ_FILE))
375            if self.check_epsg_depr.IsChecked():
376                proj_files.append(self.load_system_proj(EPSG_DEPRECATED_PROJ_FILE))
377            self.projection_list.SetProjFiles(proj_files)
378    
379      def _OnProjName(self, event):      def _OnProjName(self, event):
380          self.__VerifyButtons()          self.__VerifyButtons()
381    
# Line 459  class ProjFrame(NonModalNonParentDialog) Line 491  class ProjFrame(NonModalNonParentDialog)
491                      self.projchoice.Select(0)                      self.projchoice.Select(0)
492                      self.projchoice.Disable()                      self.projchoice.Disable()
493                      self._show_proj_panel(UnknownProjPanel)                      self._show_proj_panel(UnknownProjPanel)
494                        assert self.curProjPanel is not None
495                        self.curProjPanel.SetProjection(proj)
496          else:          else:
497              self.projfilepath.SetLabel(_("Multiple Projections selected"))              self.projfilepath.SetLabel(_("Multiple Projections selected"))
498    
# Line 536  class ProjFrame(NonModalNonParentDialog) Line 570  class ProjFrame(NonModalNonParentDialog)
570          return None          return None
571    
572      def load_user_proj(self):      def load_user_proj(self):
573          ThubanBeginBusyCursor()          """Return the user's ProjFile
574          try:  
575              if self.__usrProjFile is None:          If the file has not yet been loaded by the dialog, load it first
576            with get_user_proj_file and cache it in self.__usrProjFile.
577    
578            Show a busy cursor while loading the file.
579            """
580            if self.__usrProjFile is None:
581                ThubanBeginBusyCursor()
582                try:
583                  projfile, warnings = get_user_proj_file()                  projfile, warnings = get_user_proj_file()
584                  self.show_warnings(_("Warnings"), projfile.GetFilename(),                  self.show_warnings(_("Warnings"), projfile.GetFilename(),
585                                     warnings)                                     warnings)
586                  self.__usrProjFile = projfile                  self.__usrProjFile = projfile
587              return self.__usrProjFile              finally:
588          finally:                  ThubanEndBusyCursor()
589              ThubanEndBusyCursor()          return self.__usrProjFile
590    
591      def load_system_proj(self):      def load_system_proj(self, name):
592          ThubanBeginBusyCursor()          """Load the system ProjFile with the given name.
593          try:  
594              if self.__sysProjFile is None:          If the file has not been loaded yet, load it first with
595                  projfile, warnings = get_system_proj_file()          get_system_proj_file and put it into the cache. The name is
596            simply forwarded to get_system_proj_file.
597    
598            Show a busy cursor while loading the file.
599            """
600            if name not in self._sys_proj_files:
601                ThubanBeginBusyCursor()
602                try:
603                    projfile, warnings = get_system_proj_file(name)
604                  self.show_warnings(_("Warnings"), projfile.GetFilename(),                  self.show_warnings(_("Warnings"), projfile.GetFilename(),
605                                     warnings)                                     warnings)
606                  self.__sysProjFile = projfile                  self._sys_proj_files[name] = projfile
607              return self.__sysProjFile              finally:
608          finally:                  ThubanEndBusyCursor()
609              ThubanEndBusyCursor()          return self._sys_proj_files[name]
610    
611      def write_proj_file(self, proj_file):      def write_proj_file(self, proj_file):
612          """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 700  class UnknownProjPanel(ProjPanel):
700      def __init__(self, parent, receiver):      def __init__(self, parent, receiver):
701          ProjPanel.__init__(self, parent)          ProjPanel.__init__(self, parent)
702    
703            self.__text = _("Thuban does not know the parameters\n"
704                            "for the current projection and cannot\n"
705                            "display a configuration panel.\n\n"
706                            "The unidentified set of parameters is:\n\n")
707    
708            self.__textbox = wxTextCtrl(self, -1, self.__text, size=(100,200),
709                                style=wxTE_READONLY|wxTE_MULTILINE|wxTE_LINEWRAP)
710          self._DoLayout()          self._DoLayout()
711    
712      def _DoLayout(self):      def _DoLayout(self):
713          sizer = wxBoxSizer(wxVERTICAL)          sizer = wxBoxSizer(wxVERTICAL)
714    
715          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.")))  
716    
717          ProjPanel._DoLayout(self, sizer)          ProjPanel._DoLayout(self, sizer)
718    
# Line 667  class UnknownProjPanel(ProjPanel): Line 720  class UnknownProjPanel(ProjPanel):
720          return "Unknown"          return "Unknown"
721    
722      def SetProjection(self, proj):      def SetProjection(self, proj):
723          pass          """Append the available parameters to the info text."""
724            text = self.__text
725            for param in proj.GetAllParameters():
726                text = text + '%s\n' % param
727            self.__textbox.SetValue(text)
728    
729      def GetParameters(self):      def GetParameters(self):
730          return None          return None

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26