def __init__(self): if not scribus.haveDoc(): scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(1) if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Script Error', "There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox('Scribus - Script Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) self.textbox = scribus.getSelectedObject() ftype = scribus.getObjectType(self.textbox) if ftype != "TextFrame": scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) scribus.deleteText(self.textbox) self.insertPos = 0 self.lastPStyle = "" self.insertText('Radtouren\n', 'Radtouren_titel')
def checkForOneFrameSelected() : if not scribus.haveDoc(): scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Usage Error', "There is no frame selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox('Scribus - Usage Error', "You have more than one frame selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2)
def main(): # haben wir ein Dokument geoeffnet if scribus.haveDoc(): # haben wir in diesem Dokument genau *ein* Objekt markiert if (scribus.selectionCount() == 1): # Ist dieses Objekt ein Bild, dann if (scribus.getObjectType() == "ImageFrame"): # lese den vollstaendigen Namen der datei (inkl. Pfad) in die Variable name name = scribus.getImageFile() # bastele einen neuen Namen aus dem Pfad, %VAR_ und dem Objektnamen und schreibe ihn als Standardwert in den Dialog newname = scribus.valueDialog( os.path.split(name)[1] + " wird ersetzt durch %VAR_[name]%", "Variablenname ergänzen: ", os.path.split(name)[0] + "/%VAR_" + scribus.getSelectedObject() + "%") # uebernehme den Wert aus dem Dialogfenster (keine plausibilitaetspruefung. das ist ein beliebiger String scribus.loadImage(newname) else: scribus.messageBox("Fehler", "markierter Frame ist kein Bildrahmen", scribus.ICON_CRITICAL) else: scribus.messageBox("Fehler", "bitte *einen* Bildrahmen markieren", scribus.ICON_CRITICAL) else: scribus.messageBox("Fehler", "kein Dokument geöffnet", scribus.ICON_CRITICAL)
def run(self): selCount = scribus.selectionCount() if selCount == 0: scribus.messageBox('Scribus Data Merger- Usage Error', "There is no objects selected.\nPlease try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) csvData = self.loadCsvData() # Create a list with the names of the selected objects: selectedObjects = [] # Loop through the selected objects and put their names into the list selectedObjects o = 0 while (o < selCount): selectedObjects.append(scribus.getSelectedObject(o)) o = o + 1 startingPage = scribus.currentPage() lastRow = len(csvData) if(self.__dataObject.getNumberOfLinesToMerge() != 'All'): lastRow = int(self.__dataObject.getNumberOfLinesToMerge()) lastRow = min(lastRow, len(csvData)) # This will prevent the script from trying to merge data from non-existing rows in the data file currentPage = scribus.currentPage() rowNumber = 0 insertPageBeforeThis = -1 while (rowNumber < lastRow): if(scribus.pageCount() > currentPage): insertPageBeforeThis = currentPage + 1 scribus.newPage(insertPageBeforeThis) # Inserts a page before the page given as an argument currentPage = currentPage + 1 for selectedObject in selectedObjects: # Loop through the names of all the selected objects scribus.gotoPage(startingPage) # Set the working page to the one we want to copy objects from scribus.copyObject(selectedObject) scribus.gotoPage(currentPage) scribus.pasteObject() # Paste the copied object on the new page scribus.docChanged(1) scribus.gotoPage(currentPage) # Make sure ware are on the current page before we call getAllObjects() newPageObejcts = scribus.getAllObjects() for pastedObject in newPageObejcts: # Loop through all the items on the current page objType = scribus.getObjectType(pastedObject) text = CONST.EMPTY if(objType == 'TextFrame'): text = scribus.getAllText(pastedObject) # This should have used getText but getText does not return the text values of just pasted objects text = self.replaceText(csvData[rowNumber], text) scribus.setText(text, pastedObject) if(objType == 'ImageFrame'): text = scribus.getImageFile(pastedObject) # self.info("Image text", text) # Todo: Find out if it is possible to replace text in the ImageFile property rowNumber = rowNumber + 1 scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Merge Completed", "Merge Completed", icon=scribus.ICON_INFORMATION, button1=scribus.BUTTON_OK)
def getPosition(): if scribus.selectionCount() == 1: areaname = scribus.getSelectedObject() position= scribus.getPosition(areaname) vpos = position[1] hpos = position[0] scribus.deleteObject(areaname) return vpos, hpos else: scribus.messageBox("csv2table", "please select ONE Object to mark the drawing area for the table") sys.exit()
def checkForOneFrameSelected(): if not scribus.haveDoc(): scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) if scribus.selectionCount() == 0: scribus.messageBox( 'Scribus - Usage Error', "There is no frame selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox( 'Scribus - Usage Error', "You have more than one frame selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2)
def getSelection(): '''Returns a list of the selected TextFrame objects. Returns an empty list if there is no TextFrame Object currently selected.''' try: filtered_selection = [ ] # list we're going to use to put all the TextFrame elements # first, we check if there is something to work on if scribus.selectionCount() > 0: # then we check for each element # if it's a TextFrame object. # if so, we add it's name to the filtered list. for i in range(0, scribus.selectionCount()): if scribus.getObjectType( scribus.getSelectedObject(i)) == 'TextFrame': filtered_selection.append(scribus.getSelectedObject(i)) return filtered_selection except: print error_message_selection_error scribus.messageBox(TITLE, error_message_selection_error, scribus.ICON_WARNING) return []
def getPosition(): if scribus.selectionCount() == 1: areaname = scribus.getSelectedObject() position = scribus.getPosition(areaname) vpos = position[1] hpos = position[0] scribus.deleteObject(areaname) return vpos, hpos else: scribus.messageBox("csv2table", "please select ONE Object to mark the drawing area for the table") sys.exit()
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 # ######################### #copyPlayer("__player__","PLAYER 1") #copyPlayer("__player__","PLAYER 2") #copyPlayer("__player__","PLAYER 3") csv = scribus.fileDialog('Open input', 'CSV files (*.csv)') stuff = { 'NAME': 'Mike Hingley', 'ADDRESS': '22 Trinity Street, Cradley Heath, West Midlands', 'PHOTO': '128.jpg' } print(os.path.dirname(os.path.realpath(sys.argv[0]))) print os.getcwd() print(sys.path[0]) print(os.path.abspath('')) sourceName = "__player__" if scribus.objectExists(sourceName): scribus.selectObject(sourceName) scribus.unGroupObject() childObjectCount = scribus.selectionCount() for x in range(0, childObjectCount): element = scribus.getSelectedObject(x) if scribus.getObjectType(str(element)) == 'TextFrame': current = scribus.getAllText(element) if current in stuff: fontsize = scribus.getFontSize(element) font = scribus.getFont(element) scribus.setText(stuff[current], element) scribus.setFont(font) scribus.setFontSize(fontsize) if scribus.getObjectType(str(element)) == 'ImageFrame': current = scribus.getImageFile(element) currentName = os.path.basename(os.path.normpath(current)) print current print currentName if currentName in stuff: ExistingFolder = os.path.split(current) print ExistingFolder[0] newFile = os.path.join(ExistingFolder[0], stuff[currentName]) print newFile scribus.loadImage(newFile, element) print scribus.getObjectType(str(element)) print str(scribus.getSelectedObject(x)) scribus.groupObjects() print "name = " + scribus.getSelectedObject() scribus.setNewName("__player__", scribus.getSelectedObject())
def main(): nbrSelected = sc.selectionCount() objList = [] if nbrSelected > 0: for i in range(nbrSelected): objList.append(sc.getSelectedObject(i)) else: # nothing selected get images from current page objList = sff.get_imageframes_on_page(0, name_filter=sff.IMAGEFRAMENAME) for name in objList: x, y = sff.scale_to_frame(name) sff.center_image(name, x, y)
def alignImage(self): if scribus.haveDoc(): restore_units = scribus.getUnit( ) # since there is an issue with units other than points, scribus.setUnit(0) # we switch to points then restore later. nbrSelected = scribus.selectionCount() objList = [] for i in range(nbrSelected): objList.append(scribus.getSelectedObject(i)) scribus.deselectAll() for i in range(nbrSelected): try: obj = objList[i] scribus.selectObject(obj) frameW, frameH = scribus.getSize(obj) saveScaleX, saveScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(1, 0, obj) fullScaleX, fullScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(0, 0, obj) scribus.setImageScale(saveScaleX, saveScaleY, obj) imageW = frameW * (saveScaleX / fullScaleX) imageH = frameH * (saveScaleY / fullScaleY) imageX = 0.0 imageY = 0.0 if self.alignVar.get()[0] == "T": imageY = 0.0 elif self.alignVar.get()[0] == "M": imageY = (frameH - imageH) / 2.0 elif self.alignVar.get()[0] == "B": imageY = (frameH - imageH) if self.alignVar.get()[1] == "L": imageX = 0.0 elif self.alignVar.get()[1] == "C": imageX = (frameW - imageW) / 2.0 elif self.alignVar.get()[1] == "R": imageX = (frameW - imageW) scribus.setImageOffset(imageX, imageY, obj) scribus.docChanged(1) scribus.setRedraw(True) scribus.deselectAll() except: nothing = "nothing" scribus.setUnit(restore_units) self.master.destroy()
def alignImage(self): if scribus.haveDoc(): restore_units = scribus.getUnit() # since there is an issue with units other than points, scribus.setUnit(0) # we switch to points then restore later. nbrSelected = scribus.selectionCount() objList = [] for i in range(nbrSelected): objList.append(scribus.getSelectedObject(i)) scribus.deselectAll() for i in range(nbrSelected): try: obj = objList[i] scribus.selectObject(obj) frameW, frameH = scribus.getSize(obj) saveScaleX, saveScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(1, 0, obj) fullScaleX, fullScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(0, 0, obj) scribus.setImageScale(saveScaleX, saveScaleY, obj) imageW = frameW * (saveScaleX / fullScaleX) imageH = frameH * (saveScaleY / fullScaleY) imageX = 0.0 imageY = 0.0 if self.alignVar.get()[0] == "T": imageY = 0.0 elif self.alignVar.get()[0] == "M": imageY = (frameH - imageH) / 2.0 elif self.alignVar.get()[0] == "B": imageY = (frameH - imageH) if self.alignVar.get()[1] == "L": imageX = 0.0 elif self.alignVar.get()[1] == "C": imageX = (frameW - imageW) / 2.0 elif self.alignVar.get()[1] == "R": imageX = (frameW - imageW) scribus.setImageOffset(imageX, imageY, obj) scribus.docChanged(1) scribus.setRedraw(True) scribus.deselectAll() except: nothing = "nothing" scribus.setUnit(restore_units) self.master.destroy()
def main(): pass n = scribus.selectionCount() if n == 0: scribus.messageBox('Error', 'No item selected') return items = [] for i in range(n): items.append(scribus.getSelectedObject(i)) for item in items: pos = scribus.getPosition(item) dx, dy = pos scribus.pasteObject() new_item = scribus.getSelectedObject() pos = scribus.getPosition(new_item) dx, dy = dx - pos[0], dy - pos[1] scribus.moveObject(dx, dy, new_item) scribus.deleteObject(item)
def main(): if sc.selectionCount() == 2: images = ( sc.getSelectedObject(0), sc.getSelectedObject(1) ) for image in images: if sc.getObjectType(image) != "ImageFrame": logging.debug(f"Image type {sc.getObjectType(image)}, but 'ImageFrame' expected") error_msg(f'{image} not an image frame. But type {sc.getObjectType(image)}') image_files = (sc.getImageFile(images[0]), sc.getImageFile(images[1])) # keep Scale and Offset, before reset by image load image_0_offset = sc.getImageOffset(images[0]) image_0_scale = sc.getImageScale(images[0]) image_1_offset = sc.getImageOffset(images[1]) image_1_scale = sc.getImageScale(images[1]) sc.loadImage(image_files[1], images[0]) sc.loadImage(image_files[0], images[1]) if sc.getSize(images[0]) == sc.getSize(images[1]): # Frames have the same size swap scale and offset logging.debug(f"Frames have the same size {sc.getSize(images[0])}, swap offset and scale") logging.debug(f"Image 0: {images[0]}, Image 1: {images[1]}") logging.debug(f"Image properties: offset {sc.getImageOffset(images[0])}, scale {image_0_scale}") sc.setImageOffset(*image_1_offset, images[0]) sc.setImageScale(*image_1_scale, images[0]) sc.setImageOffset(*image_0_offset, images[1]) sc.setImageScale(*image_0_scale, images[1]) else: # scale and center logging.debug("Different size scale and center, both.") for name in images: x, y = sff.scale_to_frame(name) sff.center_image(name, x, y) else: logging.debug(f"{sc.selectionCount()} frames selected.") error_msg(f'{sc.selectionCount()} frames selected')
import scribus n = scribus.selectionCount() list = [] for i in range(0, n): list.append(scribus.getSelectedObject(i)) margin = 2 fillColor = "White" lineStyle = "noLine" lineWidth = 0 #deselectAll() for selected in list: x, y = scribus.getPosition(selected) width, height = scribus.getSize(selected) scribus.setFillColor(fillColor, selected) scribus.setLineShade(lineWidth, selected) scribus.setLineWidth(lineWidth, selected) scribus.setLineTransparency(lineWidth, selected) #scribus.setLineStyle(lineStyle, rectangle) #scribus.setStrokeColor(strokeColor, rectangle)
# (c) MIT ale rimoldi # Simple Table of Content script for Scribus # For details see the README file. try: import scribus except ImportError: print('This script must be run from inside Scribus') import sys if not scribus.haveDoc(): scribus.messageBox('Error', 'You need a Document open.', icon=0, button1=1) sys.exit(2) if scribus.selectionCount() != 1: scribus.messageBox('Error', "Please select the target text frame.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) toc_frame = scribus.getSelectedObject() if scribus.getObjectType(toc_frame) != 'TextFrame': scribus.messageBox('Error', "Please select the target text frame.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) toc_styles = {'h1': 'toc1', 'h2': 'toc2', 'h3': 'toc3'} toc_content = []
# This script scales the image so that it fills the frame completely. # One dimension of the image (width/height) may overflow the frame, # but at least one dimension will fill the frame exactly. # License # Copyright 2007, Jeremy Brown (TrnsltLife) # This script is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. import scribus as sc if sc.haveDoc(): nbrSelected = sc.selectionCount() objList = [] for i in range(nbrSelected): objList.append(sc.getSelectedObject(i)) for i in range(nbrSelected): try: obj = objList[i] sc.setScaleImageToFrame(True, False, obj) scaleX, scaleY = sc.getImageScale(obj) sc.setScaleImageToFrame(False, False, obj) if scaleX > scaleY: scale = scaleX sc.setImageScale(scale, scale, obj) elif scaleY > scaleX:
if not scribus.haveDoc(): scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) charsIgnore = ["-", "–", "", " ", ".", ":", ";", ";", "?", "!", "\n", "'", "‘", "’", "," "\"", "“", "”", "\r"] button = scribus.messageBox('Confirmation', 'You should only scramble a copy of your document', scribus.ICON_WARNING, scribus.BUTTON_OK, scribus.BUTTON_CANCEL) print button if button == scribus.BUTTON_CANCEL : sys.exit(2) selectedFrame = [] textFrame = [] imageFrame = [] if scribus.selectionCount() == 0: for page in range(scribus.pageCount()) : scribus.gotoPage(page + 1) scribus.messagebarText("Processing Page "+str(page)) scribus.redrawAll() for item in scribus.getPageItems() : if (item[1] == 4): textFrame.append(item[0]) elif (item[1] == 2) : imageFrame.append(item[0]) else : for i in range(scribus.selectionCount()) : item = scribus.getSelectedObject(i) selectedFrame.append(item) if scribus.getObjectType(item) == "TextFrame" : textFrame.append(item)
lead_single = u"\u2019" follow_single = u"\u201a" elif ((lang == 'hu') or (lang == 'nl')): lead_double = u"\u201e" follow_double = u"\u201d" lead_single = u"\u00bb" follow_single = u"\u00ab" else: scribus.messageBox('Language Error', 'You need to choose an available language', icon=0, button1=1) sys.exit(2) else: scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Usage Error', "There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox('Scribus - Usage Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() boxcount = 1 for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Usage Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
style = "Formularfeld_center" try: import scribus except ImportError: print "This script can only be run as an extension script from Scribus" sys.exit(1) # check opened document if not scribus.haveDoc(): scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(1) scribus.setRedraw(False) selectionCount = scribus.selectionCount() # str('Selected: ' + str(selectionCount)) selected = [] # remember all selected objects for index in range(0, selectionCount): # str(index) selectedObject = scribus.getSelectedObject(index) # str(selectedObject) selected.append(selectedObject) scribus.deselectAll() # change style for each selected object for obj in selected:
def main(argv): unit = scribus.getUnit() units = ['pts', 'mm', 'inches', 'picas', 'cm', 'ciceros'] unitlabel = units[unit] # get page size xysize = scribus.getPageSize() # ask for layout style layout_style = scribus.valueDialog("Guides Layout", layout_text, "1") if layout_style == "": sys.exit() # 0 = erase all guides if layout_style == "0": #guides scribus.setVGuides([]) scribus.setHGuides([]) sys.exit() # 1 = guides around page if layout_style == "1": # set guides distance pageguides_str = scribus.valueDialog( "Create Guides around Page", "Set distance to page borders (" + unitlabel + ") :\n\n- positive (e.g. 3) for page margin\n\n- negative (e.g. -3) for page bleed\n", "3") if pageguides_str != "": pageguides = float(pageguides_str) else: sys.exit() #set guides scribus.setVGuides(scribus.getVGuides() + [pageguides, xysize[0] - pageguides]) scribus.setHGuides(scribus.getHGuides() + [pageguides, xysize[1] - pageguides]) # 2 = guides around selected object if layout_style == "2": # set guides distance objectguides_str = scribus.valueDialog( "Create Guides around selected Objects", "Set distance to object borders (" + unitlabel + ") :\n\n- 0 for around the object borders\n\n- positive (e.g. 3) towards inside the object\n\n- negative (e.g. -3) towards outside the object\n", "0") if objectguides_str != "": objectguides = float(objectguides_str) else: sys.exit() if scribus.selectionCount() == 0: scribus.messageBox("Error", "Select an object first !", icon=scribus.ICON_WARNING) sys.exit() #get selected object selection_name = scribus.getSelectedObject(0) objectpos = scribus.getPosition(selection_name) objectsize = scribus.getSize(selection_name) #set guides scribus.setVGuides(scribus.getVGuides() + [ objectpos[0] + objectguides, objectpos[0] + objectsize[0] - objectguides ]) scribus.setHGuides(scribus.getHGuides() + [ objectpos[1] + objectguides, objectpos[1] + objectsize[1] - objectguides ])
Bottom and Top caption frames are sized to width of parent object and height of 24 points. Right and Left caption frames sized to 150 points width and 40 points height. """ try: import scribus except ImportError: print "Unable to import the 'scribus' module. This script will only run within" print "the Python interpreter embedded in Scribus. Try Script->Execute Script." sys.exit(1) numselect = scribus.selectionCount() count = 0 frames = [] if numselect == 0: scribus.messageBox('Selection Count', "You must have at least one object selected", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b") captionloc = captionloc[0] location = captionloc.upper() pageunits = scribus.getUnit() scribus.setUnit(scribus.UNIT_POINTS)
def main(argv): unit = scribus.getUnit() units = [' pts', 'mm', ' inches', ' picas', 'cm', ' ciceros'] unitlabel = units[unit] if scribus.selectionCount() == 0: scribus.messageBox( 'Scribus - Script Error', "There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox( 'Scribus - Script Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() boxcount = 1 for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # While we're finding out what kind of frame is selected, we'll also make sure we # will come up with a unique name for our infobox frame - it's possible we may want # more than one for a multicolumn frame. if (item[0] == ("infobox" + str(boxcount) + textbox)): boxcount += 1 left, top = scribus.getPosition(textbox) o_width, o_height = scribus.getSize(textbox) o_cols = int(scribus.getColumns(textbox)) o_gap = scribus.getColumnGap(textbox) columns_width = 0 column_pos = 0 o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols if (o_cols > 1): while (columns_width > o_cols or columns_width < 1): columns_width = scribus.valueDialog( 'Width', 'How many columns width shall the ' + 'box be (max ' + str(o_cols) + ')?', '1') columns_width = int(columns_width) if (columns_width < o_cols): max = o_cols - columns_width while (column_pos <= max and column_pos <= 1): column_pos = scribus.valueDialog( 'Placement', 'In which column do you want ' 'to place the box (1 to ' + str(o_cols) + ')?', '1') column_pos = int(column_pos) - 1 if (o_cols == 1): columns_width = 1 new_height = 0 while (new_height <= 0): new_height = scribus.valueDialog( 'Height', 'Your frame height is ' + str(o_height) + unitlabel + '. How tall\n do you want your ' + 'infobox to be in ' + unitlabel + '?\n If you load an image with the script, height will be\n calculated, so the value here will not\n matter in that case.', str(o_height)) if (not new_height): sys.exit(0) new_height = float(new_height) new_top = -1 while (new_top < 0): new_top = scribus.valueDialog( 'Y-Pos', 'The top of your infobox is currently\n' + str(top) + unitlabel + '. Where do you want \n' + 'the top to be in ' + unitlabel + '?', str(top)) if (not new_top): sys.exit(0) new_top = float(new_top) framename = scribus.valueDialog( 'Name of Frame', 'Name your frame or use this default name', "infobox" + str(boxcount) + textbox) if (not framename): sys.exit(0) frametype = 'text' frametype = scribus.valueDialog( 'Frame Type', 'Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image', frametype) if (not frametype): sys.exit(0) new_width = columns_width * o_colwidth + (columns_width - 1) * o_gap new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap) if (frametype == 'text'): new_textbox = scribus.createText(new_left, float(new_top), new_width, float(new_height), framename) scribus.setColumnGap(0, new_textbox) scribus.setColumns(1, new_textbox) scribus.textFlowMode(new_textbox, 1) else: if (frametype == 'imageL'): imageload = scribus.fileDialog( 'Load image', 'Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)', haspreview=1) new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height), framename) scribus.textFlowMode(new_image, 1) scribus.loadImage(imageload, new_image) scribus.setScaleImageToFrame(1, 0, new_image) currwidth, currheight = scribus.getSize(new_image) Xscale, Yscale = scribus.getImageScale(new_image) if (Xscale != Yscale): scribus.sizeObject(currwidth, currheight * Xscale / Yscale, new_image) scribus.setScaleImageToFrame(1, 1, new_image) else: new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height), framename) scribus.textFlowMode(new_image, 1) scribus.setScaleImageToFrame(1, 1, new_image)
def main(argv): unit = scribus.getUnit() units = ['pts','mm','inches','picas','cm','ciceros'] unitlabel = units[unit] # get page size pagesize = scribus.getPageSize() # ask for layout style layout_style = scribus.valueDialog("Select Mirror", layout_text, "v") if layout_style == "": sys.exit() # v = vertical mirror if layout_style == "v": # warn and exit if no selection if scribus.selectionCount() == 0: scribus.messageBox("Error", "Select an object first!", icon=scribus.ICON_WARNING) sys.exit() #create mirror guides scribus.setVGuides(scribus.getHGuides() + [pagesize[0]/2]) #get selected object selection_name = scribus.getSelectedObject(0) objectpos = scribus.getPosition(selection_name) objectsize = scribus.getSize(selection_name) #duplicate object scribus.duplicateObject(selection_name) #move object newobjectpos = (pagesize[0] - (objectpos[0] + objectsize[0]) , objectpos[1]) scribus.moveObjectAbs(newobjectpos[0], objectpos[1], selection_name) #flip object scribus.flipObject(1,0,selection_name) # h = horizontal mirror if layout_style == "h": # warn and exit if no selection if scribus.selectionCount() == 0: scribus.messageBox("Error", "Select an object first!", icon=scribus.ICON_WARNING) sys.exit() #create mirror guides scribus.setHGuides(scribus.getHGuides() + [pagesize[1]/2]) #get selected object selection_name = scribus.getSelectedObject(0) objectpos = scribus.getPosition(selection_name) objectsize = scribus.getSize(selection_name) #duplicate object scribus.duplicateObject(selection_name) #move object newobjectpos = (objectpos[0] , pagesize[1] - (objectpos[1] + objectsize[1])) scribus.moveObjectAbs(objectpos[0], newobjectpos[1], selection_name) #flip object scribus.flipObject(0,1,selection_name)
def main(argv): unit = scribus.getUnit() units = [' pts','mm',' inches',' picas','cm',' ciceros'] unitlabel = units[unit] if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Script Error', "There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox('Scribus - Script Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() boxcount = 1 for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # While we're finding out what kind of frame is selected, we'll also make sure we # will come up with a unique name for our infobox frame - it's possible we may want # more than one for a multicolumn frame. if (item[0] == ("infobox" + str(boxcount) + textbox)): boxcount += 1 left, top = scribus.getPosition(textbox) o_width, o_height = scribus.getSize(textbox) o_cols = int(scribus.getColumns(textbox)) o_gap = scribus.getColumnGap(textbox) columns_width = 0 column_pos = 0 o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols if (o_cols > 1): while (columns_width > o_cols or columns_width < 1): columns_width = scribus.valueDialog('Width', 'How many columns width shall the '+ 'box be (max ' + str(o_cols) + ')?','1') columns_width = int(columns_width) if (columns_width < o_cols): max = o_cols - columns_width while (column_pos <= max and column_pos <= 1): column_pos = scribus.valueDialog('Placement', 'In which column do you want ' 'to place the box (1 to ' + str(o_cols) + ')?','1') column_pos = int(column_pos) - 1 if (o_cols == 1): columns_width = 1 new_height = 0 while (new_height == 0): new_height = scribus.valueDialog('Height','Your frame height is '+ str(o_height) + unitlabel +'. How tall\n do you want your ' + 'infobox to be in '+ unitlabel +'?\n If you load an image, height will be\n calculated, so the value here does not\n matter.', str(o_height)) new_top = -1 while (new_top < 0): new_top = scribus.valueDialog('Y-Pos','The top of your infobox is currently\n'+ str(top) + unitlabel +'. Where do you want \n' + 'the top to be in '+ unitlabel +'?', str(top)) framename = scribus.valueDialog('Name of Frame','Name your frame or use this default name',"infobox" + str(boxcount) + textbox) frametype = 'text' frametype = scribus.valueDialog('Frame Type','Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',frametype) new_width = columns_width * o_colwidth + (columns_width-1) * o_gap new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap) if (frametype == 'text'): new_textbox = scribus.createText(new_left, float(new_top), new_width, float(new_height),framename) scribus.setColumnGap(0, new_textbox) scribus.setColumns(1, new_textbox) scribus.textFlowMode(new_textbox, 1) else: if (frametype == 'imageL'): imageload = scribus.fileDialog('Load image','Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',haspreview=1) new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename) scribus.loadImage(imageload, new_image) scribus.messageBox('Please Note',"Your frame will be created once you click OK.\n\nUse the Context Menu to Adjust Frame to Image.\n\nIf your image does not fill the width completely,\nstretch the frame vertically first.",scribus.BUTTON_OK) else: new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename) scribus.textFlowMode(new_image, 1) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=new_image)
charsIgnore = [ "-", "–", "", " ", ".", ":", ";", ";", "?", "!", "\n", "'", "‘", "’", "," "\"", "“", "”", "\r" ] button = scribus.messageBox( 'Confirmation', 'You should only scramble a copy of your document', scribus.ICON_WARNING, scribus.BUTTON_OK, scribus.BUTTON_CANCEL) print button if button == scribus.BUTTON_CANCEL: sys.exit(2) selectedFrame = [] textFrame = [] imageFrame = [] if scribus.selectionCount() == 0: for page in range(scribus.pageCount()): scribus.gotoPage(page + 1) scribus.messagebarText("Processing Page " + str(page)) scribus.redrawAll() for item in scribus.getPageItems(): if (item[1] == 4): textFrame.append(item[0]) elif (item[1] == 2): imageFrame.append(item[0]) else: for i in range(scribus.selectionCount()): item = scribus.getSelectedObject(i) selectedFrame.append(item) if scribus.getObjectType(item) == "TextFrame": textFrame.append(item)
def main(argv): unit = scribus.getUnit() units = [' pts','mm',' inches',' picas','cm',' ciceros'] unitlabel = units[unit] if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Script Error', "There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox('Scribus - Script Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() boxcount = 1 for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # While we're finding out what kind of frame is selected, we'll also make sure we # will come up with a unique name for our infobox frame - it's possible we may want # more than one for a multicolumn frame. if (item[0] == ("infobox" + str(boxcount) + textbox)): boxcount += 1 elem = textbox; pathUp = ''; pathUpShort = ""; while elem != None: elemId = getElemId(elem); pElemId = getParentElemId(elem); text = scribus.getText(elem); if (text.find("Holder")!=-1): text = ""; pathUpShort = "<" + getElemName(elem) + " id=\"" + str(getElemId(elem)) + "\">" + text + "\n" + pathUpShort; pathUp = dumpElem(elem) + " // " + pathUp; elem = findElemById(pElemId); if (pathUp != ''): pathUp = pathUp[0:len(pathUp)-4]; if (pathUpShort != ''): pathUpShort = pathUpShort[0:len(pathUpShort)-1]; #framename = scribus.valueDialog('XML Tree','XML Tree', elemName + '[@id=' + elemId + '] parent: ' + parent + ' text:' + text + "," + parent) #scribus.messagebarText("It works !!!"); scribus.statusMessage(pathUp); #scribus.zoomDocument(200); #scribus.selectFrameText(0,100); #framename = scribus.valueDialog('XML Tree','XML Tree (Path UP)', pathUp); #t = scribus.qApp.mainWidget(); #if (not framename) : # sys.exit(0) #scribus.messageBox('XML struct', # pathUp + "\n\n" + pathUpShort, # scribus.ICON_WARNING, scribus.BUTTON_OK) #impl = getDOMImplementation(); #newdoc = impl.createDocument(None, "root", None); newdoc = createDOMDocument(); #xmlelem = createDOMElement(newdoc, root); #newdoc.documentElement.appendChild(xmlelem); x = newdoc.toxml(); #x = str(dir(root)); scribus.structview(x);
# encoding: utf-8 try: import scribus except ImportError: print('This script must be run from inside Scribus') import sys if scribus.selectionCount() != 1 or scribus.getObjectType() != 'TextFrame': scribus.messageBox('Script failed', 'You need to select one text frame selected.') sys.exit(2) PLACEHOLDER_START = '{' PLACEHOLDER_END = '}' VALUES = {'name': 'Goofy', 'color': 'blue', 'food': 'pizza'} len_start = len(PLACEHOLDER_START) len_end = len(PLACEHOLDER_END) scribus.selectText(0, 0) text = scribus.getText() i = text.find(PLACEHOLDER_START) while i != -1: j = text.find(PLACEHOLDER_END, i) if j == -1: break key = text[i + 1:j] # print('>>>' + key)