def getColorsFromDoc(): """returns a list ("name", c,y,m,k) get all the colors of that doc. """ #get a list of al the colornames scribus.statusMessage("Reading Colors...") try: colorlist = scribus.getColorNames() scribus.progressTotal(len(colorlist)) i=0 colordata=[] for color in colorlist: colorvalues=scribus.getColor(color) c=int(colorvalues[0]/2.55) #convert values from 0-255 to 0-100 m=int(colorvalues[1]/2.55) y=int(colorvalues[2]/2.55) k=int(colorvalues[3]/2.55) name=color.strip() #eliminate leading and tailing whitespace cd = [name,c ,m,y,k] colordata.append(cd) i=i+1 scribus.progressSet(i) return colordata except: scribus.messageBox("color2csv", "Can not retrieve colors - There is no Document", icon=scribus.ICON_WARNING) sys.exit()
def extract_colors(): """ Extract and return all colors in the current document. """ colors = [] names = scribus.getColorNames() for name in names: cyan, magenta, yellow, black = scribus.getColor(name) is_spot = scribus.isSpotColor(name) colors.append(color_def("cmyk", (cyan, magenta, yellow, black), name)) return colors
def getColors(): """gets the colors and returns a list[name,c,m,y,k]""" colorNames=scribus.getColorNames() list=[] scribus.statusMessage("Reading Colors...") stepsTotal=len(colorNames) scribus.progressTotal(stepsTotal) steps=0 for name in colorNames: color=scribus.getColor(name) listitem=[name, color[0], color[1], color[2], color[3]] list.append(listitem) #update progress bar steps=steps+1 scribus.progressSet(steps) return list
def drawColor(colorname, h, v, width, height): # h horizontal position, v vertical position """draws a color chart field with its caption for the given colorname at the h and v position """ # get cmyk values and convert them to 0 - 255 values color = scribus.getColor(colorname) c = int(round(color[0] / 2.55)) m = int(round(color[1] / 2.55)) y = int(round(color[2] / 2.55)) k = int(round(color[3] / 2.55)) # get rgb color rgbcolor = scribus.getColorAsRGB(colorname) r = rgbcolor[0] g = rgbcolor[1] b = rgbcolor[2] # get webcolor webcolor = rgbhex(r, g, b) # but String for Textbox together colorDisplay = colorname if scribus.isSpotColor(colorname): colorDisplay += " (Spot Color)" colorstring = "%s\nC %i, M %i, Y %i, K %i, \nR %i, G %i, B %i \nRGB: %s" % ( colorDisplay, c, m, y, k, r, g, b, webcolor, ) # draw rectangle and set colors rect = scribus.createRect(h, v, width, height) scribus.setFillColor(colorname, rect) # if total amount of color is < 20 draw outline in Black for rectangle, else in same color if c + m + y + k < 20: scribus.setLineColor("Black", rect) else: scribus.setLineColor(colorname, rect) # create textbox and insert text textbox = scribus.createText(h + width + 5, v, 50, height) # set proper font size scribus.setFontSize(11, textbox) scribus.setTextAlignment(scribus.ALIGN_LEFT, textbox) # load the string into the textbox scribus.insertText(colorstring, 0, textbox)
import scribus # print dir(scribus) colorNames = scribus.getColorNames() for name in colorNames: color = scribus.getColor(name) print "%s %s" % (name, color) scribus.changeColor(name, 1, 2, 4, 5)