class FileChooserTarget(NSObject): interface = objc_property(py_object, weak=True) impl = objc_property(py_object, weak=True) @objc_method def onSelect_(self, obj: objc_id) -> None: if self.impl.native.indexOfSelectedItem == 2: self.impl.native.selectItemAtIndex(0) panel = NSOpenPanel.alloc().init() panel.title = self.interface.dialog_title panel.message = self.interface.dialog_message panel.canChooseFiles = self.interface.select_files panel.canChooseDirectories = self.interface.select_folders panel.canCreateDirectories = True panel.resolvesAliases = True panel.allowsMultipleSelection = False panel.directoryURL = NSURL.fileURLWithPath( osp.dirname(self.interface.current_selection)) panel.prompt = "Select" def completion_handler(r: int) -> None: if r == NSFileHandlingPanelOKButton: self.impl.set_current_selection(str(panel.URL.path)) if self.interface.on_select: self.interface.on_select(self.interface) panel.beginSheetModalForWindow( self.interface.window._impl.native, completionHandler=completion_handler)
class TogaMenuItem(NSMenuItem): interface = objc_property(py_object, weak=True) impl = objc_property(py_object, weak=True) @objc_method def onPress_(self, obj: objc_id) -> None: if self.interface.action: self.interface.action(self.interface)
class URLBox(NSObject): url = objc_property(ObjCInstance) data = objc_property(ObjCInstance) @objc_method def getSchemeIfPresent(self): if self.url is not None: return self.url.scheme return None
class URLBox(NSObject): # takes no type: All properties are pointers url = objc_property() data = objc_property() @objc_method def getSchemeIfPresent(self): if self.url is not None: return self.url.scheme return None
class SwitchTarget(NSObject): interface = objc_property(py_object, weak=True) impl = objc_property(py_object, weak=True) @objc_method def onPress_(self, obj: objc_id) -> None: if self.interface.on_toggle: self.interface.on_toggle(self.interface) self.impl.native.allowsMixedState = False
class WindowDeletage(TogaWindowDeletage): interface = objc_property(py_object, weak=True) impl = objc_property(py_object, weak=True) @objc_method def windowWillClose_(self, notification: objc_id) -> None: if not self.interface.is_dialog: if not self.interface.app._impl.has_open_windows(): self.interface.app._impl.hide_dock_icon()
class SystemTrayAppDelegate(NSObject): interface = objc_property(py_object, weak=True) impl = objc_property(py_object, weak=True) @objc_method def applicationWillTerminate_(self, sender: objc_id) -> None: if self.interface.app.on_exit: self.interface.app.on_exit(self.interface.app) @objc_method def selectMenuItem_(self, sender: objc_id) -> None: cmd = self.impl._menu_items[sender] if cmd.action: cmd.action(None)
class TogaMenu(NSMenu): interface = objc_property(py_object, weak=True) impl = objc_property(py_object, weak=True) @objc_method def menuWillOpen_(self, obj: objc_id) -> None: self.impl._visible = True if self.interface.on_open: self.interface.on_open(self.interface) @objc_method def menuDidClose_(self, obj: objc_id) -> None: self.impl._visible = False if self.interface.on_close: self.interface.on_close(self.interface)
class ObjectListContainer(NSObject): data = objc_property() @objc_method def init(self): self.data = ['x1', 'y2', 'z3'] return self @objc_method def initWithList_(self, data): self.data = data return self
class PrimitiveListContainer(NSObject): data = objc_property() @objc_method def init(self): self.data = [1, 2, 3] return self @objc_method def initWithList_(self, data): self.data = data return self
class Handler(NSObject): value = objc_property() @objc_method def initWithValue_(self, v: int): self.value = v return self @objc_method def pokeWithValue_andName_(self, v: int, name) -> float: print("My name is ", name) return v / 2.0
class ObjectDictContainer(NSObject): data = objc_property() @objc_method def init(self): self.data = {'x': 'x1', 'y': 'y2', 'z': 'z3'} return self @objc_method def initWithDict_(self, data): self.data = data return self
class PrimitiveDictContainer(NSObject): data = objc_property() @objc_method def init(self): self.data = {1: 2, 2: 4, 3: 6} return self @objc_method def initWithDict_(self, data): self.data = data return self
class MQVSongChangeDetector(objc.NSObject): lastSong = objc.objc_property() @objc.objc_method def init(self): """set attribute MQVCallback to receive notifications.""" self.musicPlayer = objc.ObjCClass( "MPMusicPlayerController").systemMusicPlayer self.MQVCallback = None index = self.musicPlayer.indexOfNowPlayingItem + 1 song = self.musicPlayer.nowPlayingItemAtIndex(index) if song: self.lastSong = song.copy() return self @objc.objc_method def pollControllerWithSender_(self, sender): index = self.musicPlayer.indexOfNowPlayingItem + 1 currentSong = self.musicPlayer.nowPlayingItemAtIndex(index) if self.lastSong: if not self.lastSong.isEqual(currentSong): self.lastSong = currentSong.copy() if callable(self.MQVCallback): self.MQVCallback() # pylint: disable=not-callable pass pass pass pass @objc.objc_method @objc_util.on_main_thread def start(self): self.timer = objc.ObjCClass("NSTimer").timerWithTimeInterval( 0.1, target=self, selector=objc.SEL("pollControllerWithSender:"), userInfo=None, repeats=True) objc.ObjCClass("NSRunLoop").currentRunLoop().addTimer( self.timer, forMode="kCFRunLoopCommonModes") pass @objc.objc_method def stop(self): self.timer.invalidate() pass pass
class ContainerViewController(UIViewController): viewport_view = objc_property() @objc_method def viewDidLoad(self): self.view.backgroundColor = UIColor.systemBackgroundColor() @objc_method def viewDidLayoutSubviews(self): if self.viewport_view is None: self.viewport_view = UIView.alloc().init().autorelease() view = self.viewport_view size = self.view.frame.size view.frame = CGRectMake(0, 0, size.width, size.height) self.widget.viewport = _ios_window.iOSViewport(view) self.widget.interface.refresh()
class ProtocolWithAProperty(metaclass=ObjCProtocol): prop = objc_property()
class Properties(NSObject): object = objc_property(ObjCInstance) int = objc_property(c_int) rect = objc_property(NSRect)
class MultitypeDictContainer(NSObject): data = objc_property()