Mercurial > enso_osx
changeset 17:df28ad0875c4
The key notifier is now automatically started and stopped by Enso--it doesn't need to be run separately.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 24 Feb 2008 20:48:51 -0600 |
parents | e07f0c7abdc0 |
children | 5477703cfb73 |
files | enso_osx/input.py |
diffstat | 1 files changed, 54 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/enso_osx/input.py Sun Feb 24 20:15:57 2008 -0600 +++ b/enso_osx/input.py Sun Feb 24 20:48:51 2008 -0600 @@ -1,3 +1,9 @@ +import logging +import subprocess +import errno +import os +import signal + import objc import Foundation import AppKit @@ -77,11 +83,48 @@ 27: "-", } +# TODO: I don't think we need this singleton... _inputManager = None def get(): return _inputManager +class _KeyNotifierController( object ): + def __init__( self ): + pass + + def __tryToStartKeyNotifier( self, path="" ): + fullPath = os.path.join( path, "EnsoKeyNotifier" ) + logging.info( "Trying to launch '%s'." % fullPath ) + popen = subprocess.Popen( [fullPath] ) + return popen + + def start( self ): + try: + # First see if the key notifier is on our path... + popen = self.__tryToStartKeyNotifier() + except OSError, e: + if e.errno == errno.ENOENT: + logging.info( "Couldn't find key notifier on path." ) + # Maybe we're running from a repository checkout... + import enso_osx + path = os.path.normpath( enso_osx.__path__[0] + "/../bin" ) + popen = self.__tryToStartKeyNotifier( path ) + else: + raise + + self._pid = popen.pid + + def stop( self ): + logging.info( "Stopping key notifier." ) + try: + os.kill( self._pid, signal.SIGINT ) + except OSError, e: + if e.errno == errno.ESRCH: + logging.warn( "Key notifier process no longer exists." ) + else: + raise + class _Timer( Foundation.NSObject ): def initWithCallback_( self, callback ): self = super( _Timer, self ).init() @@ -152,10 +195,10 @@ eventType = EVENT_KEY_DOWN self.onKeypress( eventType, keycode ) else: - print "Don't know what to do with event: %s" % info + logging.warn( "Don't know what to do with event: %s" % info ) def run( self ): - print "Entering InputManager.run()" + logging.info( "Entering InputManager.run()" ) app = AppKit.NSApplication.sharedApplication() @@ -173,6 +216,9 @@ objc.YES ) + keyNotifier = _KeyNotifierController() + keyNotifier.start() + keyListener = _KeyListener.alloc().initWithCallback_( self.__keyCallback ) @@ -192,13 +238,15 @@ app.sendEvent_( event ) finally: keyListener.unregister() + keyNotifier.stop() - print "Exiting InputManager.run()" + logging.info( "Exiting InputManager.run()" ) def stop( self ): self.__shouldStop = True def enableMouseEvents( self, isEnabled ): + # TODO: Implementation needed. self.__mouseEventsEnabled = isEnabled def onKeypress( self, eventType, vkCode ): @@ -220,12 +268,15 @@ return self.__qmKeycodes[quasimodeKeycode] def setQuasimodeKeycode( self, quasimodeKeycode, keycode ): + # TODO: Implementation needed. self.__qmKeycodes[quasimodeKeycode] = keycode def setModality( self, isModal ): + # TODO: Implementation needed. self.__isModal = isModal def setCapsLockMode( self, isCapsLockEnabled ): + # TODO: Implementation needed. pass def onTick( self, msPassed ):