Changeset 4154


Ignore:
Timestamp:
Sep 18, 2019 5:05:24 PM (2 years ago)
Author:
toby
Message:

allow open of multiple GPX files on Mac

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r4148 r4154  
    2424'''
    2525
     26import sys
     27import os
    2628import platform
    2729import wx
     
    3133__version__ = '1.0.0'
    3234
     35class G2App(wx.App):
     36    '''Used to create a wx python application for the GUI for Mac.
     37    Customized to implement drop of GPX files onto app.
     38    '''
     39    startupMode = True
     40    def ClearStartup(self):
     41        '''Call this after app startup complete because a Drop event is posted
     42        when GSAS-II is initially started.
     43        '''
     44        self.startupMode = False       
     45    def MacOpenFiles(self, filenames):
     46        if self.startupMode:
     47            return
     48        for project in filenames:
     49            #print("Start GSAS-II with project file "+str(project))
     50            GSASIIpath.MacStartGSASII(__file__,project)
     51
    3352if __name__ == '__main__':
    34     application = wx.App(0) # create the GUI framework
     53    if sys.platform == "darwin":
     54        application = G2App(0) # create the GUI framework
     55    else:
     56        application = wx.App(0) # create the GUI framework
    3557    try:
    3658        GSASIIpath.SetBinaryPath(True)
     
    5375    import GSASIIdataGUI as G2gd   
    5476    G2gd.GSASIImain(application) # start the GUI
     77    if sys.platform == "darwin":
     78        wx.CallLater(100,application.ClearStartup)
    5579    application.MainLoop()
  • trunk/GSASIIdataGUI.py

    r4151 r4154  
    440440        item = parent.Append(wx.ID_ANY,'&Open project...\tCtrl+O','Open a GSAS-II project file (*.gpx)')           
    441441        self.Bind(wx.EVT_MENU, self.OnFileOpen, id=item.GetId())
     442        if sys.platform == "darwin":
     443            item = parent.Append(wx.ID_ANY,'&Open in new window...','Open a GSAS-II project file (*.gpx) in a separate process')
     444            self.Bind(wx.EVT_MENU, self.OnNewGSASII, id=item.GetId())
    442445        item = parent.Append(wx.ID_ANY,'Reopen recent...\tCtrl+E','Reopen a previously used GSAS-II project file (*.gpx)')
    443446        self.Bind(wx.EVT_MENU, self.OnFileReopen, id=item.GetId())
     
    39693972            return self.OnFileSaveas(event)
    39703973           
     3974    def OnNewGSASII(self, event):
     3975        '''Gets a GSAS-II .gpx project file in response to the
     3976        File/Open new window menu button. Runs only on Mac.
     3977        '''
     3978        if self.LastGPXdir:
     3979            pth = self.LastGPXdir
     3980        else:
     3981            pth = '.'
     3982        GSASprojectfile = ''
     3983        dlg = wx.FileDialog(self, 'Choose GSAS-II project file', pth,
     3984                wildcard='GSAS-II project file (*.gpx)|*.gpx',style=wx.FD_OPEN)
     3985        try:
     3986            if dlg.ShowModal() == wx.ID_OK:
     3987                GSASprojectfile = dlg.GetPath()
     3988                GSASprojectfile = G2IO.FileDlgFixExt(dlg,GSASprojectfile)
     3989        finally:
     3990            dlg.Destroy()
     3991        G2script = os.path.join(os.path.split(__file__)[0],'GSASII.py')
     3992        GSASIIpath.MacStartGSASII(G2script,GSASprojectfile)
     3993
    39713994    def SetTitleByGPX(self):
    39723995        '''Set the title for the two window frames
  • trunk/GSASIIpath.py

    r4091 r4154  
    982982        configDict = {'Clip_on':True}
    983983
     984def MacStartGSASII(g2script,project=''):
     985    '''Start a new instance of GSAS-II by opening a new terminal window and starting
     986    a new GSAS-II process. Used on Mac OS X only.
     987
     988    :param str g2script: file name for the GSASII.py script
     989    :param str project: GSAS-II project (.gpx) file to be opened, default is blank
     990      which opens a new project
     991    '''
     992    if project and os.path.splitext(project)[1] != '.gpx':
     993        print('file {} cannot be used. Not GSAS-II project (.gpx) file'.format(project))
     994        return
     995    if project and not os.path.exists(project):
     996        print('file {} cannot be found.'.format(project))
     997        return
     998    elif project:
     999        project = os.path.abspath(project)
     1000    g2script = os.path.abspath(g2script)
     1001    pythonapp = sys.executable
     1002    if os.path.exists(pythonapp+'w'): pythonapp += 'w'
     1003    script = '''
     1004set python to "{}"
     1005set appwithpath to "{}"
     1006set filename to "{}"
     1007
     1008tell application "Terminal"
     1009     activate
     1010     do script python & " " & appwithpath & " " & filename & "; exit"
     1011end tell
     1012'''.format(pythonapp,g2script,project)
     1013    subprocess.Popen(["osascript","-e",script])
     1014
    9841015if __name__ == '__main__':
    9851016    '''What follows is called to update (or downdate) GSAS-II in a separate process.
Note: See TracChangeset for help on using the changeset viewer.