[1858] | 1 | # creates Windows files to aid in running GSAS-II |
---|
| 2 | # creates RunGSASII.bat and a desktop shortcut to that file |
---|
| 3 | # registers the filetype .gpx so that the GSAS-II project files exhibit the |
---|
| 4 | # GSAS-II icon and so that double-clicking on them opens them in GSAS-II |
---|
| 5 | import os, sys |
---|
| 6 | import datetime |
---|
| 7 | try: |
---|
| 8 | import _winreg as winreg |
---|
| 9 | except ImportError: |
---|
| 10 | import winreg |
---|
| 11 | |
---|
| 12 | Script = '''@echo ======================================================================== |
---|
| 13 | @echo General Structure Analysis System-II |
---|
| 14 | @echo by Robert B. Von Dreele and Brian H. Toby |
---|
| 15 | @echo Argonne National Laboratory(C), 2010 |
---|
| 16 | @echo This product includes software developed by the UChicago Argonne, LLC, |
---|
| 17 | @echo as Operator of Argonne National Laboratory. |
---|
| 18 | @echo Please cite: |
---|
| 19 | @echo B.H. Toby and R.B. Von Dreele, J. Appl. Cryst. 46, 544-549 (2013) |
---|
| 20 | @echo for small angle use also cite: |
---|
| 21 | @echo R.B. Von Dreele, J. Appl. Cryst. 47, 1784-9 (2014) |
---|
| 22 | @echo ======================================================================== |
---|
| 23 | @ |
---|
[1859] | 24 | {:s} {:s} "%~1" |
---|
[1858] | 25 | @REM To keep the window from disappearing with any error messages |
---|
| 26 | pause |
---|
| 27 | |
---|
| 28 | ''' |
---|
| 29 | gsaspath = os.path.split(sys.argv[0])[0] |
---|
| 30 | if not gsaspath: gsaspath = os.path.curdir |
---|
| 31 | gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) |
---|
| 32 | G2script = os.path.join(gsaspath,'GSASII.py') |
---|
| 33 | G2bat = os.path.join(gsaspath,'RunGSASII.bat') |
---|
| 34 | G2icon = os.path.join(gsaspath,'gsas2.ico') |
---|
| 35 | pythonexe = os.path.realpath(sys.executable) |
---|
[1901] | 36 | # Bob reports a problem using pythonw.exe w/Canopy on Windows, so change that if used |
---|
| 37 | if pythonexe.lower().endswith('pythonw.exe'): |
---|
| 38 | print " using python.exe rather than "+pythonexe |
---|
| 39 | pythonexe = os.path.join(os.path.split(pythonexe)[0],'python.exe') |
---|
| 40 | print " now pythonexe="+pythonexe |
---|
[1858] | 41 | # create a GSAS-II script |
---|
| 42 | fp = open(os.path.join(G2bat),'w') |
---|
| 43 | fp.write("@REM created by run of bootstrap.py on {:%d %b %Y %H:%M}\n".format( |
---|
| 44 | datetime.datetime.now())) |
---|
| 45 | pexe = pythonexe |
---|
| 46 | if ' ' in pythonexe: pexe = '"'+pythonexe+'"' |
---|
| 47 | G2s = G2script |
---|
| 48 | if ' ' in G2s: G2script = '"'+G2script+'"' |
---|
| 49 | fp.write(Script.format(pexe,G2s)) |
---|
| 50 | fp.close() |
---|
| 51 | print '\nCreated GSAS-II batch file RunGSASII.bat in '+gsaspath |
---|
| 52 | |
---|
| 53 | # Associate a script and icon with .gpx files |
---|
| 54 | #gpxkey = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, '.gpx') |
---|
| 55 | gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\.gpx') |
---|
| 56 | winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II.project') |
---|
| 57 | winreg.CloseKey(gpxkey) |
---|
| 58 | gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\GSAS-II.project') |
---|
| 59 | winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II project') |
---|
| 60 | iconkey = winreg.CreateKey(gpxkey, 'DefaultIcon') |
---|
| 61 | winreg.SetValue(iconkey, None, winreg.REG_SZ, G2icon) |
---|
| 62 | openkey = winreg.CreateKey(gpxkey, r'shell\open\command') |
---|
[1859] | 63 | winreg.SetValue(openkey, None, winreg.REG_SZ, G2bat+' "%1"') |
---|
[1858] | 64 | winreg.CloseKey(iconkey) |
---|
| 65 | winreg.CloseKey(openkey) |
---|
| 66 | winreg.CloseKey(gpxkey) |
---|
| 67 | print 'Assigned icon and batch file to .gpx files' |
---|
| 68 | |
---|
| 69 | try: |
---|
| 70 | import win32com.shell.shell, win32com.shell.shellcon |
---|
| 71 | win32com.shell.shell.SHChangeNotify( |
---|
| 72 | win32com.shell.shellcon.SHCNE_ASSOCCHANGED, 0, None, None) |
---|
| 73 | except ImportError: |
---|
| 74 | print 'Module pywin32 not present, login again to see file types properly' |
---|
| 75 | except: |
---|
| 76 | print 'Unexpected error on explorer refresh. Please report:' |
---|
| 77 | import traceback |
---|
| 78 | print traceback.format_exc() |
---|
| 79 | |
---|
| 80 | # make a desktop shortcut to GSAS-II |
---|
| 81 | try: |
---|
| 82 | import win32com.shell.shell, win32com.shell.shellcon, win32com.client |
---|
| 83 | desktop = win32com.shell.shell.SHGetFolderPath( |
---|
| 84 | 0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0) |
---|
| 85 | shortcut = os.path.join(desktop, "GSAS-II.lnk") |
---|
| 86 | shell = win32com.client.Dispatch('WScript.Shell') |
---|
| 87 | shobj = shell.CreateShortCut(shortcut) |
---|
| 88 | shobj.Targetpath = G2bat |
---|
| 89 | #shobj.WorkingDirectory = wDir # could specify a default project location here |
---|
| 90 | shobj.IconLocation = G2icon |
---|
| 91 | shobj.save() |
---|
| 92 | print 'Created shortcut to start GSAS-II on desktop' |
---|
| 93 | except ImportError: |
---|
| 94 | print 'Module pywin32 not present, will not make desktop shortcut' |
---|
| 95 | except: |
---|
| 96 | print 'Unexpected error making desktop shortcut. Please report:' |
---|
| 97 | import traceback |
---|
| 98 | print traceback.format_exc() |
---|
| 99 | |
---|