-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
187 lines (162 loc) · 4.9 KB
/
__init__.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
"""
Python mapping for the appkit framework.
This module does not contain docstrings for the wrapped code, check Apple's
documentation for details on how to use these functions and classes.
"""
import sys
# Manually written wrappers:
import Foundation
import objc
try:
from appkit import _metadata
from appkit._inlines import _inline_list_
except Exception as e:
from appkit import _metadata
from appkit._inlines import _inline_list_
def _setup_conveniences():
def fontdescriptor_get(self, key, default=None):
value = self.objectForKey_(key)
if value is None:
return default
return value
def fontdescriptor_getitem(self, key, default=None):
value = self.objectForKey_(key)
if value is None:
raise KeyError(key)
return value
objc.addConvenienceForClass(
"NSFontDescriptor",
(("__getitem__", fontdescriptor_getitem), ("get", fontdescriptor_get)),
)
_setup_conveniences()
def NSDictionaryOfVariableBindings(*names):
"""
Return a dictionary with the given names and there values.
"""
import sys
variables = sys._getframe(1).f_locals
return {nm: variables[nm] for nm in names}
sys.modules["appkit"] = mod = objc.ObjCLazyModule(
"appkit",
"com.apple.appkit",
objc.pathForFramework("/System/Library/Frameworks/appkit.framework"),
_metadata.__dict__,
_inline_list_,
{
"__doc__": __doc__,
"objc": objc,
"NSDictionaryOfVariableBindings": NSDictionaryOfVariableBindings,
"__path__": __path__,
"__loader__": globals().get("__loader__", None),
},
(Foundation,),
)
# NSApp is a global variable that can be changed in ObjC,
# somewhat emulate that (it is *not* possible to assign to
# NSApp in Python)
from appkit._nsapp import NSApp # isort:skip # noqa: E402
mod.NSApp = NSApp
import appkit._AppKit # isort:skip # noqa: E402
for nm in dir(appkit._AppKit):
setattr(mod, nm, getattr(appkit._AppKit, nm))
# Fix types for a number of character constants
mod.NSEnterCharacter = chr(mod.NSEnterCharacter)
mod.NSBackspaceCharacter = chr(mod.NSBackspaceCharacter)
mod.NSTabCharacter = chr(mod.NSTabCharacter)
mod.NSNewlineCharacter = chr(mod.NSNewlineCharacter)
mod.NSFormFeedCharacter = chr(mod.NSFormFeedCharacter)
mod.NSCarriageReturnCharacter = chr(mod.NSCarriageReturnCharacter)
mod.NSBackTabCharacter = chr(mod.NSBackTabCharacter)
mod.NSDeleteCharacter = chr(mod.NSDeleteCharacter)
mod.NSLineSeparatorCharacter = chr(mod.NSLineSeparatorCharacter)
mod.NSParagraphSeparatorCharacter = chr(mod.NSParagraphSeparatorCharacter)
for nm in [
"NSUpArrowFunctionKey",
"NSDownArrowFunctionKey",
"NSLeftArrowFunctionKey",
"NSRightArrowFunctionKey",
"NSF1FunctionKey",
"NSF2FunctionKey",
"NSF3FunctionKey",
"NSF4FunctionKey",
"NSF5FunctionKey",
"NSF6FunctionKey",
"NSF7FunctionKey",
"NSF8FunctionKey",
"NSF9FunctionKey",
"NSF10FunctionKey",
"NSF11FunctionKey",
"NSF12FunctionKey",
"NSF13FunctionKey",
"NSF14FunctionKey",
"NSF15FunctionKey",
"NSF16FunctionKey",
"NSF17FunctionKey",
"NSF18FunctionKey",
"NSF19FunctionKey",
"NSF20FunctionKey",
"NSF21FunctionKey",
"NSF22FunctionKey",
"NSF23FunctionKey",
"NSF24FunctionKey",
"NSF25FunctionKey",
"NSF26FunctionKey",
"NSF27FunctionKey",
"NSF28FunctionKey",
"NSF29FunctionKey",
"NSF30FunctionKey",
"NSF31FunctionKey",
"NSF32FunctionKey",
"NSF33FunctionKey",
"NSF34FunctionKey",
"NSF35FunctionKey",
"NSInsertFunctionKey",
"NSDeleteFunctionKey",
"NSHomeFunctionKey",
"NSBeginFunctionKey",
"NSEndFunctionKey",
"NSPageUpFunctionKey",
"NSPageDownFunctionKey",
"NSPrintScreenFunctionKey",
"NSScrollLockFunctionKey",
"NSPauseFunctionKey",
"NSSysReqFunctionKey",
"NSBreakFunctionKey",
"NSResetFunctionKey",
"NSStopFunctionKey",
"NSMenuFunctionKey",
"NSUserFunctionKey",
"NSSystemFunctionKey",
"NSPrintFunctionKey",
"NSClearLineFunctionKey",
"NSClearDisplayFunctionKey",
"NSInsertLineFunctionKey",
"NSDeleteLineFunctionKey",
"NSInsertCharFunctionKey",
"NSDeleteCharFunctionKey",
"NSPrevFunctionKey",
"NSNextFunctionKey",
"NSSelectFunctionKey",
"NSExecuteFunctionKey",
"NSUndoFunctionKey",
"NSRedoFunctionKey",
"NSFindFunctionKey",
"NSHelpFunctionKey",
"NSModeSwitchFunctionKey",
]:
try:
setattr(mod, nm, chr(getattr(mod, nm)))
except AttributeError:
pass
try:
mod.NSImageNameApplicationIcon
except AttributeError:
mod.NSImageNameApplicationIcon = "NSApplicationIcon"
if objc.arch == "arm64":
# XXX: Temporary adjustment until the metadata
# is updated
mod.NSImageResizingModeStretch = 1
mod.NSImageResizingModeTile = 0
mod.NSTextAlignmentCenter = 1
mod.NSTextAlignmentRight = 2
del sys.modules["appkit._metadata"]