/[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 734 by bh, Thu Apr 24 19:14:16 2003 UTC revision 741 by jonathan, Fri Apr 25 09:14:27 2003 UTC
# Line 15  from Thuban.UI.dialogs import NonModalDi Line 15  from Thuban.UI.dialogs import NonModalDi
15    
16  ID_PROJ_ADVANCED  = 4001  ID_PROJ_ADVANCED  = 4001
17  ID_PROJ_PROJCHOICE = 4002  ID_PROJ_PROJCHOICE = 4002
18  ID_PROJ_SAVEAS    = 4003  ID_PROJ_ADDTOLIST    = 4003
19  ID_PROJ_NEW       = 4004  ID_PROJ_NEW       = 4004
20  ID_PROJ_TRY       = 4005  ID_PROJ_TRY       = 4005
21  ID_PROJ_REVERT    = 4006  ID_PROJ_REVERT    = 4006
# Line 72  class ProjFrame(NonModalDialog): Line 72  class ProjFrame(NonModalDialog):
72          self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove"))          self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove"))
73          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))          self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))
74          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))          self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))
75          self.button_add = wxButton(self.panel_edit, ID_PROJ_SAVEAS,          self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,
76                                        _("Add to List"))                                        _("Add to List"))
77          self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))          self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))
78          self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))          self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))
# Line 97  class ProjFrame(NonModalDialog): Line 97  class ProjFrame(NonModalDialog):
97    
98          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)          EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
99          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)          EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
100          EVT_BUTTON(self, ID_PROJ_SAVEAS, self._OnSaveAs)          EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)
101    
102          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)          EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
103    
# Line 140  class ProjFrame(NonModalDialog): Line 140  class ProjFrame(NonModalDialog):
140              except IOError, (errno, errstr):              except IOError, (errno, errstr):
141                  wxMessageDialog(self,                  wxMessageDialog(self,
142                      _("The following error occured:\n") +                      _("The following error occured:\n") +
143                      projfile.GetFileName() + "\n" + errstr,                      projfile.GetFilename() + "\n" + errstr,
144                      _("Error"), wxOK | wxICON_ERROR).ShowModal()                      _("Error"), wxOK | wxICON_ERROR).ShowModal()
145              self.__FillAvailList()              self.__FillAvailList()
146    
147      def _OnSaveAs(self, event):      def _OnAddToList(self, event):
148    
149          proj = self.__GetProjection()          proj = self.__GetProjection()
150          if proj is not None:          if proj is not None:
# Line 154  class ProjFrame(NonModalDialog): Line 154  class ProjFrame(NonModalDialog):
154              except IOError, (errno, errstr):              except IOError, (errno, errstr):
155                  wxMessageDialog(self,                  wxMessageDialog(self,
156                      _("The following error occured:\n") +                      _("The following error occured:\n") +
157                      self.__usrProjFile.GetFileName() + "\n" + errstr,                      self.__usrProjFile.GetFilename() + "\n" + errstr,
158                      _("Error"), wxOK | wxICON_ERROR).ShowModal()                      _("Error"), wxOK | wxICON_ERROR).ShowModal()
159              self.__FillAvailList()              self.__FillAvailList()
160    
         return  
   
         """Save the projection somewhere.  
   
         There are three important cases to consider.  
             1. the file already exists and the user wants to overwrite it.  
             2. the file already exists and the user wants to append the  
                current projection to the end of the file  
             3. the file doesn't exist and the user wants to create it  
   
         The list of available projections is then updated.  
         """  
   
         proj = Projection(self.curProjPanel.GetParameters())  
         if self.projname.GetValue() != "":  
             proj.SetName(self.projname.GetValue())  
   
         dlg = wxFileDialog(self, _("Save As"), style = wxSAVE)  
         if dlg.ShowModal() == wxID_OK:  
             path = dlg.GetPath()  
   
             if os.access(path, os.F_OK):  
                 # file already exists.  
                 if os.access(path, os.W_OK | os.R_OK):  
                   
                     # is it a .proj file?  
                     try:  
                         projFile = ReadProjFile(path)  
                     except:  
                         # obviously not.  
                         dlg = wxMessageDialog(self,  
                             path + _(" already exists. Overwrite?"),  
                             "",  
                             wxYES | wxNO)  
   
                         if dlg.ShowModal() == wxID_YES:  
                             projFile = ProjFile(path)  
                         else:  
                             return # returning early  
                     else:  
                         # ask the user to overwrite or append  
                         dlg = wxMessageDialog(self,  
                             _("The selected projection file already exists.\n"+  
                               "The current projection can be added to the " +  
                               "file, or it can completely replace the " +  
                               "selected file.\n\nShould the current " +  
                               "projection be added to the file?"),  
                             _("Question"),  
                             wxYES | wxNO | wxICON_QUESTION)  
   
                         if dlg.ShowModal() == wxID_NO:  
                             projFile = ProjFile(path)  
                 else:  
                     # can't access the file  
                     dlg = wxMessageDialog(self,  
                         _("Couldn't access ") + path,  
                         "",  
                         wxOK | wxICON | wxICON_EXCLAMATION)  
                     return  
   
             else:  
                 # file doesn't exist. make a new one.  
                 projFile = ProjFile(path)  
                   
             #  
             # if we get this far we have a valid projFile and  
             # can just write the file  
             #  
             projFile.Add(proj)  
             try:  
                 WriteProjFile(projFile)  
                 self.__FillAvailList()  
             except IOError, (errno, errstr):  
                 wxMessageDialog(self,  
                     _("The following error occured:\n") +  
                     dlg.GetPath() + "\n" + errstr,  
                     _("Error"), wxOK | wxICON_ERROR).ShowModal()  
         dlg.Destroy()  
   
161      def _OnProjAvail(self, event):      def _OnProjAvail(self, event):
162          self.__DoOnProjAvail()          self.__DoOnProjAvail()
163    
# Line 263  class ProjFrame(NonModalDialog): Line 184  class ProjFrame(NonModalDialog):
184          dlg.Destroy()          dlg.Destroy()
185    
186      def _OnExport(self, event):      def _OnExport(self, event):
         proj = self.__GetProjection()  
187    
188          if proj is None: return          sel = self.availprojs.GetSelections()
189            assert len(sel) != 0, "button should be disabled"
190    
191          dlg = wxFileDialog(self, _("Export"),          dlg = wxFileDialog(self, _("Export"),
192                             style = wxSAVE|wxOVERWRITE_PROMPT)                          style = wxSAVE|wxOVERWRITE_PROMPT)
193    
194          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
195              path = dlg.GetPath()              path = dlg.GetPath()
196    
197              projFile = ProjFile(path)              projFile = ProjFile(path)
198              projFile.Add(proj)  
199                for i in sel:
200                    proj = self.availprojs.GetClientData(i)[CLIENT_PROJ]
201                    if proj is not None:
202                        projFile.Add(proj)
203    
204              try:              try:
205                  WriteProjFile(projFile)                  WriteProjFile(projFile)
206              except IOError, (errno, errstr):              except IOError, (errno, errstr):
# Line 318  class ProjFrame(NonModalDialog): Line 244  class ProjFrame(NonModalDialog):
244          except IOError, (errno, errstr):          except IOError, (errno, errstr):
245              wxMessageDialog(self,              wxMessageDialog(self,
246                  _("The following error occured:\n") +                  _("The following error occured:\n") +
247                  projfile.GetFileName() + "\n" + errstr,                  projfile.GetFilename() + "\n" + errstr,
248                  _("Error"), wxOK | wxICON_ERROR).ShowModal()                  _("Error"), wxOK | wxICON_ERROR).ShowModal()
249    
250    
# Line 388  class ProjFrame(NonModalDialog): Line 314  class ProjFrame(NonModalDialog):
314              else:              else:
315                            
316                  if projfile is not None:                  if projfile is not None:
317                      self.projfilepath.SetLabel(projfile.GetFileName())                      self.projfilepath.SetLabel(projfile.GetFilename())
318                  else:                  else:
319                      # only None if the currently used projection is selected                      # only None if the currently used projection is selected
320                      self.projfilepath.SetLabel("")                      self.projfilepath.SetLabel("")
# Line 499  class ProjFrame(NonModalDialog): Line 425  class ProjFrame(NonModalDialog):
425    
426          proj = self.receiver.GetProjection()          proj = self.receiver.GetProjection()
427          if proj is not None:          if proj is not None:
428              self.availprojs.Append(proj.GetName() + _(" (current)"),              self.availprojs.Append(_("%s (current)") % proj.GetName(),
429                                     [proj, None])                                     [proj, None])
430    
431          for proj, name, clazz in self.projPanels:          for proj, name, clazz in self.projPanels:

Legend:
Removed from v.734  
changed lines
  Added in v.741

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26