From 73972cd17ef57581438e02a80ebad4ed31755ca3 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 27 Nov 2023 16:52:17 +1100 Subject: [PATCH] Stub the parts of PyObjC I'm using (whee) --- stubs/AppKit/__init__.pyi | 33 ++++++++++++++++++ stubs/Foundation/__init__.pyi | 9 +++++ stubs/MediaPlayer/__init__.pyi | 64 ++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 stubs/AppKit/__init__.pyi create mode 100644 stubs/Foundation/__init__.pyi create mode 100644 stubs/MediaPlayer/__init__.pyi diff --git a/stubs/AppKit/__init__.pyi b/stubs/AppKit/__init__.pyi new file mode 100644 index 0000000..30512c2 --- /dev/null +++ b/stubs/AppKit/__init__.pyi @@ -0,0 +1,33 @@ +from typing import Final, Literal + +from Foundation import CGSize + +# There are many other operations available but we only actually use copy, so we don't need all of them here. +NSCompositingOperationClear: Final = 0 +NSCompositingOperationCopy: Final = 1 +NSCompositingOperation = Literal[0, 1] + +class NSRect: + pass + +def NSMakeRect(x: float, y: float, w: float, h: float) -> NSRect: ... + +class NSImage: + @staticmethod + def alloc() -> type[NSImage]: ... + + @staticmethod + def initByReferencingFile_(file: str) -> NSImage: ... + + @staticmethod + def initWithData_(data: bytes) -> NSImage: ... + + @staticmethod + def initWithSize_(size: CGSize) -> NSImage: ... + + def size(self) -> CGSize: ... + + def lockFocus(self) -> None: ... + def unlockFocus(self) -> None: ... + + def drawInRect_fromRect_operation_fraction_(self, inRect: NSRect, fromRect: NSRect, operation: NSCompositingOperation, fraction: float) -> None: ... diff --git a/stubs/Foundation/__init__.pyi b/stubs/Foundation/__init__.pyi new file mode 100644 index 0000000..5919b6b --- /dev/null +++ b/stubs/Foundation/__init__.pyi @@ -0,0 +1,9 @@ +from typing import Type + +class CGSize: + width: float + height: float + +class NSMutableDictionary(dict[str, object]): + @classmethod + def dictionary(cls: Type[NSMutableDictionary]) -> NSMutableDictionary: ... diff --git a/stubs/MediaPlayer/__init__.pyi b/stubs/MediaPlayer/__init__.pyi new file mode 100644 index 0000000..a234bab --- /dev/null +++ b/stubs/MediaPlayer/__init__.pyi @@ -0,0 +1,64 @@ +from collections.abc import Callable +from typing import Final, Literal + +from AppKit import NSImage +from Foundation import CGSize, NSMutableDictionary + +MPMusicPlaybackStateStopped: Final = 0 +MPMusicPlaybackStatePlaying: Final = 1 +MPMusicPlaybackStatePaused: Final = 2 +MPMusicPlaybackState = Literal[0, 1, 2] + +MPMediaItemPropertyAlbumTitle: Final = 'albumTitle' +MPMediaItemPropertyArtist: Final = 'artist' +MPMediaItemPropertyArtwork: Final = 'artwork' +MPMediaItemPropertyPlaybackDuration: Final = 'playbackDuration' +MPMediaItemPropertyTitle: Final = 'title' + +MPNowPlayingInfoPropertyMediaType: Final = 'MPNowPlayingInfoPropertyMediaType' +MPNowPlayingInfoMediaTypeAudio: Final = 1 +MPNowPlayingInfoMediaTypeNone: Final = 0 + +MPNowPlayingInfoPropertyElapsedPlaybackTime: Final = 'MPNowPlayingInfoPropertyElapsedPlaybackTime' + +class MPMediaItemArtwork: + @staticmethod + def alloc() -> type[MPMediaItemArtwork]: ... + @staticmethod + def initWithBoundsSize_requestHandler_(size: CGSize, handler: Callable[[CGSize], NSImage]) -> MPMediaItemArtwork: ... + +class MPNowPlayingInfoCenter: + @staticmethod + def defaultCenter() -> MPNowPlayingInfoCenter: ... + + def setNowPlayingInfo_(self, info: NSMutableDictionary) -> None: ... + def setPlaybackState_(self, state: MPMusicPlaybackState) -> None: ... + +MPRemoteCommandHandlerStatusSuccess: Literal[0] = 0 +MPRemoteCommandHandlerStatusCommandFailed: Literal[200] = 200 +MPRemoteCommandHandlerStatus = Literal[0, 200] + +class MPRemoteCommandEvent: + pass + +class MPRemoteCommand: + def setEnabled_(self, enabled: bool) -> None: ... + def removeTarget_(self, target: object) -> None: ... + def addTargetWithHandler_(self, handler: Callable[[MPRemoteCommandEvent], MPRemoteCommandHandlerStatus]) -> None: ... + +class MPRemoteCommandCenter: + @staticmethod + def sharedCommandCenter() -> MPRemoteCommandCenter: ... + + def togglePlayPauseCommand(self) -> MPRemoteCommand: ... + def playCommand(self) -> MPRemoteCommand: ... + def pauseCommand(self) -> MPRemoteCommand: ... + def stopCommand(self) -> MPRemoteCommand: ... + def nextTrackCommand(self) -> MPRemoteCommand: ... + def previousTrackCommand(self) -> MPRemoteCommand: ... + def changePlaybackRateCommand(self) -> MPRemoteCommand: ... + def seekBackwardCommand(self) -> MPRemoteCommand: ... + def skipBackwardCommand(self) -> MPRemoteCommand: ... + def seekForwardCommand(self) -> MPRemoteCommand: ... + def skipForwardCommand(self) -> MPRemoteCommand: ... + def changePlaybackPositionCommand(self) -> MPRemoteCommand: ...