Example #1
0
 def detach(self):
     assert self.state == CaptureState.ATTACHED
     session = self.session
     script = self.script
     self.session = None
     self.script = None
     self._updateState_(CaptureState.DETACHED)
     NSThread.detachNewThreadSelector_toTarget_withObject_('_doDetachWithParams:', self, (session, script))
Example #2
0
 def detach(self):
     assert self.state == CaptureState.ATTACHED
     session = self.session
     script = self.script
     self.session = None
     self.script = None
     self._updateState_(CaptureState.DETACHED)
     NSThread.detachNewThreadSelector_toTarget_withObject_('_doDetachWithParams:', self, (session, script))
    def applicationShouldTerminate_(self, sender):
        BlinkLogger().log_info('Application will terminate')
        NSThread.detachNewThreadSelector_toTarget_withObject_("killSelfAfterTimeout:", self, None)
        NotificationCenter().post_notification("BlinkShouldTerminate", None)
        NotificationCenter().add_observer(self, name="SIPApplicationDidEnd")
        SIPApplication().stop()

        return NSTerminateLater
    def applicationShouldTerminate_(self, sender):
        if self.terminating:
            return True

        self.terminating = True
        BlinkLogger().log_info('Application will be terminated')
        NSThread.detachNewThreadSelector_toTarget_withObject_("killSelfAfterTimeout:", self, None)
        NotificationCenter().post_notification("BlinkShouldTerminate", None)
        NotificationCenter().add_observer(self, name="SIPApplicationDidEnd")
        app = SIPApplication()
        app.stop()

        import Profiler
        Profiler.stop(os.path.join(ApplicationData.directory, 'logs', 'profiler.stats'))
        return False
 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()
Example #6
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
Example #7
0
 def refreshWithSender_(self, sender):
     if self.crawlTask is not None:
         return self.stopRefreshWithSender_(sender)
     logger.debug('%r refreshWithSender:%r', self, sender)
     sender.setImage_(NSImage.imageNamed_(NSImageNameStopProgressTemplate))
     self.crawlTask = NSThread.alloc().initWithTarget_selector_object_(
         self, 'crawlWithSender:', sender
     )
     self.crawlTask.start()
Example #8
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)
Example #10
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,
        )
Example #12
0
 def _post(self, message):
     NSThread.detachNewThreadSelector_toTarget_withObject_(
         '_doPostWithParams:', self, (self.script, message))
Example #13
0
 def attachToProcess_triggerPort_(self, process, triggerPort):
     assert self.state == CaptureState.DETACHED
     self._updateState_(CaptureState.ATTACHING)
     NSThread.detachNewThreadSelector_toTarget_withObject_(
         '_doAttachWithParams:', self, (process.pid, triggerPort))
Example #14
0
 def _post(self, message):
     NSThread.detachNewThreadSelector_toTarget_withObject_('_doPostWithParams:', self, (self.script, message))
Example #15
0
 def attachToProcess_triggerPort_(self, process, triggerPort):
     assert self.state == CaptureState.DETACHED
     self._updateState_(CaptureState.ATTACHING)
     NSThread.detachNewThreadSelector_toTarget_withObject_('_doAttachWithParams:', self, (process.pid, triggerPort))
Example #16
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)
Example #17
0
 def wrapper(*args, **kw):
     if NSThread.isMainThread():
         func(*args, **kw)
     else:
         NSApp.delegate().performSelectorOnMainThread_withObject_waitUntilDone_("callObject:", lambda: func(*args, **kw), False)