Line | |
---|
1 | # This code isn't loadable or sensible except on Windows. Importers all know |
---|
2 | # this and are careful. Normally I would just let an import error from ctypes |
---|
3 | # explain any mistakes but Mypy also needs some help here. This assert |
---|
4 | # explains to it that this module is Windows-only. This prevents errors about |
---|
5 | # ctypes.windll and such which only exist when running on Windows. |
---|
6 | # |
---|
7 | # Beware of the limitations of the Mypy AST analyzer. The check needs to take |
---|
8 | # exactly this form or it may not be recognized. |
---|
9 | # |
---|
10 | # https://mypy.readthedocs.io/en/stable/common_issues.html?highlight=platform#python-version-and-system-platform-checks |
---|
11 | import sys |
---|
12 | assert sys.platform == "win32" |
---|
13 | |
---|
14 | # <https://msdn.microsoft.com/en-us/library/ms680621%28VS.85%29.aspx> |
---|
15 | from win32api import ( |
---|
16 | SetErrorMode, |
---|
17 | ) |
---|
18 | from win32con import ( |
---|
19 | SEM_FAILCRITICALERRORS, |
---|
20 | SEM_NOOPENFILEERRORBOX, |
---|
21 | ) |
---|
22 | |
---|
23 | # Keep track of whether `initialize` has run so we don't do any of the |
---|
24 | # initialization more than once. |
---|
25 | _done = False |
---|
26 | |
---|
27 | |
---|
28 | def initialize(): |
---|
29 | global _done |
---|
30 | import sys |
---|
31 | if sys.platform != "win32" or _done: |
---|
32 | return True |
---|
33 | _done = True |
---|
34 | |
---|
35 | SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX) |
---|
Note: See
TracBrowser
for help on using the repository browser.