Exemple #1
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "w")
            html = doc.toHtml()
            html = re.sub("<head>","<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>",html,count=1)
            f.write(html)
            f.close()
Exemple #2
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            #cursor = doc.rootFrame().lastCursorPosition()
            #cursor = doc.lastCursor()
            #cursor.insertDefaultBlock()
            #cursor.insertHtml( ' '.join(f.readlines()) )

            f = open(file, "r")
            doc.setHtml( ' '.join(f.readlines()) )
            f.close()
Exemple #3
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "w")
            html = doc.toHtml()
            html = re.sub(
                "<head>",
                "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>",
                html,
                count=1)
            f.write(html)
            f.close()
Exemple #4
0
    def importFile(self, fromFileName, options):
        fs = KWord.mainFrameSet()
        if not fs:
            raise "No main frameset to import the content too."
        doc = fs.document()
        if not fs:
            raise "No document to import the content too."

        fileExt = os.path.splitext(fromFileName)[1].lower()
        if fileExt == '.txt' or fileExt == '.html':
            f = open(fromFileName, "r")
            if fileExt == '.txt':
                doc.setText(''.join(f.readlines()))
            else:
                doc.setHtml(' '.join(f.readlines()))
            f.close()
        else:  #odt

            #TODO this crashes horrible :-(
            KWord.document().openUrl(fromFileName)
Exemple #5
0
    def importFile(self, fromFileName, options):
        fs = KWord.mainFrameSet()
        if not fs:
            raise "No main frameset to import the content too."
        doc = fs.document()
        if not fs:
            raise "No document to import the content too."

        fileExt = os.path.splitext(fromFileName)[1].lower()
        if fileExt == '.txt' or fileExt == '.html':
            f = open(fromFileName, "r")
            if fileExt == '.txt':
                doc.setText( ''.join(f.readlines()) )
            else:
                doc.setHtml( ' '.join(f.readlines()) )
            f.close()
        else: #odt

            #TODO this crashes horrible :-(
            KWord.document().openUrl(fromFileName)
Exemple #6
0
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

# Import the KWord module.
import KWord

# Get the TextDocument.
doc = KWord.mainFrameSet().document()

# Set the default cascading stylesheet.
doc.setDefaultStyleSheet((
    # Style for the headers.
    "h1 { color:#0000ff; }"
    "h2 { color:#000099; }"

    # Style for the unsorted list. This does not seem to work :-(
    #".ulist ul { list-style-type:disc; }"
    #".ulist ul { list-style-type:none; }"
    #".ulist ul { list-style-type:circle; }"
    #".ulist ul { list-style-type:square; }"

    # Style for the items in the unsorted list.
    ".ulist1 li { margin-left:1em; }"
    ".ulist2 li { margin-left:1em; color:#aa0000; }"
    ".ulist3 li { margin-left:1em; color:#00aa00; }"
    ".ulist4 li { margin-left:1em; color:#006666; }"

    # Style for the sorted list. This does not seem to work :-(
    #".olist ul { list-style-type:decimal; }"
    #".olist ul { list-style-type:none; }"
    #".olist ul { list-style-type:lower-roman; }"
Exemple #7
0
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

# Import the KWord module.
import KWord

# Get the TextDocument.
doc = KWord.mainFrameSet().document()

# Set the default cascading stylesheet.
doc.setDefaultStyleSheet(
    (
        # Style for the headers.
        "h1 { color:#0000ff; }"
        "h2 { color:#000099; }"

        # Style for the unsorted list. This does not seem to work :-(
        #".ulist ul { list-style-type:disc; }"
        #".ulist ul { list-style-type:none; }"
        #".ulist ul { list-style-type:circle; }"
        #".ulist ul { list-style-type:square; }"

        # Style for the items in the unsorted list.
        ".ulist1 li { margin-left:1em; }"
        ".ulist2 li { margin-left:1em; color:#aa0000; }"
        ".ulist3 li { margin-left:1em; color:#00aa00; }"
        ".ulist4 li { margin-left:1em; color:#006666; }"

        # Style for the sorted list. This does not seem to work :-(
        #".olist ul { list-style-type:decimal; }"
        #".olist ul { list-style-type:none; }"
Exemple #8
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "w")
            f.write( doc.toText() )
            f.close()
Exemple #9
0
class ImportDialog:
    """ The dialog we are using to provide some frontend to the user if the script runs
    for example embedded in KWord. """
    def __init__(self, action, config):
        import Kross, KWord

        self.action = action
        self.config = config

        forms = Kross.module("forms")
        self.dialog = forms.createDialog("Import Doxygen XML File")
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("List")  #Auto Plain List Tree Tabbed

        openpage = self.dialog.addPage("Open", "Import Doxygen XML File",
                                       "document-open")
        openwidget = forms.createFileWidget(
            openpage, "kfiledialog:///kwordsampleimportfile")
        openwidget.setMode("Opening")
        #openwidget.minimumWidth = 540
        #openwidget.minimumHeight = 400
        openwidget.setFilter("*.xml|XML Files\n*|All Files")

        configpage = self.dialog.addPage("Options", "Import Options",
                                         "preferences-other")
        configwidget = forms.createWidgetFromUIFile(
            configpage,
            os.path.join(action.currentPath(), "importdoxyxmloptions.ui"))

        stylepage = self.dialog.addPage("Styles", "Cascading Style Sheet",
                                        "preferences-web-browser-stylesheets")
        stylewidget = forms.createWidgetFromUIFile(
            stylepage,
            os.path.join(action.currentPath(), "importdoxyxmlstyle.ui"))
        styleedit = stylewidget["textEdit"]

        if self.dialog.exec_loop():
            fileName = openwidget.selectedFile()
            if not fileName:
                raise "No file selected"

            self.config.FileName = fileName
            self.config.TableOfContent = configwidget["TocCheckBox"].checked
            self.config.IndexPage = configwidget["IndexPageCheckBox"].checked
            self.config.OtherPages = configwidget["OtherPagesCheckBox"].checked
            self.config.EnablePages = configwidget["PagesCheckBox"].checked
            self.config.PageDescription = configwidget[
                "PageDescriptionCheckBox"].checked
            self.config.EnableClasses = configwidget["ClassesCheckBox"].checked
            self.config.ClassDescription = configwidget[
                "ClassDescriptionCheckBox"].checked
            self.config.MemberDescription = configwidget[
                "MemberDescriptionCheckBox"].checked
            self.config.EnableSlots = configwidget["SlotsCheckBox"].checked
            self.config.EnableSignals = configwidget["SignalsCheckBox"].checked
            self.config.EnableProperties = configwidget[
                "PropertiesCheckBox"].checked
            self.config.EnableFunctions = configwidget[
                "FunctionsCheckBox"].checked
            self.config.EnableVariables = configwidget[
                "VariablesCheckBox"].checked

            self.importFile(styleedit.plainText)

    def __del__(self):
        self.dialog.delayedDestruct()

    def importFile(self, styles):
        import Kross, KWord

        try:
            file = open(self.config.FileName, "r")
        except IOError, (errno, strerror):
            raise "Failed to read file \"%s\":\n%s" % (self.config.FileName,
                                                       strerror)

        xmldoc = xml.dom.minidom.parse(file)

        kwdoc = KWord.mainFrameSet().document()
        kwdoc.setDefaultStyleSheet("%s" % styles)

        class KWordFileWriter:
            def __init__(self, kwdoc):
                self.kwdoc = kwdoc
                self.lines = []

            def write(self, line):
                self.lines.append(line.encode('utf-8'))

            def flush(self):
                self.kwdoc.setHtml(' '.join(self.lines))

        writer = Writer(xmldoc, self.config)
        kwwriter = KWordFileWriter(kwdoc)
        writer.writeHtml(kwwriter)
        kwwriter.flush()
Exemple #10
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "r")
            doc.setText( ''.join(f.readlines()) )
            f.close()
Exemple #11
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "w")
            f.write(doc.toText())
            f.close()