示例#1
0
 def mouseDragged_(self, event):
     pointerLocInWindow = self.mouseLocationOutsideOfEventStream()
     currentDragLocation = self.convertBaseToScreen_(pointerLocInWindow)
     newOrigin = NSMakePoint(currentDragLocation.x - self._firstDragOffset.x, currentDragLocation.y - self._firstDragOffset.y)
     if newOrigin.y + self.window_frame.size.height > self.screen_frame.origin.y + self.screen_frame.size.height:
         newOrigin.y = self.screen_frame.origin.y + (self.screen_frame.size.height - self.window_frame.size.height)
     self.setFrameOrigin_(newOrigin)
     super(WizkitWindow, self).mouseDragged_(event)
示例#2
0
    def drawRect_(self, rect):
        defaults = NSUserDefaultsController.sharedUserDefaultsController().values()
        favoriteColor = NSUnarchiver.unarchiveObjectWithData_(getKey(defaults, 'FavoriteColor'))
        fontName = getKey(defaults, 'FontName')
        fontSize = getKey(defaults, 'FontSize')
        favoriteFont = NSFont.fontWithName_size_(fontName, fontSize)
        wordOfTheDay = getKey(defaults, 'WordOfTheDay')

        # Do the actual drawing
        myBounds = self.bounds() # = (x, y), (bw, bh)
        NSDrawLightBezel(myBounds, myBounds)
        favoriteColor.set()
        NSRectFill(NSInsetRect(myBounds, 2, 2))
        attrsDictionary = {NSFontAttributeName: favoriteFont}
        attrString = NSAttributedString.alloc().initWithString_attributes_(wordOfTheDay, attrsDictionary)
        attrSize = attrString.size() # = (bw, bh)
        attrString.drawAtPoint_(
            NSMakePoint(
                (attrSize.width / -2) + (myBounds.size.width / 2),
                (attrSize.height / -2) + (myBounds.size.height / 2),
            ),
        )
示例#3
0
    def drawRect_(self, rect):
        """
        Basic goals here:
        If either the angle or the offset has a "bad selection":
        then draw a gray rectangle, and that's it.
        Note: bad selection is set if there's a multiple selection
        but the "allows multiple selection" binding is NO.

        If there's a multiple selection for either angle or offset:
        then what you draw depends on what's multiple.

        - First, draw a white background to show all's OK.

        - If both are multiple, then draw a special symbol.

        - If offset is multiple, draw a line from the center of the view
        - to the edge at the shared angle.

        - If angle is multiple, draw a circle of radius the shared offset
        - centered in the view.

        If neither is multiple, draw a cross at the center of the view
        and a cross at distance 'offset' from the center at angle 'angle'
        """
        myBounds = self.bounds()
        if self.badSelectionForAngle or self.badSelectionForOffset:
            # "disable" and exit
            NSDrawDarkBezel(myBounds, myBounds)
            return
        # user can do something, so draw white background and
        # clip in anticipation of future drawing
        NSDrawLightBezel(myBounds, myBounds)
        clipRect = NSBezierPath.bezierPathWithRect_(
            NSInsetRect(myBounds, 2.0, 2.0))
        clipRect.addClip()

        if self.multipleSelectionForAngle or self.multipleSelectionForOffset:
            originOffsetX = myBounds.size.width / 2 + 0.5
            originOffsetY = myBounds.size.height / 2 + 0.5
            if self.multipleSelectionForAngle and self.multipleSelectionForOffset:
                # draw a diagonal line and circle to denote
                # multiple selections for angle and offset
                NSBezierPath.strokeLineFromPoint_toPoint_(
                    NSMakePoint(0, 0),
                    NSMakePoint(myBounds.size.width, myBounds.size.height),
                )
                circleBounds = NSMakeRect(originOffsetX - 5, originOffsetY - 5,
                                          10, 10)
                path = NSBezierPath.bezierPathWithOvalInRect_(circleBounds)
                path.stroke()
                return
            if self.multipleSelectionForOffset:
                # draw a line from center to a point outside
                # bounds in the direction specified by angle
                angleRadians = self.angle * (pi / 180.0)
                x = sin(angleRadians) * myBounds.size.width + originOffsetX
                y = cos(angleRadians) * myBounds.size.height + originOffsetX
                NSBezierPath.strokeLineFromPoint_toPoint_(
                    NSMakePoint(originOffsetX, originOffsetY),
                    NSMakePoint(x, y))
                return
            if self.multipleSelectionForAngle:
                # draw a circle with radius the shared offset
                # dont' draw radius < 1.0, else invisible
                drawRadius = self.offset
                if drawRadius < 1.0:
                    drawRadius = 1.0
                offsetBounds = NSMakeRect(
                    originOffsetX - drawRadius,
                    originOffsetY - drawRadius,
                    drawRadius * 2,
                    drawRadius * 2,
                )
                path = NSBezierPath.bezierPathWithOvalInRect_(offsetBounds)
                path.stroke()
                return
            # shouldn't get here
            return
        trans = NSAffineTransform.transform()
        trans.translateXBy_yBy_(myBounds.size.width / 2 + 0.5,
                                myBounds.size.height / 2 + 0.5)
        trans.concat()
        path = NSBezierPath.bezierPath()

        # draw + where shadow extends
        angleRadians = self.angle * (pi / 180.0)
        xOffset = sin(angleRadians) * self.offset
        yOffset = cos(angleRadians) * self.offset

        path.moveToPoint_(NSMakePoint(xOffset, yOffset - 5))
        path.lineToPoint_(NSMakePoint(xOffset, yOffset + 5))
        path.moveToPoint_(NSMakePoint(xOffset - 5, yOffset))
        path.lineToPoint_(NSMakePoint(xOffset + 5, yOffset))

        NSColor.lightGrayColor().set()
        path.setLineWidth_(1.5)
        path.stroke()

        # draw + in center of view
        path = NSBezierPath.bezierPath()

        path.moveToPoint_(NSMakePoint(0, -5))
        path.lineToPoint_(NSMakePoint(0, +5))
        path.moveToPoint_(NSMakePoint(-5, 0))
        path.lineToPoint_(NSMakePoint(+5, 0))

        NSColor.blackColor().set()
        path.setLineWidth_(1.0)
        path.stroke()