willsonlincake 发表于 2022-4-15 01:52:42

Scribus目录插件

#!/usr/bin/env python
# File: createTOC.py - Creates a Table of Contents from text
# and image frames, using frame names as the reference
# This version 2011.08.06
# This program 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

def exportText(textfile):
    page = 1
    pagenum = scribus.pageCount()
    T = []
    while (page <= pagenum):
      scribus.gotoPage(page)
      d = scribus.getPageItems()
      strpage = str(page)
      for item in d:
            if (item == 4):
                rawname = item
                newname = rawname.replace('_',' ')
                T.append(newname + '\t'+ strpage + '\n')
            elif (item == 2):
                rawname = item
                newname = rawname.replace('_',' ')   # where we switch underline to space
                T.append(newname + ' (image)' + '\t' + strpage + '\n')
      page += 1
    output_file = open(textfile,'w')
    output_file.writelines(T)
    output_file.close()
    endmessage = textfile + ' was created'
    scribus.messageBox("Finished", endmessage,icon=0,button1=1)
if scribus.haveDoc():
    textfile = scribus.fileDialog('Enter name of file to save to', filter='Text Files (*.txt);;All Files (*)')
    try:
      if textfile == '':
            raise Exception
      if (textfile[-4:] != '.txt'):
            textfile = textfile + '.txt'
      exportText(textfile)
    except Exception, e:
      print e
else:
    scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', icon=0, button1=1)

页: [1]
查看完整版本: Scribus目录插件