예제 #1
0
def prepareDocument():
    """creates the new document, sets up colors """
    colorList = getColorsFromDocument()
    spotDict = getSpotColors()
    scribus.statusMessage("Preparing new document...")
    scribus.newDocument(scribus.PAPER_A4,  (15,15,  20, 20),  scribus.PORTRAIT, 1, scribus.UNIT_POINTS,  scribus.PAGE_1, 0, 1) 
    scribus.setUnit(scribus.UNIT_MILLIMETERS)
    #delete existing colors
    cols = scribus.getColorNames()
    for col in cols:
        scribus.deleteColor(col, "None")

    #create our new colors
    for color in colorList:
        cname=color[0]
        c = int(color[1])
        m = int(color[2])
        y = int(color[3])
        k = int(color[4])
        scribus.defineColorCMYK(cname,  c, m, y, k )
        if spotDict.has_key(cname):
            scribus.setSpotColor(cname, spotDict[cname])

    #get the pageTitle form user and store it in PageTitle
    global pageTitle
    pageTitle=scribus.valueDialog("ColorChart by Sebastian Stetter", "Please enter document title", "Scribus COLOR CHART")
    drawHeaderFooter(pageTitle)
예제 #2
0
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()
예제 #3
0
def main(argv):
    """Translate imported RGB colors to CMYK colors."""
    #########################
    #  YOUR CODE GOES HERE  #
    #########################
    if scribus.haveDoc():
        clrs = scribus.getColorNames()
        newname = ""
        for clr in clrs:
            if clr.find("From") == 0:
                cmyk = scribus.getColor(clr)
                c = cmyk[0]
                cd = c * 100 / 255
                ca = "c" + str(cd)
                m = cmyk[1]
                md = m * 100 / 255
                ma = "m" + str(md)
                y = cmyk[2]
                yd = y * 100 / 255
                ya = "y" + str(yd)
                k = cmyk[3]
                kd = k * 100 / 255
                ka = "k" + str(kd)
                newname = ca + ma + ya + ka
                scribus.defineColor(newname, c, m, y, k)
                scribus.replaceColor(clr, newname)
                scribus.deleteColor(clr, newname)
예제 #4
0
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()
예제 #5
0
def getSpotColors():
    """ Get spot colors from an original document.
        Must be called after getColorsFromDocument().
    """
    ret = {}
    for color in scribus.getColorNames():
        ret[color] = scribus.isSpotColor(color)
    return ret
예제 #6
0
def getColorDict():
    """get the colors that already exist from the opened Document and return a dictionary"""
    colornames = scribus.getColorNames()
    scribus.progressTotal(len(colornames))
    colordict={}
    for name in colornames:
        colordict[name]=None

    return colordict #we can ask this dict if the color already exists
예제 #7
0
def getColorDict():
    """get the colors that already exist from the opened Document and return a dictionary"""
    scribus.statusMessage("Reading existing colors...")
    colornames = scribus.getColorNames()
    scribus.progressTotal(len(colornames))
    i = 0
    colordict = {}
    for name in colornames:
        colordict[name] = None
        i = i + 1
        scribus.progressSet(i)
    return colordict  #we can ask this dict if the color already exists
예제 #8
0
def getColorDict():
    """get the colors that already exist from the opened Document and return a dictionary"""
    scribus.statusMessage("Reading existing colors...")
    colornames = scribus.getColorNames()
    scribus.progressTotal(len(colornames))
    i=0
    colordict={}
    for name in colornames:
        colordict[name]=None
        i=i+1
        scribus.progressSet(i)
    return colordict #we can ask this dict if the color already exists
예제 #9
0
def main():
    if not scribus.haveDoc():
        return

    for color_name in scribus.getColorNames():
        if not color_name.startswith(('FromSVG', 'FromPDF')):
            continue
        c, m, y, k = scribus.getColor(color_name)
        cmyk_name = color_name[0:8]
        cmyk_name += f"{c*100//255:02x}{m*100//255:02x}{y*100//255:02x}{k*100//255:02x}"
        scribus.defineColor(cmyk_name, c, m, y, k)
        scribus.deleteColor(color_name, cmyk_name)
예제 #10
0
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
예제 #11
0
 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
예제 #12
0
def processColors(xlat):
    if xlat is None:
        return
    logger.info('! process colors')

    rclean = re.compile(r'[{}]')
    # rcmyk = re.compile(r'[(]*([\d\s,]+)[)]*')
    rcmyk = re.compile(r'[(]*(?:(\d+)[\%\s,]*)[)]*')

    try:
        colcodes = [
            rclean.sub('', n) for n in scribus.getColorNames()
            if '{' in n and '}' in n
        ]

        logger.info("..colcodes %s", str(colcodes))

        for i in colcodes:
            logger.info('..%s => %s', i, xlat[i])

        cn = {
            name: map(int, rcmyk.findall(xlat[name]))
            for name in colcodes if name in xlat and ',' in xlat[name]
        }

        logger.info("..colors xlat %s ", str(cn))

        for name, val in cn.iteritems():
            cname = '{{%s}}' % name
            scribus.changeColor(cname, *val)
            logger.info('...replaced color %s => (%s)', cname, xlat[name])

    except scribus.ScribusException:
        logger.error('..scribus failed: %s', sys.exc_info()[1].message)
    except StandardError:
        logger.error('..standard error: %s', sys.exc_info()[1].message)
예제 #13
0
def createChart():
    """actually handles the whole chart creation process"""
    prepareDocument()
    # get page size
    pageSize=scribus.getPageSize()
    pageWidth=pageSize[0]
    pageHeight=pageSize[1]
    #pageMargins
    pageMargins=scribus.getPageMargins()
    topMargin=pageMargins[0]
    leftMargin=pageMargins[1]
    rightMargin=pageMargins[2]
    bottomMargin=pageMargins[3]

    #color field dimensions
    colorFieldWidth= pageWidth - leftMargin - rightMargin - (TEXT_BOX_WIDTH+HSPACE) #50+5 is the with of the textbox plus the space between textbox and colorfield

    #how much space does one field use?
    vSpaceUsedByField = COLOR_FIELD_HEIGHT+VSPACE

    #how much space is available per row?
    vSpaceAvailable=pageHeight-topMargin-bottomMargin-HEADERSIZE-FOOTERSIZE

    #counts the colorFields created for a page. reset this variable after creation of new page
    colorFieldCounter=0

    #get list of all colors in document
    colorList = scribus.getColorNames()
    #prepare the progressbar
    colorNumber=len(colorList)
    scribus.progressTotal(colorNumber)
    #@TODO: implement possibility to abort script (button2=scribus.BUTTON_CANCEL) buttons should return int 1 or 2
    #scribus.messageBox("ColorChart Script by Sebastian Stetter", "...going to create a chart of "+str(colorNumber)+" colors.\n This may take a while.",  button1 = scribus.BUTTON_OK)
    scribus.statusMessage("Drawing color fields...")
    stepCompleted=0
    #disable redrawing for better performance
    scribus.setRedraw(False)
    for color in colorList:
        if (vSpaceUsedByField * (colorFieldCounter+1)) <= vSpaceAvailable:
            # when there is enought space left draw a color field...

            #calculate Position for new colorField
            h=leftMargin
            v=topMargin + (vSpaceUsedByField * colorFieldCounter)+HEADERSIZE
            #draw the colorField
            drawColor(color, h, v,  colorFieldWidth, COLOR_FIELD_HEIGHT)
            colorFieldCounter = colorFieldCounter+1
            #update progressbar
            stepCompleted = stepCompleted+1
            scribus.progressSet(stepCompleted)
        else:
            #not enough space? create a new page!
            createPage()
            #reset the colorFieldCounter to '0' since we created a new page
            colorFieldCounter = 0
            h=leftMargin
            v=topMargin + (vSpaceUsedByField * colorFieldCounter)+HEADERSIZE
            drawColor(color, h, v,  colorFieldWidth, COLOR_FIELD_HEIGHT)
            colorFieldCounter = colorFieldCounter+1

            #update progressbar
            stepCompleted = stepCompleted+1
            scribus.progressSet(stepCompleted)

    #make shure pages are redrawn
    scribus.setRedraw(True)
# add the baseline grid (when it's not too close to a guide)
baseline_start = 0 # in mm
baseline = 14.4 # in pt

multiplicator = 10000
baseline = int(baseline * 0.352777 * multiplicator) # 14.4 pt in mm
#baseline = int(baseline * 0.351459 * multiplicator) # 14.4 pt in mm

if baseline > 0 :
  guide_i = 0
  guide_list = scribus.getHGuides()
  guide_list.append(page[1])
  guide = guide_list[guide_i]
  guide_n = len(guide_list)
  if not 'Gray' in scribus.getColorNames() :
      scribus.defineColor('Gray', 10, 10, 10, 10)
  for item in range(baseline + baseline_start*multiplicator, int(page[1] * multiplicator + baseline_start*multiplicator), baseline) :
    # print item/multiplicator
    while guide_i < guide_n - 1 and item/multiplicator > guide + 0.15 :
        guide_i = guide_i + 1
        guide = guide_list[guide_i]
    if item/multiplicator < guide - 0.15 :
        line = scribus.createLine(0, item/multiplicator , page[0], item/multiplicator)
        scribus.setLineColor('Gray', line)
        scribus.setLineWidth(0.6, line)
        # scribus.setLineStyle(scribus.LINE_DASHDOT, line)


# add the page margins
rectangle = scribus.createRect(margin[1], margin[0], (page[0] - margin[1] - margin[2]), (page[1] - margin[0] - margin[3]))
예제 #15
0
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)