def drawRect_( self, rect ):
        parent = self.__parent()
        if not parent:
            return

        surface = parent._surface
        if not surface:
            return

        context = AppKit.NSGraphicsContext.currentContext()

        # Taken from the OS X Cocoa Drawing Guide section on
        # "Creating a Flip Transform".
        frameRect = self.bounds()
        xform = AppKit.NSAffineTransform.transform()
        sendMsg( xform,
                 "translateXBy:", 0.0,
                 "yBy:", frameRect.size.height )

        sendMsg( xform,
                 "scaleXBy:", 1.0,
                 "yBy:", -1.0 )

        xform.concat()

        parent._imageRep.draw()
Esempio n. 2
0
    def makeCairoSurface( self ):
        if not self._surface:
            self._imageRep = sendMsg(
                AppKit.NSBitmapImageRep.alloc(),
                "initWithBitmapDataPlanes:", None,
                "pixelsWide:", self.__maxWidth,
                "pixelsHigh:", self.__maxHeight,
                "bitsPerSample:", 8,
                "samplesPerPixel:", 4,
                "hasAlpha:", True,
                "isPlanar:", False,
                "colorSpaceName:", AppKit.NSCalibratedRGBColorSpace,
                "bitmapFormat:", 0,
                "bytesPerRow:", 4 * self.__maxWidth,
                "bitsPerPixel:", 32
                )

            # This NSGraphicsContext retains the NSBitmapImageRep we
            # pass it, but for some reason it doesn't release it on
            # destruction... See this class' __del__() method for how
            # we deal with this.
            nsContext = sendMsg(
                AppKit.NSGraphicsContext,
                "graphicsContextWithBitmapImageRep:",
                self._imageRep
                )

            self._surface = cairo_surface_from_NSGraphicsContext(
                nsContext,
                self.__maxWidth,
                self.__maxHeight
                )

        return self._surface
Esempio n. 3
0
    def drawRect_( self, rect ):
        parent = self.__parent()
        if not parent:
            return

        surface = parent._surface
        if not surface:
            return

        context = AppKit.NSGraphicsContext.currentContext()

        # Taken from the OS X Cocoa Drawing Guide section on
        # "Creating a Flip Transform".
        frameRect = self.bounds()
        xform = AppKit.NSAffineTransform.transform()
        sendMsg( xform,
                 "translateXBy:", 0.0,
                 "yBy:", frameRect.size.height )

        sendMsg( xform,
                 "scaleXBy:", 1.0,
                 "yBy:", -1.0 )

        xform.concat()

        parent._imageRep.draw()
    def makeCairoSurface( self ):
        if not self._surface:
            self._imageRep = sendMsg(
                AppKit.NSBitmapImageRep.alloc(),
                "initWithBitmapDataPlanes:", None,
                "pixelsWide:", self.__maxWidth,
                "pixelsHigh:", self.__maxHeight,
                "bitsPerSample:", 8,
                "samplesPerPixel:", 4,
                "hasAlpha:", True,
                "isPlanar:", False,
                "colorSpaceName:", AppKit.NSCalibratedRGBColorSpace,
                "bitmapFormat:", 0,
                "bytesPerRow:", 4 * self.__maxWidth,
                "bitsPerPixel:", 32
                )

            # This NSGraphicsContext retains the NSBitmapImageRep we
            # pass it, but for some reason it doesn't release it on
            # destruction... See this class' __del__() method for how
            # we deal with this.
            nsContext = sendMsg(
                AppKit.NSGraphicsContext,
                "graphicsContextWithBitmapImageRep:",
                self._imageRep
                )

            self._surface = cairo_surface_from_NSGraphicsContext(
                nsContext,
                self.__maxWidth,
                self.__maxHeight
                )

        return self._surface
Esempio n. 5
0
 def register( self ):
     NSDNC = Foundation.NSDistributedNotificationCenter
     self.__center = NSDNC.defaultCenter()
     sendMsg(
         self.__center,
         "addObserver:", self,
         "selector:", self.onNotification,
         "name:", u"EnsoKeyNotifier_msg",
         "object:", u"EnsoKeyNotifier"
         )
Esempio n. 6
0
    def run( self ):
        logging.info( "Entering InputManager.run()" )

        app = AppKit.NSApplication.sharedApplication()

        if not app.delegate():
            logging.info( "Attaching app delegate." )
            delegate = _AppDelegate.alloc().init()
            app.setDelegate_( delegate )
        else:
            logging.info( "An app delegate is already attached; "
                          "skipping installation." )

        timer = sendMsg(
            _Timer.alloc(),
            "initWithCallback:", self.__timerCallback
            )

        signature = sendMsg(
            timer,
            "methodSignatureForSelector:", timer.onTimer
            )

        invocation = sendMsg(
            Foundation.NSInvocation,
            "invocationWithMethodSignature:", signature
            )

        sendMsg( invocation, "setSelector:", timer.onTimer )
        sendMsg( invocation, "setTarget:", timer )

        sendMsg( Foundation.NSTimer,
                  "scheduledTimerWithTimeInterval:", _TIMER_INTERVAL,
                  "invocation:", invocation,
                  "repeats:", objc.YES )

        keyNotifier = _KeyNotifierController()
        keyNotifier.start()
        atexit.register( keyNotifier.stop )

        keyListener = sendMsg(
            _KeyListener.alloc(),
            "initWithCallback:", self.__keyCallback
            )
        keyListener.register()
        atexit.register( keyListener.unregister )

        self.onInit()

        if not app.isRunning():
            logging.info( "Calling app.run()." )
            app.run()
        else:
            logging.info( "Application appears to be running already; "
                          "skipping app.run()." )
Esempio n. 7
0
 def onNotification(self, notification):
     #print "notification received: %s" % notification.name()
     userInfo = notification.userInfo()
     eventDict = {}
     for key in userInfo:
         eventDict[key] = sendMsg(userInfo, "objectForKey:", key)
     self.__callback(eventDict)
Esempio n. 8
0
    def __init__( self, x, y, maxWidth, maxHeight ):
        self.__x = x
        self.__y = y
        self.__maxWidth = maxWidth
        self.__maxHeight = maxHeight
        self.__width = maxWidth
        self.__height = maxHeight
        self._surface = None
        self.__opacity = 0xff

        rect = Foundation.NSMakeRect( self.__x,
                                      _convertY( self.__y, self.__height ),
                                      self.__width,
                                      self.__height )
        style = AppKit.NSBorderlessWindowMask
        self.__wind = sendMsg(
            AppKit.NSWindow.alloc(),
            "initWithContentRect:", rect,
            "styleMask:", style,
            "backing:", AppKit.NSBackingStoreBuffered,
            "defer:", objc.YES
            )

        self.__wind.setBackgroundColor_( AppKit.NSColor.clearColor() )
        self.__view = _TransparentWindowView.alloc().initWithParent_( self )
        self.__wind.setContentView_( self.__view )
        self.__wind.setLevel_( AppKit.NSPopUpMenuWindowLevel )
        self.__wind.setOpaque_( objc.NO )
        self.__wind.setAlphaValue_( 1.0 )
Esempio n. 9
0
    def __init__(self, x, y, maxWidth, maxHeight):
        self.__x = x
        self.__y = y
        self.__maxWidth = maxWidth
        self.__maxHeight = maxHeight
        self.__width = maxWidth
        self.__height = maxHeight
        self._surface = None
        self.__opacity = 0xff

        rect = Foundation.NSMakeRect(self.__x,
                                     _convertY(self.__y, self.__height),
                                     self.__width, self.__height)
        self.__wind = AppKit.NSWindow.alloc(
        ).initWithContentRect_styleMask_backing_defer_(
            rect, AppKit.NSBorderlessWindowMask, AppKit.NSBackingStoreBuffered,
            objc.YES)
        self.__wind.setBackgroundColor_(AppKit.NSColor.clearColor())
        self.__view = _TransparentWindowView.alloc().initWithParent_(self)
        self.__wind.setContentView_(self.__view)
        self.__wind.setLevel_(AppKit.NSPopUpMenuWindowLevel)
        self.__wind.setOpaque_(objc.NO)
        self.__wind.setAlphaValue_(1.0)
        self._imageRep = sendMsg(
            AppKit.NSBitmapImageRep.alloc(), "initWithBitmapDataPlanes:", None,
            "pixelsWide:", self.__maxWidth, "pixelsHigh:", self.__maxHeight,
            "bitsPerSample:", 8, "samplesPerPixel:", 4, "hasAlpha:", True,
            "isPlanar:", False, "colorSpaceName:",
            AppKit.NSCalibratedRGBColorSpace, "bitmapFormat:", 0,
            "bytesPerRow:", 4 * self.__maxWidth, "bitsPerPixel:", 32)
    def __init__( self, x, y, maxWidth, maxHeight ):
        self.__x = x
        self.__y = y
        self.__maxWidth = maxWidth
        self.__maxHeight = maxHeight
        self.__width = maxWidth
        self.__height = maxHeight
        self._surface = None
        self.__opacity = 0xff

        rect = Foundation.NSMakeRect( self.__x,
                                      _convertY( self.__y, self.__height ),
                                      self.__width,
                                      self.__height )
        style = AppKit.NSBorderlessWindowMask
        self.__wind = sendMsg(
            AppKit.NSWindow.alloc(),
            "initWithContentRect:", rect,
            "styleMask:", style,
            "backing:", AppKit.NSBackingStoreBuffered,
            "defer:", objc.YES
            )

        self.__wind.setBackgroundColor_( AppKit.NSColor.clearColor() )
        self.__view = _TransparentWindowView.alloc().initWithParent_( self )
        self.__wind.setContentView_( self.__view )
        self.__wind.setLevel_( AppKit.NSPopUpMenuWindowLevel )
        self.__wind.setOpaque_( objc.NO )
        self.__wind.setAlphaValue_( 1.0 )
Esempio n. 11
0
 def onNotification( self, notification ):
     #print "notification received: %s" % notification.name()
     userInfo = notification.userInfo()
     eventDict = {}
     for key in userInfo:
         eventDict[key] = sendMsg( userInfo,
                                    "objectForKey:", key )
     self.__callback( eventDict )
Esempio n. 12
0
    def run(self):
        logging.info("Entering InputManager.run()")

        app = AppKit.NSApplication.sharedApplication()

        if not app.delegate():
            logging.info("Attaching app delegate.")
            delegate = _AppDelegate.alloc().init()
            app.setDelegate_(delegate)
        else:
            logging.info("An app delegate is already attached; "
                         "skipping installation.")

        timer = sendMsg(_Timer.alloc(), "initWithCallback:",
                        self.__timerCallback)

        signature = sendMsg(timer, "methodSignatureForSelector:",
                            timer.onTimer)

        invocation = sendMsg(Foundation.NSInvocation,
                             "invocationWithMethodSignature:", signature)

        sendMsg(invocation, "setSelector:", timer.onTimer)
        sendMsg(invocation, "setTarget:", timer)

        sendMsg(Foundation.NSTimer, "scheduledTimerWithTimeInterval:",
                _TIMER_INTERVAL, "invocation:", invocation, "repeats:",
                objc.YES)

        keyNotifier = _KeyNotifierController()
        keyNotifier.start()
        atexit.register(keyNotifier.stop)

        keyListener = sendMsg(_KeyListener.alloc(), "initWithCallback:",
                              self.__keyCallback)
        keyListener.register()
        atexit.register(keyListener.unregister)

        self.onInit()

        if not app.isRunning():
            logging.info("Calling app.run().")
            app.run()
        else:
            logging.info("Application appears to be running already; "
                         "skipping app.run().")
Esempio n. 13
0
def set( seldict ):
    success = False
    tryToPaste = False

    # TODO: Set 'files' selection.

    selClipboardMapping = {
        "text" : AppKit.NSStringPboardType,
        "html" : AppKit.NSHTMLPboardType
        }

    # TODO: Actually decide on an ordering of richest to least-rich
    # clipboard types, b/c this matters in OS X.

    typesToPaste = [ selType for selType in selClipboardMapping
                     if seldict.has_key( selType ) ]

    if typesToPaste:
        pb = AppKit.NSPasteboard.generalPasteboard()

        sendMsg( pb,
                 "declareTypes:", [ selClipboardMapping[selType]
                                    for selType in typesToPaste ],
                 "owner:", None )

        for selType in typesToPaste:
            if sendMsg( pb,
                        "setString:", seldict[selType],
                        "forType:", selClipboardMapping[selType] ):
                tryToPaste = True

        if tryToPaste:
            # TODO: Figure out whether the paste is successful.
            key_utils.simulatePaste()
            success = True

    return success
Esempio n. 14
0
def set(seldict):
    success = False
    tryToPaste = False

    # TODO: Set 'files' selection.

    selClipboardMapping = {
        "text": AppKit.NSStringPboardType,
        "html": AppKit.NSHTMLPboardType
    }

    # TODO: Actually decide on an ordering of richest to least-rich
    # clipboard types, b/c this matters in OS X.

    typesToPaste = [
        selType for selType in selClipboardMapping if seldict.has_key(selType)
    ]

    if typesToPaste:
        pb = AppKit.NSPasteboard.generalPasteboard()

        sendMsg(pb, "declareTypes:",
                [selClipboardMapping[selType] for selType in typesToPaste],
                "owner:", None)

        for selType in typesToPaste:
            if sendMsg(pb, "setString:", seldict[selType], "forType:",
                       selClipboardMapping[selType]):
                tryToPaste = True

        if tryToPaste:
            # TODO: Figure out whether the paste is successful.
            key_utils.simulatePaste()
            success = True

    return success
Esempio n. 15
0
    def __init__( self, x, y, maxWidth, maxHeight ):
        self.__x = x
        self.__y = y
        self.__maxWidth = maxWidth
        self.__maxHeight = maxHeight
        self.__width = maxWidth
        self.__height = maxHeight
        self._surface = None
        self.__opacity = 0xff

        rect = Foundation.NSMakeRect( self.__x,
                                      _convertY( self.__y, self.__height ),
                                      self.__width,
                                      self.__height )
        self.__wind = AppKit.NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
                                                rect, AppKit.NSBorderlessWindowMask,
                                                AppKit.NSBackingStoreBuffered, objc.YES)
        self.__wind.setBackgroundColor_( AppKit.NSColor.clearColor() )
        self.__view = _TransparentWindowView.alloc().initWithParent_( self )
        self.__wind.setContentView_( self.__view )
        self.__wind.setLevel_( AppKit.NSPopUpMenuWindowLevel )
        self.__wind.setOpaque_( objc.NO )
        self.__wind.setAlphaValue_( 1.0 )
        self._imageRep = sendMsg(
                AppKit.NSBitmapImageRep.alloc(),
                "initWithBitmapDataPlanes:", None,
                "pixelsWide:", self.__maxWidth,
                "pixelsHigh:", self.__maxHeight,
                "bitsPerSample:", 8,
                "samplesPerPixel:", 4,
                "hasAlpha:", True,
                "isPlanar:", False,
                "colorSpaceName:", AppKit.NSCalibratedRGBColorSpace,
                "bitmapFormat:", 0,
                "bytesPerRow:", 4 * self.__maxWidth,
                "bitsPerPixel:", 32
                )
Esempio n. 16
0
 def unregister( self ):
     sendMsg( self.__center,
               "removeObserver:", self )
Esempio n. 17
0
 def register(self):
     NSDNC = Foundation.NSDistributedNotificationCenter
     self.__center = NSDNC.defaultCenter()
     sendMsg(self.__center, "addObserver:", self, "selector:",
             self.onNotification, "name:", u"EnsoKeyNotifier_msg",
             "object:", u"EnsoKeyNotifier")
Esempio n. 18
0
 def unregister(self):
     sendMsg(self.__center, "removeObserver:", self)