def initWithFrame_(self, frame): """ basic constructor for views. here we init colors and gradients """ self = super(CBGraphView, self).initWithFrame_(frame) if self: self.gradientGray = NSColor.colorWithCalibratedRed_green_blue_alpha_(50/255.0, 50/255.0, 50/255.0, 1.0) self.lineColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(33/255.0, 104/255.0, 198/255.0, 1.0) self.lineColorAboveLimit = NSColor.redColor() self.borderColor = NSColor.whiteColor() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_(NSColor.blackColor(), self.gradientGray) self.grad.retain() return self
def colorForParameterValue( self, parameterString ): """ Turns '0.3;0.4;0.9' into RGB values and returns an NSColor object. """ try: # default color: RGBA = [ 0.4, 0.0, 0.3, 0.15 ] # if set, take user input as color: if parameterString is not None: parameterValues = parameterString.split(";") for i in range(len( parameterValues )): thisValueString = parameterValues[i] try: thisValue = abs(float( thisValueString )) if thisValue > 1.0: thisValue %= 1.0 RGBA[i] = thisValue except Exception as e: pass # self.logToConsole( "Could not convert '%s' (from '%s') to a float. Keeping default." % (thisValueString, parameterString) ) # return the color: thisColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( RGBA[0], RGBA[1], RGBA[2], RGBA[3] ) return thisColor except Exception as e: self.logToConsole( "colorForParameterValue: %s" % str(e) )
def colorForParameterValue(self, parameterString): """ Turns '0.3;0.4;0.9' into RGB values and returns an NSColor object. """ try: # default color: RGBA = [0.4, 0.0, 0.3, 0.15] # if set, take user input as color: if parameterString is not None: parameterValues = parameterString.split(";") for i in range(len(parameterValues)): thisValueString = parameterValues[i] try: thisValue = abs(float(thisValueString)) if thisValue > 1.0: thisValue %= 1.0 RGBA[i] = thisValue except Exception as e: pass # self.logToConsole( "Could not convert '%s' (from '%s') to a float. Keeping default." % (thisValueString, parameterString) ) # return the color: thisColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( RGBA[0], RGBA[1], RGBA[2], RGBA[3]) return thisColor except Exception as e: self.logToConsole("colorForParameterValue: %s" % str(e))
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())
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())
def initWithFrame_(self, frame): """ basic constructor for views. here we init colors and gradients """ self = objc.super(CBGraphView, self).initWithFrame_(frame) if self: self.gradientGray = NSColor.colorWithCalibratedRed_green_blue_alpha_( 50 / 255.0, 50 / 255.0, 50 / 255.0, 1.0) self.lineColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 33 / 255.0, 104 / 255.0, 198 / 255.0, 1.0) self.lineColorAboveLimit = NSColor.redColor() self.borderColor = NSColor.whiteColor() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_( NSColor.blackColor(), self.gradientGray) self.grad.retain() return self
def scrollView(self): ''' Generate vanilla attribute ScrollView''' m = 10 bgColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(.96, .96, .96, 1) # NSColor.yellowColor() s = ScrollView((self.scrollViewMargin, self.scrollViewMargin, self.previewSize - self.scrollViewMargin*2, self.previewSize - self.scrollViewMargin*2), # with margins self.view, hasHorizontalScroller=False, hasVerticalScroller=False, backgroundColor=bgColor, # drawsBackground=False, ) return s
def show(self): BlinkLogger().log_debug('Show %s' % self) self.active = True if self.captureSession is None: # Find a video camera device = self.getDevice() if not device: return self.captureSession = AVCaptureSession.alloc().init() if self.captureSession.canSetSessionPreset_( AVCaptureSessionPresetHigh): self.captureSession.setSessionPreset_( AVCaptureSessionPresetHigh) NSWorkspace.sharedWorkspace().notificationCenter( ).addObserver_selector_name_object_( self, "computerDidWake:", NSWorkspaceDidWakeNotification, None) NSWorkspace.sharedWorkspace().notificationCenter( ).addObserver_selector_name_object_( self, "computerWillSleep:", NSWorkspaceWillSleepNotification, None) max_resolution = (0, 0) BlinkLogger().log_debug( "%s camera provides %d formats" % (device.localizedName(), len(device.formats()))) for desc in device.formats(): m = self.resolution_re.match(repr(desc)) if m: data = m.groupdict() width = int(data['width']) height = int(data['height']) BlinkLogger().log_debug( "Supported resolution: %dx%d %.2f" % (width, height, width / float(height))) if width > max_resolution[0]: max_resolution = (width, height) width, height = max_resolution if width == 0 or height == 0: width = 1280 height = 720 BlinkLogger().log_info( "Error: %s camera does not provide any supported video format" % device.localizedName()) else: if NSApp.delegate( ).contactsWindowController.sessionControllersManager.isMediaTypeSupported( 'video'): BlinkLogger().log_info( "Opened %s camera at %0.fx%0.f resolution" % (SIPApplication.video_device.real_name, width, height)) self.aspect_ratio = width / float( height) if width > height else height / float(width) self.captureDeviceInput = AVCaptureDeviceInput.alloc( ).initWithDevice_error_(device, None) if self.captureDeviceInput: try: self.captureSession.addInput_(self.captureDeviceInput[0]) except ValueError as e: BlinkLogger().log_info( 'Failed to add camera input to capture session: %s' % str(e)) return else: BlinkLogger().log_info('Failed to aquire input %s' % self) return self.setWantsLayer_(True) self.videoPreviewLayer = AVCaptureVideoPreviewLayer.alloc( ).initWithSession_(self.captureSession) self.layer().addSublayer_(self.videoPreviewLayer) self.videoPreviewLayer.setFrame_(self.layer().bounds()) self.videoPreviewLayer.setAutoresizingMask_( kCALayerWidthSizable | kCALayerHeightSizable) self.videoPreviewLayer.setBackgroundColor_( CGColorGetConstantColor(kCGColorBlack)) self.videoPreviewLayer.setVideoGravity_( AVLayerVideoGravityResizeAspectFill) self.videoPreviewLayer.setCornerRadius_(5.0) self.videoPreviewLayer.setMasksToBounds_(True) self.setMirroring() self.stillImageOutput = AVCaptureStillImageOutput.new() pixelFormat = NSNumber.numberWithInt_(kCVPixelFormatType_32BGRA) self.stillImageOutput.setOutputSettings_( NSDictionary.dictionaryWithObject_forKey_( pixelFormat, kCVPixelBufferPixelFormatTypeKey)) self.captureSession.addOutput_(self.stillImageOutput) if self.captureSession and self.videoPreviewLayer: BlinkLogger().log_info('Start aquire local video %s' % self) self.videoPreviewLayer.setBackgroundColor_( NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 0.4)) self.captureSession.startRunning()