Пример #1
0
 def drawRect_(self, rect):
     if self.inLiveResize():
         self._recalcSize()
     from random import random
     NSColor.redColor().set()
     NSRectFill(self.bounds())
     width, height = self.frame()[1]
     w = width / 5
     h = height / 5
     for xI in range(5):
         for yI in range(5):
             x = xI * w
             y = height - (yI * h) - h
             r = ((x, y), (w, h))
             NSColor.colorWithDeviceRed_green_blue_alpha_(random(), random(), random(), 1.0).set()
             NSRectFill(r)
Пример #2
0
 def drawRect_(self, rect):
     NSColor.whiteColor().set()
     NSRectFill(self.bounds())
     origin = (self.center[0] - self.radius, self.center[1] - self.radius)
     size = (2 * self.radius, 2 * self.radius)
     dotRect = (origin, size)
     self.color.set()
     NSBezierPath.bezierPathWithOvalInRect_(dotRect).fill()
Пример #3
0
 def drawRect_(self, rect):
     from AppKit import NSRectFill, NSBezierPath, NSColor
     self.color.set()
     NSRectFill(self.bounds())
     NSColor.blackColor().set()
     p = NSBezierPath.bezierPathWithRect_(self.bounds())
     p.setLineWidth_(10)
     p.stroke()
Пример #4
0
 def drawBackground(self):
     if "glyphViewBackgroundColor" in self._theme:
         self._backgroundColor = drawing.colorToNSColor(
             self._theme["glyphViewBackgroundColor"])
     else:
         self._backgroundColor = NSColor.whiteColor()
     self._backgroundColor.set()
     NSRectFill(self.bounds())
Пример #5
0
	def drawRect_(self, rect):
		try:
			bounds = self.bounds()
			if self._backgroundColor != None:
				self._backgroundColor.set()
				NSRectFill(bounds)
			self._layer.drawInFrame_(bounds)
		except:
			print traceback.format_exc()
Пример #6
0
    def drawRect_(self, rect):
        VerticalBoxView.drawRect_(self, rect)

        if self.alternateRows:
            i = 0
            NSColor.colorWithCalibratedRed_green_blue_alpha_(
                237 / 256.0, 243 / 256.0, 254 / 256.0, 1.0).set()
            for v in self.subviews():
                if i % 2 == 1:
                    NSRectFill(v.frame())
                i += 1

        if self.selection != -1 and self.selection < self.subviews().count():
            if self.window().isKeyWindow():
                NSColor.alternateSelectedControlColor().set()
            else:
                NSColor.lightGrayColor().set()
            NSRectFill(self.subviews()[self.selection].frame())
Пример #7
0
 def drawRect_(self, rect):
     try:
         if self._backgroundColor is not None:
             self._backgroundColor.set()
             NSRectFill(rect)
         if self._delegate != None:
             self._delegate.draw(self)
     except:
         print(traceback.format_exc())
Пример #8
0
 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
     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.drawCellHorizontalMetrics(bodyRect)
         self.drawCellVerticalMetrics(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
Пример #9
0
 def drawRect_(self, rect):
     frame = self.frame()
     NSColor.whiteColor().set()
     NSRectFill(frame)
     try:
         if self._glyph is not None:
             if self._glyph.__class__.__name__ in ("NSKVONotifying_GSLayer",
                                                   "GSLayer"):
                 layer = self._glyph
             elif isinstance(self._glyph, RGlyph):
                 layer = self._glyph._layer
             if layer:
                 layer.drawInFrame_(frame)
     except:
         print(traceback.format_exc())
Пример #10
0
 def drawUnderline(self, layer, options):
     try:
         if Glyphs.boolDefaults["GeorgSeifert_showUnderline"]:
             master = layer.associatedFontMaster()
             thinkness = master.customParameters["underlineThickness"]
             position = master.customParameters["underlinePosition"]
             if thinkness != None and position != None:
                 thinkness = float(thinkness)
                 position = float(position)
                 rect = NSMakeRect(0, position - (thinkness * 0.5),
                                   layer.width, thinkness)
                 NSColor.colorWithDeviceRed_green_blue_alpha_(
                     64.0 / 255.0, 79.0 / 255.0, 104.0 / 255.0, 1).set()
                 NSRectFill(rect)
     except:
         NSLog(traceback.format_exc())
Пример #11
0
 def drawCellHeaderBackground(self, rect):
     (xMin, yMin), (width, height) = rect
     # background
     try:
         gradient = NSGradient.alloc().initWithColors_(
             [cellHeaderHighlightColor, cellHeaderBaseColor])
         gradient.drawInRect_angle_(rect, 90)
     except NameError:
         cellHeaderBaseColor.set()
         NSRectFill(rect)
     # bottom line
     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 drawRect_(self, rect):
            try:
                NSColor.whiteColor().set()
                NSRectFill(self.bounds())
                NSColor.blackColor().setFill()
                p = NSBezierPath.bezierPath()
                xcursor = 0
                ycursor = 0
                for i, g in enumerate(self.glyphs):
                    layer = g.layers[0]
                    if i > 0:
                        # Do anchor correction here
                        prevlayer = self.glyphs[i - 1].layers[0]
                        entry = prevlayer.anchors["entry"]
                        exit = layer.anchors["exit"]
                        if entry and exit:
                            diffX = entry.position.x - exit.position.x
                            diffY = entry.position.y - exit.position.y
                            xcursor = xcursor + diffX
                            ycursor = ycursor + diffY
                        else:
                            NSColor.redColor().setFill()
                    else:
                        xcursor = xcursor - layer.bounds.origin.x
                    thisPath = NSBezierPath.bezierPath()
                    thisPath.appendBezierPath_(layer.completeBezierPath)
                    t = NSAffineTransform.transform()
                    t.translateXBy_yBy_(xcursor,
                                        -layer.master.descender + ycursor)
                    thisPath.transformUsingAffineTransform_(t)
                    p.appendBezierPath_(thisPath)

                t = NSAffineTransform.transform()
                if xcursor > 0:
                    master = self.glyphs[0].layers[0].master
                    vscale = self.bounds().size.height / (master.ascender -
                                                          master.descender)
                    hscale = self.bounds().size.width / xcursor
                    t.scaleBy_(min(hscale, vscale))
                    p.transformUsingAffineTransform_(t)
                p.fill()
            except Exception as e:
                print("Oops!", sys.exc_info()[0], "occured.")
                traceback.print_exc(file=sys.stdout)
Пример #13
0
    def drawRect_(self, rect):
        try:
            NSColor.whiteColor().set()
            NSRectFill(self.bounds())
            NSColor.blackColor().setFill()
            NSColor.blueColor().setStroke()
            p = NSBezierPath.bezierPath()
            xcursor = 0
            string = self.string
            master = self.master
            for s in range(0, len(string)):
                thisPath = NSBezierPath.bezierPath()
                gsglyph = master.font.glyphs[string[s]]
                layer = gsglyph.layers[master.id]
                thisPath.appendBezierPath_(layer.completeBezierPath)
                # print("X cursor was",xcursor)
                xcursor = xcursor - layer.bounds.origin.x
                # print("Moving backwards", layer.bounds.origin.x)
                t = NSAffineTransform.transform()
                t.translateXBy_yBy_(xcursor, -master.descender)
                thisPath.transformUsingAffineTransform_(t)
                # print("Drawing at",xcursor)
                # print(thisPath)
                xcursor = xcursor + layer.bounds.origin.x
                xcursor = xcursor + layer.bounds.size.width
                # print("Adding width", layer.bounds.size.width)
                if s < len(string) - 1:
                    xcursor = xcursor + self.distances[(string[s],
                                                        string[s + 1])]
                p.appendBezierPath_(thisPath)

            t = NSAffineTransform.transform()
            if xcursor > 0:
                vscale = self.bounds().size.height / (master.ascender -
                                                      master.descender)
                hscale = self.bounds().size.width / xcursor
                t.scaleBy_(min(hscale, vscale))
                p.transformUsingAffineTransform_(t)
            p.fill()
        except:
            print("Oops!", sys.exc_info()[0], "occured.")
            traceback.print_exc(file=sys.stdout)
Пример #14
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)
Пример #15
0
 def drawWithFrame_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)
     placardBorderColor.set()
     path.stroke()
     # draw segments
     x, y = frame.origin
     h = frame.size[1]
     for index in range(self.segmentCount()):
         w = self.widthForSegment_(index)
         self.drawSegment_inFrame_withView_(index, ((x, y), (w, h)), view)
         x += w
Пример #16
0
	def drawRect_(self, rect):
		# self._layer.drawInFrame_(bounds)  # used in Georgs GlyphView
		try:
			bounds = self.bounds()
			NSColor.textBackgroundColor().set()
			NSRectFill(bounds)
			scaleFactor = self._scaleFactor

			thisGlyph = self._layer.parent
			layerWidth = self._layer.width * scaleFactor
			descender = self._layer.glyphMetrics()[3] * scaleFactor
			ascender = self._layer.glyphMetrics()[1] * scaleFactor

			## This order is important! Wont work the other way around.
			bezierPathOnly = self._layer.bezierPath # Path Only
			if bezierPathOnly is not None:
				bezierPathOnly = bezierPathOnly.copy()
			bezierPathWithComponents = self._layer.completeBezierPath  # Path & Components
			bezierPathOpenWithComponents = self._layer.completeOpenBezierPath  # Path & Components
			
			# Set the scale
			#--------------
			scale = NSAffineTransform.transform()
			scale.translateXBy_yBy_((bounds.size.width - layerWidth) / 2.0, (bounds.size.height - ascender + descender) / 2.0 - descender)
			scale.scaleBy_(scaleFactor)
			
			
			# Draw only path in black
			#------------------------
			if thisGlyph.export:
				pathColor = NSColor.textColor()
				componentColor = NSColor.secondaryLabelColor()
			else:
				pathColor = NSColor.orangeColor()
				componentColor = NSColor.orangeColor()
				
			if bezierPathWithComponents:
				bezierPathWithComponents.transformUsingAffineTransform_(scale)
				componentColor.set() # Draw components in gray
				bezierPathWithComponents.fill()
			if bezierPathOnly:
				pathColor.set()
				bezierPathOnly.transformUsingAffineTransform_(scale)
				bezierPathOnly.fill()
			if bezierPathOpenWithComponents:
				pathColor.set()
				bezierPathOpenWithComponents.transformUsingAffineTransform_(scale)
				bezierPathOpenWithComponents.stroke()
			# Draw non-exported glyphs in orange
			#-----------------------------------
			else:
				NSColor.orangeColor().set()
				bezierPathWithComponents.transformUsingAffineTransform_(scale)
				bezierPathWithComponents.fill()
			
			attributes = {}
			attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(14)
			attributes[NSForegroundColorAttributeName] = NSColor.secondaryLabelColor()
			
			thisLKG = thisGlyph.leftKerningGroup
			thisRKG = thisGlyph.rightKerningGroup
			if thisLKG is not None:
				String = NSAttributedString.alloc().initWithString_attributes_(thisLKG, attributes)
				String.drawAtPoint_alignment_((12, 5), 0)
			if thisRKG is not None:
				String = NSAttributedString.alloc().initWithString_attributes_(thisRKG, attributes)
				String.drawAtPoint_alignment_((bounds.size.width - 12, 5), 2)

			# AUTO-WIDTH LABEL
			#-----------------
			if self._layer.hasAlignedWidth():
				attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor()
				attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(11)
				String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes)
				String.drawAtPoint_alignment_((bounds.size.width / 2.0, 5), 1)
		except:
			print(traceback.format_exc())
Пример #17
0
 def drawRectRightToLeft_(self, rect):
     self._alternateRects = {}
     # draw the background
     bounds = self.bounds()
     self._backgroundColor.set()
     NSRectFill(bounds)
     # create some reusable values
     scale = self._scale
     descender = self._descender
     upm = self._upm
     scrollWidth = bounds.size[0]
     # offset for the buffer
     ctx = NSGraphicsContext.currentContext()
     ctx.saveGraphicsState()
     aT = NSAffineTransform.transform()
     aT.translateXBy_yBy_(scrollWidth - self._bufferLeft, self._bufferTop)
     aT.concat()
     # offset for the descender
     aT = NSAffineTransform.transform()
     aT.scaleBy_(scale)
     aT.translateXBy_yBy_(0, descender)
     aT.concat()
     # flip
     flipTransform = NSAffineTransform.transform()
     flipTransform.translateXBy_yBy_(0, upm)
     flipTransform.scaleXBy_yBy_(1.0, -1.0)
     flipTransform.concat()
     # set the glyph color
     self._glyphColor.set()
     # draw the records
     left = scrollWidth - self._bufferLeft
     bottom = self._bufferTop
     height = upm * scale
     previousXA = 0
     for recordIndex, glyphRecord in enumerate(reversed(
             self._glyphRecords)):
         glyph = glyphRecord.glyph
         w = glyphRecord.advanceWidth
         h = glyphRecord.advanceHeight
         xP = glyphRecord.xPlacement
         yP = glyphRecord.yPlacement
         xA = glyphRecord.xAdvance
         yA = glyphRecord.yAdvance
         # handle offsets from the record
         bottom += yP * scale
         glyphHeight = height + ((h + yA) * scale)
         glyphLeft = left + ((-w + xP - xA) * scale)
         glyphWidth = (-w - xA) * scale
         # store the glyph rect for the alternate menu
         rect = ((glyphLeft, bottom), (glyphWidth, glyphHeight))
         self._alternateRects[rect] = recordIndex
         self._currentZeroZeroPoint = NSPoint(
             glyphLeft, bottom + height + (descender * scale))
         # handle the placement
         aT = NSAffineTransform.transform()
         if xP:
             xP += previousXA
         aT.translateXBy_yBy_(-w - xA + xP, yP)
         aT.concat()
         # draw the glyph
         rect = ((-w + xA - xP, descender - yP), (w, upm))
         self.drawGlyph(glyph, rect, alternate=bool(glyphRecord.alternates))
         # shift for the next glyph
         aT = NSAffineTransform.transform()
         aT.translateXBy_yBy_(-xP, h + yA - yP)
         aT.concat()
         left += (-w - xP - xA) * scale
         previousXA = xA
     ctx.restoreGraphicsState()
Пример #18
0
 def drawRect_(self, rect):
     HUDWindowLineColor.set()
     NSRectFill(rect)
Пример #19
0
 def drawRect_(self, rect):
     if self.background_color:
         self.background_color.set()
         NSRectFill(rect)
Пример #20
0
    def drawHashMarksAndLabelsInRect_(self, rect):
        bounds = self.bounds()
        view = self.clientView()

        rulerBackgroundColor = self.rulerBackgroundColor()
        if rulerBackgroundColor is not None:
            rulerBackgroundColor.set()
            NSRectFill(bounds)

        if not isinstance(view, NSTextView):
            return

        layoutManager = view.layoutManager()
        container = view.textContainer()
        text = view.string()
        nullRange = NSMakeRange(NSNotFound, 0)
        yinset = view.textContainerInset().height
        visibleRect = self.scrollView().contentView().bounds()
        textAttributes = self.textAttributes()

        lines = self.lineIndices()

        glyphRange = layoutManager.glyphRangeForBoundingRect_inTextContainer_(
            visibleRect, container)
        _range = layoutManager.characterRangeForGlyphRange_actualGlyphRange_(
            glyphRange, None)[0]
        _range.length += 1

        count = len(lines)
        index = 0

        lineNumber = self.lineNumberForCharacterIndex_inText_(
            _range.location, text)

        for line in range(lineNumber, count):
            index = lines[line]
            if NSLocationInRange(index, _range):
                rects, rectCount = layoutManager.rectArrayForCharacterRange_withinSelectedCharacterRange_inTextContainer_rectCount_(
                    NSMakeRange(index, 0), nullRange, container, None)
                if rectCount > 0:
                    ypos = yinset + NSMinY(rects[0]) - NSMinY(visibleRect)
                    labelText = NSString.stringWithString_("%s" % (line + 1))
                    stringSize = labelText.sizeWithAttributes_(textAttributes)

                    x = NSWidth(bounds) - stringSize.width - self.RULER_MARGIN
                    y = ypos + (NSHeight(rects[0]) - stringSize.height) / 2.0
                    w = NSWidth(bounds) - self.RULER_MARGIN * 2.0
                    h = NSHeight(rects[0])

                    labelText.drawInRect_withAttributes_(
                        NSMakeRect(x, y, w, h), textAttributes)

            if index > NSMaxRange(_range):
                break

        path = NSBezierPath.bezierPath()
        path.moveToPoint_(
            (bounds.origin.x + bounds.size.width, bounds.origin.y))
        path.lineToPoint_((bounds.origin.x + bounds.size.width,
                           bounds.origin.y + bounds.size.height))
        NSColor.grayColor().set()
        path.stroke()
Пример #21
0
 def drawBackground(self):
     self._backgroundColor.set()
     NSRectFill(self.bounds())