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 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 copyPlayer(sourceName, destinationName): if scribus.objectExists(sourceName): doc = scribus.getDocName() unit = scribus.getUnit() (PageWidth, PageHeight) = scribus.getPageSize() (iT, iI, iO, iB) = scribus.getPageMargins() NewPagepoint = PageHeight - iT - iB player = scribus.selectObject(sourceName) #Duplicate the object... scribus.duplicateObject(sourceName) x = scribus.getSelectedObject() newObjectName = str(x) size = scribus.getSize(newObjectName) scribus.moveObject(0, size[1], newObjectName) (x, y) = scribus.getPosition(newObjectName) scribus.setRedraw(1) scribus.docChanged(1) if (y + size[1] > NewPagepoint): currentPage = scribus.currentPage() scribus.newPage(-1) newPage = currentPage + 1 scribus.copyObject(newObjectName) scribus.deleteObject(newObjectName) scribus.gotoPage(newPage) scribus.pasteObject(newObjectName) scribus.moveObjectAbs(iO, iT, newObjectName) scribus.setNewName(destinationName, sourceName) scribus.setNewName(sourceName, newObjectName)
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 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 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 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 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 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 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 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')
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 duplicate_content(pages, named_items): """ duplicate the content of pages at the end of the document and track the new item names for the items in named_items return the list of created item names from named_items """ result = {} page_n = scribus.pageCount() for page in pages: scribus.gotoPage(page) items = [item[0] for item in scribus.getPageItems()] scribus.newPage(-1, scribus.getMasterPage(page)) page_n += 1 for item in items: scribus.gotoPage(page) scribus.copyObject(item) scribus.gotoPage(page_n) scribus.pasteObject() if item in named_items: result[item] = scribus.getSelectedObject() return result
def main(): md_name = scribus.fileDialog("Select a file", 'Markdown (*.md)') if not md_name: return f = NamedTemporaryFile(suffix='.html') markdown.markdownFromFile(md_name, f) f.flush() html_name = f.name i = 0 while True: ob_name = scribus.getSelectedObject(i) if not ob_name: break if scribus.getObjectType(ob_name) == 'TextFrame': scribus.insertHtmlText(html_name, ob_name) i += 1
def slotOkClicked(self): global CWD text = self.text.text() preamble = self.preamble.text() scale = self.scale.value() CWD = self.cwd.text() DPI = 600.0 os.chdir(CWD) try: img = scribus.getSelectedObject() scribus.getImageFile(img) except scribus.NoValidObjectError: img = self.get_new_image_name() scribus.createImage(0, 0, 10, 10, img) img_file = os.path.abspath('%s.png' % img) self.generate_latex(text, preamble, scale, img_file, DPI*scale) info = open(img_file + '.info', 'w') info.write("%s\n" % preamble) info.write("%g\n" % scale) info.write(text) info.close() x = Image.open(img_file, 'r') w, h = x.size del x scribus.setUnit(scribus.UNIT_MILLIMETERS) scribus.loadImage(img_file, img) scribus.setScaleImageToFrame(True, True, img) x, y = scribus.getPosition(img) scribus.sizeObject(x + w*25.4/DPI, y + h*25.4/DPI, img) self.accept()
def format(self, tokensource, outfile): current_frame = scribus.getSelectedObject() # TODO: also support formatting a selection as soon as the API has getTextSelection -> (start, length) # resete the character styles scribus.setCharacterStyle(self.base_char_style) pos = 0 last_val = '' last_type = None for token_type, token_value in tokensource: print(token_type) print(token_value) token_length = len(token_value) # scribus does not have a \n after the last character, # the code has it if pos + token_length > self.code_length: token_length -= 1 # print(pos) # print(token_length) scribus.selectText(pos, token_length, current_frame) pos += token_length style_name = self.get_char_style(token_type) scribus.setCharacterStyle(style_name, current_frame)
def slotDoIt(self): nfs = self.val.value() obj = scribus.getSelectedObject(0) t = scribus.getText(obj) scribus.deselectAll() t0 = scribus.getText(obj) fs = scribus.getFontSize(obj) tl = scribus.getTextLength(obj) idx = t0.find(t) + (len(t) / 2) base = fs #print t0 #print t #print "FS %i NFS %i IDX %i START %i" % (fs,nfs,idx,idx - int((nfs - fs) / 0.1)) for i in xrange(max(idx - int((nfs - fs) * 10), 0), idx): scribus.selectText(i, 1, obj) base += 0.1 scribus.setFontSize(base,obj) for i in xrange(idx, min(idx + int((nfs - fs) * 10), tl - 1)): scribus.selectText(i, 1, obj) base -= 0.1 scribus.setFontSize(base,obj) scribus.setRedraw(True) scribus.selectObject(obj)
# print(item) frameName = item[0] if (item[1] == 4): if frameName != sampleFrameName and remove_copy_prefix(frameName).startswith(pattern): print(frameName + " found") position = scribus.getPosition(frameName) scribus.selectObject(sampleFrameName) scribus.duplicateObject() #duplicateFrameName = scribus.getSelectedObject() scribus.moveObjectAbs(position[0], position[1]) scribus.deleteObject(frameName) # TODO: rename the duplicate to the old frameName checkForOneFrameSelected() currentFrameName = scribus.getSelectedObject() print(currentFrameName) if (scribus.getObjectType(currentFrameName) == 4): scribus.messageBox('Scribus - Usage Error', "You did not select a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # the pattern is the name of the current frame up to the first digit # and with the "Copy of " at the beginning stripped away. matchNonDigit = re.compile(r'(^\D+)') matchResult = matchNonDigit.search(currentFrameName) pattern = matchResult.group(1) pattern = remove_copy_prefix(pattern) pattern = remove_copy_prefix(pattern) print("pattern: " + pattern)
def load_song(data, offset, settings): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin( page_num) start_point = margin_top + offset new_width = page_width - margin_left - margin_right if not FAST: scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0) eps = scribus.getSelectedObject() eps_width, eps_height = scribus.getSize(eps) #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5 scribus.sizeObject(eps_width * 0.86, eps_height * 0.86, eps) scribus.moveObjectAbs(margin_left, start_point + SPACING_HEADLINE_SONG, eps) eps_width, eps_height = scribus.getSize(eps) else: eps_height = 0 scribus.deselectAll() textbox = scribus.createText(margin_left, start_point, new_width, 20) style_suffix = get_style_suffix() if data["composer"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) if data["poet"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) scribus.deselectAll() scribus.insertText(u"{}\n".format(data["name"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("headline_{}".format(style_suffix), textbox) text = data["text"] text = [t.strip() for t in text if t.strip() != ""] # TODO: exit if text == [] textbox = scribus.createText( margin_left, start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT, new_width, 50) scribus.setStyle("text", textbox) # let's see how many digits are in there: num_verses = len([l for l in text if l.isdigit()]) num_chars = 0 num_line_total = len(text) num_line_actually = 0 no_new_line = False verse_counter = 0 text_columns_height = 0 # TODO: should be None for num_line, line in enumerate(text): if line.strip == "": continue num_line_actually += 1 if line.isdigit(): print "#", verse_counter, math.ceil( num_verses * 0.5), num_verses, data["filename"] if verse_counter == math.ceil( num_verses * 0.5 ): # this is the first verse that should be in the new column, so let's see what's the height print text_columns_height, num_line_actually text_columns_height = BASELINE_GRID * (num_line_actually - 1) first_char = "\n" if num_line == 0: first_char = "" no_new_line = True line = u"{}{}.\t".format(first_char, line) scribus.insertText(line, -1, textbox) scribus.deselectAll() scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("num", textbox) # no character styles available #scribus.setFontSize(5, textbox) # TODO: testing only # BUG? scribus.setFont("Linux Libertine O Bold", textbox) num_chars += len(line) verse_counter += 1 else: if no_new_line: first_char = "" else: first_char = chr(28) no_new_line = False line = u"{}{}".format(first_char, line) scribus.insertText(line, -1, textbox) #scribus.deselectAll() #scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("text", textbox) num_chars += len(line) scribus.setColumnGap(5, textbox) columns = settings.get("columns", 2) scribus.setColumns(columns, textbox) if columns != 2: fit_height(textbox) else: scribus.sizeObject(new_width, text_columns_height, textbox) l, t = scribus.getPosition(textbox) scribus.moveObjectAbs(l, round(t / BASELINE_GRID) * BASELINE_GRID, textbox) if scribus.textOverflows(textbox): fit_height(textbox) # there are some cases,.. text_width, text_height = scribus.getSize(textbox) text_left, text_top = scribus.getPosition(textbox) return text_top + text_height - start_point + SPACING_SONGS, page_num
def load_song(data, offset, settings): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(page_num) start_point = margin_top + offset new_width = page_width - margin_left - margin_right if not FAST: scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0) eps = scribus.getSelectedObject() eps_width, eps_height = scribus.getSize(eps) #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5 scribus.sizeObject(eps_width*0.86, eps_height*0.86, eps) scribus.moveObjectAbs(margin_left, start_point+SPACING_HEADLINE_SONG, eps) eps_width, eps_height = scribus.getSize(eps) else: eps_height = 0 scribus.deselectAll() textbox = scribus.createText(margin_left, start_point, new_width, 20) style_suffix = get_style_suffix() if data["composer"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) if data["poet"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) scribus.deselectAll() scribus.insertText(u"{}\n".format(data["name"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("headline_{}".format(style_suffix), textbox) text = data["text"] text = [t.strip() for t in text if t.strip() != ""] # TODO: exit if text == [] textbox = scribus.createText(margin_left, start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT, new_width, 50) scribus.setStyle("text", textbox) # let's see how many digits are in there: num_verses = len([l for l in text if l.isdigit()]) num_chars = 0 num_line_total = len(text) num_line_actually = 0 no_new_line = False verse_counter = 0 text_columns_height = 0 # TODO: should be None for num_line, line in enumerate(text): if line.strip == "": continue num_line_actually += 1 if line.isdigit(): print "#", verse_counter, math.ceil(num_verses * 0.5), num_verses, data["filename"] if verse_counter == math.ceil(num_verses*0.5): # this is the first verse that should be in the new column, so let's see what's the height print text_columns_height, num_line_actually text_columns_height = BASELINE_GRID * (num_line_actually -1) first_char = "\n" if num_line == 0: first_char = "" no_new_line = True line = u"{}{}.\t".format(first_char, line) scribus.insertText(line, -1, textbox) scribus.deselectAll() scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("num", textbox) # no character styles available #scribus.setFontSize(5, textbox) # TODO: testing only # BUG? scribus.setFont("Linux Libertine O Bold", textbox) num_chars += len(line) verse_counter += 1 else: if no_new_line: first_char = "" else: first_char = chr(28) no_new_line = False line = u"{}{}".format(first_char, line) scribus.insertText(line, -1, textbox) #scribus.deselectAll() #scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("text", textbox) num_chars += len(line) scribus.setColumnGap(5, textbox) columns = settings.get("columns", 2) scribus.setColumns(columns, textbox) if columns != 2: fit_height(textbox) else: scribus.sizeObject(new_width, text_columns_height, textbox) l, t = scribus.getPosition(textbox) scribus.moveObjectAbs(l, round(t/BASELINE_GRID)*BASELINE_GRID, textbox) if scribus.textOverflows(textbox): fit_height(textbox) # there are some cases,.. text_width, text_height = scribus.getSize(textbox) text_left, text_top = scribus.getPosition(textbox) return text_top + text_height - start_point + SPACING_SONGS, page_num
if (item[1] == 4): if frameName != sampleFrameName and remove_copy_prefix( frameName).startswith(pattern): print(frameName + " found") position = scribus.getPosition(frameName) scribus.selectObject(sampleFrameName) scribus.duplicateObject() #duplicateFrameName = scribus.getSelectedObject() scribus.moveObjectAbs(position[0], position[1]) scribus.deleteObject(frameName) # TODO: rename the duplicate to the old frameName checkForOneFrameSelected() currentFrameName = scribus.getSelectedObject() print(currentFrameName) if (scribus.getObjectType(currentFrameName) == 4): scribus.messageBox('Scribus - Usage Error', "You did not select a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # the pattern is the name of the current frame up to the first digit # and with the "Copy of " at the beginning stripped away. matchNonDigit = re.compile(r'(^\D+)') matchResult = matchNonDigit.search(currentFrameName) pattern = matchResult.group(1) pattern = remove_copy_prefix(pattern) pattern = remove_copy_prefix(pattern)
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)
import sys import scribus if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() if scribus.selectionCount() == 0: scribus.messagebarText("No frame selected.") sys.exit() if scribus.selectionCount() > 1: scribus.messagebarText("Please select one single frame.") sys.exit() master_frame = scribus.getSelectedObject() x, y = scribus.getPosition() width, height = scribus.getSize() path = scribus.fileDialog("Pick a directory", scribus.getDocName(), isdir=True) if path == '': scribus.messagebarText("No directory selected.") extensions = ['jpg', 'png', 'tif'] filenames = [ f for f in os.listdir(path) if any(f.endswith(ext) for ext in extensions) ] if not filenames: scribus.messagebarText("No image found.")
# 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: scale = scaleY sc.setImageScale(scale, scale, obj) sc.docChanged(1) sc.setRedraw(True)
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 ])
import sys import scribus if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() if scribus.selectionCount() == 0: scribus.messagebarText("No frame selected.") sys.exit() if scribus.selectionCount() > 1: scribus.messagebarText("Please select one single frame.") sys.exit() master_frame = scribus.getSelectedObject() x,y = scribus.getPosition() width, height = scribus.getSize() path = scribus.fileDialog("Pick a directory", scribus.getDocName(), isdir = True) if path == '': scribus.messagebarText("No directory selected.") extensions = ['jpg', 'png', 'tif'] filenames = [f for f in os.listdir(path) if any(f.endswith(ext) for ext in extensions)] if not filenames:
import scribus if scribus.haveDoc(): if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Usage Error', "There is no object selected.\nPlease 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 object and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) pagelist = scribus.valueDialog('Paste to...',"Paste to which pages? \n(page numbers, separated by white space)","1") pageslist = pagelist.split() selframe = scribus.getSelectedObject() pages = scribus.pageCount() for p in pageslist: p_no = int(p) if ((p_no > pages) or (p_no < 1)): scribus.messageBox('OOPS!', "You have a page number outside the range of pages in your document", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) scribus.copyObject(selframe) for p in pageslist: p_no = int(p) scribus.gotoPage(p_no) scribus.pasteObject(selframe) scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Finished", "Done",icon=0,button1=1)
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);
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) while count < numselect: frames.append(scribus.getSelectedObject(count)) count += 1 for frame in frames: fwidth, fheight = scribus.getSize(frame) fx, fy = scribus.getPosition(frame) if location == "B": textf = scribus.createText(fx, fy+fheight, fwidth, 24) elif location == "T": textf = scribus.createText(fx, fy-24, fwidth, 24) elif location == "R": textf = scribus.createText(fx + fwidth, fy, 150, 40) elif location == "L": textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40) scribus.setUnit(pageunits)
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)
# -*- coding: utf-8 -*- # © 2018, MIT license, Ale Rimoldi <*****@*****.**> import scribus import sys if not scribus.haveDoc(): scribus.messageBox('Usage Error', 'You need a Document open') sys.exit(2) if scribus.selectionCount() == 0: scribus.messageBox('Usage Error', 'You need to select a frame') sys.exit(2) item = scribus.getSelectedObject() if (scribus.getObjectType(item) != 'TextFrame'): scribus.messageBox('Usage Error', 'You need to select a text frame') sys.exit(2) print(scribus.getTextLength(item)) if scribus.getTextLength(item) > 0: scribus.messageBox('Usage Error', 'The text frame should be empty') sys.exit(2) answer = scribus.valueDialog('Numbered lines', 'Start number, step', '1,1') start, step = answer.split(',') start = int(start) step = int(step) i = start
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) if scribus.getObjectType(item) == "ImageFrame" : imageFrame.append(item[0]) # print textFrame # print imageFrame scribus.deselectAll() chars = [] for item in textFrame : scribus.deselectAll() scribus.selectObject(item) n = scribus.getTextLength()
#!/usr/bin/python import sys try: import scribus except ImportError: print "This script only works from within Scribus" sys.exit(1) obj = scribus.getSelectedObject(0) sdir = 1 # options fs = 8 fsmax = 14 fsmin = 8 inc = 0.0005 ### tl = scribus.getTextLength() for c in range(tl - 1): scribus.selectText(c, 1, obj) if(sdir == 1): fs += inc if(fs > fsmax): sdir = 0 else: fs -= inc if(fs < fsmin): sdir = 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) sys.exit(2) contents = scribus.getTextLength(textbox) while c <= (contents -1): if ((c + 1) > contents - 1): nextchar = ' ' else: scribus.selectText(c+1, 1, textbox) nextchar = scribus.getText(textbox) scribus.selectText(c, 1, textbox)
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)
run_script = True import scribus from tempfile import NamedTemporaryFile try: import markdown except: scribus.messageBox( 'python-markdown not installed', 'You need to install python-markdown for this script to work', scribus.ICON_WARNING) run_script = False run_script &= bool( scribus.getSelectedObject(0)) # We must have at least one selected object if run_script and scribus.getSelectedObject(1): result = scribus.messageBox('', 'More than one item selected, load all?', button1=scribus.BUTTON_CANCEL, button2=scribus.BUTTON_YES) if result == scribus.BUTTON_CANCEL: run_script = False def main(): md_name = scribus.fileDialog("Select a file", 'Markdown (*.md)') if not md_name: return
# 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: # str(obj) scribus.selectObject(obj) scribus.selectText(0, scribus.getTextLength(obj), obj) scribus.setStyle(style, obj) scribus.deselectAll() scribus.setRedraw(True) scribus.docChanged(True)