def createCPALfromMasterColors( theseMasters, indexOfTargetMaster ): # create color palette: palette = NSMutableArray.alloc().init() # go through all masters and collect their color info: for thisMaster in theseMasters: # query master color: colorString = thisMaster.customParameters["Master Color"] # black as fallback: if not colorString: colorString = "0,0,0,255" # derive RGBA values: r,g,b,a = [float(value)/255 for value in colorString.split(",") ] # create SRGB color: color = NSColorSpaceColor.colorWithRed_green_blue_alpha_(r,g,b,a) color = color.colorUsingColorSpace_(NSColorSpace.sRGBColorSpace()) # and add it to the palette: palette.addObject_( color ) # create array of palettes, containing the one palette we just created: paletteArray = NSMutableArray.alloc().initWithObject_(palette) print("Created CPAL palette with %i colors." % len(theseMasters)) # add that array as "Color Palettes" parameter to target (=usually first) master targetMaster = theseMasters[indexOfTargetMaster] targetMaster.customParameters["Color Palettes"] = paletteArray del targetMaster.customParameters["Master Color"]
def copy(self): nscolor = panel.color().colorUsingColorSpace_(NSColorSpace.deviceRGBColorSpace()) r = nscolor.redComponent() g = nscolor.greenComponent() b = nscolor.blueComponent() a = panel.alpha() color = r,g,b,a copy_to_clipboard({ "hex": color_to_hex, "uicolor": color_to_uicolor, "rgba": color_to_rgba, "rgb": color_to_rgb }.get(format, color_to_hex)(color)) self.close()
def copy(self): nscolor = panel.color().colorUsingColorSpace_( NSColorSpace.deviceRGBColorSpace()) r = nscolor.redComponent() g = nscolor.greenComponent() b = nscolor.blueComponent() a = panel.alpha() color = r, g, b, a copy_to_clipboard({ "hex": color_to_hex, "uicolor": color_to_uicolor, "rgba": color_to_rgba, "rgb": color_to_rgb }.get(format, color_to_hex)(color)) self.close()
def drawPath(path=None): # draws the path if path is None: path = currentPath if currentFillColor is not None: currentFillColor.set() path.fill() if currentGradient is not None: save() path.addClip() (gradientType, startPoint, endPoint, colors, locations) = currentGradient NSColors = [] for color in colors: a = 1 g = None if len(color) == 1: r = color[0] elif len(color) == 2: r, a = color elif len(color) == 3: r, g, b = color elif len(color) == 4: r, g, b, a = color if g is not None: NSColors.append( NSColor.colorWithCalibratedRed_green_blue_alpha_( r, g, b, a)) else: NSColors.append(NSColor.colorWithCalibratedWhite_alpha_(r, a)) gradient = NSGradient.alloc().initWithColors_atLocations_colorSpace_( NSColors, locations, NSColorSpace.deviceRGBColorSpace()) if gradientType == "linear": gradient.drawFromPoint_toPoint_options_( startPoint, endPoint, NSGradientDrawsBeforeStartingLocation | NSGradientDrawsAfterEndingLocation) elif gradient.gradientType == "radial": pass restore() if currentStrokeWidth is not None: path.setLineWidth_(currentStrokeWidth) if currentStrokeColor is not None: currentStrokeColor.set() path.stroke()
def drawPath(path=None): # draws the path if path is None: path = currentPath if currentFillColor is not None: currentFillColor.set() path.fill() if currentGradient is not None: save() path.addClip() (gradientType, startPoint, endPoint, colors, locations) = currentGradient NSColors = [] for color in colors: a = 1 g = None if len(color) == 1: r = color[0] elif len(color) == 2: r, a = color elif len(color) == 3: r, g, b = color elif len(color) == 4: r, g, b, a = color if g is not None: NSColors.append(NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a)) else: NSColors.append(NSColor.colorWithCalibratedWhite_alpha_(r, a)) gradient = NSGradient.alloc().initWithColors_atLocations_colorSpace_(NSColors, locations, NSColorSpace.deviceRGBColorSpace()) if gradientType == "linear": gradient.drawFromPoint_toPoint_options_(startPoint, endPoint, NSGradientDrawsBeforeStartingLocation | NSGradientDrawsAfterEndingLocation) elif gradient.gradientType == "radial": pass restore() if currentStrokeColor is not None: currentStrokeColor.set() path.stroke()