2323from winpython import utils
2424
2525KEY_C = r"Software\Classes\%s"
26- KEY_C0 = KEY_C % r"Python.%sFile\shell\%s"
27- KEY_C1 = KEY_C0 + r"\command"
26+ KEY_C0 = KEY_C % r"Python.%sFile\shell"
27+ KEY_C1 = KEY_C % r"Python.%sFile\shell\%s"
28+ KEY_C2 = KEY_C1 + r"\command"
2829KEY_I = KEY_C % r"Python.%sFile\DefaultIcon"
2930KEY_D = KEY_C % r"Python.%sFile"
3031EWI = "Edit with IDLE"
3132EWS = "Edit with Spyder"
3233
34+ KEY_S = r"Software\Python"
35+ KEY_S0 = KEY_S + r"\PythonCore"
36+ KEY_S1 = KEY_S0 + r"\%s"
37+
3338
3439def _get_shortcut_data (target , current = True ):
3540 wpgroup = utils .create_winpython_start_menu_folder (current = current )
@@ -67,24 +72,24 @@ def register(target, current=True):
6772 # Verbs
6873 python = osp .abspath (osp .join (target , 'python.exe' ))
6974 pythonw = osp .abspath (osp .join (target , 'pythonw.exe' ))
70- winreg .SetValueEx (winreg .CreateKey (root , KEY_C1 % ("" , "open" )),
75+ winreg .SetValueEx (winreg .CreateKey (root , KEY_C2 % ("" , "open" )),
7176 "" , 0 , winreg .REG_SZ , '"%s" "%%1" %%*' % python )
72- winreg .SetValueEx (winreg .CreateKey (root , KEY_C1 % ("NoCon" , "open" )),
77+ winreg .SetValueEx (winreg .CreateKey (root , KEY_C2 % ("NoCon" , "open" )),
7378 "" , 0 , winreg .REG_SZ , '"%s" "%%1" %%*' % pythonw )
74- winreg .SetValueEx (winreg .CreateKey (root , KEY_C1 % ("Compiled" , "open" )),
79+ winreg .SetValueEx (winreg .CreateKey (root , KEY_C2 % ("Compiled" , "open" )),
7580 "" , 0 , winreg .REG_SZ , '"%s" "%%1" %%*' % python )
76- winreg .SetValueEx (winreg .CreateKey (root , KEY_C1 % ("" , EWI )),
81+ winreg .SetValueEx (winreg .CreateKey (root , KEY_C2 % ("" , EWI )),
7782 "" , 0 , winreg .REG_SZ ,
7883 '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"'
7984 % (pythonw , target ))
80- winreg .SetValueEx (winreg .CreateKey (root , KEY_C1 % ("NoCon" , EWI )),
85+ winreg .SetValueEx (winreg .CreateKey (root , KEY_C2 % ("NoCon" , EWI )),
8186 "" , 0 , winreg .REG_SZ ,
8287 '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"'
8388 % (pythonw , target ))
84- winreg .SetValueEx (winreg .CreateKey (root , KEY_C1 % ("" , EWS )),
89+ winreg .SetValueEx (winreg .CreateKey (root , KEY_C2 % ("" , EWS )),
8590 "" , 0 , winreg .REG_SZ ,
8691 '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw , target ))
87- winreg .SetValueEx (winreg .CreateKey (root , KEY_C1 % ("NoCon" , EWS )),
92+ winreg .SetValueEx (winreg .CreateKey (root , KEY_C2 % ("NoCon" , EWS )),
8893 "" , 0 , winreg .REG_SZ ,
8994 '"%s" "%s\Scripts\spyder" "%%1"' % (pythonw , target ))
9095
@@ -105,6 +110,25 @@ def register(target, current=True):
105110 winreg .SetValueEx (winreg .CreateKey (root , KEY_D % "Compiled" ),
106111 "" , 0 , winreg .REG_SZ , "Compiled Python File" )
107112
113+ # PythonCore entries
114+ short_version = utils .get_python_infos (target )[0 ]
115+ long_version = utils .get_python_long_version (target )
116+ key_core = (KEY_S1 % short_version ) + r'\%s'
117+ winreg .SetValueEx (winreg .CreateKey (root , key_core % 'InstallPath' ),
118+ "" , 0 , winreg .REG_SZ , target )
119+ winreg .SetValueEx (winreg .CreateKey (root ,
120+ key_core % r'InstallPath\InstallGroup' ),
121+ "" , 0 , winreg .REG_SZ , "Python %s" % short_version )
122+ winreg .SetValueEx (winreg .CreateKey (root , key_core % 'Modules' ),
123+ "" , 0 , winreg .REG_SZ , "" )
124+ winreg .SetValueEx (winreg .CreateKey (root , key_core % 'PythonPath' ),
125+ "" , 0 , winreg .REG_SZ ,
126+ r"%s\Lib;%s\DLLs" % (target , target ))
127+ winreg .SetValueEx (winreg .CreateKey (root ,
128+ key_core % r'Help\Main Python Documentation' ),
129+ "" , 0 , winreg .REG_SZ ,
130+ r"%s\Doc\python%s.chm" % (target , long_version ))
131+
108132 # Create start menu entries for all WinPython launchers
109133 for path , desc , fname in _get_shortcut_data (target , current = current ):
110134 utils .create_shortcut (path , desc , fname )
@@ -123,32 +147,47 @@ def unregister(target, current=True):
123147 """Unregister a Python distribution in Windows registry"""
124148 # Registry entries
125149 root = winreg .HKEY_CURRENT_USER if current else winreg .HKEY_LOCAL_MACHINE
150+ short_version = utils .get_python_infos (target )[0 ]
151+ key_core = (KEY_S1 % short_version ) + r'\%s'
126152 for key in (
127153 # Icons
128154 KEY_I % "NoCon" , KEY_I % "Compiled" , KEY_I % "" ,
129155 # Edit with IDLE
156+ KEY_C2 % ("" , EWI ), KEY_C2 % ("NoCon" , EWI ),
130157 KEY_C1 % ("" , EWI ), KEY_C1 % ("NoCon" , EWI ),
131- KEY_C0 % ("" , EWI ), KEY_C0 % ("NoCon" , EWI ),
132158 # Edit with Spyder
159+ KEY_C2 % ("" , EWS ), KEY_C2 % ("NoCon" , EWS ),
133160 KEY_C1 % ("" , EWS ), KEY_C1 % ("NoCon" , EWS ),
134- KEY_C0 % ("" , EWS ), KEY_C0 % ("NoCon" , EWS ),
135161 # Verbs
136- KEY_C1 % ("" , "open" ), KEY_C1 % ("NoCon" , "open" ),
162+ KEY_C2 % ("" , "open" ),
163+ KEY_C2 % ("NoCon" , "open" ),
164+ KEY_C2 % ("Compiled" , "open" ),
165+ KEY_C1 % ("" , "open" ),
166+ KEY_C1 % ("NoCon" , "open" ),
137167 KEY_C1 % ("Compiled" , "open" ),
168+ KEY_C0 % "" , KEY_C0 % "NoCon" , KEY_C0 % "Compiled" ,
138169 # Descriptions
139170 KEY_D % "NoCon" , KEY_D % "Compiled" , KEY_D % "" ,
140- # Parent key
141- KEY_C ,
171+ # PythonCore
172+ key_core % r'InstallPath\InstallGroup' ,
173+ key_core % 'InstallPath' ,
174+ key_core % 'Modules' ,
175+ key_core % 'PythonPath' ,
176+ key_core % r'Help\Main Python Documentation' ,
177+ key_core % 'Help' ,
178+ KEY_S1 % short_version , KEY_S0 , KEY_S ,
142179 ):
143180 try :
181+ print (key )
144182 winreg .DeleteKey (root , key )
145183 except WindowsError :
146184 rootkey = 'HKEY_CURRENT_USER' if current else 'HKEY_LOCAL_MACHINE'
147185 raise WindowsError (r'Unable to remove %s\%s' % (rootkey , key ))
148186
149187 # Start menu shortcuts
150188 for path , desc , fname in _get_shortcut_data (target , current = current ):
151- os .remove (fname )
189+ if osp .exists (fname ):
190+ os .remove (fname )
152191
153192
154193if __name__ == '__main__' :
0 commit comments