Ignore:
Timestamp:
Nov 17, 2022 10:59:43 AM (7 months ago)
Author:
toby
Message:

add .gpx browser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIdataGUI.py

    r5362 r5373  
    678678        '''Add items to File menu
    679679        '''
    680         item = parent.Append(wx.ID_ANY,'&Open project...\tCtrl+O','Open a GSAS-II project file (*.gpx)')           
     680        item = parent.Append(wx.ID_ANY,'&Open project...\tCtrl+O','Open a GSAS-II project (.gpx) file')           
    681681        self.Bind(wx.EVT_MENU, self.OnFileOpen, id=item.GetId())
    682682        if sys.platform == "darwin":
    683             item = parent.Append(wx.ID_ANY,'&Open in new window...','Open a GSAS-II project file (*.gpx) in a separate process')
     683            item = parent.Append(wx.ID_ANY,'&Open in new window...','Open a GSAS-II project (.gpx) file in a separate process')
    684684            self.Bind(wx.EVT_MENU, self.OnNewGSASII, id=item.GetId())
    685         item = parent.Append(wx.ID_ANY,'Reopen recent...\tCtrl+E','Reopen a previously used GSAS-II project file (*.gpx)')
     685        item = parent.Append(wx.ID_ANY,'Reopen recent...\tCtrl+E','Reopen a previously used GSAS-II project (.gpx) file')
    686686        self.Bind(wx.EVT_MENU, self.OnFileReopen, id=item.GetId())
     687        item = parent.Append(wx.ID_ANY,'&Open w/project browser\tCtrl+B','Use project browser to a GSAS-II project (.gpx) file')           
     688        self.Bind(wx.EVT_MENU, self.OnFileBrowse, id=item.GetId())
    687689        item = parent.Append(wx.ID_ANY,'&Save project\tCtrl+S','Save project under current name')
    688690        self.Bind(wx.EVT_MENU, self.OnFileSave, id=item.GetId())
     
    43254327            print('file not found',f)       
    43264328       
     4329    def _SaveOld(self):
     4330        '''See if we should save current project and continue
     4331        to read another.
     4332        returns True if the project load should continue
     4333        '''
     4334        if self.dataWindow:
     4335            self.dataWindow.ClearData()
     4336            dlg = wx.MessageDialog(self,
     4337                    'Do you want to save and replace the current project?\n'
     4338                    '(Use No to read without saving or Cancel to continue '
     4339                    'with current project)',
     4340                'Save & Overwrite?',
     4341                wx.YES|wx.NO|wx.CANCEL)
     4342        try:
     4343            result = dlg.ShowModal()
     4344        finally:
     4345            dlg.Destroy()
     4346        if result == wx.ID_NO:
     4347            result = True
     4348        elif result == wx.ID_CANCEL:
     4349            return False
     4350        else:
     4351            if not self.OnFileSave(None):
     4352                return False
     4353        self.GPXtree.DeleteChildren(self.root)
     4354        self.GSASprojectfile = ''
     4355        self.HKL = []
     4356        self.Extinct = []
     4357        if self.G2plotNB.plotList:
     4358            self.G2plotNB.clear()
     4359        return True
     4360       
    43274361    def OnFileOpen(self, event, filename=None):
    43284362        '''Gets a GSAS-II .gpx project file in response to the
    43294363        File/Open Project menu button
    43304364        '''
    4331         def SaveOld():
    4332             '''See if we should save current project and continue
    4333             to read another.
    4334             returns True if the project load should continue
    4335             '''
    4336             if self.dataWindow:
    4337                 self.dataWindow.ClearData()
    4338             dlg = wx.MessageDialog(self,
    4339                     'Do you want to save and replace the current project?\n(Use No to read without saving or Cancel to continue with current project)',
    4340                     'Save & Overwrite?',
    4341                     wx.YES|wx.NO|wx.CANCEL)
    4342             try:
    4343                 result = dlg.ShowModal()
    4344             finally:
    4345                 dlg.Destroy()
    4346             if result == wx.ID_NO:
    4347                 result = True
    4348             elif result == wx.ID_CANCEL:
    4349                 return False
    4350             else:
    4351                 if not self.OnFileSave(None): return False
    4352             self.GPXtree.DeleteChildren(self.root)
    4353             self.GSASprojectfile = ''
    4354             self.HKL = []
    4355             self.Extinct = []
    4356             if self.G2plotNB.plotList:
    4357                 self.G2plotNB.clear()
    4358             return True
    43594365       
    43604366        def GetGPX():
     
    43764382        self.EnablePlot = False
    43774383        if self.GPXtree.GetChildrenCount(self.root,False):
    4378             if not SaveOld(): return
     4384            if not self._SaveOld(): return
    43794385
    43804386        if not filename:
     
    43984404            print (traceback.format_exc())
    43994405
     4406    def OnFileBrowse(self, event):
     4407        '''Gets a GSAS-II .gpx project using the GPX browser, in response
     4408        to the File/"Open Project browser" menu button
     4409        '''       
     4410        self.EnablePlot = False
     4411        if self.LastGPXdir:
     4412            pth = self.LastGPXdir
     4413        else:
     4414            pth = '.'
     4415
     4416        try:
     4417            dlg = G2G.gpxFileSelector(parent=self,startdir=pth)
     4418            if wx.ID_OK == dlg.ShowModal():
     4419                filename = dlg.Selection
     4420            else:
     4421                return
     4422        finally:
     4423            dlg.Destroy()
     4424       
     4425        if self.GPXtree.GetChildrenCount(self.root,False):
     4426            if not self._SaveOld(): return # cancel was entered; nothing changed
     4427        self.GSASprojectfile = filename
     4428        self.LastGPXdir = os.path.split(os.path.abspath(filename))[0]
     4429
     4430        self.init_vars()
     4431        try:
     4432            self.StartProject()         #open the file if possible
     4433        except:
     4434            print ('\nError opening file '+filename)
     4435            import traceback
     4436            print (traceback.format_exc())
     4437
     4438           
    44004439    def StartProject(self):
    44014440        '''Opens a GSAS-II project file & selects the 1st available data set to
Note: See TracChangeset for help on using the changeset viewer.