/[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 1819 by bh, Mon Oct 13 15:55:43 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
29  from sizers import NotebookLikeSizer  from sizers import NotebookLikeSizer
30    from projlist import PROJ_SELECTION_CHANGED, ProjectionList
31    from common import ThubanBeginBusyCursor, ThubanEndBusyCursor
32    
33    
34    
 ID_PROJ_ADVANCED  = 4001  
35  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
36  ID_PROJ_ADDTOLIST    = 4003  ID_PROJ_ADDTOLIST    = 4003
37  ID_PROJ_NEW       = 4004  ID_PROJ_NEW       = 4004
# Line 56  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
70            self._sys_proj_files = {}
71    
72          self.build_dialog()          self.build_dialog()
73          self.Layout()          self.Layout()
74    
75          self.originalProjection = self.receiver.GetProjection()          self.originalProjection = self.receiver.GetProjection()
76    
77          self.__DoOnProjAvail()          self.projection_list.SelectProjection(self.originalProjection)
78          self.button_ok.SetFocus()          self.projection_list.SetFocus()
         self.availprojs.SetFocus()  
79    
80      def build_dialog(self):      def build_dialog(self):
81          """Build the dialog's widgets and set the event handlers"""          """Build the dialog's widgets and set the event handlers"""
# Line 81  class ProjFrame(NonModalNonParentDialog) Line 88  class ProjFrame(NonModalNonParentDialog)
88          #    The projection list and associated controls          #    The projection list and associated controls
89          #          #
90          vbox = wxBoxSizer(wxVERTICAL)          vbox = wxBoxSizer(wxVERTICAL)
91          main_box.Add(vbox, 0, wxALL|wxEXPAND)          main_box.Add(vbox, 4, wxALL|wxEXPAND)
92    
93          label = wxStaticText(self, -1, _("Available Projections:"))          #label = wxStaticText(self, -1, _("Available Projections:"))
94          vbox.Add(label, 0, wxLEFT|wxRIGHT|wxTOP, 4)          #vbox.Add(label, 0, wxLEFT|wxRIGHT|wxTOP, 4)
95    
96          hbox = wxBoxSizer(wxHORIZONTAL)          hbox = wxBoxSizer(wxHORIZONTAL)
97          vbox.Add(hbox, 1, wxALL|wxEXPAND)          vbox.Add(hbox, 1, wxALL|wxEXPAND)
98          self.availprojs = wxListBox(self, ID_PROJ_AVAIL,          proj_files = [self.load_user_proj(),
99                                      style=wxLB_EXTENDED|wxLB_SORT)                        self.load_system_proj(DEFAULT_PROJ_FILE)]
100          EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)          self.projection_list = ProjectionList(self, proj_files,
101          hbox.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)                                                self.receiver.GetProjection())
102          self.__FillAvailList(selectCurrent = True)          hbox.Add(self.projection_list, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
103            self.projection_list.Subscribe(PROJ_SELECTION_CHANGED,
104                                           self.proj_selection_changed)
105    
106          # Projection List specific actions (Import/Export/Remove)          # Projection List specific actions (Import/Export/Remove)
107          buttons = wxBoxSizer(wxVERTICAL)          buttons = wxBoxSizer(wxVERTICAL)
# Line 108  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 117  class ProjFrame(NonModalNonParentDialog) Line 130  class ProjFrame(NonModalNonParentDialog)
130          #          #
131          self.edit_box = wxStaticBox(self, -1, _("Edit"))          self.edit_box = wxStaticBox(self, -1, _("Edit"))
132          sizer_edit = wxStaticBoxSizer(self.edit_box, wxHORIZONTAL)          sizer_edit = wxStaticBoxSizer(self.edit_box, wxHORIZONTAL)
133          main_box.Add(sizer_edit, 1, wxALL|wxEXPAND)          main_box.Add(sizer_edit, 5, wxALL|wxEXPAND)
134    
135          # Projection Specific Entries (Name/Projection)          # Projection Specific Entries (Name/Projection)
136          self.sizer_projctrls = wxBoxSizer(wxVERTICAL)          self.sizer_projctrls = wxBoxSizer(wxVERTICAL)
# Line 144  class ProjFrame(NonModalNonParentDialog) Line 157  class ProjFrame(NonModalNonParentDialog)
157          self.sizer_projctrls.Add(self.nbsizer, 1,          self.sizer_projctrls.Add(self.nbsizer, 1,
158                                   wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)                                   wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)
159          self.projection_panels = []          self.projection_panels = []
160            self.projchoice.Append(_("<Unknown>"), "")
161          for proj_type, name, cls in self.projection_panel_defs:          for proj_type, name, cls in self.projection_panel_defs:
162              self.projchoice.Append(name, proj_type)              self.projchoice.Append(name, proj_type)
163              panel = cls(self, self.receiver)              panel = cls(self, self.receiver)
# Line 198  class ProjFrame(NonModalNonParentDialog) Line 212  class ProjFrame(NonModalNonParentDialog)
212          top_box.Fit(self)          top_box.Fit(self)
213          top_box.SetSizeHints(self)          top_box.SetSizeHints(self)
214    
215        def OnClose(self, event):
216            self.projection_list.Unsubscribe(PROJ_SELECTION_CHANGED,
217                                             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)
224    
225      def OnApply(self, event):      def OnApply(self, event):
226          self.__SetProjection()          self.__SetProjection()
227          self.haveTried = True          self.haveTried = True
# Line 219  class ProjFrame(NonModalNonParentDialog) Line 243  class ProjFrame(NonModalNonParentDialog)
243    
244      def _OnNew(self, event):      def _OnNew(self, event):
245    
246          # clear all selections          self.projection_list.ClearSelection()
         sel = self.availprojs.GetSelections()  
         for index in sel:  
             self.availprojs.SetSelection(index, False)  
   
247          self.projname.Clear()          self.projname.Clear()
248    
249          # supply a projection panel if there wasn't one          # supply a projection panel if there wasn't one
# Line 231  class ProjFrame(NonModalNonParentDialog) Line 251  class ProjFrame(NonModalNonParentDialog)
251              self.projchoice.SetSelection(0)              self.projchoice.SetSelection(0)
252              self.__DoOnProjChoice()              self.__DoOnProjChoice()
253    
254          self.curProjPanel.Clear()          if self.curProjPanel is not None:
255                self.curProjPanel.Clear()
256    
257      def _OnSave(self, event):      def _OnSave(self, event):
258    
259          sel = self.availprojs.GetSelections()          sel = self.projection_list.selected_projections()
260          assert len(sel) == 1,  "button shouldn't be enabled"          assert len(sel) == 1,  "button shouldn't be enabled"
261    
262          proj, projfile = self.availprojs.GetClientData(sel[0])          proj, projfile = sel[0]
263    
264          assert proj is not None and projfile is not None          assert proj is not None and projfile is not None
265    
266          newproj = self.__GetProjection()          newproj = self.__GetProjection()
267    
268          if newproj is not None:          if newproj is not None:
269                # FIXME: we should only allow this for the user proj file.
270              projfile.Replace(proj, newproj)              projfile.Replace(proj, newproj)
271              try:              self.write_proj_file(projfile)
272                  write_proj_file(projfile)              self.projection_list.SelectProjection(newproj)
             except IOError, (errno, errstr):  
                 self.__ShowError(projfile.GetFilename(), errstr)  
             self.availprojs.SetClientData(sel[0], [newproj, projfile])  
   
             self.__FillAvailList( selectProj = newproj.Label())  
273    
274      def _OnAddToList(self, event):      def _OnAddToList(self, event):
275    
276          proj = self.__GetProjection()          proj = self.__GetProjection()
277          if proj is not None:          if proj is not None:
278              self.__usrProjFile.Add(proj)              self.__usrProjFile.Add(proj)
279              try:              self.write_proj_file(self.__usrProjFile)
280                  write_proj_file(self.__usrProjFile)              self.projection_list.SelectProjection(proj)
             except IOError, (errno, errstr):  
                 self.__ShowError(self.__userProjFile.GetFilename(), errstr)  
   
             self.__FillAvailList( selectProj = proj.Label())  
   
     def _OnProjAvail(self, event):  
         self.__DoOnProjAvail()  
281    
282      def show_warnings(self, title, filename, warnings):      def show_warnings(self, title, filename, warnings):
283          """Show the warnings (a list of strings) in a dialog          """Show the warnings (a list of strings) in a dialog
# Line 280  class ProjFrame(NonModalNonParentDialog) Line 290  class ProjFrame(NonModalNonParentDialog)
290              self.parent.RunMessageBox(title, text)              self.parent.RunMessageBox(title, text)
291    
292      def _OnImport(self, event):      def _OnImport(self, event):
293            """Handler for the 'Import' button
294    
295            Ask the user for a filename, read the projections from that file
296            add them to the user ProjFile object and write the user file
297            back to disk.
298            """
299          dlg = wxFileDialog(self, _("Import"), style = wxOPEN)          dlg = wxFileDialog(self, _("Import"), style = wxOPEN)
300    
301          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
302              path = dlg.GetPath()              path = dlg.GetPath()
303    
304                ThubanBeginBusyCursor()
305              try:              try:
306                  projFile, warnings = read_proj_file(path)                  try:
307                  self.show_warnings(_("Warnings"), path, warnings)                      projFile, warnings = read_proj_file(path)
308                  for proj in projFile.GetProjections():                  except IOError, (errno, errstr):
309                      self.__usrProjFile.Add(proj)                      self.__ShowError(dlg.GetPath(), errstr)
310                  write_proj_file(self.__usrProjFile)                  else:
311              except IOError, (errno, errstr):                      self.show_warnings(_("Warnings"), path, warnings)
312                  self.__ShowError(dlg.GetPath(), errstr)                      for proj in projFile.GetProjections():
313                            self.__usrProjFile.Add(proj)
314              self.__FillAvailList()                      self.write_proj_file(self.__usrProjFile)
315                finally:
316                    ThubanEndBusyCursor()
317          dlg.Destroy()          dlg.Destroy()
318    
319      def _OnExport(self, event):      def _OnExport(self, event):
320            """Handler for the 'Export' button.
321    
322          sel = self.availprojs.GetSelections()          Ask the user for a filename and write the selected projections
323            to that file.
324            """
325            sel = self.projection_list.selected_projections()
326          assert len(sel) != 0, "button should be disabled"          assert len(sel) != 0, "button should be disabled"
327    
328          dlg = wxFileDialog(self, _("Export"),          dlg = wxFileDialog(self, _("Export"), style=wxSAVE|wxOVERWRITE_PROMPT)
                         style = wxSAVE|wxOVERWRITE_PROMPT)  
329    
330          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
331              path = dlg.GetPath()              proj_file = ProjFile(dlg.GetPath())
332                for proj, pf in sel:
             projFile = ProjFile(path)  
   
             for i in sel:  
                 proj = self.availprojs.GetClientData(i)[CLIENT_PROJ]  
333                  if proj is not None:                  if proj is not None:
334                      projFile.Add(proj)                      proj_file.Add(proj)
335                self.write_proj_file(proj_file)
             try:  
                 write_proj_file(projFile)  
             except IOError, (errno, errstr):  
                 self.__ShowError(dlg.GetPath(), errstr)  
336    
337          dlg.Destroy()          dlg.Destroy()
338    
339      def _OnRemove(self, event):      def _OnRemove(self, event):
340            """Handler for the 'Remove' button
341    
342          sel = self.availprojs.GetSelections()          Remove any selected projection that came from the user's
343            ProjFile. If the user ProjFile was modified write it back to
344            disk.
345            """
346            sel = self.projection_list.selected_projections()
347          assert len(sel) != 0, "button should be disabled!"          assert len(sel) != 0, "button should be disabled!"
348    
349          #          modified = False
350          # remove the items backwards so the indices don't change          for proj, pf in sel:
351          #              if proj is not None and pf is self.__usrProjFile:
352          sel = list(sel)                  pf.Remove(proj)
353          sel.sort()                  modified = True
         sel.reverse()  
   
         newselection = -1  
         if len(sel) == 1:  
             newselection = sel[0] - 1  
             if newselection < 0:  
                 newselection = 0  
   
         for i in sel:  
             proj, projfile = self.availprojs.GetClientData(i)  
   
             #  
             # this could be the case if they selected <None> or  
             # the currently used projection  
             #  
             if proj is not None and projfile is not None:  
                 projfile.Remove(proj)  
   
         try:  
             write_proj_file(projfile)  
         except IOError, (errno, errstr):  
             self.__ShowError(projfile.GetFilename(), errstr)  
354    
355          self.__FillAvailList()          if modified:
356                self.write_proj_file(self.__usrProjFile)
357    
358          #      def _OnShowEPSG(self, event):
359          # this *could* produce incorrect results if the .proj files          """Handler for the EVT_CHECKBOX events from the EPSG check button
         # change between the last list update and this selection  
         # because the list has been repopulated.  
         #  
         if newselection != -1 and self.availprojs.GetCount() > 0:  
             self.availprojs.SetSelection(newselection)  
360    
361          self.__VerifyButtons()          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    
376      def __ShowError(self, filename, errstr):      def __ShowError(self, filename, errstr):
377          wxMessageDialog(self,          wxMessageDialog(self,
378              _("The following error occured:\n") +              _("The following error occured:\n") +
379              filename + "\n" + errstr,              filename + "\n" + errstr,
380              _("Error"), wxOK | wxICON_ERROR).ShowModal()              _("Error"), wxOK | wxICON_ERROR).ShowModal()
381    
382      def __VerifyButtons(self):      def __VerifyButtons(self):
383          """Enable or disable the appropriate buttons based on the          """Update button sensitivity"""
         current state of the dialog.  
         """  
384    
385          sel = self.availprojs.GetSelections()          num_sel = self.projection_list.GetSelectedItemCount()
386    
387          self.button_import.Enable(True)          self.button_import.Enable(True)
388          self.button_export.Enable(True)          self.button_export.Enable(True)
# Line 405  class ProjFrame(NonModalNonParentDialog) Line 404  class ProjFrame(NonModalNonParentDialog)
404          if self.curProjPanel is not None:          if self.curProjPanel is not None:
405              self.curProjPanel.Enable(True)              self.curProjPanel.Enable(True)
406    
407          if len(sel) == 0:          if num_sel == 0:
408              self.button_import.Enable(True)              self.button_import.Enable(True)
409              self.button_export.Enable(False)              self.button_export.Enable(False)
410              self.button_remove.Enable(False)              self.button_remove.Enable(False)
411              self.button_save.Enable(False)              self.button_save.Enable(False)
412    
413          elif len(sel) == 1:          elif num_sel == 1:
414    
415              proj, projFile = self.availprojs.GetClientData(sel[0])              selection = self.projection_list.selected_projections()
416                proj, projFile = selection[0]
417    
418              self.button_save.Enable(len(self.projname.GetValue()) > 0)              self.button_save.Enable(len(self.projname.GetValue()) > 0)
419              self.button_add.Enable(len(self.projname.GetValue()) > 0)              self.button_add.Enable(len(self.projname.GetValue()) > 0)
# Line 440  class ProjFrame(NonModalNonParentDialog) Line 440  class ProjFrame(NonModalNonParentDialog)
440          else:          else:
441              self.edit_box.Enable(False)              self.edit_box.Enable(False)
442    
443      def __DoOnProjAvail(self):      def proj_selection_changed(self, projs):
444            """Subscribed to the projection_list's PROJ_SELECTION_CHANGED message
         sel = self.availprojs.GetSelections()  
         if len(sel) == 1:  
   
             proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ]  
             projfile = self.availprojs.GetClientData(sel[0])[CLIENT_PROJFILE]  
445    
446            Update the dialog to reflect the new selection.
447            """
448            if len(projs) == 0:
449                self.projfilepath.SetLabel(_("No Projections selected"))
450            elif len(projs) == 1:
451                proj, projfile = projs[0]
452              if proj is None:              if proj is None:
453                  # user selected <None>                  # user selected <None>
454                  self.projname.Clear()                  self.projname.Clear()
455                  self.projfilepath.SetLabel(_("Projection File: "))                  self.projfilepath.SetLabel("")
456              else:              else:
   
457                  if projfile is not None:                  if projfile is not None:
458                      self.projfilepath.SetLabel(_("Projection File: ") +                      filename = os.path.basename(projfile.GetFilename())
459                          os.path.basename(projfile.GetFilename()))                      self.projfilepath.SetLabel(_("Source of Projection: %s")
460                                                   % filename)
461                  else:                  else:
462                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
463                      self.projfilepath.SetLabel(_("Projection File: "))                      self.projfilepath.SetLabel("")
464    
465                  self.projname.SetValue(proj.Label())                  self.projname.SetValue(proj.Label())
466    
# Line 468  class ProjFrame(NonModalNonParentDialog) Line 469  class ProjFrame(NonModalNonParentDialog)
469                  for projType, name, cls in self.projection_panel_defs:                  for projType, name, cls in self.projection_panel_defs:
470                      if myProjType == projType:                      if myProjType == projType:
471                          self.projchoice.Enable(True)                          self.projchoice.Enable(True)
472                          self.projchoice.SetSelection(i)                          self.projchoice.SetSelection(i + 1)
473                          self.__DoOnProjChoice()                          self.__DoOnProjChoice()
474    
475                          #                          #
# Line 481  class ProjFrame(NonModalNonParentDialog) Line 482  class ProjFrame(NonModalNonParentDialog)
482                          break                          break
483                      i += 1                      i += 1
484                  else:                  else:
485                        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:
491                self.projfilepath.SetLabel(_("Multiple Projections selected"))
492    
493          self.__VerifyButtons()          self.__VerifyButtons()
494    
# Line 540  class ProjFrame(NonModalNonParentDialog) Line 546  class ProjFrame(NonModalNonParentDialog)
546          Could be None.          Could be None.
547          """          """
548    
549          sel = self.availprojs.GetSelections()          assert self.projection_list.GetSelectedItemCount() < 2, \
550          assert len(sel) < 2, "button should be disabled"                 "button should be disabled"
   
551    
552            sel = self.projection_list.selected_projections()
553          if len(sel) == 1:          if len(sel) == 1:
554              proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ]              if sel[0][0] is None:
             if proj is None:  
555                  # <None> is selected                  # <None> is selected
556                  return None                  return None
557    
558          #          # self.curProjPanel should always contain the most relevant data
559          # self.curProjPanel should always contain the most          # for a projection
         # relevant data for a projection  
         #  
560          if self.curProjPanel is not None:          if self.curProjPanel is not None:
561              return Projection(self.curProjPanel.GetParameters(),              return Projection(self.curProjPanel.GetParameters(),
562                                self.projname.GetValue())                                self.projname.GetValue())
563    
564          return None          return None
565    
566      def __FillAvailList(self, selectCurrent = False, selectProj = None):      def load_user_proj(self):
567          """Populate the list of available projections.          """Return the user's ProjFile
           
         selectCurrent -- if True, select the projection used by  
                          the receiver, otherwise select nothing.  
         selectProj    -- if set, select the projection found under the  
                          specified name. This overwrites any other  
                          selection estimate.  
         """  
568    
569          self.availprojs.Clear()          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          # the list can never be empty. there will always be          """
574          # at least this one item          if self.__usrProjFile is None:
575          #              ThubanBeginBusyCursor()
576          self.availprojs.Append("<None>", (None, None))              try:
577                    projfile, warnings = get_user_proj_file()
578                    self.show_warnings(_("Warnings"), projfile.GetFilename(),
579                                       warnings)
580                    self.__usrProjFile = projfile
581                finally:
582                    ThubanEndBusyCursor()
583            return self.__usrProjFile
584    
585        def load_system_proj(self, name):
586            """Load the system ProjFile with the given name.
587    
588            If the file has not been loaded yet, load it first with
589            get_system_proj_file and put it into the cache. The name is
590            simply forwarded to get_system_proj_file.
591    
592          projfile, warnings = get_system_proj_file()          Show a busy cursor while loading the file.
593          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)          """
594          for proj in projfile.GetProjections():          if name not in self._sys_proj_files:
595              self.availprojs.Append(proj.Label(), [proj, projfile])              ThubanBeginBusyCursor()
596          self.__sysProjFile = projfile              try:
597                    projfile, warnings = get_system_proj_file(name)
598                    self.show_warnings(_("Warnings"), projfile.GetFilename(),
599                                       warnings)
600                    self._sys_proj_files[name] = projfile
601                finally:
602                    ThubanEndBusyCursor()
603            return self._sys_proj_files[name]
604    
605          projfile, warnings = get_user_proj_file()      def write_proj_file(self, proj_file):
606          self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)          """Write the ProjFile object proj_file back to its file
607          for proj in projfile.GetProjections():  
608              self.availprojs.Append(proj.Label(), [proj, projfile])          Show a busy cursor while writing and if an error occurs show a
609          self.__usrProjFile = projfile          dialog with the error message.
610            """
611            try:
612                ThubanBeginBusyCursor()
613                try:
614                    write_proj_file(proj_file)
615                finally:
616                    ThubanEndBusyCursor()
617            except IOError, (errno, errstr):
618                self.__ShowError(proj_file.GetFilename(), errstr)
619    
         #  
         # We add the current projection to the list at last.  
         # Since the list is resorted immediately a following FindString()  
         # determines the index correctly.  
         #  
         proj = self.receiver.GetProjection()  
         if proj is not None:  
             proj_item = _("%s (current)") % proj.Label()  
             self.availprojs.Append(proj_item, [proj, None])  
             if selectCurrent:  
                 self.availprojs.SetSelection(  
                         self.availprojs.FindString(proj_item)  
                     )  
         else:  
             if selectCurrent:  
                 self.availprojs.SetSelection(  
                         self.availprojs.FindString("<None>")  
                     )  
         if selectProj:  
             self.availprojs.SetSelection(  
                         self.availprojs.FindString(selectProj)  
                     )  
620    
621    
622  class ProjPanel(wxPanel):  class ProjPanel(wxPanel):
# Line 621  class ProjPanel(wxPanel): Line 626  class ProjPanel(wxPanel):
626          wxPanel.__init__(self, parent, -1)          wxPanel.__init__(self, parent, -1)
627    
628          self.__ellps = wxChoice(self, -1)          self.__ellps = wxChoice(self, -1)
629          self.ellpsData = [("airy"  , _("Airy")),          self.ellpsData = [("", _("<Unknown>")),
630                              ("airy"  , _("Airy")),
631                            ("bessel", _("Bessel 1841")),                            ("bessel", _("Bessel 1841")),
632                            ("clrk66", _("Clarke 1866")),                            ("clrk66", _("Clarke 1866")),
633                            ("clrk80", _("Clarke 1880")),                            ("clrk80", _("Clarke 1880")),
634                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),                            ("GRS80" , _("GRS 1980 (IUGG, 1980)")),
635                            ("intl"  , _("International 1909 (Hayford)")),                            ("intl"  , _("International 1909 (Hayford)")),
# Line 669  class ProjPanel(wxPanel): Line 675  class ProjPanel(wxPanel):
675          self.__ellps.SetSelection(0)          self.__ellps.SetSelection(0)
676    
677      def GetParameters(self):      def GetParameters(self):
678          return ["ellps=" + self.__ellps.GetClientData(          ellps = self.__ellps.GetSelection()
679                                          self.__ellps.GetSelection())]          if ellps > 0:
680                return ["ellps=" + self.__ellps.GetClientData(ellps)]
681            return []
682    
683    
684  ID_TMPANEL_LAT = 4001  ID_TMPANEL_LAT = 4001
# Line 686  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 702  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
# Line 715  class TMPanel(ProjPanel): Line 731  class TMPanel(ProjPanel):
731    
732          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)          self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)
733          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)          self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)
         self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)  
734          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)          self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)
735          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)          self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)
736            self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)
737    
738          self._DoLayout()          self._DoLayout()
739    
# Line 852  class LCCPanel(ProjPanel): Line 868  class LCCPanel(ProjPanel):
868                    
869          self.__fspLatitude = wxTextCtrl(self, -1)          self.__fspLatitude = wxTextCtrl(self, -1)
870          self.__sspLatitude = wxTextCtrl(self, -1)          self.__sspLatitude = wxTextCtrl(self, -1)
         self.__originLat   = wxTextCtrl(self, -1)  
871          self.__meridian    = wxTextCtrl(self, -1)          self.__meridian    = wxTextCtrl(self, -1)
872            self.__originLat   = wxTextCtrl(self, -1)
873          self.__falseEast   = wxTextCtrl(self, -1)          self.__falseEast   = wxTextCtrl(self, -1)
874          self.__falseNorth  = wxTextCtrl(self, -1)          self.__falseNorth  = wxTextCtrl(self, -1)
875    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26