Пример #1
0
 def knowsPageRange_(self, aRange):
     return True, Cocoa.NSRange(1, 1)
Пример #2
0
    def rectForPage_(self, page):
        pi = Cocoa.NSPrintOperation.currentOperation().printInfo()

        # Calculate the page height in points.
        paperSize = pi.paperSize()
        return Cocoa.NSMakeRect(0, 0, paperSize.width, paperSize.height)
Пример #3
0
def makeRandomPointInRect(rect):
    return Cocoa.NSPoint(
        x=random.uniform(Cocoa.NSMinX(rect), Cocoa.NSMaxX(rect)),
        y=random.uniform(Cocoa.NSMinY(rect), Cocoa.NSMaxY(rect)),
    )
Пример #4
0
    def drawRect_(self, r):
        self.openGLContext().makeCurrentContext()

        # Allocate a CoreImage rendering context using the view's OpenGL
        # context as its destination if none already exists.

        if self._context is None:
            pf = self.pixelFormat()
            if pf is None:
                pf = type(self).defaultPixelFormat()

            self._context = Quartz.CIContext.contextWithCGLContext_pixelFormat_options_(
                CGL.CGLGetCurrentContext(), pf.CGLPixelFormatObj(), None)

        ir = Cocoa.CGRectIntegral(r)

        if Cocoa.NSGraphicsContext.currentContextDrawingToScreen():
            self.updateMatrices()

            # Clear the specified subrect of the OpenGL surface then
            # render the image into the view. Use the GL scissor test to
            # clip to * the subrect. Ask CoreImage to generate an extra
            # pixel in case * it has to interpolate (allow for hardware
            # inaccuracies)

            rr = Cocoa.CGRectIntersection(Cocoa.CGRectInset(ir, -1.0, -1.0),
                                          self._lastBounds)

            glScissor(ir.origin.x, ir.origin.y, ir.size.width, ir.size.height)
            glEnable(GL_SCISSOR_TEST)

            glClear(GL_COLOR_BUFFER_BIT)

            if self.respondsToSelector_('drawRect:inCIContext:'):
                self.drawRect_inCIContext_(rr, self._context)

            elif self._image is not None:
                self._context.drawImage_atPoint_fromRect_(
                    self._image, rr.origin, rr)

            glDisable(GL_SCISSOR_TEST)

            # Flush the OpenGL command stream. If the view is double
            # buffered this should be replaced by [[self openGLContext]
            # flushBuffer].

            glFlush()

        else:
            # Printing the view contents. Render using CG, not OpenGL.

            if self.respondsToSelector_('drawRect:inCIContext:'):
                self.drawRect_inCIContext_(ir, self._context)

            elif self._image is not None:
                cgImage = self._context.createCGImage_fromRect_(
                    self._image, ir)

                if cgImage is not None:
                    Quartz.CGContextDrawImage(
                        Cocoa.NSGraphicsContext.currentContext().graphicsPort(
                        ), ir, cgImage)
Пример #5
0
 def didEnterPane_(self, direction):
     """
     pane's entry point: code called when user enters this pane
     """
     Cocoa.NSLog("DIDENTER")
     self._updateNextButtonState()
Пример #6
0
import objc
from objc import super
import Cocoa
import PreferencePanes
from PyObjCTools import AppHelper
import os

# Uncomment this during development, you'll get exception tracebacks when
# the Python code fails.
# objc.setVerbose(1)

# Location of the environment.plist
ENVPLIST = "~/.MacOSX/environment.plist"

# Template for new keys
NEWTMPL = Cocoa.NSLocalizedString("New_Variable_%d", "")


class EnvironmentPane(PreferencePanes.NSPreferencePane):
    """
    The 'model/controller' for the "Shell Environment" preference pane
    """

    deleteButton = objc.IBOutlet()
    mainTable = objc.IBOutlet()

    # __slots__ = (
    #    'environ',  # The actual environment, as a NSMutableDictionary
    #    'keys',     # The list of keys, in the right order for the tableView
    #    'changed',  # True if we should save before exitting
    # )
Пример #7
0
def timer_callback(timer, streamRef):
    settings.debug("CFAbsoluteTimeGetCurrent() => %.3f", Cocoa.CFAbsoluteTimeGetCurrent())
    settings.debug("FSEventStreamFlushAsync(streamRef = %s)", streamRef)
    FSEvents.FSEventStreamFlushAsync(streamRef)
Пример #8
0
 def getRelativeCenterPositionFromEvent_(self, theEvent):
     curMousePt = self.convertPoint_fromView_(theEvent.locationInWindow(), None)
     pt = Cocoa.NSMakePoint( (curMousePt.x - Cocoa.NSMidX(self.bounds())) / (self.bounds().size.width / 2.0),
                       (curMousePt.y - Cocoa.NSMidY(self.bounds())) / (self.bounds().size.height / 2.0))
     return pt
Пример #9
0
class DraggableItemView(Cocoa.NSView):
    """."""

    _locationDefault = Cocoa.NSMakePoint(0.0, 0.0)
    _itemColorDefault = Cocoa.NSColor.redColor()
    _backgroundColorDefault = Cocoa.NSColor.whiteColor()

    def awakeFromNib(self):
        self.dragging = None

    def initWithFrame_(self, frame):
        """."""
        result = super(DraggableItemView, self).initWithFrame_(frame)
        if result is not None:
            result._location = self._locationDefault
            result._itemColor = self._itemColorDefault
            result._backgroundColor = self._backgroundColorDefault
        return result

    def drawRect_(self, rect):
        """."""
        Cocoa.NSColor.whiteColor().set()
        Cocoa.NSBezierPath.fillRect_(rect)
        self.itemColor().set()
        Cocoa.NSBezierPath.fillRect_(self.calculatedItemBounds())

    def isOpaque(self):
        """."""
        return self.backgroundColor().alphaComponent() >= 1.0

    def offsetLocationByX_andY_(self, x, y):
        """."""
        self.setNeedsDisplayInRect_(self.calculatedItemBounds())
        if self.isFlipped():
            invertDeltaY = -1
        else:
            invertDeltaY = 1
        self.location().x = self.location().x + x
        self.location().y = self.location().y + y * invertDeltaY
        self.setNeedsDisplayInRect_(self.calculatedItemBounds())

    def mouseDown_(self, event):
        """."""
        clickLocation = self.convertPoint_fromView_(event.locationInWindow(),
                                                    None)
        itemHit = self.isPointInItem_(clickLocation)
        if itemHit:
            self.dragging = True
            self.lastDragLocation = clickLocation
            Cocoa.NSCursor.closedHandCursor().push()

    def mouseDragged_(self, event):
        """."""
        if self.dragging:
            newDragLocation = self.convertPoint_fromView_(
                event.locationInWindow(), None)
            self.offsetLocationByX_andY_(
                newDragLocation.x - self.lastDragLocation.x,
                newDragLocation.y - self.lastDragLocation.y,
            )
            self.lastDragLocation = newDragLocation
            self.autoscroll_(event)

    def mouseUp_(self, event):
        """."""
        self.dragging = False
        Cocoa.NSCursor.pop()
        self.window().invalidateCursorRectsForView_(self)

    def acceptsFirstResponder(self):
        """."""
        return True

    def keyDown_(self, event):
        """."""
        handled = False
        characters = event.charactersIgnoringModifiers()
        if characters.isEqual_("r"):
            handled = True
            self.setItemPropertiesToDefault_(self)
        if handled is False:
            super(DraggableItemView, self).keyDown_(event)

    @objc.IBAction
    def changeColor_(self, sender):
        """."""
        self.setItemColor_(sender.color())

    def resetCursorRects(self):
        """."""
        self.discardCursorRects()
        self.addCursorRect_cursor_(self.calculatedItemBounds(),
                                   Cocoa.NSCursor.openHandCursor())

    @objc.IBAction
    def moveUp_(self, sender):
        """."""
        self.offsetLocationByX_andY_(0.0, 10.0)
        self.window().invalidateCursorRectsForView_(self)

    @objc.IBAction
    def moveDown_(self, sender):
        """."""
        self.offsetLocationByX_andY_(0.0, -10.0)
        self.window().invalidateCursorRectsForView_(self)

    @objc.IBAction
    def moveLeft_(self, sender):
        """."""
        self.offsetLocationByX_andY_(-10.0, 0.0)
        self.window().invalidateCursorRectsForView_(self)

    @objc.IBAction
    def moveRight_(self, sender):
        """."""
        self.offsetLocationByX_andY_(10.0, 0.0)
        self.window().invalidateCursorRectsForView_(self)

    @objc.IBAction
    def setItemPropertiesToDefault_(self, sender):
        """."""
        self.setLocation_(self._locationDefault)
        self.setItemColor_(self._itemColorDefault)
        self.setBackgroundColor_(self._backgroundColorDefault)

    def setLocation_(self, point):
        """."""
        if not Cocoa.NSEqualPoints(point, self.location()):
            self.setNeedsDisplayInRect_(self.calculatedItemBounds())
            self._location = point
            self.setNeedsDisplayInRect_(self.calculatedItemBounds())
            self.window().invalidateCursorRectsForView_(self)

    def location(self):
        """."""
        return self._location

    def setBackgroundColor_(self, aColor):
        """."""
        if not self.backgroundColor().isEqual_(aColor):
            self._backgroundColor = aColor
            self.setNeedsDisplayInRect_(self.calculatedItemBounds())

    def backgroundColor(self):
        """."""
        return self._backgroundColor

    def setItemColor_(self, aColor):
        """."""
        if not self.itemColor().isEqual_(aColor):
            self._itemColor = aColor
            self.setNeedsDisplayInRect_(self.calculatedItemBounds())

    def itemColor(self):
        """."""
        return self._itemColor

    def calculatedItemBounds(self):
        """."""
        return Cocoa.NSMakeRect(self.location().x,
                                self.location().y, 60.0, 20.0)

    def isPointInItem_(self, testPoint):
        """."""
        itemHit = Cocoa.NSPointInRect(testPoint, self.calculatedItemBounds())
        if itemHit:
            pass
        return itemHit
Пример #10
0
 def isPointInItem_(self, testPoint):
     """."""
     itemHit = Cocoa.NSPointInRect(testPoint, self.calculatedItemBounds())
     if itemHit:
         pass
     return itemHit
Пример #11
0
 def calculatedItemBounds(self):
     """."""
     return Cocoa.NSMakeRect(self.location().x,
                             self.location().y, 60.0, 20.0)