def drawWithFrame_inView_(self, frame, view): if hasattr(self, '_path'): if not hasattr(self, '_image'): self._image = self._callbackTarget.imageForPath_(self._path) self.setTitle_(self._callbackTarget.titleForPath_(self._path)) self._checkCell.setIntValue_(self._callbackTarget.stateForPath_(self._path)) x = frame.origin.x y = frame.origin.y + 1 height = frame.size.height - 1 if self.state() or self.isHighlighted(): highlight_rect = NSMakeRect(x, y, frame.size.width, height) if view.needsToDrawRect_(highlight_rect): self.highlightColorInView_(view).set() NSBezierPath.bezierPathWithRect_(highlight_rect).fill() x += CHECK_CELL_LEFT_PADDING checkCellSize = self._checkCell.cellSize() check_cell_rect = NSMakeRect(x, y, checkCellSize.width, height) if view.needsToDrawRect_(check_cell_rect): self._checkCell.drawWithFrame_inView_(check_cell_rect, view) x += checkCellSize.width - 1 imageSize = self._image.size() image_rect = NSMakeRect(x, y, imageSize.width, imageSize.height) if view.needsToDrawRect_(image_rect): self._image.drawInRect_fromRect_operation_fraction_(image_rect, NSZeroRect, NSCompositeSourceOver, 1.0) x += imageSize.width + 4 rest_of_cell_rect = NSMakeRect(x, y, frame.size.width - x, height) if view.needsToDrawRect_(rest_of_cell_rect): super(SelectiveSyncBrowserCell, self).drawWithFrame_inView_(rest_of_cell_rect, view) else: super(SelectiveSyncBrowserCell, self).drawWithFrame_inView_(frame, view)
def drawRect_(self, rect): if not self.border: return super(ThumbnailBoxView, self).drawRect_(rect) with save_graphics_state(): self._shadow.set() NSColor.whiteColor().set() NSBezierPath.bezierPathWithRect_(NSInsetRect(rect, self.BORDER_INSET, self.BORDER_INSET)).fill() size = self.image().size() self.image().drawInRect_fromRect_operation_fraction_(NSInsetRect(rect, self.IMAGE_INSET, self.IMAGE_INSET), NSMakeRect(*rect_to_centered_square(size.width, size.height)), NSCompositeSourceOver, 1.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()
def draw(self, rect): #NSColor.redColor().set() yellowColor.set() for n in range(50): rgba(random(), random(), random()) rect = NSMakeRect(n * 400 + M, n * 400 + M, M, M) path = NSBezierPath.bezierPathWithRect_(rect) path.fill()
def draw(self, scale): if self.isDragging() and self.pStart and self.pEnd: r = self.getMarqueRect() if r: color = getDefaultColor('glyphViewSelectionMarqueColor') color.set() path = NSBezierPath.bezierPathWithRect_(r) path.fill() return self.drawSelection(scale)
def drawWithFrame_inView_(self, frame, view): frame.origin.x -= 1 frame.size.width += 2 frame.origin.y -= 2 frame.size.height += 2 textFrame = NSInsetRect(frame, 2, 2) text = self.objectValue() color = getColorDefault("PyDEBackgroundColor", fallbackBackgroundColor) color.set() NSBezierPath.bezierPathWithRect_(frame).fill() if self.isHighlighted(): frame.origin.y += 1 frame.size.height -= 1 color = getColorDefault("PyDEHightLightColor", fallbackHightLightColor) color.set() NSBezierPath.bezierPathWithRect_(frame).fill() text.drawInRect_(textFrame)
def icon_setter(self, _=False): if (self.started or not _) and self.render_icon: p = (sum(self.current_passthrough_volume) / len(self.current_passthrough_volume) * 2.5) ** 0.25 if _ else 0 img = NSImage.alloc().initWithSize_((11, 26)) img.lockFocus() fp = NSBezierPath.bezierPathWithRect_(((2, 2), (7, 22))) NSColor.darkGrayColor().set() fp.fill() rp = NSBezierPath.bezierPathWithRect_(((3, 3), (5, p * 20))) if p > 0.90: NSColor.colorWithRed_green_blue_alpha_((0.5 if self.dark else 1), 0.15, 0.15, 1).set() elif p > 0.60: NSColor.\ colorWithRed_green_blue_alpha_((0.5 if self.dark else 1), (0.5 if self.dark else 0.9), 0, 1).set() else: NSColor.colorWithRed_green_blue_alpha_(0, (0 if self.dark else 1), (0.5 if self.dark else 0), 1).set() rp.fill() img.unlockFocus() self._icon_nsimage = img try: self._nsapp.setStatusBarIcon() except AttributeError: pass
def _drawTextLabel(self, transform, text, size, vector, percent=1.0): if text is None: return if vector is None: vector = (-1, 1) angle = atan2(vector[0], -vector[1]) text_size = 0.5 * size # para_style = NSMutableParagraphStyle.alloc().init() # para_style.setAlignment_(NSCenterTextAlignment) attrs = { NSFontAttributeName: NSFont.systemFontOfSize_(text_size), NSForegroundColorAttributeName: NSColor.colorWithCalibratedRed_green_blue_alpha_( text_color[0], text_color[1], text_color[2], text_color[3] * percent, ), # NSParagraphStyleAttributeName: para_style, } myString = NSString.string().stringByAppendingString_(text) bbox = myString.sizeWithAttributes_(attrs) bw = bbox.width bh = bbox.height text_pt = NSPoint() text_pt.y = 0 if -0.5 * pi < angle <= 0.5 * pi: text_pt.x = -1.3 * size - bw / 2 * cos(angle) - bh / 2 * sin(angle) else: text_pt.x = -1.3 * size + bw / 2 * cos(angle) + bh / 2 * sin(angle) text_pt = transform.transformPoint_(text_pt) rr = NSRect(origin=(text_pt.x - bw / 2, text_pt.y - bh / 2), size=(bw, bh)) if DEBUG: NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 0.15).set() myRect = NSBezierPath.bezierPathWithRect_(rr) myRect.setLineWidth_(0.05 * size) myRect.stroke() myString.drawInRect_withAttributes_(rr, attrs)
def drawImage(paths, foregroundColor, backgroundColor): image = NSImage.alloc().initWithSize_((19, 19)) 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
def _drawTextLabel(self, transform, text, size, vector): if vector is None: vector = (-1, 1) angle = atan2(vector[0], -vector[1]) text_size = 0.5 * size #para_style = NSMutableParagraphStyle.alloc().init() #para_style.setAlignment_(NSCenterTextAlignment) attrs = { NSFontAttributeName: NSFont.systemFontOfSize_(text_size), NSForegroundColorAttributeName: NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.4, 0.4, 0.6, 0.7 ), #NSParagraphStyleAttributeName: para_style, } myString = NSString.string().stringByAppendingString_(text) bbox = myString.sizeWithAttributes_(attrs) bw = bbox.width bh = bbox.height text_pt = NSPoint() text_pt.y = 0 if -0.5 * pi < angle <= 0.5 * pi: text_pt.x = -1.3 * size - bw / 2 * cos(angle) - bh / 2 * sin(angle) else: text_pt.x = -1.3 * size + bw / 2 * cos(angle) + bh / 2 * sin(angle) text_pt = transform.transformPoint_(text_pt) rr = NSRect( origin = (text_pt.x - bw / 2, text_pt.y - bh / 2), size = (bw, bh) ) if DEBUG: NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 0, 0.15 ).set() myRect = NSBezierPath.bezierPathWithRect_(rr) myRect.setLineWidth_(0.05 * size) myRect.stroke() myString.drawInRect_withAttributes_( rr, attrs )
def rect(x, y, width, height): # draws a rectangle drawPath(NSBezierPath.bezierPathWithRect_(NSMakeRect(x, y, width, height)))
def drawRect_(self, rect): NSColor.colorWithCalibratedWhite_alpha_(0.5, 0.5).set() p = NSBezierPath.bezierPathWithRect_(self.bounds()) p.fill()
def draw(self, rect): # Drawing delegate from the Canvas drawing evening for n in range(50): rgba(random(), random(), random()).set() rect = NSMakeRect(random() * 400 + M, random() * 400 + M, M, M) path = NSBezierPath.bezierPathWithRect_(rect) path.fill()
def drawDividerInRect_(self, rect): if self.dividerThickness() > 2: super(SimpleNSSplitView, self).drawDividerInRect_(rect) else: NSColor.colorWithCalibratedWhite_alpha_(0, .42).set() NSBezierPath.bezierPathWithRect_(rect).fill()
def drawWithFrame_inView_(self, frame, view): color = self.objectValue() color.set() rect = NSInsetRect(frame, 2, 2) NSBezierPath.bezierPathWithRect_(rect).fill()
def __init__(self, canvas=None, image=None): self.canvas = canvas self.gradient = None self.image = image self.color = None self.clip = NSBezierPath.bezierPathWithRect_(self.rect())
def drawRect_(self, rect): NSColor.whiteColor().set() NSBezierPath.bezierPathWithRect_(NSRect((0, 0), self.frame().size)).fill() NSGraphicsContext.currentContext().CIContext().drawImage_atPoint_fromRect_(self._filter.valueForKey_('outputImage'), (0, 0), self.image.extent())