def main(timeout=None): # prepare and set our delegate app = NSApplication.sharedApplication() TheDelegate = ObjCClass('TheDelegate') # the actual class delegate = TheDelegate.alloc().init() # PYCHOK expected app.setDelegate_(delegate) delegate.app = app delegate.badge = app.dockTile() delegate.writer(0) # on a separate thread, run the scheduler t = threading.Thread(target=schedule, args=(delegate.writer, )) t.setDaemon(1) t.start() # set up the timeout if timeout is not None: try: # PyCocoa/test from test import terminating terminating(app, timeout) except ImportError: pass # let her rip!-) app.run() # AppHelper.runEventLoop()
def application(name='Menu'): app = NSApplication.sharedApplication() create_autorelease_pool() create_window(title=name + ' - Type ⌘Q or select Quit from the Python menu') create_menu(name=name, app=app) return app
def main(timeout=None): # Create a new application instance ... app = NSApplication.sharedApplication() # ... and create its delgate. Note the use of the # Objective C constructors below, because Delegate # is a subclass of an Objective C class, NSObject delegate = _Delegate.alloc().init(app) # Tell the application which delegate object to use. app.setDelegate_(delegate) # Now we can can start to create the window ... frame = NSMakeRect(10, 10, 600, 300) # (Don't worry about these parameters for the moment. They just # specify the type of window, its size and position etc) window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_( frame, NSWindowStyleMaskUsual, NSBackingStoreBuffered, False) # or 0 # tell it which delegate object to use (here it happens # to be the same delegate as the application is using), # otherwise method .windowWillClose_ will not be called window.setDelegate_(delegate) # set some properties. Unicode strings are preferred. window.setTitle_(NSStr('Delegated - Close window to Quit')) # All set. Now we can show the window window.orderFrontRegardless() # set up the timeout if timeout is not None: try: # PyCocoa/test from test import terminating terminating(app, timeout) except ImportError: pass # ... and start the application app.run() # .runEventLoop()
def main(timeout=None): # prepare and set our delegate app = NSApplication.sharedApplication() TheDelegate = ObjCClass('TheDelegate') # the actual class delegate = TheDelegate.alloc().init() # PYCHOK expected app.setDelegate_(delegate) delegate.app = app delegate.badge = app.dockTile() delegate.writer(0) # on a separate thread, run the scheduler t = threading.Thread(target=schedule, args=(delegate.writer,)) if sys.version_info[0] > 2: t.deamon = True else: # throws DeprecationWarning t.setDaemon(1) t.start() # set up the timeout terminating(app, timeout) # let her rip!-) app.run() # AppHelper.runEventLoop()
def application(argv=[]): if len(argv) > 1: app = NSApplication.sharedApplication() terminating(app, argv[1]) else: app = send_message('NSApplication', 'sharedApplication') create_autorelease_pool() create_window() return app
def run_window(): app = NSApplication.sharedApplication() # pool = NSAutoreleasePool.alloc().init() # PYCHOK expected window = NSWindow.alloc() window.initWithContentRect_styleMask_backing_defer_( NSRect4_t(100, 100, 300, 300), NSWindowStyleMaskUsual, NSBackingStoreBuffered, False) window.setTitle_(NSStr("Class Window")) window.makeKeyAndOrderFront_(None) app.run()
def appVLC(title=_Title, video='', timeout=None): '''Create the application and start the VLC player, before calling app.run() to start the application. ''' app = NSApplication.sharedApplication() # pool = NSAutoreleasePool.alloc().init() # created by NSApplication dlg = _Delegate.alloc().init(app, title, video) app.setDelegate_(dlg) if timeout is not None: try: from test import terminating terminating(app, timeout) except (ImportError, ValueError): pass return app
def simpleVLCplay(player, title=_argv0, video='', timeout=None): '''Create a minimal NS application, drawable window and basic menu for the given VLC player (with media) and start the player. @note: This function never returns, but the VLC player and other Python thread(s) do run. ''' if not player: raise ValueError('%s invalid: %r' % ('player', player)) app = NSApplication.sharedApplication() # pool = NSAutoreleasePool.alloc().init() # created by NSApplication dlg = _Delegate.alloc().init( app, player, title or _argv0, video or basename(player.get_media().get_mrl())) app.setDelegate_(dlg) terminating(app, timeout) app.run() # never returns
def main(timeout=None): app = NSApplication.sharedApplication() frame = NSMakeRect(10, 10, 500, 400) window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_( frame, NSWindowStyleMaskUsual, NSBackingStoreBuffered, False) window.setTitle_(NSStr('Drawing - Close window to Quit')) view = _View.alloc().initWithFrame_(frame, 10) window.setContentView_(view) delegate = _Delegate.alloc().init(app) window.setDelegate_(delegate) window.display() window.orderFrontRegardless() # set up the timeout terminating(app, timeout) app.run()
def new_app(title, url): app = NSApplication.sharedApplication() # pool = NSAutoreleasePool.alloc().init() # created by NSApplication dlg = _Delegate.alloc().init(title, app, url) app.setDelegate_(dlg) return app