コード例 #1
0
    def __init__(self, dimensions):
        super(DashedRectangle, self).__init__(dimensions, scale="none")

        box_width = self.getPosSize()[2]
        box_height = self.getPosSize()[3]

        line_image = NSImage.alloc().initWithSize_((box_width, box_height))
        line_image.lockFocus()
        path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(NSMakeRect(.5, .5, box_width - 1, box_height - 1), 5, 5)
        path.setLineWidth_(1.0)
        path.setLineDash_count_phase_((5, 5), 2, 0)
        NSColor.colorWithCalibratedWhite_alpha_(0, 0.1).set()
        path.stroke()
        line_image.unlockFocus()

        self.setImage(imageObject=line_image)
コード例 #2
0
    def __init__(self, dimensions):
        super(DashedRectangle, self).__init__(dimensions, scale="none")

        box_width = self.getPosSize()[2]
        box_height = self.getPosSize()[3]

        line_image = NSImage.alloc().initWithSize_((box_width, box_height))
        line_image.lockFocus()
        path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
            NSMakeRect(.5, .5, box_width - 1, box_height - 1), 5, 5)
        path.setLineWidth_(1.0)
        path.setLineDash_count_phase_((5, 5), 2, 0)
        NSColor.colorWithCalibratedWhite_alpha_(0, 0.1).set()
        path.stroke()
        line_image.unlockFocus()

        self.setImage(imageObject=line_image)
コード例 #3
0
    def init(self):
        self = super(LineNumberNSRulerView, self).init()
        self._font = NSFont.labelFontOfSize_(NSFont.systemFontSizeForControlSize_(NSMiniControlSize))
        self._textColor = NSColor.colorWithCalibratedWhite_alpha_(.42, 1)
        self._rulerBackgroundColor = None

        self._lineIndices = None
        return self
コード例 #4
0
    def init(self):
        self = super(LineNumberNSRulerView, self).init()
        self._font = NSFont.labelFontOfSize_(
            NSFont.systemFontSizeForControlSize_(NSMiniControlSize))
        self._textColor = NSColor.colorWithCalibratedWhite_alpha_(.42, 1)
        self._rulerBackgroundColor = None

        self._lineIndices = None
        return self
コード例 #5
0
 def drawSegment_inFrame_withView_(self, segment, frame, view):
     (x, y), (w, h) = frame
     # draw highlight
     if self.isSelectedForSegment_(segment):
         NSColor.colorWithCalibratedWhite_alpha_(0, .2).set()
         NSRectFillUsingOperation(frame, NSCompositeSourceOver)
     # draw border
     if segment != 0:
         path = NSBezierPath.bezierPath()
         path.moveToPoint_((x + .5, y + h))
         path.lineToPoint_((x + .5, y))
         path.setLineWidth_(1.0)
         placardBorderColor.set()
         path.stroke()
         x += 1
     # draw image
     image = self.imageForSegment_(segment)
     if image is not None:
         image.drawAtPoint_fromRect_operation_fraction_((x, y), ((0, 0), image.size()), NSCompositeSourceOver, 1.0)
コード例 #6
0
 def drawSegment_inFrame_withView_(self, segment, frame, view):
     (x, y), (w, h) = frame
     # draw highlight
     if self.isSelectedForSegment_(segment):
         NSColor.colorWithCalibratedWhite_alpha_(0, .2).set()
         NSRectFillUsingOperation(frame, NSCompositeSourceOver)
     # draw border
     if segment != 0:
         path = NSBezierPath.bezierPath()
         path.moveToPoint_((x + .5, y + h))
         path.lineToPoint_((x + .5, y))
         path.setLineWidth_(1.0)
         placardBorderColor.set()
         path.stroke()
         x += 1
     # draw image
     image = self.imageForSegment_(segment)
     if image is not None:
         image.drawAtPoint_fromRect_operation_fraction_((x, y), ((0, 0), image.size()), NSCompositeSourceOver, 1.0)
コード例 #7
0
    def __init__(self, dimensions, alpha=1):
        super(Background, self).__init__(dimensions, scale="fit")

        colorTile = NSImage.alloc().initWithSize_((10, 10))
        colorTile.lockFocus()
        color = NSColor.colorWithCalibratedWhite_alpha_(0, alpha)
        color.set()
        NSRectFillUsingOperation(((0, 0), (10, 10)), NSCompositeSourceOver)
        colorTile.unlockFocus()

        self.setImage(imageObject=colorTile)
コード例 #8
0
ファイル: overlay.py プロジェクト: jackjennings/Mechanic
        def __init__(self, dimensions, opacity):
            super(Overlay.Background, self).__init__(dimensions, scale="fit")

            colorTile = NSImage.alloc().initWithSize_((10, 10))
            colorTile.lockFocus()
            color = NSColor.colorWithCalibratedWhite_alpha_(0, opacity)
            color.set()
            NSRectFillUsingOperation(((0, 0), (10, 10)), NSCompositeSourceOver)
            colorTile.unlockFocus()

            self.setImage(imageObject=colorTile)
コード例 #9
0
 def __init__(self, posSize, text, callback=None):
     # there must be a callback as it triggers the creation of the delegate
     if callback is None:
         callback = self._fallbackCallback
     super(FeatureTextEditor, self).__init__(posSize, "", callback=callback)
     self._nsObject.setHasHorizontalScroller_(True)
     font = NSFont.fontWithName_size_("Monaco", 10)
     self._textView.setFont_(font)
     self._textView.setUsesFindPanel_(True)
     ## line numbers
     #ruler = DefconAppKitLineNumberView.alloc().init()
     #ruler.setClientView_(self._textView)
     #self._nsObject.setVerticalRulerView_(ruler)
     #self._nsObject.setHasHorizontalRuler_(False)
     #self._nsObject.setHasVerticalRuler_(True)
     #self._nsObject.setRulersVisible_(True)
     #notificationCenter = NSNotificationCenter.defaultCenter()
     #notificationCenter.addObserver_selector_name_object_(
     #    ruler, "clientViewSelectionChanged:", NSTextViewDidChangeSelectionNotification, self._textView
     #)
     # colors
     self._mainColor = NSColor.blackColor()
     self._commentColor = NSColor.colorWithCalibratedWhite_alpha_(.6, 1)
     self._keywordColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
         .8, 0, 0, 1)
     self._tokenColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
         .8, .4, 0, 1)
     self._classNameColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
         0, 0, .8, 1)
     self._includeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
         .8, 0, .8, 1)
     self._stringColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
         0, .6, 0, 1)
     # build the placard
     placardW = 65
     placardH = 16
     self._placardJumps = []
     self._placard = vanilla.Group((0, 0, placardW, placardH))
     self._placard.featureJumpButton = PlacardPopUpButton(
         (0, 0, placardW, placardH), [],
         callback=self._placardFeatureSelectionCallback,
         sizeStyle="mini")
     self._nsObject.setPlacard_(self._placard.getNSView())
     # registed for syntax coloring notifications
     self._programmaticallySettingText = False
     delegate = self._textViewDelegate
     delegate.vanillaWrapper = weakref.ref(self)
     notificationCenter = NSNotificationCenter.defaultCenter()
     notificationCenter.addObserver_selector_name_object_(
         self._textViewDelegate, "textStorageDidProcessEditing:",
         NSTextStorageDidProcessEditingNotification,
         self._textView.textStorage())
     # set the text
     self.set(text)
コード例 #10
0
 def drawBorderAndBackgroundWithFrame_inView_(self, frame, view):
     # draw background
     try:
         gradient = NSGradient.alloc().initWithColors_([placardGradientColor1, placardGradientColor2])
         gradient.drawInRect_angle_(frame, 90)
     except NameError:
         placardGradientColorFallback.set()
         NSRectFill(frame)
     # draw border
     (x, y), (w, h) = frame
     path = NSBezierPath.bezierPath()
     path.moveToPoint_((x + w - .5, h))
     path.lineToPoint_((x + w - .5, .5))
     path.lineToPoint_((x, .5))
     path.setLineWidth_(1.0)
     NSColor.colorWithCalibratedWhite_alpha_(.5, .7).set()
     path.stroke()
     # let the super do the rest
     w -= 1
     if inOS104:
         w -= 4
     frame = ((x, y), (w, h))
     super(DefconAppKitPlacardNSPopUpButtonCell, self).drawBorderAndBackgroundWithFrame_inView_(frame, view)
コード例 #11
0
 def drawBorderAndBackgroundWithFrame_inView_(self, frame, view):
     # draw background
     try:
         gradient = NSGradient.alloc().initWithColors_([placardGradientColor1, placardGradientColor2])
         gradient.drawInRect_angle_(frame, 90)
     except NameError:
         placardGradientColorFallback.set()
         NSRectFill(frame)
     # draw border
     (x, y), (w, h) = frame
     path = NSBezierPath.bezierPath()
     path.moveToPoint_((x + w - .5, h))
     path.lineToPoint_((x + w - .5, .5))
     path.lineToPoint_((x, .5))
     path.setLineWidth_(1.0)
     NSColor.colorWithCalibratedWhite_alpha_(.5, .7).set()
     path.stroke()
     # let the super do the rest
     w -= 1
     if inOS104:
         w -= 4
     frame = ((x, y), (w, h))
     super(DefconAppKitPlacardNSPopUpButtonCell, self).drawBorderAndBackgroundWithFrame_inView_(frame, view)
コード例 #12
0
 def __init__(self, posSize, text, callback=None):
     # there must be a callback as it triggers the creation of the delegate
     if callback is None:
         callback = self._fallbackCallback
     super(FeatureTextEditor, self).__init__(posSize, "", callback=callback)
     self._nsObject.setHasHorizontalScroller_(True)
     font = NSFont.fontWithName_size_("Monaco", 10)
     self._textView.setFont_(font)
     self._textView.setUsesFindPanel_(True)
     ## line numbers
     #ruler = DefconAppKitLineNumberView.alloc().init()
     #ruler.setClientView_(self._textView)
     #self._nsObject.setVerticalRulerView_(ruler)
     #self._nsObject.setHasHorizontalRuler_(False)
     #self._nsObject.setHasVerticalRuler_(True)
     #self._nsObject.setRulersVisible_(True)
     #notificationCenter = NSNotificationCenter.defaultCenter()
     #notificationCenter.addObserver_selector_name_object_(
     #    ruler, "clientViewSelectionChanged:", NSTextViewDidChangeSelectionNotification, self._textView
     #)
     # colors
     self._mainColor = NSColor.blackColor()
     self._commentColor = NSColor.colorWithCalibratedWhite_alpha_(.6, 1)
     self._keywordColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, 0, 0, 1)
     self._tokenColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, .4, 0, 1)
     self._classNameColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, .8, 1)
     self._includeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, 0, .8, 1)
     self._stringColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, .6, 0, 1)
     # build the placard
     placardW = 65
     placardH = 16
     self._placardJumps = []
     self._placard = vanilla.Group((0, 0, placardW, placardH))
     self._placard.featureJumpButton = PlacardPopUpButton((0, 0, placardW, placardH),
         [], callback=self._placardFeatureSelectionCallback, sizeStyle="mini")
     self._nsObject.setPlacard_(self._placard.getNSView())
     # registed for syntax coloring notifications
     self._programmaticallySettingText = False
     delegate = self._textViewDelegate
     delegate.vanillaWrapper = weakref.ref(self)
     notificationCenter = NSNotificationCenter.defaultCenter()
     notificationCenter.addObserver_selector_name_object_(
         self._textViewDelegate, "textStorageDidProcessEditing", NSTextStorageDidProcessEditingNotification, self._textView.textStorage())
     # set the text
     self.set(text)
コード例 #13
0
def drawPath(path=None):
    # draws the path
    if path is None:
        path = currentPath
    if currentFillColor is not None:
        currentFillColor.set()
        path.fill()
    if currentGradient is not None:
        save()
        path.addClip()
        (gradientType, startPoint, endPoint, colors,
         locations) = currentGradient
        NSColors = []
        for color in colors:
            a = 1
            g = None
            if len(color) == 1:
                r = color[0]
            elif len(color) == 2:
                r, a = color
            elif len(color) == 3:
                r, g, b = color
            elif len(color) == 4:
                r, g, b, a = color
            if g is not None:
                NSColors.append(
                    NSColor.colorWithCalibratedRed_green_blue_alpha_(
                        r, g, b, a))
            else:
                NSColors.append(NSColor.colorWithCalibratedWhite_alpha_(r, a))
        gradient = NSGradient.alloc().initWithColors_atLocations_colorSpace_(
            NSColors, locations, NSColorSpace.deviceRGBColorSpace())
        if gradientType == "linear":
            gradient.drawFromPoint_toPoint_options_(
                startPoint, endPoint, NSGradientDrawsBeforeStartingLocation
                | NSGradientDrawsAfterEndingLocation)
        elif gradient.gradientType == "radial":
            pass
        restore()
    if currentStrokeWidth is not None:
        path.setLineWidth_(currentStrokeWidth)
    if currentStrokeColor is not None:
        currentStrokeColor.set()
        path.stroke()
コード例 #14
0
def drawPath(path=None):
	# draws the path
	if path is None:
		path = currentPath
	if currentFillColor is not None:
		currentFillColor.set()
		path.fill()
	if currentGradient is not None:
		save()
		path.addClip()
		(gradientType, startPoint, endPoint, colors, locations) = currentGradient
		NSColors = []
		for color in colors:
			a = 1
			g = None
			if len(color) == 1:
				r = color[0]
			elif len(color) == 2:
				r, a = color
			elif len(color) == 3:
				r, g, b = color
			elif len(color) == 4:
				r, g, b, a = color
			if g is not None:
				NSColors.append(NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a))
			else:
				NSColors.append(NSColor.colorWithCalibratedWhite_alpha_(r, a))
		gradient = NSGradient.alloc().initWithColors_atLocations_colorSpace_(NSColors, locations, NSColorSpace.deviceRGBColorSpace())
		if gradientType == "linear":
			gradient.drawFromPoint_toPoint_options_(startPoint, endPoint, NSGradientDrawsBeforeStartingLocation | NSGradientDrawsAfterEndingLocation)
		elif gradient.gradientType == "radial":
			pass
		restore()
	if currentStrokeWidth is not None:
		path.setLineWidth_(currentStrokeWidth)
	if currentStrokeColor is not None:
		currentStrokeColor.set()
		path.stroke()
コード例 #15
0
        return status


# --------------------
# Misc. Internal Stuff
# --------------------

class DefconAppKitTopAnchoredNSView(NSView):

    def isFlipped(self):
        return True


# title attributes
shadow = NSShadow.alloc().init()
shadow.setShadowColor_(NSColor.colorWithCalibratedWhite_alpha_(1, 1))
shadow.setShadowBlurRadius_(1.0)
shadow.setShadowOffset_((1.0, -1.0))
titleControlAttributes = {
    NSForegroundColorAttributeName: NSColor.colorWithCalibratedWhite_alpha_(.4, 1),
    NSShadowAttributeName: shadow,
    NSFontAttributeName: NSFont.boldSystemFontOfSize_(NSFont.systemFontSizeForControlSize_(NSSmallControlSize))
}


# all script and language tags
_scriptTags = """arab
armn
beng
bopo
brai
コード例 #16
0
ファイル: drawing.py プロジェクト: RafalBuchner/defconAppKit
# ------
# Colors
# ------

defaultColors = dict(

    # General
    # -------
    background=NSColor.whiteColor(),

    # Font
    # ----

    # vertical metrics
    fontVerticalMetrics=NSColor.colorWithCalibratedWhite_alpha_(.4, .5),
    fontPostscriptBlues=NSColor.colorWithCalibratedRed_green_blue_alpha_(
        .5, .7, 1, .3),
    fontPostscriptFamilyBlues=NSColor.colorWithCalibratedRed_green_blue_alpha_(
        1, 1, .5, .3),

    # Glyph
    # -----

    # margins
    glyphMarginsFill=NSColor.colorWithCalibratedWhite_alpha_(.5, .11),
    glyphMarginsStroke=NSColor.colorWithCalibratedWhite_alpha_(.7, .5),

    # contour fill
    glyphContourFill=NSColor.colorWithCalibratedRed_green_blue_alpha_(
        0, 0, 0, 1),
コード例 #17
0
 def drawDividerInRect_(self, rect):
     if self.dividerThickness() > 2:
         super(SimpleNSSplitView, self).drawDividerInRect_(rect)
     else:
         NSColor.colorWithCalibratedWhite_alpha_(0, .42).set()
         NSBezierPath.bezierPathWithRect_(rect).fill()
コード例 #18
0
from AppKit import NSColor, NSGraphicsContext, NSForegroundColorAttributeName, NSAttributedString, NSFont, \
    NSFontAttributeName, NSAffineTransform, NSRectFill, NSRectFillListUsingOperation, NSImage, NSParagraphStyleAttributeName, \
    NSBezierPath, NSMutableParagraphStyle, NSCenterTextAlignment, NSLineBreakByTruncatingMiddle, NSCompositeSourceOver
from defconAppKit.tools.drawing import colorToNSColor

GlyphCellHeaderHeight = 14
GlyphCellMinHeightForHeader = 40

cellBackgroundColor = NSColor.whiteColor()
cellHeaderBaseColor = NSColor.colorWithCalibratedWhite_alpha_(0.968, 1.0)
cellHeaderHighlightColor = NSColor.colorWithCalibratedWhite_alpha_(0.98, 1.0)
cellHeaderLineColor = NSColor.colorWithCalibratedWhite_alpha_(0, .2)
cellMetricsLineColor = NSColor.colorWithCalibratedWhite_alpha_(0, .08)
cellMetricsFillColor = NSColor.colorWithCalibratedWhite_alpha_(0, .08)


def GlyphCellFactory(glyph, width, height, drawHeader=False, drawMetrics=False):
    obj = GlyphCellFactoryDrawingController(glyph=glyph, font=glyph.font, width=width, height=height, drawHeader=drawHeader, drawMetrics=drawMetrics)
    return obj.getImage()


class GlyphCellFactoryDrawingController(object):

    """
    This draws the cell with the layers stacked in this order:
    ------------------
    header text
    ------------------
    header background
    ------------------
    foreground
コード例 #19
0
from AppKit import NSColor, NSGraphicsContext, NSForegroundColorAttributeName, NSAttributedString, NSFont, \
    NSFontAttributeName, NSAffineTransform, NSRectFill, NSRectFillListUsingOperation, NSImage, NSParagraphStyleAttributeName, \
    NSBezierPath, NSMutableParagraphStyle, NSCenterTextAlignment, NSLineBreakByTruncatingMiddle, NSCompositeSourceOver
from defconAppKit.tools.drawing import colorToNSColor

GlyphCellHeaderHeight = 14
GlyphCellMinHeightForHeader = 40

cellBackgroundColor = NSColor.whiteColor()
cellHeaderBaseColor = NSColor.colorWithCalibratedWhite_alpha_(0.968, 1.0)
cellHeaderHighlightColor = NSColor.colorWithCalibratedWhite_alpha_(0.98, 1.0)
cellHeaderLineColor = NSColor.colorWithCalibratedWhite_alpha_(0, .2)
cellMetricsLineColor = NSColor.colorWithCalibratedWhite_alpha_(0, .08)
cellMetricsFillColor = NSColor.colorWithCalibratedWhite_alpha_(0, .08)


def GlyphCellFactory(glyph,
                     width,
                     height,
                     drawHeader=False,
                     drawMetrics=False):
    obj = GlyphCellFactoryDrawingController(glyph=glyph,
                                            font=glyph.font,
                                            width=width,
                                            height=height,
                                            drawHeader=drawHeader,
                                            drawMetrics=drawMetrics)
    return obj.getImage()


class GlyphCellFactoryDrawingController(object):
コード例 #20
0
def GlyphCellDetailFactory(glyph):
    font = glyph.font

    imageWidth = 200
    imageHeight = 280

    scale = 120 / font.info.unitsPerEm
    glyphLeftOffset = (imageWidth - (glyph.width * scale)) / 2

    basePath = roundedRectBezierPath(
        ((.5, .5), (imageWidth - 1, imageHeight - 1)), 7)
    basePath.setLineWidth_(1.0)

    glyphPath = glyph.getRepresentation("defconAppKit.NSBezierPath")

    line1Path = NSBezierPath.bezierPath()
    line1Path.moveToPoint_((1, 120.5))
    line1Path.lineToPoint_((imageWidth - 1, 120.5))
    line1Path.setLineWidth_(1.0)

    line2Path = NSBezierPath.bezierPath()
    line2Path.moveToPoint_((1, 121.5))
    line2Path.lineToPoint_((imageWidth - 1, 121.5))
    line2Path.setLineWidth_(1.0)

    lineColor = NSColor.colorWithCalibratedWhite_alpha_(.5, 1.0)

    paragraph = NSMutableParagraphStyle.alloc().init()
    paragraph.setAlignment_(NSRightTextAlignment)
    paragraph.setLineBreakMode_(NSLineBreakByCharWrapping)
    leftAttributes = {
        NSFontAttributeName: NSFont.systemFontOfSize_(12.0),
        NSForegroundColorAttributeName: NSColor.whiteColor(),
        NSParagraphStyleAttributeName: paragraph
    }

    paragraph = NSMutableParagraphStyle.alloc().init()
    paragraph.setAlignment_(NSLeftTextAlignment)
    paragraph.setLineBreakMode_(NSLineBreakByTruncatingMiddle)
    rightAttributes = {
        NSFontAttributeName: NSFont.systemFontOfSize_(12.0),
        NSForegroundColorAttributeName: NSColor.whiteColor(),
        NSParagraphStyleAttributeName: paragraph
    }

    nameTitle = NSAttributedString.alloc().initWithString_attributes_(
        "Name", leftAttributes)
    nameText = NSAttributedString.alloc().initWithString_attributes_(
        glyph.name, rightAttributes)

    uniTitle = NSAttributedString.alloc().initWithString_attributes_(
        "Unicode", leftAttributes)
    uni = glyph.unicode
    if uni is None:
        uni = ""
    else:
        uni = hex(uni)[2:].upper()
        if len(uni) < 4:
            uni = uni.zfill(4)
    uniText = NSAttributedString.alloc().initWithString_attributes_(
        str(uni), rightAttributes)

    widthTitle = NSAttributedString.alloc().initWithString_attributes_(
        "Width", leftAttributes)
    width = glyph.width
    if width is None:
        width = 0
    width = round(width, 3)
    if width == int(width):
        width = int(width)
    widthText = NSAttributedString.alloc().initWithString_attributes_(
        str(width), rightAttributes)

    leftTitle = NSAttributedString.alloc().initWithString_attributes_(
        "Left Margin", leftAttributes)
    leftMargin = glyph.leftMargin
    if leftMargin is None:
        leftMargin = 0
    leftMargin = round(leftMargin, 3)
    if leftMargin == int(leftMargin):
        leftMargin = int(leftMargin)
    leftText = NSAttributedString.alloc().initWithString_attributes_(
        str(leftMargin), rightAttributes)

    rightTitle = NSAttributedString.alloc().initWithString_attributes_(
        "Right Margin", leftAttributes)
    rightMargin = glyph.rightMargin
    if rightMargin is None:
        rightMargin = 0
    rightMargin = round(rightMargin, 3)
    if rightMargin == int(rightMargin):
        rightMargin = int(rightMargin)
    rightText = NSAttributedString.alloc().initWithString_attributes_(
        str(rightMargin), rightAttributes)

    image = NSImage.alloc().initWithSize_((imageWidth, imageHeight))
    image.setFlipped_(True)
    image.lockFocus()

    NSColor.colorWithCalibratedWhite_alpha_(0, .65).set()
    basePath.fill()
    lineColor.set()
    basePath.stroke()

    context = NSGraphicsContext.currentContext()
    context.saveGraphicsState()
    transform = NSAffineTransform.transform()
    transform.translateXBy_yBy_(glyphLeftOffset, 145)
    transform.scaleBy_(scale)
    transform.translateXBy_yBy_(0, -font.info.descender)
    transform.concat()

    NSColor.whiteColor().set()
    glyphPath.fill()
    context.restoreGraphicsState()

    lineColor.set()
    line1Path.stroke()
    NSColor.colorWithCalibratedWhite_alpha_(0, .5).set()
    line2Path.stroke()

    transform = NSAffineTransform.transform()
    transform.translateXBy_yBy_(0, 110)
    transform.scaleXBy_yBy_(1.0, -1.0)
    transform.concat()

    nameTitle.drawInRect_(((0, 0), (90, 17)))
    nameText.drawInRect_(((95, 0), (85, 17)))

    uniTitle.drawInRect_(((0, 20), (90, 17)))
    uniText.drawInRect_(((95, 20), (85, 17)))

    widthTitle.drawInRect_(((0, 40), (90, 17)))
    widthText.drawInRect_(((95, 40), (85, 17)))

    leftTitle.drawInRect_(((0, 60), (90, 17)))
    leftText.drawInRect_(((95, 60), (85, 17)))

    rightTitle.drawInRect_(((0, 80), (90, 17)))
    rightText.drawInRect_(((95, 80), (85, 17)))

    image.unlockFocus()
    return image
コード例 #21
0
ファイル: drawing.py プロジェクト: typemytype/defconAppKit
# ------
# Colors
# ------

defaultColors = dict(

    # General
    # -------

    background=NSColor.whiteColor(),

    # Font
    # ----

    # vertical metrics
    fontVerticalMetrics=NSColor.colorWithCalibratedWhite_alpha_(.4, .5),

    fontPostscriptBlues=NSColor.colorWithCalibratedRed_green_blue_alpha_(.5, .7, 1, .3),
    fontPostscriptFamilyBlues=NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 1, .5, .3),

    # Glyph
    # -----

    # margins
    glyphMarginsFill=NSColor.colorWithCalibratedWhite_alpha_(.5, .11),
    glyphMarginsStroke=NSColor.colorWithCalibratedWhite_alpha_(.7, .5),

    # contour fill
    glyphContourFill=NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 1),

    # contour stroke
コード例 #22
0
from AppKit import NSColor, NSScrollView, NSRectFill, NSRectFillUsingOperation, NSBezierPath, \
    NSCompositeSourceOver, NSPopUpButtonCell, NSSegmentedCell, NSGradientConvexStrong
import vanilla
import platform

inOS104 = platform.mac_ver()[0].startswith("10.4.")

placardBorderColor = NSColor.colorWithCalibratedWhite_alpha_(.5, .7)


class DefconAppKitPlacardNSScrollView(NSScrollView):

    def dealloc(self):
        if hasattr(self, "placard"):
            del self.placard
        super(DefconAppKitPlacardNSScrollView, self).dealloc()

    def tile(self):
        super(DefconAppKitPlacardNSScrollView, self).tile()
        if self.window() is None:
            return
        if hasattr(self, "placard"):
            placardWidth = self.placard.frame().size[0]
            scroller = self.horizontalScroller()
            (x, y), (w, h) = scroller.frame()
            if w > 0 and h > 0:
                scroller.setFrame_(((x + placardWidth, y), (w - placardWidth, h)))
            self.placard.setFrame_(((x, y), (placardWidth, h)))

    def setPlacard_(self, view):
        if hasattr(self, "placard") and self.placard is not None:
コード例 #23
0
def GlyphCellDetailFactory(glyph):
    font = glyph.font

    imageWidth = 200
    imageHeight = 280

    scale = 120 / font.info.unitsPerEm
    glyphLeftOffset = (imageWidth - (glyph.width * scale)) / 2

    basePath = roundedRectBezierPath(((.5, .5), (imageWidth - 1, imageHeight - 1)), 7)
    basePath.setLineWidth_(1.0)

    glyphPath = glyph.getRepresentation("defconAppKit.NSBezierPath")

    line1Path = NSBezierPath.bezierPath()
    line1Path.moveToPoint_((1, 120.5))
    line1Path.lineToPoint_((imageWidth - 1, 120.5))
    line1Path.setLineWidth_(1.0)

    line2Path = NSBezierPath.bezierPath()
    line2Path.moveToPoint_((1, 121.5))
    line2Path.lineToPoint_((imageWidth - 1, 121.5))
    line2Path.setLineWidth_(1.0)

    lineColor = NSColor.colorWithCalibratedWhite_alpha_(.5, 1.0)

    paragraph = NSMutableParagraphStyle.alloc().init()
    paragraph.setAlignment_(NSRightTextAlignment)
    paragraph.setLineBreakMode_(NSLineBreakByCharWrapping)
    leftAttributes = {
        NSFontAttributeName: NSFont.systemFontOfSize_(12.0),
        NSForegroundColorAttributeName: NSColor.whiteColor(),
        NSParagraphStyleAttributeName: paragraph
    }

    paragraph = NSMutableParagraphStyle.alloc().init()
    paragraph.setAlignment_(NSLeftTextAlignment)
    paragraph.setLineBreakMode_(NSLineBreakByTruncatingMiddle)
    rightAttributes = {
        NSFontAttributeName: NSFont.systemFontOfSize_(12.0),
        NSForegroundColorAttributeName: NSColor.whiteColor(),
        NSParagraphStyleAttributeName: paragraph
    }

    nameTitle = NSAttributedString.alloc().initWithString_attributes_("Name", leftAttributes)
    nameText = NSAttributedString.alloc().initWithString_attributes_(glyph.name, rightAttributes)

    uniTitle = NSAttributedString.alloc().initWithString_attributes_("Unicode", leftAttributes)
    uni = glyph.unicode
    if uni is None:
        uni = ""
    else:
        uni = hex(uni)[2:].upper()
        if len(uni) < 4:
            uni = uni.zfill(4)
    uniText = NSAttributedString.alloc().initWithString_attributes_(str(uni), rightAttributes)

    widthTitle = NSAttributedString.alloc().initWithString_attributes_("Width", leftAttributes)
    width = glyph.width
    if width is None:
        width = 0
    width = round(width, 3)
    if width == int(width):
        width = int(width)
    widthText = NSAttributedString.alloc().initWithString_attributes_(str(width), rightAttributes)

    leftTitle = NSAttributedString.alloc().initWithString_attributes_("Left Margin", leftAttributes)
    leftMargin = glyph.leftMargin
    if leftMargin is None:
        leftMargin = 0
    leftMargin = round(leftMargin, 3)
    if leftMargin == int(leftMargin):
        leftMargin = int(leftMargin)
    leftText = NSAttributedString.alloc().initWithString_attributes_(str(leftMargin), rightAttributes)

    rightTitle = NSAttributedString.alloc().initWithString_attributes_("Right Margin", leftAttributes)
    rightMargin = glyph.rightMargin
    if rightMargin is None:
        rightMargin = 0
    rightMargin = round(rightMargin, 3)
    if rightMargin == int(rightMargin):
        rightMargin = int(rightMargin)
    rightText = NSAttributedString.alloc().initWithString_attributes_(str(rightMargin), rightAttributes)

    image = NSImage.alloc().initWithSize_((imageWidth, imageHeight))
    image.setFlipped_(True)
    image.lockFocus()

    NSColor.colorWithCalibratedWhite_alpha_(0, .65).set()
    basePath.fill()
    lineColor.set()
    basePath.stroke()

    context = NSGraphicsContext.currentContext()
    context.saveGraphicsState()
    transform = NSAffineTransform.transform()
    transform.translateXBy_yBy_(glyphLeftOffset, 145)
    transform.scaleBy_(scale)
    transform.translateXBy_yBy_(0, -font.info.descender)
    transform.concat()

    NSColor.whiteColor().set()
    glyphPath.fill()
    context.restoreGraphicsState()

    lineColor.set()
    line1Path.stroke()
    NSColor.colorWithCalibratedWhite_alpha_(0, .5).set()
    line2Path.stroke()

    transform = NSAffineTransform.transform()
    transform.translateXBy_yBy_(0, 110)
    transform.scaleXBy_yBy_(1.0, -1.0)
    transform.concat()

    nameTitle.drawInRect_(((0, 0), (90, 17)))
    nameText.drawInRect_(((95, 0), (85, 17)))

    uniTitle.drawInRect_(((0, 20), (90, 17)))
    uniText.drawInRect_(((95, 20), (85, 17)))

    widthTitle.drawInRect_(((0, 40), (90, 17)))
    widthText.drawInRect_(((95, 40), (85, 17)))

    leftTitle.drawInRect_(((0, 60), (90, 17)))
    leftText.drawInRect_(((95, 60), (85, 17)))

    rightTitle.drawInRect_(((0, 80), (90, 17)))
    rightText.drawInRect_(((95, 80), (85, 17)))

    image.unlockFocus()
    return image
コード例 #24
0
from AppKit import NSColor, NSScrollView, NSRectFill, NSRectFillUsingOperation, NSBezierPath, \
    NSCompositeSourceOver, NSPopUpButtonCell, NSSegmentedCell, NSGradientConvexStrong
import vanilla
import platform

inOS104 = platform.mac_ver()[0].startswith("10.4.")

placardBorderColor = NSColor.colorWithCalibratedWhite_alpha_(.5, .7)


class DefconAppKitPlacardNSScrollView(NSScrollView):

    def dealloc(self):
        if hasattr(self, "placard"):
            del self.placard
        super(DefconAppKitPlacardNSScrollView, self).dealloc()

    def tile(self):
        super(DefconAppKitPlacardNSScrollView, self).tile()
        if self.window() is None:
            return
        if hasattr(self, "placard"):
            placardWidth = self.placard.frame().size[0]
            scroller = self.horizontalScroller()
            (x, y), (w, h) = scroller.frame()
            if w > 0 and h > 0:
                scroller.setFrame_(((x + placardWidth, y), (w - placardWidth, h)))
            self.placard.setFrame_(((x, y), (placardWidth, h)))

    def setPlacard_(self, view):
        if hasattr(self, "placard") and self.placard is not None:
コード例 #25
0
 def drawRect_(self, rect):
     NSColor.colorWithCalibratedWhite_alpha_(0.5, 0.5).set()
     p = NSBezierPath.bezierPathWithRect_(self.bounds())
     p.fill()
コード例 #26
0
class GlyphCellFactoryDrawingController(object):
    """
    This draws the cell with the layers stacked in this order:
    ------------------
    header text
    ------------------
    header background
    ------------------
    foreground
    ------------------
    glyph
    ------------------
    vertical metrics
    ------------------
    horizontal metrics
    ------------------
    background
    ------------------

    Subclasses may override the layer drawing methods to customize
    the appearance of cells.
    """

    cellBackgroundColor = NSColor.whiteColor()
    cellHeaderBaseColor = NSColor.colorWithCalibratedWhite_alpha_(0.968, 1.0)
    cellHeaderHighlightColor = NSColor.colorWithCalibratedWhite_alpha_(
        0.98, 1.0)
    cellHeaderLineColor = NSColor.colorWithCalibratedWhite_alpha_(0, .2)
    cellMetricsLineColor = NSColor.colorWithCalibratedWhite_alpha_(0, .08)
    cellMetricsFillColor = NSColor.colorWithCalibratedWhite_alpha_(0, .08)

    def __init__(self,
                 glyph,
                 font,
                 width,
                 height,
                 drawHeader=False,
                 drawMetrics=False):
        self.glyph = glyph
        self.font = font
        self.width = width
        self.height = height
        self.bufferPercent = .2
        self.shouldDrawHeader = drawHeader
        self.shouldDrawMetrics = drawMetrics

        self.headerHeight = 0
        if drawHeader:
            self.headerHeight = GlyphCellHeaderHeight
        availableHeight = (height -
                           self.headerHeight) * (1.0 -
                                                 (self.bufferPercent * 2))
        self.buffer = height * self.bufferPercent
        self.scale = availableHeight / font.info.unitsPerEm
        self.xOffset = (width - (glyph.width * self.scale)) / 2
        self.yOffset = abs(font.info.descender * self.scale) + self.buffer

    def getImage(self):
        image = NSImage.alloc().initWithSize_((self.width, self.height))
        image.setFlipped_(True)
        image.lockFocus()
        context = NSGraphicsContext.currentContext()
        bodyRect = ((0, 0), (self.width, self.height - self.headerHeight))
        headerRect = ((0, -self.height + self.headerHeight),
                      (self.width, self.headerHeight))
        # draw a background color
        self.cellBackgroundColor.set()
        NSRectFill(((0, 0), (self.width, self.height)))
        # background
        context.saveGraphicsState()
        bodyTransform = NSAffineTransform.transform()
        bodyTransform.translateXBy_yBy_(0, self.height - self.headerHeight)
        bodyTransform.scaleXBy_yBy_(1.0, -1.0)
        bodyTransform.concat()
        self.drawCellBackground(bodyRect)
        context.restoreGraphicsState()
        # glyph
        if self.shouldDrawMetrics:
            self.drawCellVerticalMetrics(bodyRect)
            self.drawCellHorizontalMetrics(bodyRect)
        context.saveGraphicsState()
        NSBezierPath.clipRect_(
            ((0, 0), (self.width, self.height - self.headerHeight)))
        glyphTransform = NSAffineTransform.transform()
        glyphTransform.translateXBy_yBy_(self.xOffset, self.yOffset)
        glyphTransform.scaleBy_(self.scale)
        glyphTransform.concat()
        self.drawCellGlyph()
        context.restoreGraphicsState()
        # foreground
        context.saveGraphicsState()
        bodyTransform.concat()
        self.drawCellForeground(bodyRect)
        context.restoreGraphicsState()
        # header
        if self.shouldDrawHeader:
            context.saveGraphicsState()
            headerTransform = NSAffineTransform.transform()
            headerTransform.translateXBy_yBy_(0, self.headerHeight)
            headerTransform.scaleXBy_yBy_(1.0, -1.0)
            headerTransform.concat()
            self.drawCellHeaderBackground(headerRect)
            self.drawCellHeaderText(headerRect)
            context.restoreGraphicsState()
        # done
        image.unlockFocus()
        return image

    def drawCellBackground(self, rect):
        pass

    def drawCellHorizontalMetrics(self, rect):
        (xMin, yMin), (width, height) = rect
        font = self.font
        scale = self.scale
        yOffset = self.yOffset
        path = NSBezierPath.bezierPath()
        lines = set((0, font.info.descender, font.info.xHeight,
                     font.info.capHeight, font.info.ascender))
        for y in lines:
            y = round((y * scale) + yMin + yOffset) - .5
            path.moveToPoint_((xMin, y))
            path.lineToPoint_((xMin + width, y))
        self.cellMetricsLineColor.set()
        path.setLineWidth_(1.0)
        path.stroke()

    def drawCellVerticalMetrics(self, rect):
        (xMin, yMin), (width, height) = rect
        glyph = self.glyph
        scale = self.scale
        xOffset = self.xOffset
        left = round((0 * scale) + xMin + xOffset) - .5
        right = round((glyph.width * scale) + xMin + xOffset) - .5
        rects = [((xMin, yMin), (left - xMin, height)),
                 ((xMin + right, yMin), (width - xMin + right, height))]
        self.cellMetricsFillColor.set()
        NSRectFillListUsingOperation(rects, len(rects), NSCompositeSourceOver)

#    def drawCellGlyph(self):
#        NSColor.blackColor().set()
#        path = self.glyph.getRepresentation("defconAppKit.NSBezierPath")
#        path.fill()

    def drawCellGlyph(self):
        layers = self.font.layers
        for layerName in reversed(layers.layerOrder):
            layer = layers[layerName]
            if self.glyph.name not in layer:
                continue
            layerColor = None
            if layer.color is not None:
                layerColor = colorToNSColor(layer.color)
            if layerColor is None:
                layerColor = NSColor.blackColor()
            glyph = layer[self.glyph.name]
            path = glyph.getRepresentation("defconAppKit.NSBezierPath")
            layerColor.set()
            path.fill()

    def drawCellForeground(self, rect):
        pass

    def drawCellHeaderBackground(self, rect):
        (xMin, yMin), (width, height) = rect
        # background
        try:
            gradient = NSGradient.alloc().initWithColors_(
                [cellHeaderHighlightColor, self.cellHeaderBaseColor])
            gradient.drawInRect_angle_(rect, 90)
        except NameError:
            self.cellHeaderBaseColor.set()
            NSRectFill(rect)
        # bottom line
        self.cellHeaderLineColor.set()
        bottomPath = NSBezierPath.bezierPath()
        bottomPath.moveToPoint_((xMin, yMin + height - .5))
        bottomPath.lineToPoint_((xMin + width, yMin + height - .5))
        bottomPath.setLineWidth_(1.0)
        bottomPath.stroke()

    def drawCellHeaderText(self, rect):
        paragraph = NSMutableParagraphStyle.alloc().init()
        paragraph.setAlignment_(NSCenterTextAlignment)
        paragraph.setLineBreakMode_(NSLineBreakByTruncatingMiddle)
        attributes = {
            NSFontAttributeName:
            NSFont.systemFontOfSize_(10.0),
            NSForegroundColorAttributeName:
            NSColor.colorWithCalibratedRed_green_blue_alpha_(
                .22, .22, .27, 1.0),
            NSParagraphStyleAttributeName:
            paragraph,
        }
        text = NSAttributedString.alloc().initWithString_attributes_(
            self.glyph.name, attributes)
        text.drawInRect_(rect)
コード例 #27
0
 def drawDividerInRect_(self, rect):
     if self.dividerThickness() > 2:
         super(SimpleNSSplitView, self).drawDividerInRect_(rect)
     else:
         NSColor.colorWithCalibratedWhite_alpha_(0, .42).set()
         NSBezierPath.bezierPathWithRect_(rect).fill()
コード例 #28
0
    image.lockFocus()
    backgroundColor.set()
    NSRectFillUsingOperation(((0, 0), (19, 19)), NSCompositeSourceOver)
    foregroundColor.set()
    path = NSBezierPath.bezierPathWithRect_(((0.5, 0.5), (18, 18)))
    for (mT, lT) in paths:
        path.moveToPoint_(mT)
        path.lineToPoint_(lT)
    path.setLineWidth_(1.0)
    path.stroke()
    image.unlockFocus()
    return image


color1 = NSColor.blackColor()
color2 = NSColor.colorWithCalibratedWhite_alpha_(1, 0.5)

pathYT = [((6.5, 7.5), (6.5, 18.5)), ((12.5, 7.5), (12.5, 18.5))]
pathYC = [((6.5, 4.5), (6.5, 14.5)), ((12.5, 4.5), (12.5, 14.5))]
pathYB = [((6.5, 0.5), (6.5, 11.5)), ((12.5, 0.5), (12.5, 11.5))]

pathXL = [((0.5, 6.5), (11.5, 6.5)), ((0.5, 12.5), (11.5, 12.5))]
pathXC = [((4.5, 6.5), (14.5, 6.5)), ((4.5, 12.5), (14.5, 12.5))]
pathXR = [((7.5, 6.5), (18.5, 6.5)), ((7.5, 12.5), (18.5, 12.5))]

pathCC = [((9.5, 4.5), (9.5, 14.5)), ((4.5, 9.5), (14.5, 9.5))]
pathDX = [((6.5, 0.5), (6.5, 18.5)), ((12.5, 0.5), (12.5, 18.5))]
pathDY = [((0.5, 6.5), (18.5, 6.5)), ((0.5, 12.5), (18.5, 12.5))]

pathDT = [((0.5, 6.5), (18.5, 6.5)), ((0.5, 12.5), (18.5, 12.5)),
          ((6.5, 8.5), (6.5, 12.5)), ((12.5, 2.5), (12.5, 6.5))]
コード例 #29
0
import time
from AppKit import NSColor, NSView, NSBorderlessWindowMask, NSTornOffMenuWindowLevel, NSInsetRect, NSPanel, NSRectFill
import vanilla
from vanilla.py23 import python_method
from defconAppKit.tools.roundedRectBezierPath import roundedRectBezierPath


# ----------
# Basic View
# ----------


HUDWindowLineColor = NSColor.colorWithCalibratedWhite_alpha_(.5, 1.0)
HUDWindowColor = NSColor.colorWithCalibratedWhite_alpha_(0, .65)


class DefconAppKitInformationPopUpWindowContentView(NSView):

    windowColor = HUDWindowColor
    windowLineColor = HUDWindowLineColor

    def drawRect_(self, rect):
        rect = self.bounds()
        rect = NSInsetRect(rect, .5, .5)
        path = roundedRectBezierPath(rect, 7)
        self.windowColor.set()
        path.fill()
        self.windowLineColor.set()
        path.stroke()