def drawRect_(self, rect): myBounds = self.bounds() NSDrawLightBezel(myBounds, myBounds) # AppKit Function clipRect = NSBezierPath.bezierPathWithRect_(NSInsetRect(myBounds, 2.0, 2.0)) clipRect.addClip() # Draw graphics graphicsArray = self.graphics() if graphicsArray: for graphic in graphicsArray: graphicDrawingBounds = graphic.drawingBounds() if NSIntersectsRect(rect, graphicDrawingBounds): graphic.drawInView_(self) # Draw a red box around items in the current selection. # Selection should be handled by the graphic, but this is a # shortcut simply for display. currentSelectionIndexes = ( self.selectionIndexes() ) # ist das wir ein Array im Indezes? if currentSelectionIndexes is not None: path = NSBezierPath.bezierPath() index = currentSelectionIndexes.firstIndex() while index != NSNotFound: graphicDrawingBounds = graphicsArray[index].drawingBounds() if NSIntersectsRect(rect, graphicDrawingBounds): path.appendBezierPathWithRect_(graphicDrawingBounds) index = currentSelectionIndexes.indexGreaterThanIndex_(index) NSColor.redColor().set() path.setLineWidth_(1.5) path.stroke()
def drawRect_(self, rect): myBounds = self.bounds() NSDrawLightBezel(myBounds, myBounds) # AppKit Function clipRect = NSBezierPath.bezierPathWithRect_(NSInsetRect(myBounds, 2.0, 2.0)) clipRect.addClip() # Draw graphics graphicsArray = self.graphics() if graphicsArray: for graphic in graphicsArray: graphicDrawingBounds = graphic.drawingBounds() if NSIntersectsRect(rect, graphicDrawingBounds): graphic.drawInView_(self) # Draw a red box around items in the current selection. # Selection should be handled by the graphic, but this is a # shortcut simply for display. currentSelectionIndexes = self.selectionIndexes() # ist das wir ein Array im Indezes? if currentSelectionIndexes != None: path = NSBezierPath.bezierPath() index = currentSelectionIndexes.firstIndex() while index != NSNotFound: graphicDrawingBounds = graphicsArray[index].drawingBounds() if NSIntersectsRect(rect, graphicDrawingBounds): path.appendBezierPathWithRect_(graphicDrawingBounds) index = currentSelectionIndexes.indexGreaterThanIndex_(index) NSColor.redColor().set() path.setLineWidth_(1.5) path.stroke()
def drawRect_(self, rect): start = time.monotonic() f = self.frame() f.origin.x = f.origin.y = 0.0 self.backgroundColor.set() NSBezierPath.fillRect_(f) if self._rssi_values: hstep = f.size.width / len(self._rssi_values) vstep = f.size.height / 4096 self.maxRssiColor.set() max_rssi_y = int(self._max_rssi * vstep) path = NSBezierPath.bezierPath() path.moveToPoint_((0, max_rssi_y)) path.lineToPoint_((f.size.width, max_rssi_y)) path.stroke() path = NSBezierPath.bezierPath() x = 0.0 path.moveToPoint_((0, int(self._rssi_values[0] * vstep))) for v in self._rssi_values[1:]: x += hstep self._max_rssi = max(v, self._max_rssi) path.lineToPoint_((x, int(v * vstep))) self.graphColor.set() path.stroke() self.currentRSSI.setFloatValue_(v / 4096 * 3.3) self.rssiValuesPerSecond.setIntValue_( int(self._filtered_value_per_second)) if time.monotonic() - start > self.FRAMETIME: self._retained_samples = int(self._retained_samples * 0.95)
def drawRect_(self, rect): f = self.frame() f.origin.x = f.origin.y = 0.0 self.color.set() NSBezierPath.fillRect_(f) img = self.image_from_buffer() img.drawInRect_fromRect_operation_fraction_( f, ((0,0), (0, 0)), NSCompositeCopy, 1.0, )
def drawInView_(self, aView): # ignore aView here for simplicity... (xLoc, yLoc, radius, shadowOffset, shadowAngle) = (self.xLoc, self.yLoc, self.radius, self.shadowOffset, self.shadowAngle) circleBounds = NSMakeRect(xLoc-radius, yLoc-radius, radius*2, radius*2) # draw shadow if we'll see it shadow = NSShadow.alloc().init() if shadowOffset > 0.00001: shadowXOffset = sin(shadowAngle)*shadowOffset shadowYOffset = cos(shadowAngle)*shadowOffset shadow.setShadowOffset_(NSMakeSize(shadowXOffset,shadowYOffset)) shadow.setShadowBlurRadius_(shadowOffset) shadow.set() # draw circle circle = NSBezierPath.bezierPathWithOvalInRect_(circleBounds) myColor = self.color if myColor is None: myColor = NSColor.redColor() myColor.set() circle.fill() shadow.setShadowColor_(None) shadow.set()
def drawInView_(self, aView): # ignore aView here for simplicity... (xLoc, yLoc, radius, shadowOffset, shadowAngle) = ( self.xLoc, self.yLoc, self.radius, self.shadowOffset, self.shadowAngle, ) circleBounds = NSMakeRect(xLoc - radius, yLoc - radius, radius * 2, radius * 2) # draw shadow if we'll see it shadow = NSShadow.alloc().init() if shadowOffset > 0.00001: shadowXOffset = sin(shadowAngle) * shadowOffset shadowYOffset = cos(shadowAngle) * shadowOffset shadow.setShadowOffset_(NSMakeSize(shadowXOffset, shadowYOffset)) shadow.setShadowBlurRadius_(shadowOffset) shadow.set() # draw circle circle = NSBezierPath.bezierPathWithOvalInRect_(circleBounds) myColor = self.color if myColor is None: myColor = NSColor.redColor() myColor.set() circle.fill() shadow.setShadowColor_(None) shadow.set()
def drawRect_(self, rect): f = self.frame() f.origin.x = f.origin.y = 0.0 self.backgroundColor.set() NSBezierPath.fillRect_(f) padding_pixels = int(self.PADDING * f.size.width / (self.CHANNELS + 1)) bar_width = int((f.size.width - (self.CHANNELS + 1) * padding_pixels) / self.CHANNELS) vstep = f.size.height / 4096 self.barColor.set() left_padding = padding_pixels + (f.size.width - (bar_width + padding_pixels) * self.CHANNELS) // 2 for i, value in enumerate(self.channelValues): x = i * (bar_width + padding_pixels) + left_padding y = 0 h = int(value * vstep) r = ((x, y), (bar_width, h)) NSBezierPath.fillRect_(r)
def drawRect_(self, rect): f = self.frame() f.origin.x = f.origin.y = 0.0 color = NSColor.blackColor() color.set() NSBezierPath.fillRect_(f)
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()
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()