/[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 1833 by bh, Mon Oct 20 11:00:57 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
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 57  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 82  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 109  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 118  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 145  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 199  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 220  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 232  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              self.write_proj_file(projfile)              self.write_proj_file(projfile)
272              self.availprojs.SetClientData(sel[0], [newproj, projfile])              self.projection_list.SelectProjection(newproj)
   
             self.__FillAvailList( selectProj = newproj.Label())  
273    
274      def _OnAddToList(self, event):      def _OnAddToList(self, event):
275    
# Line 258  class ProjFrame(NonModalNonParentDialog) Line 277  class ProjFrame(NonModalNonParentDialog)
277          if proj is not None:          if proj is not None:
278              self.__usrProjFile.Add(proj)              self.__usrProjFile.Add(proj)
279              self.write_proj_file(self.__usrProjFile)              self.write_proj_file(self.__usrProjFile)
280              self.__FillAvailList( selectProj = proj.Label())              self.projection_list.SelectProjection(proj)
   
     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 274  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:
# Line 293  class ProjFrame(NonModalNonParentDialog) Line 314  class ProjFrame(NonModalNonParentDialog)
314                      self.write_proj_file(self.__usrProjFile)                      self.write_proj_file(self.__usrProjFile)
315              finally:              finally:
316                  ThubanEndBusyCursor()                  ThubanEndBusyCursor()
   
             self.__FillAvailList()  
   
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)
             self.write_proj_file(projFile)  
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)  
354    
355          self.write_proj_file(projfile)          if modified:
356                self.write_proj_file(self.__usrProjFile)
         self.__FillAvailList()  
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 398  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 433  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 461  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 474  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 533  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
568            
569          selectCurrent -- if True, select the projection used by          If the file has not yet been loaded by the dialog, load it first
570                           the receiver, otherwise select nothing.          with get_user_proj_file and cache it in self.__usrProjFile.
571          selectProj    -- if set, select the projection found under the  
572                           specified name. This overwrites any other          Show a busy cursor while loading the file.
                          selection estimate.  
573          """          """
574            if self.__usrProjFile is None:
575                ThubanBeginBusyCursor()
576                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          self.availprojs.Clear()      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          # the list can never be empty. there will always be          get_system_proj_file and put it into the cache. The name is
590          # at least this one item          simply forwarded to get_system_proj_file.
         #  
         self.availprojs.Append(_("<None>"), (None, None))  
591    
592          ThubanBeginBusyCursor()          Show a busy cursor while loading the file.
593          try:          """
594              projfile, warnings = get_system_proj_file()          if name not in self._sys_proj_files:
595              self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)              ThubanBeginBusyCursor()
596              for proj in projfile.GetProjections():              try:
597                  self.availprojs.Append(proj.Label(), [proj, projfile])                  projfile, warnings = get_system_proj_file(name)
598              self.__sysProjFile = projfile                  self.show_warnings(_("Warnings"), projfile.GetFilename(),
599                                       warnings)
600              projfile, warnings = get_user_proj_file()                  self._sys_proj_files[name] = projfile
601              self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings)              finally:
602              for proj in projfile.GetProjections():                  ThubanEndBusyCursor()
603                  self.availprojs.Append(proj.Label(), [proj, projfile])          return self._sys_proj_files[name]
             self.__usrProjFile = projfile  
         finally:  
             ThubanEndBusyCursor()  
   
         #  
         # 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)  
                     )  
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 634  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 682  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 699  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 715  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 728  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 865  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.1833  
changed lines
  Added in v.1933

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26