import sys try: import scribus except ModuleNotFoundError: raise ImportError 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) textbox = scribus.getSelectedObject() ftype = scribus.getObjectType(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) len1 = scribus.getTextLength(textbox) if len1 < 5: scribus.messageBox('Scribus - Script Error', "Textframe should contain a few characters already. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) scribus.insertText("12345", 0, textbox) # need a "flush" function here? saveDoc has a limited effect in the general case #scribus.saveDocAs("test1.sla") #scribus.docChanged(True) len2 = scribus.getTextLength(textbox) if len2 != len1 + 5: scribus.messageBox('Scribus - Script Error', "Expected textLength to increase by 5.", scribus.ICON_WARNING, scribus.BUTTON_OK) # this should print 12345xxxxx, where xxxxx are the former first 5 chars res1 = scribus.getAllText(textbox) scribus.selectText(0, 10,textbox) res2 = scribus.getText(textbox) scribus.messageBox('Scribus - Test Result', "Text length=" + str(len2) + ", getAlltext: " + res1 + ", getText: " + res2, scribus.ICON_WARNING, scribus.BUTTON_OK)