add skeleton for variant type support
[pywinlite.git] / winlitecfg.py
blob9f524c7c1cf33780c0586b873078a05c25e02120
1 #Copyright (c) 2008 Vincent Povirk
3 #Permission is hereby granted, free of charge, to any person
4 #obtaining a copy of this software and associated documentation
5 #files (the "Software"), to deal in the Software without
6 #restriction, including without limitation the rights to use,
7 #copy, modify, merge, publish, distribute, sublicense, and/or sell
8 #copies of the Software, and to permit persons to whom the
9 #Software is furnished to do so, subject to the following
10 #conditions:
12 #The above copyright notice and this permission notice shall be
13 #included in all copies or substantial portions of the Software.
15 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 #OTHER DEALINGS IN THE SOFTWARE.
24 """
25 winlitecfg module - allows configuration before the bindings are first imported.
27 To use ANSI, call set_ansi() before importing other modules:
29 import winlitecfg
30 winlitecfg.set_ansi()
31 import winuser
32 """
34 import ctypes
36 class CfgTooLateError(Exception):
37 pass
39 # ANSI/Unicode setting
41 can_set_aw = True
43 def set_unicode():
44 """set_unicode - Call before importing other modules to prefer W-suffixed objects
46 import winlitecfg
47 winlitecfg.set_unicode()
48 import winuser
49 """
50 global aw
51 if not can_set_aw:
52 raise CfgTooLateError("Call winlitecfg.set_unicode() before importing other modules")
53 aw = 'W'
55 def set_ansi():
56 """set_ansi - Call before importing other modules to prefer A-suffixed objects
58 import winlitecfg
59 winlitecfg.set_ansi()
60 import winuser
61 """
62 global aw
63 if not can_set_aw:
64 raise CfgTooLateError("Call winlitecfg.set_ansi() before importing other modules")
65 aw = 'A'
67 if ctypes.windll.kernel32.GetTempPathW(0, 0) == 0 and ctypes.GetLastError() == 120: # 120 == ERROR_CALL_NOT_IMPLEMENTED
68 set_ansi()
69 else:
70 set_unicode()
72 def create_aw_aliases(module_dict):
73 """create_aw_aliases(globals())
75 If nameA and nameW exists but name does not, set name to equal nameA or
76 nameW depending on whether ANSI or Unicode is being used.
77 """
78 global can_set_aw
79 if aw == 'W':
80 not_aw = 'A'
81 else:
82 not_aw = 'W'
83 for name in module_dict.keys():
84 if name.endswith(aw) and name[:-1]+not_aw in module_dict and name[:-1] not in module_dict:
85 module_dict[name[:-1]] = module_dict[name]
86 can_set_aw = False
88 def get_aw_symbols(globals, module, names):
89 global can_set_aw
90 can_set_aw = False
91 for name in names:
92 globals[name] = getattr(module, name+aw)
94 #FIXME: define WINVER, _WIN32_IE, _WIN32_WINDOWS, and _WIN32_WINNT