1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
### WARNING:
# I don't have a clue what I'm doing here!
import win32api
### Following is the "normal" approach,
### but it requires loading the entire win32con file (which is big)
### for two values...
##import win32con
##HKEY_CLASSES_ROOT = win32con.HKEY_CLASSES_ROOT
##REG_SZ = win32con.REG_SZ
### These are the hard-coded values, should work everywhere as far as I know...
HKEY_CLASSES_ROOT = 0x80000000
REG_SZ= 1
def associate( extension, filetype, description="", commands=(), iconfile="" ):
'''Warning: I don't have a clue what I'm doing here!
extension -- extension including "." character, e.g. .proc
filetype -- formal name, no spaces allowed, e.g. SkeletonBuilder.RulesFile
description -- human-readable description of the file type
commands -- sequence of (command, commandline), e.g. (("Open", "someexe.exe %1"),)
iconfile -- optional default icon file for the filetype
'''
win32api.RegSetValue(
HKEY_CLASSES_ROOT,
extension,
REG_SZ,
filetype
)
if description:
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
filetype,
REG_SZ,
description
)
if iconfile:
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
"%(filetype)s\\DefaultIcon" % locals(),
REG_SZ,
iconfile
)
for (command, commandline) in commands:
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
"%(filetype)s\\Shell\\%(command)s" % locals(),
REG_SZ,
command,
)
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
"%(filetype)s\\Shell\\%(command)s\\Command" % locals(),
REG_SZ,
commandline
)
if __name__ == "__main__":
associate(
".proc",
"SkeletonBuilder.Processing",
"SkeletonBuilder Processing File",
(("Open", '''z:\\skeletonbuilder\\skeletonbuilder.exe "%1" %*'''),),
'''z:\\skeletonbuilder\\bitmaps\\skeletonbuildericon.ico''',
)
|