home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / scribus-ng / samples / ExtractText.py < prev    next >
Encoding:
Python Source  |  2009-03-29  |  2.4 KB  |  82 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5.  
  6. (C)2006.03.04 Gregory Pittman
  7.  
  8. (C)2008.02.28 Petr Vanek - fileDialog replaces valueDialog
  9.  
  10. this version 2008.02.28
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the  GPL, v2 (GNU General Public License as published by
  14. the Free Software Foundation, version 2 of the License), or any later version.
  15. See the Scribus Copyright page in the Help Browser for further informaton 
  16. about GPL, v2.
  17.  
  18. SYNOPSIS
  19.  
  20. This script takes the current document and extracts all the text from text frames,
  21. and also gets the pathnames to all images. This is then saved to a file named
  22. by the user.
  23.  
  24. REQUIREMENTS
  25.  
  26. You must run from Scribus and must have a file open.
  27.  
  28. USAGE
  29.  
  30. Start the script. A file dialog appears for the name of the file 
  31. to save to. The above information is saved to the file.
  32.  
  33. """
  34. # Craig Bradney, Scribus Team
  35. # 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826, script is GPLd
  36.  
  37. import scribus
  38.  
  39.  
  40. def exportText(textfile):
  41.     page = 1
  42.     pagenum = scribus.pageCount()
  43.     T = []
  44.     content = []
  45.     while (page <= pagenum):
  46.         scribus.gotoPage(page)
  47.         d = scribus.getPageItems()
  48.         strpage = str(page)
  49.         T.append('Page '+ strpage + '\n\n')
  50.         for item in d:
  51.             if (item[1] == 4):
  52.                 contents = scribus.getAllText(item[0])
  53.                 if (contents in content):
  54.                     contents = 'Duplication, perhaps linked-to frame'
  55.                 T.append(item[0]+': '+ contents + '\n\n')
  56.                 content.append(contents)
  57.             elif (item[1] == 2):
  58.                 imgname = scribus.getImageFile(item[0])
  59.                 T.append(item[0]+': ' + imgname + '\n')
  60.         page += 1
  61.         T.append('\n')
  62.     output_file = open(textfile,'w')
  63.     output_file.writelines(T)
  64.     output_file.close()
  65.     endmessage = textfile + ' was created'
  66.     scribus.messageBox("Finished", endmessage,icon=0,button1=1)
  67.  
  68.  
  69. if scribus.haveDoc():
  70.     textfile = scribus.fileDialog('Enter name of file to save to', \
  71.                                   filter='Text Files (*.txt);;All Files (*)')
  72.     try:
  73.         if textfile == '':
  74.             raise Exception
  75.         exportText(textfile)
  76.     except Exception, e:
  77.         print e
  78.  
  79. else:
  80.     scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \
  81.                        icon=0, button1=1)
  82.