예제 #1
0
 def execAction(self):
     try:
         name = self.actions[ self.widgetlist.currentRow ]
         KWord.tool().triggerAction( name.strip() )
     except:
         message = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
         self.forms.showMessageBox("Error", "Error", "%s" % message)
예제 #2
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog("Insert Shape")
        self.dialog.minimumWidth = 500
        self.dialog.minimumHeight = 360
        self.dialog.setButtons("Ok|Cancel")
        #self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed

        self.shapes = KWord.shapeKeys()
        page = self.dialog.addPage("", "")
        widget = self.forms.createWidgetFromUI(page,
            '<ui version="4.0" >'
            ' <class>Form</class>'
            ' <widget class="QWidget" name="Form" >'
            '  <layout class="QHBoxLayout" >'
            '   <item>'
            '    <widget class="QListWidget" name="List">'
            '     <property name="currentRow"><number>%i</number></property>'
            '     %s'
            '    </widget>'
            '   </item>'
            '  </layout>'
            ' </widget>'
            '</ui>'
            % ( 0, ''.join( [ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.shapes ] ) )
        )
        self.widgetlist = widget["List"]

        if self.dialog.exec_loop():
            self.doInsert()
예제 #3
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog("Insert Shape")
        self.dialog.minimumWidth = 500
        self.dialog.minimumHeight = 360
        self.dialog.setButtons("Ok|Cancel")
        #self.dialog.setFaceType("List") #Auto Plain List Tree Tabbed

        self.shapes = KWord.shapeKeys()
        page = self.dialog.addPage("", "")
        widget = self.forms.createWidgetFromUI(
            page, '<ui version="4.0" >'
            ' <class>Form</class>'
            ' <widget class="QWidget" name="Form" >'
            '  <layout class="QHBoxLayout" >'
            '   <item>'
            '    <widget class="QListWidget" name="List">'
            '     <property name="currentRow"><number>%i</number></property>'
            '     %s'
            '    </widget>'
            '   </item>'
            '  </layout>'
            ' </widget>'
            '</ui>' % (0, ''.join([
                '<item><property name="text" ><string>%s</string></property></item>'
                % s for s in self.shapes
            ])))
        self.widgetlist = widget["List"]

        if self.dialog.exec_loop():
            self.doInsert()
예제 #4
0
파일: exportfile.py 프로젝트: KDE/koffice
        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()
예제 #5
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog("Execute Action")
        self.dialog.minimumWidth = 500
        self.dialog.minimumHeight = 360
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("Plain")  #Auto Plain List Tree Tabbed

        self.objects = [
            ('application', KWord.application()),
            ('shell', KWord.shell()),
            ('mainwindow', KWord.mainWindow()),
            ('document', KWord.document()),
        ]

        self.actions = []
        for obj in self.objects:
            for s in dir(obj[1]):
                if s.startswith('slot'):
                    self.actions.append("%s.%s" % (obj[0], s))

        page = self.dialog.addPage("", "")
        widget = self.forms.createWidgetFromUI(
            page, '<ui version="4.0" >'
            ' <class>Form</class>'
            ' <widget class="QWidget" name="Form" >'
            '  <layout class="QHBoxLayout" >'
            '   <item>'
            '    <widget class="QListWidget" name="List">'
            '     <property name="currentRow"><number>%i</number></property>'
            '     %s'
            '    </widget>'
            '   </item>'
            '  </layout>'
            ' </widget>'
            '</ui>' % (0, ''.join([
                '<item><property name="text" ><string>%s</string></property></item>'
                % s for s in self.actions
            ])))
        self.widgetlist = widget["List"]

        if self.dialog.exec_loop():
            self.execAction()
예제 #6
0
    def __init__(self, scriptaction):
        self.scriptaction = scriptaction
        #self.currentpath = self.scriptaction.currentPath()
        self.forms = Kross.module("forms")
        self.dialog = self.forms.createDialog("Execute Action")
        self.dialog.minimumWidth = 500
        self.dialog.minimumHeight = 360
        self.dialog.setButtons("Ok|Cancel")
        self.dialog.setFaceType("Plain") #Auto Plain List Tree Tabbed

        self.objects = [
            ('application', KWord.application()),
            ('shell',       KWord.shell()),
            ('mainwindow',  KWord.mainWindow()),
            ('document',    KWord.document()),
        ]

        self.actions = []
        for obj in self.objects:
            for s in dir(obj[1]):
                if s.startswith('slot'):
                    self.actions.append( "%s.%s" % (obj[0],s) )

        page = self.dialog.addPage("", "")
        widget = self.forms.createWidgetFromUI(page,
            '<ui version="4.0" >'
            ' <class>Form</class>'
            ' <widget class="QWidget" name="Form" >'
            '  <layout class="QHBoxLayout" >'
            '   <item>'
            '    <widget class="QListWidget" name="List">'
            '     <property name="currentRow"><number>%i</number></property>'
            '     %s'
            '    </widget>'
            '   </item>'
            '  </layout>'
            ' </widget>'
            '</ui>'
            % ( 0, ''.join( [ '<item><property name="text" ><string>%s</string></property></item>' % s for s in self.actions ] ) )
        )
        self.widgetlist = widget["List"]

        if self.dialog.exec_loop():
            self.execAction()
예제 #7
0
파일: ooimport.py 프로젝트: KDE/koffice
    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)
예제 #8
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()
예제 #9
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)
예제 #10
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()
예제 #11
0
    def doInsert(self):
        try:
            shapeId = self.shapes[ self.widgetlist.currentRow ]

            frame = KWord.addFrame("myshape", shapeId)
            if frame == None:
                raise "No such shape \"%s\"" % shapeId

            #frame.setTextRunAround(tableframe.RunThrough)
            #frame.setPosition(200, 160)
            #frame.resize(160, 160)

        except:
            message = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
            self.forms.showMessageBox("Error", "Error", "%s" % message)
예제 #12
0
def addList(text,liststyle):
    global KWord, cursor
    # The block seems to be needed cause else additional insertHtml-calls don't respect the line-break whyever.
    cursor.insertDefaultBlock()
    #cursor.insertBlock()
    # We like to create a new list
    cursor.insertHtml("<br><h2>%s</h2>" % text)
    # Create a new style and set the liststyle
    s = KWord.addParagraphStyle("My%sStyle" % text)
    #s.setListStyle( getattr(s,liststyle) ) # e.g. s.setListStyle( s.SquareItem )
    # Create the list and apply the style
    l = cursor.insertList()
    l.setStyle(s)
    # Fill the list with some items
    for i in range(1, 6):
        if i != 1:
            cursor.insertBlock()
        cursor.insertHtml( "item nr=%i count=%i" % (i,l.countItems()) )
예제 #13
0
def addList(text, liststyle):
    global KWord, cursor
    # The block seems to be needed cause else additional insertHtml-calls don't respect the line-break whyever.
    cursor.insertDefaultBlock()
    #cursor.insertBlock()
    # We like to create a new list
    cursor.insertHtml("<br><h2>%s</h2>" % text)
    # Create a new style and set the liststyle
    s = KWord.addParagraphStyle("My%sStyle" % text)
    #s.setListStyle( getattr(s,liststyle) ) # e.g. s.setListStyle( s.SquareItem )
    # Create the list and apply the style
    l = cursor.insertList()
    l.setStyle(s)
    # Fill the list with some items
    for i in range(1, 6):
        if i != 1:
            cursor.insertBlock()
        cursor.insertHtml("item nr=%i count=%i" % (i, l.countItems()))
예제 #14
0
    def doInsert(self):
        try:
            shapeId = self.shapes[self.widgetlist.currentRow]

            frame = KWord.addFrame("myshape", shapeId)
            if frame == None:
                raise "No such shape \"%s\"" % shapeId

            #frame.setTextRunAround(tableframe.RunThrough)
            #frame.setPosition(200, 160)
            #frame.resize(160, 160)

        except:
            message = "".join(
                traceback.format_exception(sys.exc_info()[0],
                                           sys.exc_info()[1],
                                           sys.exc_info()[2]))
            self.forms.showMessageBox("Error", "Error", "%s" % message)
예제 #15
0
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

import KWord, time, sys, os

#if KWord.pageCount() < 1: KWord.insertPage(0)
#doc = KWord.frameSet(0).document()

doc = KWord.mainFrameSet().document()

# Set the default cascading stylesheet.
doc.setDefaultStyleSheet(("li { margin-left:1em; }"
                          ".my1 { text-transform: lowercase; }"
                          ".my2 { text-transform: uppercase; }"
                          ".my3 { text-transform: capitalize; }"))

# Set the html with some general informations.
doc.setHtml((
    "<h1><font color=\"blue\">Python Sample: Text</font></h1>"
    "<p><i>italic</i> and <b>bold</b> and <u>underlined</u> and a <a href=\"test\">link</a></p>."
    "<div class='my1'>lOwErCaSe</div>"
    "<div class='my2'>uPpErCaSe</div>"
    "<div class='my3'>capitalize</div>"
    "<ul>"
    "<li>Time: <b>%s</b></li>"
    "<li>Operating System: <b>%s</b></li>"
    "<li>Python Version: <b>%s</b></li>"
    "<li>Documents: <b>%s</b></li>"
    "<li>Views: <b>%s</b></li>"
    "<li>Windows: <b>%s</b></li>"
    "<li>PageCount: <b>%s</b></li>"
예제 #16
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; }"
예제 #17
0
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

import KWord, time

# fetch the main window
komainwindow = KWord.shell()

# set the statusbar text
komainwindow.slotSetStatusBarText("This is the sample_progressbar.py script")

try:
    # increment the progressbar from 0% to 100%
    for i in range(1, 101):
        komainwindow.slotProgress(i)
        # wait some seconds else we are to fast ;)
        time.sleep(0.1)
finally:
    # reset the statusbar-text and the progressbar.
    komainwindow.slotSetStatusBarText("")
    komainwindow.slotProgress(-1)
예제 #18
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; }"
예제 #19
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "r")
            doc.setText( ''.join(f.readlines()) )
            f.close()
예제 #20
0
파일: exportfile.py 프로젝트: KDE/koffice
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "w")
            f.write( doc.toText() )
            f.close()
예제 #21
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()
예제 #22
0
파일: sample_text.py 프로젝트: KDE/koffice
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

import KWord, time, sys, os

#if KWord.pageCount() < 1: KWord.insertPage(0)
#doc = KWord.frameSet(0).document()

doc = KWord.mainFrameSet().document()

# Set the default cascading stylesheet.
doc.setDefaultStyleSheet(
    (
        "li { margin-left:1em; }"
        ".my1 { text-transform: lowercase; }"
        ".my2 { text-transform: uppercase; }"
        ".my3 { text-transform: capitalize; }"
    )
)

# Set the html with some general informations.
doc.setHtml(
    (
        "<h1><font color=\"blue\">Python Sample: Text</font></h1>"
        "<p><i>italic</i> and <b>bold</b> and <u>underlined</u> and a <a href=\"test\">link</a></p>."

        "<div class='my1'>lOwErCaSe</div>"
        "<div class='my2'>uPpErCaSe</div>"
        "<div class='my3'>capitalize</div>"

        "<ul>"
예제 #23
0
    def __del__(self):
        self.dialog.delayedDestruct()

config = MyConfig()

try:
    # try to import KWord. If this fails we are not running embedded in KWord.
    import KWord
    config.showDialog = True
except ImportError:
    # looks as we are not running embedded within KWord. So, let's use Kross to import the KWord library.
    KWord = Kross.module("kword")

    if config.readOdfFile:
        KWord.document().openUrl(config.readOdfFile)

    if not KWord.document().url():
        # if KWord does not have a loaded document now we show a fileopen-dialog to let the user choose the odt file.
        forms = Kross.module("forms")
        dialog = forms.createDialog("ReportLab.org")
        dialog.setButtons("Ok|Cancel")
        dialog.setFaceType("Plain")
        openwidget = forms.createFileWidget(dialog.addPage("Open","Open ODT File"))
        openwidget.setMode("Opening")
        openwidget.setFilter("*.odt|ODT Files\n*|All Files")
        if not dialog.exec_loop():
            raise Exception("Aborted.")
        if not KWord.document().openUrl(openwidget.selectedFile()):
            raise Exception("Failed to open file: %s" % openwidget.selectedFile())
예제 #24
0
    def __del__(self):
        self.dialog.delayedDestruct()

config = MyConfig()

try:
    # try to import KWord. If this fails we are not running embedded in KWord.
    import KWord
    config.showDialog = True
except ImportError:
    # looks as we are not running embedded within KWord. So, let's use Kross to import the KWord library.
    KWord = Kross.module("kword")

    if config.readOdfFile:
        KWord.document().openUrl(config.readOdfFile)

    if not KWord.document().url():
        # if KWord does not have a loaded document now we show a fileopen-dialog to let the user choose the odt file.
        forms = Kross.module("forms")
        dialog = forms.createDialog("ReportLab.org")
        dialog.setButtons("Ok|Cancel")
        dialog.setFaceType("Plain")
        openwidget = forms.createFileWidget(dialog.addPage("Open","Open ODT File"))
        openwidget.setMode("Opening")
        openwidget.setFilter("*.odt|ODT Files\n*|All Files")
        if not dialog.exec_loop():
            raise Exception("Aborted.")
        if not KWord.document().openUrl(openwidget.selectedFile()):
            raise Exception("Failed to open file: %s" % openwidget.selectedFile())
예제 #25
0
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

import KWord, time

# fetch the main window
komainwindow = KWord.shell()

# set the statusbar text
komainwindow.slotSetStatusBarText("This is the sample_progressbar.py script")

try:
    # increment the progressbar from 0% to 100%
    for i in range(1,101):
        komainwindow.slotProgress(i)
        # wait some seconds else we are to fast ;)
        time.sleep(0.1)
finally:
    # reset the statusbar-text and the progressbar.
    komainwindow.slotSetStatusBarText("")
    komainwindow.slotProgress(-1)
예제 #26
0
        def __init__(self, file):
            doc = KWord.mainFrameSet().document()

            f = open(file, "w")
            f.write(doc.toText())
            f.close()
예제 #27
0
#!/usr/bin/env kross
# -*- coding: utf-8 -*-

import KWord

idx = 0
shapes = KWord.shapeKeys()
for shapeId in shapes:
    frame = KWord.addFrame("myshape", shapeId)
    if frame != None:
        #frame.setTextRunAround(tableframe.RunThrough)
        frame.setPosition(idx % 6 * 80 + 20, 100 * idx + 20)
        #frame.resize(160, 160)
        idx += 1