Changeset 983 for install


Ignore:
Timestamp:
Jul 7, 2013 10:03:10 AM (8 years ago)
Author:
toby
Message:

new Mac app

File:
1 edited

Legend:

Unmodified
Added
Removed
  • install/bootstrap.py

    r901 r983  
    1717    for pkg in missing: print " ",pkg,
    1818    print
    19     print "We suggest installing the EPDfree package at\nhttp://www.enthought.com/products/epd_free.php/"
     19    print "We suggest installing the Canopy Express package (must be 32 bit) at\nhttp://www.enthought.com/store"
    2020    sys.exit()
    2121
     
    7474#===========================================================================
    7575# on a Mac, make an applescript
    76 if sys.platform.startswith('darwin'):
    77     script = '''
    78 (*   GSAS-II AppleScript by B. Toby (brian.toby@anl.gov)
    79          It can launch GSAS-II by double clicking or by dropping a data file
    80          or folder over the app.
    81          It runs GSAS-II in a terminal window.
    82          
    83          Thanks to F. Farges (farges@univ-mlv.fr) for many applescript tricks
    84 *)
    85 
    86 
    87 (*
    88 --------------------------------------------
    89 Define subroutines used in later sections of code
    90 --------------------------------------------
    91 *)
    92 
    93 (*  get  directory  from a file name *)
    94 on GetParentPath(theFile)
    95         tell application "Finder" to return container of theFile as text
    96 end GetParentPath
    97 
    98 (* test if a file is present and exit with an error message if it is not  *)
    99 on TestFilePresent(appwithpath)
    100         tell application "System Events"
    101                 if (file appwithpath exists) then
    102                 else
    103                         display dialog "Error: file " & appwithpath & " not found. This AppleScript must be run from a directory containing the GSAS-II python code. Did you move it?" with icon caution buttons {"Quit"}
    104                         return
    105                 end if
    106         end tell
    107 end TestFilePresent
    108 
    109 (*
    110 --------------------------------------------------------------
    111 this section responds to a double-click. No file is supplied to GSAS-II
    112  o  First find the location of the script
    113  o  then convert the colon-delimited macintosh file location to a POSIX filename
    114  o  start the app with no file as argument -- opens last file or none (depending on GSAS-II preferences)
    115 --------------------------------------------------------------
    116 *)
    117 on run
    118         set python to "%s"
    119         set myPath to (path to me)
    120         set ParentPath to GetParentPath(myPath)
    121         set appwithpath to ParentPath & "GSASII.py"
    122         TestFilePresent(appwithpath)
    123         set posixapp to quoted form of the POSIX path of appwithpath
    124         tell application "Terminal"
    125                 activate
    126                 do script python & " " & posixapp & "; exit"
    127         end tell
    128 end run
    129 
    130 (*
    131 ----------------------------------------------------------------------
    132 this section handles opening files dragged into the AppleScript
    133  o it finds the location of the current script and finds the GSAS-II
    134      executable relative to the applescript
    135  o it goes through the list of files dragged in
    136  o then it converts the colon-delimited macintosh file location to a POSIX filename
    137  o for every non-directory file dragged into the icon, it tries to pass that file  to GSAS-II
    138  o for directories select a file from the directory
    139 -----------------------------------------------------------------------
    140 *)
    141 
    142 on open names
    143        
    144         set python to "%s"
    145         set myPath to (path to me)
    146         set ParentPath to GetParentPath(myPath)
    147         set appwithpath to ParentPath & "GSASII.py"
    148         TestFilePresent(appwithpath)
    149         set posixapp to the quoted form of the POSIX path of appwithpath
    150         set filePath to ""
    151         repeat with filename in names
    152                 set filestr to (filename as string)
    153                 if filestr ends with ":" then
    154                         set myfile to choose file default location filename with prompt "Select a GSAS-II input file" multiple selections allowed no
    155                         set myfile to the quoted form of the POSIX path of myfile
    156                         tell application "Terminal"
    157                                 activate
    158                                 do script python & " " & posixapp & " " & myfile & "; exit"
    159                         end tell
    160                 else
    161                         (* if this is an input file, open it *)
    162                         set filename to the quoted form of the POSIX path of filename
    163                         tell application "Terminal"
    164                                 activate
    165                                 do script python & " " & posixapp & " " & filename & "; exit"
    166                         end tell
    167                 end if
    168         end repeat
    169 end open
    170 '''
    171     app = os.path.join(gsaspath, 'GSASII.app')
    172     p = subprocess.Popen(['/usr/bin/osacompile','-o',app],stdin=subprocess.PIPE)
    173     p.stdin.write(script % (sys.executable,sys.executable) )
    174     p.stdin.close()
    175     p.communicate()
    176     if os.path.exists('GSAS2.rsrc'):
    177         print "Note: ignore the previous -d warning from osacompile"
    178         p = subprocess.call(['/Developer/Tools/Rez','-append','GSAS2.rsrc','-o',app + "/Icon\r"])
    179         p = subprocess.call(['/Developer/Tools/SetFile','-a','C',app])
    180 
     76if sys.platform.startswith('darwin') and os.path.exists(
     77    os.path.join(gsaspath,"makeMacApp.py")):
     78    execfile(os.path.join(gsaspath,"makeMacApp.py"))
    18179#===========================================================================
    18280# On linux, make desktop icon
Note: See TracChangeset for help on using the changeset viewer.