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 for DIFFaX use also cite: |
---|
23 | @echo M.M.J. Treacy, J.M. Newsam and M.W. Deem, |
---|
24 | @echo Proc. Roy. Soc. Lond. 433A, 499-520 (1991) |
---|
25 | @echo ======================================================================== |
---|
26 | @ |
---|
27 | {:s} {:s} "%~1" |
---|
28 | @REM To keep the window from disappearing with any error messages |
---|
29 | pause |
---|
30 | |
---|
31 | ''' |
---|
32 | gsaspath = os.path.split(sys.argv[0])[0] |
---|
33 | if not gsaspath: gsaspath = os.path.curdir |
---|
34 | gsaspath = os.path.abspath(os.path.expanduser(gsaspath)) |
---|
35 | G2script = os.path.join(gsaspath,'GSASII.py') |
---|
36 | G2bat = os.path.join(gsaspath,'RunGSASII.bat') |
---|
37 | G2icon = os.path.join(gsaspath,'gsas2.ico') |
---|
38 | pythonexe = os.path.realpath(sys.executable) |
---|
39 | # Bob reports a problem using pythonw.exe w/Canopy on Windows, so change that if used |
---|
40 | if pythonexe.lower().endswith('pythonw.exe'): |
---|
41 | print " using python.exe rather than "+pythonexe |
---|
42 | pythonexe = os.path.join(os.path.split(pythonexe)[0],'python.exe') |
---|
43 | print " now pythonexe="+pythonexe |
---|
44 | # create a GSAS-II script |
---|
45 | fp = open(os.path.join(G2bat),'w') |
---|
46 | fp.write("@REM created by run of bootstrap.py on {:%d %b %Y %H:%M}\n".format( |
---|
47 | datetime.datetime.now())) |
---|
48 | pexe = pythonexe |
---|
49 | if ' ' in pythonexe: pexe = '"'+pythonexe+'"' |
---|
50 | G2s = G2script |
---|
51 | if ' ' in G2s: G2s = '"'+G2script+'"' |
---|
52 | fp.write(Script.format(pexe,G2s)) |
---|
53 | fp.close() |
---|
54 | print '\nCreated GSAS-II batch file RunGSASII.bat in '+gsaspath |
---|
55 | |
---|
56 | # Associate a script and icon with .gpx files |
---|
57 | #gpxkey = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, '.gpx') |
---|
58 | gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\.gpx') |
---|
59 | winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II.project') |
---|
60 | winreg.CloseKey(gpxkey) |
---|
61 | gpxkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER,r'Software\CLASSES\GSAS-II.project') |
---|
62 | winreg.SetValue(gpxkey, None, winreg.REG_SZ, 'GSAS-II project') |
---|
63 | iconkey = winreg.CreateKey(gpxkey, 'DefaultIcon') |
---|
64 | winreg.SetValue(iconkey, None, winreg.REG_SZ, G2icon) |
---|
65 | openkey = winreg.CreateKey(gpxkey, r'shell\open\command') |
---|
66 | winreg.SetValue(openkey, None, winreg.REG_SZ, G2bat+' "%1"') |
---|
67 | winreg.CloseKey(iconkey) |
---|
68 | winreg.CloseKey(openkey) |
---|
69 | winreg.CloseKey(gpxkey) |
---|
70 | print 'Assigned icon and batch file to .gpx files' |
---|
71 | |
---|
72 | try: |
---|
73 | import win32com.shell.shell, win32com.shell.shellcon |
---|
74 | win32com.shell.shell.SHChangeNotify( |
---|
75 | win32com.shell.shellcon.SHCNE_ASSOCCHANGED, 0, None, None) |
---|
76 | except ImportError: |
---|
77 | print 'Module pywin32 not present, login again to see file types properly' |
---|
78 | except: |
---|
79 | print 'Unexpected error on explorer refresh. Please report:' |
---|
80 | import traceback |
---|
81 | print traceback.format_exc() |
---|
82 | |
---|
83 | # make a desktop shortcut to GSAS-II |
---|
84 | try: |
---|
85 | import win32com.shell.shell, win32com.shell.shellcon, win32com.client |
---|
86 | desktop = win32com.shell.shell.SHGetFolderPath( |
---|
87 | 0, win32com.shell.shellcon.CSIDL_DESKTOP, None, 0) |
---|
88 | shortcut = os.path.join(desktop, "GSAS-II.lnk") |
---|
89 | shell = win32com.client.Dispatch('WScript.Shell') |
---|
90 | shobj = shell.CreateShortCut(shortcut) |
---|
91 | shobj.Targetpath = G2bat |
---|
92 | #shobj.WorkingDirectory = wDir # could specify a default project location here |
---|
93 | shobj.IconLocation = G2icon |
---|
94 | shobj.save() |
---|
95 | print 'Created shortcut to start GSAS-II on desktop' |
---|
96 | except ImportError: |
---|
97 | print 'Module pywin32 not present, will not make desktop shortcut' |
---|
98 | except: |
---|
99 | print 'Unexpected error making desktop shortcut. Please report:' |
---|
100 | import traceback |
---|
101 | print traceback.format_exc() |
---|
102 | |
---|