|
1 | 1 | from __future__ import print_function |
2 | | -from ctypes import * |
| 2 | +from ctypes import c_char_p, c_int, c_short, c_wchar_p |
| 3 | +from ctypes import POINTER |
| 4 | +from ctypes import byref, create_string_buffer, create_unicode_buffer |
3 | 5 | from ctypes.wintypes import DWORD, WIN32_FIND_DATAA, WIN32_FIND_DATAW, MAX_PATH |
| 6 | +from typing import Tuple, TYPE_CHECKING |
| 7 | + |
4 | 8 | from comtypes import IUnknown, GUID, COMMETHOD, HRESULT, CoClass |
5 | 9 |
|
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + from comtypes import hints # type: ignore |
| 13 | + |
| 14 | + |
6 | 15 | # for GetPath |
7 | 16 | SLGP_SHORTPATH = 0x1 |
8 | 17 | SLGP_UNCPRIORITY = 0x2 |
@@ -113,31 +122,52 @@ class IShellLinkA(IUnknown): |
113 | 122 | COMMETHOD([], HRESULT, "SetPath", (["in"], c_char_p, "pszFile")), |
114 | 123 | ] |
115 | 124 |
|
116 | | - def GetPath(self, flags=SLGP_SHORTPATH): |
| 125 | + if TYPE_CHECKING: |
| 126 | + # fmt: off |
| 127 | + def GetIDList(self) -> hints.Incomplete: ... # noqa |
| 128 | + def SetIDList(self, pidl: hints.Incomplete) -> hints.Incomplete: ... # noqa |
| 129 | + def SetDescription(self, pszName: bytes) -> hints.Incomplete: ... # noqa |
| 130 | + def SetWorkingDirectory(self, pszDir: bytes) -> hints.Hresult: ... # noqa |
| 131 | + def SetArguments(self, pszArgs: bytes) -> hints.Hresult: ... # noqa |
| 132 | + @property |
| 133 | + def Hotkey(self) -> int: ... # noqa |
| 134 | + @Hotkey.setter |
| 135 | + def Hotkey(self, pwHotkey: int) -> None: ... # noqa |
| 136 | + @property |
| 137 | + def ShowCmd(self) -> int: ... # noqa |
| 138 | + @ShowCmd.setter |
| 139 | + def ShowCmd(self, piShowCmd: int) -> None: ... # noqa |
| 140 | + def SetIconLocation(self, pszIconPath: bytes, iIcon: int) -> hints.Hresult: ... # noqa |
| 141 | + def SetRelativePath(self, pszPathRel: bytes, dwReserved: hints.Literal[0]) -> hints.Hresult: ... # noqa |
| 142 | + def Resolve(self, hwnd: int, fFlags: int) -> hints.Hresult: ... # noqa |
| 143 | + def SetPath(self, pszFile: bytes) -> hints.Hresult: ... # noqa |
| 144 | + # fmt: on |
| 145 | + |
| 146 | + def GetPath(self, flags: int = SLGP_SHORTPATH) -> bytes: |
117 | 147 | buf = create_string_buffer(MAX_PATH) |
118 | 148 | # We're not interested in WIN32_FIND_DATA |
119 | | - self.__com_GetPath(buf, MAX_PATH, None, flags) |
| 149 | + self.__com_GetPath(buf, MAX_PATH, None, flags) # type: ignore |
120 | 150 | return buf.value |
121 | 151 |
|
122 | | - def GetDescription(self): |
| 152 | + def GetDescription(self) -> bytes: |
123 | 153 | buf = create_string_buffer(1024) |
124 | | - self.__com_GetDescription(buf, 1024) |
| 154 | + self.__com_GetDescription(buf, 1024) # type: ignore |
125 | 155 | return buf.value |
126 | 156 |
|
127 | | - def GetWorkingDirectory(self): |
| 157 | + def GetWorkingDirectory(self) -> bytes: |
128 | 158 | buf = create_string_buffer(MAX_PATH) |
129 | | - self.__com_GetWorkingDirectory(buf, MAX_PATH) |
| 159 | + self.__com_GetWorkingDirectory(buf, MAX_PATH) # type: ignore |
130 | 160 | return buf.value |
131 | 161 |
|
132 | | - def GetArguments(self): |
| 162 | + def GetArguments(self) -> bytes: |
133 | 163 | buf = create_string_buffer(1024) |
134 | | - self.__com_GetArguments(buf, 1024) |
| 164 | + self.__com_GetArguments(buf, 1024) # type: ignore |
135 | 165 | return buf.value |
136 | 166 |
|
137 | | - def GetIconLocation(self): |
| 167 | + def GetIconLocation(self) -> Tuple[bytes, int]: |
138 | 168 | iIcon = c_int() |
139 | 169 | buf = create_string_buffer(MAX_PATH) |
140 | | - self.__com_GetIconLocation(buf, MAX_PATH, byref(iIcon)) |
| 170 | + self.__com_GetIconLocation(buf, MAX_PATH, byref(iIcon)) # type: ignore |
141 | 171 | return buf.value, iIcon.value |
142 | 172 |
|
143 | 173 |
|
@@ -226,31 +256,52 @@ class IShellLinkW(IUnknown): |
226 | 256 | COMMETHOD([], HRESULT, "SetPath", (["in"], c_wchar_p, "pszFile")), |
227 | 257 | ] |
228 | 258 |
|
229 | | - def GetPath(self, flags=SLGP_SHORTPATH): |
| 259 | + if TYPE_CHECKING: |
| 260 | + # fmt: off |
| 261 | + def GetIDList(self) -> hints.Incomplete: ... # noqa |
| 262 | + def SetIDList(self, pidl: hints.Incomplete) -> hints.Incomplete: ... # noqa |
| 263 | + def SetDescription(self, pszName: str) -> hints.Incomplete: ... # noqa |
| 264 | + def SetWorkingDirectory(self, pszDir: str) -> hints.Hresult: ... # noqa |
| 265 | + def SetArguments(self, pszArgs: str) -> hints.Hresult: ... # noqa |
| 266 | + @property |
| 267 | + def Hotkey(self) -> int: ... # noqa |
| 268 | + @Hotkey.setter |
| 269 | + def Hotkey(self, pwHotkey: int) -> None: ... # noqa |
| 270 | + @property |
| 271 | + def ShowCmd(self) -> int: ... # noqa |
| 272 | + @ShowCmd.setter |
| 273 | + def ShowCmd(self, piShowCmd: int) -> None: ... # noqa |
| 274 | + def SetIconLocation(self, pszIconPath: str, iIcon: int) -> hints.Hresult: ... # noqa |
| 275 | + def SetRelativePath(self, pszPathRel: str, dwReserved: hints.Literal[0]) -> hints.Hresult: ... # noqa |
| 276 | + def Resolve(self, hwnd: int, fFlags: int) -> hints.Hresult: ... # noqa |
| 277 | + def SetPath(self, pszFile: str) -> hints.Hresult: ... # noqa |
| 278 | + # fmt: on |
| 279 | + |
| 280 | + def GetPath(self, flags: int = SLGP_SHORTPATH) -> str: |
230 | 281 | buf = create_unicode_buffer(MAX_PATH) |
231 | 282 | # We're not interested in WIN32_FIND_DATA |
232 | | - self.__com_GetPath(buf, MAX_PATH, None, flags) |
| 283 | + self.__com_GetPath(buf, MAX_PATH, None, flags) # type: ignore |
233 | 284 | return buf.value |
234 | 285 |
|
235 | | - def GetDescription(self): |
| 286 | + def GetDescription(self) -> str: |
236 | 287 | buf = create_unicode_buffer(1024) |
237 | | - self.__com_GetDescription(buf, 1024) |
| 288 | + self.__com_GetDescription(buf, 1024) # type: ignore |
238 | 289 | return buf.value |
239 | 290 |
|
240 | | - def GetWorkingDirectory(self): |
| 291 | + def GetWorkingDirectory(self) -> str: |
241 | 292 | buf = create_unicode_buffer(MAX_PATH) |
242 | | - self.__com_GetWorkingDirectory(buf, MAX_PATH) |
| 293 | + self.__com_GetWorkingDirectory(buf, MAX_PATH) # type: ignore |
243 | 294 | return buf.value |
244 | 295 |
|
245 | | - def GetArguments(self): |
| 296 | + def GetArguments(self) -> str: |
246 | 297 | buf = create_unicode_buffer(1024) |
247 | | - self.__com_GetArguments(buf, 1024) |
| 298 | + self.__com_GetArguments(buf, 1024) # type: ignore |
248 | 299 | return buf.value |
249 | 300 |
|
250 | | - def GetIconLocation(self): |
| 301 | + def GetIconLocation(self) -> Tuple[str, int]: |
251 | 302 | iIcon = c_int() |
252 | 303 | buf = create_unicode_buffer(MAX_PATH) |
253 | | - self.__com_GetIconLocation(buf, MAX_PATH, byref(iIcon)) |
| 304 | + self.__com_GetIconLocation(buf, MAX_PATH, byref(iIcon)) # type: ignore |
254 | 305 | return buf.value, iIcon.value |
255 | 306 |
|
256 | 307 |
|
|
0 commit comments