Scribus目录插件

电脑技术 电脑技术 916 人阅读 | 0 人回复 | 2022-04-15

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #!/usr/bin/env python
  2. # File: createTOC.py - Creates a Table of Contents from text
  3. # and image frames, using frame names as the reference
  4. # This version 2011.08.06
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.

  9. import scribus

  10. def exportText(textfile):
  11.     page = 1
  12.     pagenum = scribus.pageCount()
  13.     T = []
  14.     while (page <= pagenum):
  15.         scribus.gotoPage(page)
  16.         d = scribus.getPageItems()
  17.         strpage = str(page)
  18.         for item in d:
  19.             if (item[1] == 4):
  20.                 rawname = item[0]
  21.                 newname = rawname.replace('_',' ')
  22.                 T.append(newname + '\t'+ strpage + '\n')
  23.             elif (item[1] == 2):
  24.                 rawname = item[0]
  25.                 newname = rawname.replace('_',' ')   # where we switch underline to space
  26.                 T.append(newname + ' (image)' + '\t' + strpage + '\n')
  27.         page += 1
  28.     output_file = open(textfile,'w')
  29.     output_file.writelines(T)
  30.     output_file.close()
  31.     endmessage = textfile + ' was created'
  32.     scribus.messageBox("Finished", endmessage,icon=0,button1=1)
  33. if scribus.haveDoc():
  34.     textfile = scribus.fileDialog('Enter name of file to save to', filter='Text Files (*.txt);;All Files (*)')
  35.     try:
  36.         if textfile == '':
  37.             raise Exception
  38.         if (textfile[-4:] != '.txt'):
  39.             textfile = textfile + '.txt'
  40.         exportText(textfile)
  41.     except Exception, e:
  42.         print e
  43. else:
  44.     scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', icon=0, button1=1)
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门推荐