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): 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): """ 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()