Ejemplo n.º 1
0
 def delegate(cls):
     if not NSThread.isMainThread():
         thread = threading.current_thread()
         pool = getattr(thread, 'ns_autorelease_pool', None)
         if pool is None:
             print("--- calling NSApp.delegate() without an autorelease pool from {}".format(thread))
             traceback.print_stack()
     return NSApp.delegate()
Ejemplo n.º 2
0
def call_in_gui_thread(func, *args, **kwargs):
    if NSThread.isMainThread():
        func(*args, **kwargs)
    else:
        pool = NSAutoreleasePool.alloc().init()
        NSApp.delegate().performSelectorOnMainThread_withObject_waitUntilDone_(
            "callObject:", lambda: func(*args, **kwargs), False)
        del pool
Ejemplo n.º 3
0
    def performCall(self):
        """
        Actually runs the payload.
        """
        assert NSThread.isMainThread(), "Call is not executing on the Main thread!"

        # Unpack the payload.
        (func, args, kwargs) = self._payload

        # Run it.
        func(*args, **kwargs)
    def performCall(self):
        """
        Actually runs the payload.
        """
        assert NSThread.isMainThread(), "Call is not executing on the Main thread!"

        # Unpack the payload.
        (func, args, kwargs) = self._payload

        # Run it.
        func(*args, **kwargs)
Ejemplo n.º 5
0
    def scheduleCallWithDelay_(self, delay):
        """
        This is run once we're on the Main thread.
        """
        assert NSThread.isMainThread(), "Call is not executing on the Main thread!"

        # There's no delay, just run the call now.
        if not delay:
            self.performCall()
            return

        # There's a delay, schedule it for later.
        self.performSelector_withObject_afterDelay_(self.performCall, None, delay)
    def scheduleCallWithDelay_(self, delay):
        """
        This is run once we're on the Main thread.
        """
        assert NSThread.isMainThread(), "Call is not executing on the Main thread!"

        # There's no delay, just run the call now.
        if not delay:
            self.performCall()
            return

        # There's a delay, schedule it for later.
        self.performSelector_withObject_afterDelay_(
            self.performCall, None, delay,
        )
Ejemplo n.º 7
0
 def wrapper(*args, **kw):
     if NSThread.isMainThread():
         func(*args, **kw)
     else:
         NSApp.delegate().performSelectorOnMainThread_withObject_waitUntilDone_("callObject:", lambda: func(*args, **kw), False)
Ejemplo n.º 8
0
def call_in_gui_thread(func, *args, **kwargs):
    if NSThread.isMainThread():
        func(*args, **kwargs)
    else:
        NSApp.delegate().performSelectorOnMainThread_withObject_waitUntilDone_("callObject:", lambda: func(*args, **kwargs), False)