def create_content(): dirname = scribus.fileDialog("Select Directory", "", "", False, False, True) files = sorted(glob(os.path.join(dirname, "*"))) if len(files) == 0: return scribus.progressReset() scribus.progressTotal(len(files)) scribus.messagebarText("Creating pages...") progress = 0 for f in files: scribus.progressSet(progress) progress = progress + 1 add_image(f) if len(files) > progress: # add page for next image scribus.newPage(-1) scribus.progressReset() scribus.messagebarText("") scribus.deselectAll() scribus.gotoPage(1)
def main_wrapper(argv): try: scribus.statusMessage("Running script...") scribus.progressReset() main(argv) finally: if scribus.haveDoc(): scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset()
def main(): cache = defaultdict(dict) try: with open(CACHE_FILE, "rb") as cache_file: cache = defaultdict(dict, json.load(cache_file)) except: pass with open(DATA_FILE, "rb") as data_file: songs_data = json.load(data_file) with open(MANUEL_PROCESSING_FILE, "rb") as manual_file: manual_processing = defaultdict(dict, json.load(manual_file)) scribus.statusMessage("Running script...") scribus.progressReset() scribus.progressTotal(len(songs_data)) init() front_matter() add_page_number() # trying to get the best sorting # setting all songs to the max height all_songs = dict(zip(songs_data.keys(), [EFFECTIVE_PAGE_HEIGHT] * len(songs_data))) # update according to cache for song_name, data in cache.iteritems(): all_songs[song_name] = min(data.get("height", EFFECTIVE_PAGE_HEIGHT), EFFECTIVE_PAGE_HEIGHT) # let's see which songs should be set on a double sided page: songs_double_page = filter(lambda x: manual_processing[x].get("double_page", False), manual_processing) for double_page in songs_double_page: all_songs[double_page] = EFFECTIVE_PAGE_HEIGHT # all double page songs should get a whole page despite their height appendix_filter = lambda a_s, boolean : {k:v for k,v in a_s.iteritems() if manual_processing[k].get("appendix", False) == boolean} main_songs = appendix_filter(all_songs, False) add_songs(main_songs, songs_double_page, manual_processing, songs_data, cache) appendix_songs = appendix_filter(all_songs, True) add_songs(appendix_songs, songs_double_page, manual_processing, songs_data, cache) toc = [] for filename in filter(lambda s: manual_processing[s].get("show", True), all_songs.keys()): toc.append((songs_data[filename]["name"], cache[filename].get("page", "XX"))) toc.sort(key=lambda (x,y): x) create_toc(toc) if scribus.haveDoc(): scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset() with open(CACHE_FILE, "wb") as cache_file: json.dump(cache, cache_file, indent=2)
def main_wrapper(argv): try: scribus.statusMessage("Importing .csv table...") scribus.progressReset() main(argv) finally: #exit if scribus.haveDoc() > 0: scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset()
def main(argv): """This is a documentation string. Write a description of what your code does here. You should generally put documentation strings ("docstrings") on all your Python functions.""" ######################### # YOUR CODE GOES HERE # ######################### userdim = scribus.getUnit() # get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) cellwidthleft = 0 cellwidthright = 0 cellHeight = 0 pos = getPosition() while cellwidthleft <= 0: cellwidthL = scribus.valueDialog("Left Cell Width", "How wide (mm) do you wish left cells to be?", "30.0") cellwidthleft = float(cellwidthL) while cellwidthright <= 0: cellwidthR = scribus.valueDialog("Right Cell Width", "How wide (mm) do you wish right cells to be?", "30.0") cellwidthright = float(cellwidthR) while cellHeight <= 0: cellheight = scribus.valueDialog("Cell Height", "How tall (mm) do you wish cells to be?", "10.0") cellHeight = float(cellheight) data = getCSVdata() di = getDataInformation(data) hposition = pos[1] vposition = pos[0] objectlist = [] # here we keep a record of all the created textboxes so we can group them later i = 0 scribus.progressTotal(len(data)) scribus.setRedraw(False) for row in data: c = 0 for cell in row: cell = cell.strip() cellsize = cellwidthleft if c == 1: cellsize = cellwidthright textbox = scribus.createText(hposition, vposition, cellsize, cellHeight) # create a textbox objectlist.append(textbox) scribus.insertText(cell, 0, textbox) # insert the text into the textbox hposition = hposition + cellwidthleft # move the position for the next cell c = 1 vposition = vposition + cellHeight # set vertical position for next row hposition = pos[1] # reset vertical position for next row i = i + 1 scribus.progressSet(i) scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
def main_wrapper(argv): try: scribus.statusMessage("Running script...") scribus.progressReset() main(argv) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset()
def main(argv): rectColor = "Black" topMargin, leftMargin, rightMargin, bottomMargin = scribus.getPageMargins() pageWidth, pageHeight = scribus.getPageSize() printAreaWidth = pageWidth - leftMargin - rightMargin printAreaHeight = pageHeight - topMargin - bottomMargin vertRectW = random.randrange(2,4) vertRectH = random.randrange(48,50) horRectW = random.randrange(47,49) horRectH = random.randrange(2,5) startx = leftMargin endx = pageWidth - leftMargin - horRectW starty = topMargin endy = pageHeight - topMargin - vertRectH numberRectVert = random.randrange(400,600) numberRectHor = random.randrange(400,600) opacity = 0 scribus.progressTotal(numberRectVert+numberRectHor) scribus.setRedraw(False) for i in range(1, numberRectVert): opacity = opacity + 0.002 xpos = random.randrange(int(startx),int(endx)) ypos = random.randrange(int(starty),int(endy)) rect = scribus.createRect(xpos, ypos, vertRectW, vertRectH) scribus.setFillColor(rectColor, rect) scribus.setLineColor("None", rect) if opacity < 1: scribus.setFillTransparency(opacity, rect) scribus.progressSet(i*2) for i in range(1, numberRectVert): opacity = opacity + 0.002 xpos = random.randrange(int(startx),int(endx)) ypos = random.randrange(int(starty),int(endy)) recthor = scribus.createRect(xpos, ypos, horRectW, horRectH) scribus.setFillColor(rectColor, recthor) scribus.setLineColor("None", recthor) if opacity < 1: scribus.setFillTransparency(opacity, recthor) scribus.progressReset() scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
def main_wrapper(argv): try: if(scribus.haveDoc()): scribus.setRedraw(False) scribus.statusMessage(CONST.APP_NAME) scribus.progressReset() main(argv) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if(scribus.haveDoc()): scribus.setRedraw(True) scribus.statusMessage('') scribus.progressReset()
def main_wrapper(argv): try: if (scribus.haveDoc()): scribus.setRedraw(False) scribus.statusMessage(CONST.APP_NAME) scribus.progressReset() main(argv) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if (scribus.haveDoc()): scribus.setRedraw(True) scribus.statusMessage('') scribus.progressReset()
def main_wrapper(argv): """The main_wrapper() function disables redrawing, sets a sensible generic status bar message, and optionally sets up the progress bar. It then runs the main() function. Once everything finishes it cleans up after the main() function, making sure everything is sane before the script terminates.""" try: #scribus.statusMessage("Running script...") scribus.progressReset() main(argv) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset()
def main_wrapper(argv): try: if(scribus.haveDoc()): scribus.setRedraw(False) scribus.statusMessage(CONST.APP_NAME) scribus.progressReset() main(argv) else: scribus.messageBox('Usage Error', 'You need a Document open', icon=scribus.ICON_WARNING, button1=scribus.BUTTON_OK) sys.exit(2) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset()
def main_wrapper(): """The main_wrapper() function disables redrawing, sets a sensible generic status bar message, and optionally sets up the progress bar. It then runs the main() function. Once everything finishes it cleans up after the main() function, making sure everything is sane before the script terminates.""" scribus.messageBox("Version", SCRIPT_VERSION) if not scribus.haveDoc(): scribus.messageBox("Bwaaaahaha", "Need a base document open") else: scribus.setRedraw(False) try: scribus.statusMessage("Running script...") scribus.progressReset() main() finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.docChanged(True) scribus.statusMessage("") scribus.progressReset()
def main(argv): """The main() function disables redrawing, sets a sensible generic status bar message, and optionally sets up the progress bar. It then runs the main() function. Once everything finishes it cleans up after the create() function, making sure everything is sane before the script terminates.""" currentDoc = scribus.getDocName() try: scribus.statusMessage("Importing .csv table...") scribus.progressReset() create(argv) if scribus.haveDoc(): scribus.closeDoc() scribus.openDoc(currentDoc) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.closeDoc() scribus.openDoc(currentDoc) scribus.statusMessage("") scribus.progressReset()
def main_wrapper(): """The main_wrapper() function disables redrawing, sets a sensible generic status bar message, and optionally sets up the progress bar. It then runs the main() function. Once everything finishes it cleans up after the main() function, making sure everything is sane before the script terminates.""" scribus.messageBox("Version",SCRIPT_VERSION) if not scribus.haveDoc(): scribus.messageBox("Bwaaaahaha","Need a base document open") else: scribus.setRedraw(False) try: scribus.statusMessage("Running script...") scribus.progressReset() main() finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.docChanged(True) scribus.statusMessage("") scribus.progressReset()
# open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing "+str(nol)+" elements") scribus.progressTotal(len(data)) for row in data: scribus.messagebarText("Processing "+str(nol)+" elements") celltext = row[numcol].strip() if len(celltext)!=0: createCell(celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], isBlack) nol=nol+1 if cr==colstotal and cc==rowstotal: #create new page scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) cr=1 cc=1 else: if cr==colstotal: cr=1 cc=cc+1 else: cr=cr+1 scribus.progressSet(nol) scribus.messagebarText("Processed "+str(nol)+" items. ") scribus.progressReset()
def create_guide(gp): fh = FrameHandler() toc = TableOfContents(gp.numpagesforcontents) index = ClimbIndex() scribus.statusMessage("Creating document...") nchapters = len(gp.chapters) scribus.progressTotal(nchapters) scribus.progressReset() progress = 0 currentregion = "" crag = "" for (xmlid, region) in gp.chapters: scribus.statusMessage("Parsing " + xmlid + "...") progress = progress + 1 scribus.progressTotal(nchapters) scribus.progressSet(progress) p = xml.dom.minidom.parse(gp.path + os.sep + xmlid + os.sep + xmlid + ".xml") for g in p.getElementsByTagName("guide"): for n in g.childNodes: if n.nodeName == "header": intro = n.getAttribute("intro") name = n.getAttribute("name") rock = n.getAttribute("rock") sun = n.getAttribute("sun") access = n.getAttribute("access") acknow = n.getAttribute("acknowledgement") walk = n.getAttribute("walk") camping = n.getAttribute("camping") history = n.getAttribute("history") stars = g.getAttribute("guidestars").replace( "*", GLYPH_STAR) scribus.statusMessage("Parsing " + xmlid + " (" + name + ")...") scribus.progressTotal(nchapters) scribus.progressSet(progress) fh.endFrame() #fh.sidebar.setText("") fh.sidebar.setText(name) fh.newPage() fh.setColumns(1) #if scribus.currentPage() % 2 != 0: # fh.newPage() fh.placeText(name, "Title", columns=1, keepwithnext=True, nosplit=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(name + " " + stars, 2, scribus.currentPage()) crag = name #fh.sidebar.setText(crag) graphpath = gp.path + os.sep + xmlid + os.sep + "graph.pdf" fh.placeGuide(rock, sun, walk, graphpath, iconpath=gp.path) if len(acknow) > 0: fh.placeText("Contributors", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(acknow, "Intro", nosplit=True) if len(intro) > 0: fh.placeText("General Rave", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(intro, "Intro") if len(history) > 0: fh.placeText("History", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(history, "Intro") if len(access) > 0: fh.placeText("Access", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(access, "Intro") if len(camping) > 0: fh.placeText("Camping", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(camping, "Intro") fh.endFrame() fh.setColumns(2) elif n.nodeName == "climb" or n.nodeName == "problem": extra = n.getAttribute("extra") grade = n.getAttribute("grade") length = n.getAttribute("length") name = n.getAttribute("name") fa = n.getAttribute("fa") stars = n.getAttribute("stars").replace("*", GLYPH_STAR) number = n.getAttribute("number") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") " + name) scribus.progressTotal(nchapters) scribus.progressSet(progress) # OK for now, but we will want to break this up later routename = stars + " " + name + " " + length + " " + grade + " " + extra if number != "": routename = "(" + number + ") " + routename #routename = chr(TAB) + stars + chr(TAB) + name + chr(TAB) + length + chr(TAB) + grade + chr(TAB) + extra #if number != "": # routename = "(" + number + ")" + routename fh.placeText(routename, "Route Name", columns=2, nosplit=True, keepwithnext=True) for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue #fh.placeText(t.nodeValue, "Route Description", columns=2, nosplit=True, keepwithnext=(len(fa)>0)) fh.placeText(txt, "Route Description", columns=2, nosplit=(len(txt) < NOSPLIT_LIMIT), keepwithnext=(len(fa) > 0)) if len(fa) > 0: fh.placeText(fa, "FA Details", columns=2, nosplit=True) if n.nodeName == "climb": index.add(name, grade, stars, crag, scribus.currentPage()) if name[:3] == "The": index.add(name[4:] + ", The", grade, stars, crag, scribus.currentPage()) #if name in gp.aliases: # index.add(gp.aliases[name].decode("utf-8"), grade, stars, crag, scribus.currentPage()) # print "Alias Match (via key): " + name + " matches " + route + " substitute " + alternatename for (route, alternatename) in gp.aliases.iteritems(): if name == route: # print "Alias Match(via unrolled niceness): " + name + " matches " + route + " substitute " + alternatename index.add(alternatename.decode("utf-8"), grade, stars, crag, scribus.currentPage()) elif n.nodeName == "text": # class can be one of... # text, heading1, heading2, heading3, intro, indentedHeader # Editor, Discussion, DiscussionNoIndents, noPrint # assign Style to class name & control layout from Scribus Style Editor clss = n.getAttribute("class") if clss == "": clss = "text" for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue if clss == "indentedHeader": firstline = txt.split("\n")[0] rest = txt[len(firstline) + 1:] if firstline[-1] == ":": fh.placeText(firstline[:-1], "heading3", nosplit=True, keepwithnext=True) fh.placeText(rest, "Intro") else: fh.placeText(txt, "Intro") elif clss == "heading3": fh.placeText(GLYPH_RIGHTPOINTER + " " + txt, clss, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt, 4, scribus.currentPage()) elif clss == "heading2": #fh.endFrame() fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt, 3, scribus.currentPage()) elif clss == "heading1": fh.endFrame() fh.sidebar.setText("") #fh.sidebar.setText(txt) fh.newPage() fh.placeText(txt, "Title", columns=1, nosplit=True, keepwithnext=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(txt, 2, scribus.currentPage()) elif clss == "intro": fh.placeText(txt, "Intro", nosplit=True, keepwithnext=True) elif clss == "text": fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #fh.placeText(txt, clss, nosplit=True, keepwithnext=False) elif n.nodeName == "image": src = n.getAttribute("src") legend = n.getAttribute("legend") legendtitle = n.getAttribute("legendTitle") legendfooter = n.getAttribute("legendFooter") noprint = n.getAttribute("noPrint") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") image=" + src) scribus.progressTotal(nchapters) scribus.progressSet(progress) if src in gp.images: attr = gp.images[src] else: attr = {} if noprint != "true": fullsrc = gp.path + os.sep + xmlid + os.sep + src if not os.path.exists(fullsrc): scribus.messageBox('Bummer, dude', 'Image file missing: ' + fullsrc, icon=scribus.ICON_WARNING) else: try: i = Image.open(fullsrc) (width, height) = i.size attr["width"] = width attr["height"] = height if legend == "true": if len(legendtitle.strip()) > 0: attr["title"] = legendtitle if len(legendfooter.strip()) > 0: attr["footer"] = legendfooter fh.placeImage(fullsrc, attr) except IOError: scribus.messageBox( "Bummer, dude", "Image file corrupt: " + fullsrc) fh.expandFrame() fh.endGuide() if gp.includeindexbyname: scribus.statusMessage("Creating index by name...") scribus.progressReset() scribus.newPage(-1) if scribus.currentPage() % 2 == 0: # even page scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByName() toc.add("Index by Route Name", 1, page) if gp.includeindexbygrade: scribus.statusMessage("Creating index by grade...") scribus.progressReset() scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByGrade() toc.add("Index by Grade", 1, page) if gp.levelsofcontents > 0: scribus.statusMessage("Creating table of contents...") scribus.progressReset() toc.draw(gp.levelsofcontents)
def main(): colstotal = get_multipl(WIDTH, CARDWIDTH, MARGINS[0], MARGINS[1]) rowstotal = get_multipl(HEIGHT, CARDHEIGHT, MARGINS[2], MARGINS[3]) # create a new document t = scribus.newDocument( (WIDTH, HEIGHT), MARGINS, scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT, 1, ) cr = 1 cc = 1 nol = 0 # ask for CSV infos tstr = scribus.valueDialog( 'Cvs Delimiter, Quote and Column to process', 'Type 1 delimiter, 1 quote character ' 'and the column number (Clear for default ,"0):', ';"0', ) if len(tstr) > 0: delim = tstr[0] else: delim = ',' if len(tstr) > 1: qc = tstr[1] else: qc = '"' if len(tstr) > 2: numcol = int(tstr[2]) else: numcol = 0 # select black or white cards color = scribus.valueDialog( 'Color of the cards :', 'black (b) or white (w)', 'w', ) if len(color) > 0 and 'b' == color[0]: is_black = True else: is_black = False # open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing " + str(nol) + " elements") scribus.progressTotal(len(data)) for row in data: scribus.messagebarText("Processing " + str(nol) + " elements") celltext = row[numcol].strip() if len(celltext) != 0: createCell( celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], is_black, ) nol = nol + 1 if cr == colstotal and cc == rowstotal: #create new page scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) cr = 1 cc = 1 else: if cr == colstotal: cr = 1 cc = cc + 1 else: cr = cr + 1 scribus.progressSet(nol) scribus.messagebarText("Processed " + str(nol) + " items. ") # open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing " + str(nol) + " elements") scribus.progressReset() scribus.progressTotal(len(data)) nol = 0 cr = 1 cc = cc + 2 for row in data: scribus.messagebarText("Processing " + str(nol) + " elements") celltext = row[numcol].strip() if len(celltext) != 0: createCell( celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], is_black=True, ) nol = nol + 1 if cr == colstotal and cc == rowstotal: #create new page scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) cr = 1 cc = 1 else: if cr == colstotal: cr = 1 cc = cc + 1 else: cr = cr + 1 scribus.progressSet(nol) scribus.messagebarText("Processed " + str(nol) + " items. ") scribus.progressReset()
def main(): cache = defaultdict(dict) try: with open(CACHE_FILE, "rb") as cache_file: cache = defaultdict(dict, json.load(cache_file)) except: pass with open(DATA_FILE, "rb") as data_file: songs_data = json.load(data_file) with open(MANUEL_PROCESSING_FILE, "rb") as manual_file: manual_processing = defaultdict(dict, json.load(manual_file)) scribus.statusMessage("Running script...") scribus.progressReset() scribus.progressTotal(len(songs_data)) init() front_matter() add_page_number() # trying to get the best sorting # setting all songs to the max height all_songs = dict( zip(songs_data.keys(), [EFFECTIVE_PAGE_HEIGHT] * len(songs_data))) # update according to cache for song_name, data in cache.iteritems(): all_songs[song_name] = min(data.get("height", EFFECTIVE_PAGE_HEIGHT), EFFECTIVE_PAGE_HEIGHT) # let's see which songs should be set on a double sided page: songs_double_page = filter( lambda x: manual_processing[x].get("double_page", False), manual_processing) for double_page in songs_double_page: all_songs[ double_page] = EFFECTIVE_PAGE_HEIGHT # all double page songs should get a whole page despite their height appendix_filter = lambda a_s, boolean: { k: v for k, v in a_s.iteritems() if manual_processing[k].get("appendix", False) == boolean } main_songs = appendix_filter(all_songs, False) add_songs(main_songs, songs_double_page, manual_processing, songs_data, cache) appendix_songs = appendix_filter(all_songs, True) add_songs(appendix_songs, songs_double_page, manual_processing, songs_data, cache) toc = [] for filename in filter(lambda s: manual_processing[s].get("show", True), all_songs.keys()): toc.append( (songs_data[filename]["name"], cache[filename].get("page", "XX"))) toc.sort(key=lambda (x, y): x) create_toc(toc) if scribus.haveDoc(): scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset() with open(CACHE_FILE, "wb") as cache_file: json.dump(cache, cache_file, indent=2)
def create_guide(gp): fh = FrameHandler() toc = TableOfContents(gp.numpagesforcontents) index = ClimbIndex() scribus.statusMessage("Creating document...") nchapters = len(gp.chapters) scribus.progressTotal(nchapters) scribus.progressReset() progress = 0 currentregion = "" crag = "" for (xmlid,region) in gp.chapters: scribus.statusMessage("Parsing " + xmlid + "...") progress = progress + 1 scribus.progressTotal(nchapters) scribus.progressSet(progress) p = xml.dom.minidom.parse(gp.path + os.sep + xmlid + os.sep + xmlid + ".xml") for g in p.getElementsByTagName("guide"): for n in g.childNodes: if n.nodeName == "header": intro = n.getAttribute("intro") name = n.getAttribute("name") rock = n.getAttribute("rock") sun = n.getAttribute("sun") access = n.getAttribute("access") acknow = n.getAttribute("acknowledgement") walk = n.getAttribute("walk") camping = n.getAttribute("camping") history = n.getAttribute("history") stars = g.getAttribute("guidestars").replace("*",GLYPH_STAR) scribus.statusMessage("Parsing " + xmlid + " (" + name + ")...") scribus.progressTotal(nchapters) scribus.progressSet(progress) fh.endFrame() #fh.sidebar.setText("") fh.sidebar.setText(name) fh.newPage() fh.setColumns(1) #if scribus.currentPage() % 2 != 0: # fh.newPage() fh.placeText(name, "Title", columns=1, keepwithnext=True, nosplit=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(name + " " + stars,2,scribus.currentPage()) crag = name #fh.sidebar.setText(crag) graphpath = gp.path + os.sep + xmlid + os.sep + "graph.pdf" fh.placeGuide(rock, sun, walk, graphpath, iconpath=gp.path) if len(acknow) > 0: fh.placeText("Contributors", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(acknow, "Intro", nosplit=True) if len(intro) > 0: fh.placeText("General Rave", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(intro, "Intro") if len(history) > 0: fh.placeText("History", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(history, "Intro") if len(access) > 0: fh.placeText("Access", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(access, "Intro") if len(camping) > 0: fh.placeText("Camping", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(camping, "Intro") fh.endFrame() fh.setColumns(2) elif n.nodeName == "climb" or n.nodeName == "problem": extra = n.getAttribute("extra") grade = n.getAttribute("grade") length = n.getAttribute("length") name = n.getAttribute("name") fa = n.getAttribute("fa") stars = n.getAttribute("stars").replace("*",GLYPH_STAR) number = n.getAttribute("number") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") " + name) scribus.progressTotal(nchapters) scribus.progressSet(progress) # OK for now, but we will want to break this up later routename = stars + " " + name + " " + length + " " + grade + " " + extra if number != "": routename = "(" + number + ") " + routename #routename = chr(TAB) + stars + chr(TAB) + name + chr(TAB) + length + chr(TAB) + grade + chr(TAB) + extra #if number != "": # routename = "(" + number + ")" + routename fh.placeText(routename, "Route Name", columns=2, nosplit=True, keepwithnext=True) for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue #fh.placeText(t.nodeValue, "Route Description", columns=2, nosplit=True, keepwithnext=(len(fa)>0)) fh.placeText(txt, "Route Description", columns=2, nosplit=(len(txt)<NOSPLIT_LIMIT), keepwithnext=(len(fa)>0)) if len(fa) > 0: fh.placeText(fa, "FA Details", columns=2, nosplit=True) if n.nodeName == "climb": index.add(name, grade, stars, crag, scribus.currentPage()) if name[:3] == "The": index.add(name[4:] + ", The", grade, stars, crag, scribus.currentPage()) #if name in gp.aliases: # index.add(gp.aliases[name].decode("utf-8"), grade, stars, crag, scribus.currentPage()) # print "Alias Match (via key): " + name + " matches " + route + " substitute " + alternatename for (route, alternatename) in gp.aliases.iteritems(): if name == route: # print "Alias Match(via unrolled niceness): " + name + " matches " + route + " substitute " + alternatename index.add(alternatename.decode("utf-8"), grade, stars, crag, scribus.currentPage()) elif n.nodeName == "text": # class can be one of... # text, heading1, heading2, heading3, intro, indentedHeader # Editor, Discussion, DiscussionNoIndents, noPrint # assign Style to class name & control layout from Scribus Style Editor clss = n.getAttribute("class") if clss == "": clss = "text" for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue if clss == "indentedHeader": firstline = txt.split("\n")[0] rest = txt[len(firstline)+1:] if firstline[-1] == ":": fh.placeText(firstline[:-1], "heading3", nosplit=True, keepwithnext=True) fh.placeText(rest, "Intro") else: fh.placeText(txt, "Intro") elif clss == "heading3": fh.placeText(GLYPH_RIGHTPOINTER + " " + txt, clss, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt,4,scribus.currentPage()) elif clss == "heading2": #fh.endFrame() fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt,3,scribus.currentPage()) elif clss == "heading1": fh.endFrame() fh.sidebar.setText("") #fh.sidebar.setText(txt) fh.newPage() fh.placeText(txt, "Title", columns=1, nosplit=True, keepwithnext=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(txt,2,scribus.currentPage()) elif clss == "intro": fh.placeText(txt, "Intro", nosplit=True, keepwithnext=True) elif clss == "text": fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #fh.placeText(txt, clss, nosplit=True, keepwithnext=False) elif n.nodeName == "image": src = n.getAttribute("src") legend = n.getAttribute("legend") legendtitle = n.getAttribute("legendTitle") legendfooter = n.getAttribute("legendFooter") noprint = n.getAttribute("noPrint") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") image=" + src) scribus.progressTotal(nchapters) scribus.progressSet(progress) if src in gp.images: attr = gp.images[src] else: attr = {} if noprint != "true": fullsrc = gp.path + os.sep + xmlid + os.sep + src if not os.path.exists(fullsrc): scribus.messageBox('Bummer, dude', 'Image file missing: ' + fullsrc, icon=scribus.ICON_WARNING) else: try: i = Image.open(fullsrc) (width,height) = i.size attr["width"] = width attr["height"] = height if legend == "true": if len(legendtitle.strip()) > 0: attr["title"] = legendtitle if len(legendfooter.strip()) > 0: attr["footer"] = legendfooter fh.placeImage(fullsrc, attr) except IOError: scribus.messageBox("Bummer, dude", "Image file corrupt: " + fullsrc) fh.expandFrame() fh.endGuide() if gp.includeindexbyname: scribus.statusMessage("Creating index by name...") scribus.progressReset() scribus.newPage(-1) if scribus.currentPage() % 2 == 0: # even page scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByName() toc.add("Index by Route Name",1,page) if gp.includeindexbygrade: scribus.statusMessage("Creating index by grade...") scribus.progressReset() scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByGrade() toc.add("Index by Grade",1,page) if gp.levelsofcontents > 0: scribus.statusMessage("Creating table of contents...") scribus.progressReset() toc.draw(gp.levelsofcontents)
def main(argv): """This is a documentation string. Write a description of what your code does here. You should generally put documentation strings ("docstrings") on all your Python functions.""" ######################### # YOUR CODE GOES HERE # ######################### userdim = scribus.getUnit() #get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) cellwidthleft = 0 cellwidthright = 0 cellHeight = 0 pos = getPosition() while cellwidthleft <= 0: cellwidthL = scribus.valueDialog( 'Left Cell Width', 'How wide (mm) do you wish left cells to be?', '30.0') cellwidthleft = float(cellwidthL) while cellwidthright <= 0: cellwidthR = scribus.valueDialog( 'Right Cell Width', 'How wide (mm) do you wish right cells to be?', '30.0') cellwidthright = float(cellwidthR) while cellHeight <= 0: cellheight = scribus.valueDialog( 'Cell Height', 'How tall (mm) do you wish cells to be?', '10.0') cellHeight = float(cellheight) data = getCSVdata() di = getDataInformation(data) hposition = pos[1] vposition = pos[0] objectlist = [ ] # here we keep a record of all the created textboxes so we can group them later i = 0 scribus.progressTotal(len(data)) scribus.setRedraw(False) for row in data: c = 0 for cell in row: cell = cell.strip() cellsize = cellwidthleft if c == 1: cellsize = cellwidthright textbox = scribus.createText(hposition, vposition, cellsize, cellHeight) #create a textbox objectlist.append(textbox) scribus.insertText(cell, 0, textbox) #insert the text into the textbox hposition = hposition + cellwidthleft #move the position for the next cell c = 1 vposition = vposition + cellHeight #set vertical position for next row hposition = pos[1] #reset vertical position for next row i = i + 1 scribus.progressSet(i) scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
def main(argv): userdim = scribus.getUnit() # get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) cellwidthleft = 0 cellwidthright = 0 # Set starting position hposition = 28 vposition = 20 data = getCSVdata() di = getDataInformation(data) ncol = len(data[0]) nrow = len(data) scribus.messageBox("Table", " " + str(ncol) + " columns, " + str(nrow) + " rows ") #jpg ColWidthList = [] TableWidth = 0 RowHeightList = [] TableHeight = 0 i = 0 for row in data: if i == 0: c = 0 for cell in row: ColWidth = 40 ColWidthList.append(ColWidth) TableWidth = TableWidth + ColWidth c = c + 1 RowHeight = 15 RowHeightList.append(RowHeight) TableHeight = TableHeight + RowHeight i = i + 1 objectlist = [ ] # here we keep a record of all the created textboxes so we can group them later i = 0 scribus.progressTotal(len(data)) scribus.setRedraw(False) rowindex = 0 new_row_indication = 1 new_page_indication = 1 firstorigin_indicator = 1 while rowindex < len(data): c = 0 origin_cd = data[rowindex][0].strip() origin = data[rowindex][1].strip() origin_complete = origin + ' (' + origin_cd + ")" headerorigin = origin_complete origin_added = 0 destination_cd = data[rowindex][2].strip() destination = data[rowindex][3].strip() destination_complete = destination + ' (' + destination_cd + ")" fareplan = data[rowindex][4].strip() fareplan_type = data[rowindex][5].strip() fareplan_complete = fareplan + ' ' + fareplan_type[:1] fare = data[rowindex][6].strip() fare = float(fare) fare = "{0:.2f}".format(fare) fare_onboard = data[rowindex][7].strip() fare_onboard = float(fare_onboard) fare_onboard = "{0:.2f}".format(fare_onboard) cellheight_market = 5 cellheight_market_dos = 5 try: last_origin = data[rowindex - 1][1].strip() except: last_origin = origin try: last_destination = data[rowindex - 1][3].strip() except: last_destination = destination cellsize = ColWidthList[c] cellHeight = RowHeightList[i] # Check to see if near bottom of the page, if so wrap it over if (vposition > 227): hposition = hposition + cellsize vposition = 20 new_row_indication = 1 # If at end, reset and create new page if (hposition > 174): scribus.newPage(-1) hposition = 28 vposition = 20 new_page_indication = 1 firstorigin_indicator = 0 if new_row_indication == 1: textbox = scribus.createText(hposition, 16, cellsize / 2, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle('FareplanHeader', textbox) scribus.insertText('Fareplan', 0, textbox) c = c + 1 textbox = scribus.createText(hposition + (cellsize / 2), 16, cellsize / 2, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle('FareplanHeader', textbox) scribus.insertText('Amount', 0, textbox) c = c + 1 # if (firstorigin_indicator == 1): # headerorigin = origin_complete # textbox = scribus.createText(20, 10, cellsize*4, 4) # create a textbox. # objectlist.append(textbox) # scribus.setStyle('HeaderOrigin', textbox) # scribus.insertText(headerorigin, 0, textbox) # c = c + 1 # Origin textbox if (rowindex < len(data)): if ((origin != last_origin) or (rowindex == 0)): # Add 'btwn' text textbox = scribus.createText(hposition, vposition, cellsize, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'Headings', textbox ) # set it in the style 'Headings' as defined in Scribus. scribus.insertText( 'btwn', 0, textbox) # insert the origin into the textbox. # scribus.setDistances(1,1,1,1) # set the distances. vposition = vposition + 4 # Shift position of cell down. c = c + 1 textbox = scribus.createText( hposition, vposition, cellsize, cellheight_market_dos) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'Headings', textbox ) # set it in the style 'Headings' as defined in Scribus. scribus.insertText( origin_complete, 0, textbox) # insert the origin into the textbox. while (scribus.textOverflows(textbox) > 0): cellheight_market_dos += 1 scribus.sizeObject(cellsize, cellheight_market_dos, textbox) vposition = vposition + cellheight_market_dos # Shift position of cell down. c = c + 1 # Add 'and' text textbox = scribus.createText(hposition, vposition, cellsize, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'andStyle', textbox ) # set it in the style 'andStyle' as defined in Scribus. scribus.insertText( 'and', 0, textbox) # insert the origin into the textbox. vposition = vposition + 4 # Shift position of cell down. c = c + 1 origin_added = 1 firstorigin_indicator = firstorigin_indicator + 1 # Insert the origin at the top margin if (firstorigin_indicator == 1 or rowindex == 0): headerorigin = origin_complete textbox = scribus.createText(28, 10, cellsize * 4, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle('HeaderOrigin', textbox) scribus.insertText(headerorigin, 0, textbox) c = c + 1 # Destination textbox if ((destination != last_destination) or (rowindex == 0) or (origin_added == 1)): textbox = scribus.createText( hposition, vposition, cellsize, cellheight_market) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'Headings', textbox ) # set it in the style 'Headings' as defined in Scribus. scribus.insertText( destination_complete, 0, textbox) # insert the destination into the textbox. while (scribus.textOverflows(textbox) > 0): cellheight_market += 1 scribus.sizeObject(cellsize, cellheight_market, textbox) vposition = vposition + cellheight_market # Shift position of cell down. c = c + 1 rowindex = rowindex + 1 # Fareplan textbox fareplan_box_height = 5 if fare_onboard != '0.00': fareplan_box_height = 10 textbox = scribus.createText(hposition, vposition, cellsize / 2, fareplan_box_height) # create a textbox. objectlist.append(textbox) scribus.insertText(fareplan_complete, 0, textbox) # insert the fareplan into the textbox. hposition = hposition + (cellsize / 2) # Shift position of cell right. c = c + 1 # Fare textbox textbox = scribus.createText(hposition, vposition, cellsize / 2, 5) # create a textbox. objectlist.append(textbox) scribus.insertText(fare, 0, textbox) # insert the fare into the textbox. c = c + 1 if fare_onboard != '0.00': vposition = vposition + 5 # Shift position of cell down. textbox = scribus.createText(hposition, vposition, cellsize / 2, 5) # create a textbox. objectlist.append(textbox) scribus.setStyle('OnBoard', textbox) scribus.insertText(fare_onboard, 0, textbox) # insert the fare into the textbox. hposition = hposition - (cellsize / 2 ) # Shift position of cell back. vposition = vposition + 5 # Shift position of cell down. c = c + 1 else: hposition = hposition - (cellsize / 2 ) # Shift position of cell back. vposition = vposition + 5 # Shift position of cell down. i = i + 1 new_row_indication = 0 new_page_indication = 0 scribus.deselectAll() scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
def generateContent(string, window): #generates all the elements/only one element start = 0 end = 0 if string == "all": #dont include the first line to make the data sort work [1:] #sort the the elements by date data = sorted(getCSVdata()[1:], key=lambda row: dateFun(str.strip(row[5])), reverse=True) end = len(data) print(str(end) + " " + str(start)) print("generating elements from all lines") window.destroy() elif RepresentsInt(string): start = int(string) - 1 #index shifting end = int(string) print("only generating line " + string) data = getCSVdata() window.destroy() else: print(string + " is not a valid value") print("exiting") window.destroy() sys.exit() if not scribus.haveDoc() > 0: #do we have a doc? scribus.messageBox("importcvs2table", "No opened document.\nPlease open one first.") sys.exit() userdim = scribus.getUnit() #get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) lineWidth = 3.92 #aka 1.383mm, kp warum rowDate = "" for i in range(start, end): rowName = str.strip(data[i][0]) rowCategory = str.strip(data[i][1]) rowDescription = str.strip(data[i][2]) rowPrice = str.strip(data[i][3]) rowPlace = str.strip(data[i][4]) rowDate = str.strip(data[i][5]) rowTime = str.strip(data[i][6]) if rowName == "": #skip empty csv lines continue print("add element: " + rowName) #random values hpos = 120.0 vpos = 200.0 hposition = 120.0 vposition = 200.0 objectlist = [] #list for all boxes x = 0 #sets the progress #create the blue box print("create the blue line") blueBox = scribus.createLine(hposition + 1, vposition, hposition + 1, vposition + 5.863) scribus.setLineColor("Cyan", blueBox) scribus.setLineWidth(lineWidth, blueBox) objectlist.append(blueBox) scribus.progressSet(x) x = 1 #create the data character box #these are the width values for the numbers zero = 4.608 one = 2.839 two = 4.724 three = 4.393 four = 4.625 five = 4.261 six = 4.278 seven = 4.261 eight = 4.625 nine = 4.708 lenArray = [zero, one, two, three, four, five, six, seven, eight, nine] marginleft = 1.3 margintop = 0.519 #substract, cause the box is heigher that the blue line cellwidthright = 10.951 cellHeight = 8.282 hposition = hposition + marginleft + 1 textbox = scribus.createText(hposition, vposition - margintop, cellwidthright, cellHeight) scribus.setFont("Quicksand Regular", textbox) scribus.setFontSize(20.0, textbox) finalDate = "" rowDateLength = 0 #checks if the rowDate is from 01-09, in that case remove the zero if rowDate[0] == '0': finalDate = rowDate[1] rowDateLength = lenArray[int(rowDate[1])] else: finalDate = rowDate[:2] rowDateLength = lenArray[int(rowDate[0])] + lenArray[int( rowDate[1])] scribus.insertText(finalDate, 0, textbox) print("day: " + finalDate) objectlist.append(textbox) scribus.progressSet(x) x = 2 #create the month/day box print("create the box with the day and month") width = 19.447 height = 8.025 marginleft = rowDateLength #gain that from the calculations above, depends on the width of the rowDate characters monthBox = scribus.createText(hposition + marginleft + 0.7, vposition, width, height) scribus.setFont("Quicksand Regular", monthBox) scribus.setFontSize(8.5, monthBox) month = "" m = rowDate[3:5] if m == '01': month = "Januar" elif m == '02': month = "Februar" elif m == '03': month = "März" elif m == '04': month = "April" elif m == '05': month = "Mai" elif m == '06': month = "Juni" elif m == '07': month = "Juli" elif m == '08': month = "August" elif m == '09': month = "September" elif m == '10': month = "Oktober" elif m == '11': month = "November" elif m == '12': month = "Dezember" else: print("cant determine month!") day = datetime.date(int(rowDate[6:]), int(m), int(rowDate[:2])).weekday() dayName = "" if day == 0: dayName = "Montag" elif day == 1: dayName = "Dienstag" elif day == 2: dayName = "Mittwoch" elif day == 3: dayName = "Donnerstag" elif day == 4: dayName = "Freitag" elif day == 5: dayName = "Samstag" elif day == 6: dayName = "Sonntag" else: print("cant determine day!") text = month + "\n" + dayName scribus.setStyle("Kalender_neu_Monat und Tag", monthBox) scribus.insertText(text, 0, monthBox) print("month: " + month + " day: " + dayName) objectlist.append(monthBox) scribus.progressSet(x) x = 3 #create the main text box print("create the main text box") margintop = 5.5 hpos = hpos - 0.383 #i dont know why but scribus always places the element 0.383 right than it should be :/ mainTextBox = scribus.createText( hpos, vposition + margintop, 43.0, 45.0) #minus eins weil der blaue balken seinen kasten overflowed #insert category print("insert the category: " + rowCategory) scribus.insertText(rowCategory, 0, mainTextBox) endCategory = scribus.getTextLength(mainTextBox) scribus.selectText(0, endCategory, mainTextBox) scribus.setFontSize(10.5, mainTextBox) scribus.selectText(0, endCategory, mainTextBox) scribus.setStyle("Kalender_Eventname", mainTextBox) #insert main text print("insert the main text") scribus.insertText("\n" + rowDescription, endCategory, mainTextBox) endMainText = scribus.getTextLength(mainTextBox) - endCategory scribus.selectText(endCategory, endMainText, mainTextBox) scribus.setStyle("Kalender_Eventbeschreibung", mainTextBox) #get start length to color everything black and set font size startAll = scribus.getTextLength(mainTextBox) createPlaceTimePrice(mainTextBox, "\n| Ort: ", "", "Kalender_Eventname") #insert value for place createPlaceTimePrice(mainTextBox, rowPlace, "Heuristica Regular", "") #insert time letters createPlaceTimePrice(mainTextBox, " | Zeit: ", "Quicksand Regular", "") #insert time value createPlaceTimePrice(mainTextBox, rowTime, "Heuristica Regular", "") #insert price letters createPlaceTimePrice(mainTextBox, " | Eintritt: ", "Quicksand Regular", "") #insert price value createPlaceTimePrice(mainTextBox, rowPrice, "Heuristica Regular", "") #setFontSize and black color for the whole detail box endAll = scribus.getTextLength(mainTextBox) - startAll scribus.selectText(startAll, endAll, mainTextBox) scribus.setFontSize(8.5, mainTextBox) scribus.selectText(startAll, endAll, mainTextBox) scribus.setTextColor("Black", mainTextBox) objectlist.append(mainTextBox) scribus.progressSet(x) #do some generell stuff scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True) print("done") return 0