diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
| commit | 7ed83b6c6666eb8b6b104c211ae7e52907350372 (patch) | |
| tree | 4430b556abac0ad660a0aacf1887d77f85d8be02 /scribus/plugins/scriptplugin/samples/quote.py | |
| download | scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.gz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.xz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.zip | |
Branch 1.3.5 tree to 1.4.x tree, goodbye 1.3.x
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17163 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/plugins/scriptplugin/samples/quote.py')
| -rw-r--r-- | scribus/plugins/scriptplugin/samples/quote.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/scribus/plugins/scriptplugin/samples/quote.py b/scribus/plugins/scriptplugin/samples/quote.py new file mode 100644 index 0000000..aee0337 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/quote.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: iso-8859-1 -*- + +""" This script changes quotation marks from " " to french style """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +import re + +TITLE = "Text quoting" + +# These need to be declared as unicode strings until some +# charset issues in the scripter are worked out. +QUOTE_START = u"" +QUOTE_END = u"" + +def quote(textobj): + quoted_re = re.compile('"[^"]*"') + try: + text = getText(textobj) + except WrongFrameTypeError: + messageBox("quote.py", "Cannot quote text in a non-text frame", ICON_INFORMATION); + sys.exit(1) + if len(text) == 0: + return 0 # We can't very well change anything in an empty frame + count = 0 + i = 0 + selectText(0, 0, textobj) + while i < len(text): + match = quoted_re.match(text[i:]) + if match: + end = match.end() + selectText(i, 1, textobj) + deleteText(textobj) + insertText(QUOTE_START, i, textobj) + selectText(i + end - 1, 1, textobj) + deleteText(textobj) + insertText(QUOTE_END, i + end - 1, textobj) + count += 1 + i = i + end + else: + i = i + 1 + return count + + +def main(): + changed = 0 + sel_count = selectionCount() + if sel_count: + for i in range(sel_count): + changed += quote(getSelectedObject(i)) + else: + for page in range(pageCount()): + gotoPage(page) + for obj in getAllObjects(): + changed += quote(obj) + messageBox(TITLE, "%s quotations changed" % changed, + ICON_INFORMATION, BUTTON_OK) + +if __name__ == '__main__': + if haveDoc(): + try: + setRedraw(False) + main() + finally: + setRedraw(True) + redrawAll() + else: + messageBox(TITLE, "No document open", ICON_WARNING, BUTTON_OK) |
