/[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 730 by jonathan, Thu Apr 24 16:07:41 2003 UTC revision 747 by jonathan, Fri Apr 25 11:02:08 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 61  class ProjFrame(NonModalDialog): Line 61  class ProjFrame(NonModalDialog):
61          self.panel_edit = wxPanel(self, -1)          self.panel_edit = wxPanel(self, -1)
62          self.panel_buttons = wxPanel(self, -1)          self.panel_buttons = wxPanel(self, -1)
63          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))          self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))
64          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED |wxLB_SORT)          self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED|wxLB_SORT)
65          self.projfilepath = wxStaticText(self.panel_1, -1, "")          self.projfilepath = wxStaticText(self.panel_1, -1, "")
66          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))          self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))
67          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")          self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")
# 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 459  class ProjFrame(NonModalDialog): Line 385  class ProjFrame(NonModalDialog):
385    
386          return proj          return proj
387    
388      def __FillAvailList(self):      def __FillAvailList(self, selectCurrent = False):
389          self.availprojs.Clear()          self.availprojs.Clear()
390    
391          #          #
392            # We add the current projection to the list first so that
393            # we are sure that it's at index 0. That way we can
394            # set the selection with confidence. The problem is the
395            # the list is automatically sorted when an item is appended
396            # and the index of where it was inserted is not returned.
397            #
398            proj = self.receiver.GetProjection()
399            if proj is not None:
400                self.availprojs.Append(_("%s (current)") % proj.GetName(),
401                                       [proj, None])
402                if selectCurrent:
403                    self.availprojs.SetSelection(0)
404                    self.availprojs.SetFirstItem(0)
405    
406            #
407          # the list can never be empty. there will always be          # the list can never be empty. there will always be
408          # at least this one item          # at least this one item
409          #          #
# Line 485  class ProjFrame(NonModalDialog): Line 426  class ProjFrame(NonModalDialog):
426                  self.availprojs.Append(proj.GetName(), [proj, projfile])                  self.availprojs.Append(proj.GetName(), [proj, projfile])
427              self.__usrProjFile = projfile              self.__usrProjFile = projfile
428    
 #       projfiles = GetSystemProjFiles()  
 #       for projfile in projfiles:  
 #           for proj in projfile.GetProjections():  
 #               self.availprojs.Append(proj.GetName(), [proj, projfile])  
 #       self.__sysProjFiles = projfiles  
   
 #       projfiles = GetUserProjFiles()  
 #       for projfile in projfiles:  
 #           for proj in projfile.GetProjections():  
 #               self.availprojs.Append(proj.GetName(), [proj, projfile])  
 #       self.__usrProjFiles = projfiles  
   
         proj = self.receiver.GetProjection()  
         if proj is not None:  
             self.availprojs.Append(proj.GetName() + _(" (current)"),  
                                    [proj, None])  
   
429          for proj, name, clazz in self.projPanels:          for proj, name, clazz in self.projPanels:
430              self.projchoice.Append(name, [clazz, None])              self.projchoice.Append(name, [clazz, None])
431    
432      def __set_properties(self):      def __set_properties(self):
         self.__FillAvailList()  
433    
         # begin wxGlade: ProjFrame.__set_properties  
434          self.SetTitle(_("Projections"))          self.SetTitle(_("Projections"))
435          self.availprojs.SetSelection(0)          self.availprojs.SetSelection(0)
436          self.projchoice.SetSelection(0)          self.projchoice.SetSelection(0)
437          # end wxGlade  
438            self.__FillAvailList(selectCurrent = True)
439    
440          self.projname.SetMaxLength(32)          self.projname.SetMaxLength(32)
441    

Legend:
Removed from v.730  
changed lines
  Added in v.747

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26