Exemplo n.º 1
0
 def stop(self):
     # FIXME: 经过测试发现,这个 stop 函数并不会正常工作。
     # 现在是将 thread 为 daemon thread,让线程在程序退出时停止。
     if self._started:
         loop = Quartz.CFRunLoopGetCurrent()
         Quartz.CFRunLoopStop(loop)
         self._t.join()
Exemplo n.º 2
0
    def stop(self):
        """Call once from the main thread to stop the thread.
        After this returns no callback will be called anymore.
        """

        # wait until we fail or the observer tells us that the loop has started
        self._event.wait()

        # failed to create a tap, nothing to stop
        if self._tap is None:
            return

        # remove the runloop source
        Quartz.CFRunLoopRemoveSource(
            self._loop,
            self._runLoopSource,
            Quartz.kCFRunLoopDefaultMode
        )
        self._runLoopSource = None

        # remove observer
        Quartz.CFRunLoopRemoveObserver(
            self._loop, self._observ, Quartz.kCFRunLoopCommonModes)
        self._observ = None

        # stop the loop
        Quartz.CFRunLoopStop(self._loop)
        self._loop = None

        # Disable the tap
        Quartz.CGEventTapEnable(self._tap, False)
        self._tap = None
    def stop_event_loop(self):
        """
        Stop event loop.

        :return: None.
        """
        # Stop the current run loop
        Quartz.CFRunLoopStop(Quartz.CFRunLoopGetCurrent())
Exemplo n.º 4
0
 def _stop(self):
     # The base class sets the running flag to False; this will cause the
     # loop around run loop invocations to terminate and set this event
     try:
         if self._loop is not None:
             Quartz.CFRunLoopStop(self._loop)
     except AttributeError:
         # The loop may not have been created
         pass
Exemplo n.º 5
0
    def keyboard_cb(proxy, type_, event, refcon):
        nonlocal typed_keys

        if not event:
            return None

        # Convert the Quartz CGEvent into something more useful
        ns_event = AppKit.NSEvent.eventWithCGEvent_(event)

        if not ns_event:
            return None

        if ns_event.type() == Quartz.kCGEventKeyDown:
            typed_keys += ns_event.characters()

            if typed_keys.endswith(EXIT_STRING):
                logging.info('Emergency exit!')

                Quartz.CFRunLoopStop(Quartz.CFRunLoopGetCurrent())

        # Filter every event
        return None
Exemplo n.º 6
0
 def off():
     Quartz.CFRunLoopStop()
Exemplo n.º 7
0
 def stop(self):
     import Quartz
     Quartz.CFRunLoopStop(self.runLoopRef)
Exemplo n.º 8
0
 def stop(self):
     import AppKit
     pool = AppKit.NSAutoreleasePool.alloc().init()
     import Quartz
     Quartz.CFRunLoopStop(self.runLoopRef)
     del pool
Exemplo n.º 9
0
 def stop(self):
     """Stop listening for keyboard input events."""
     Quartz.CFRunLoopStop(self.loop)
     self.state = False