Top > OOoSF > Jython > Examples

Edit

uno.py Edit

拡張機能パッケージにいれてあるものとは異なるかもしれません。

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
#!
# -*- coding: utf-8 -*-
 
from com.sun.star.uno import UnoRuntime
from com.sun.star.lib.uno.helper import WeakBase
 
 
def query(type, object):
    return UnoRuntime.queryInterface(type, object)
 
 
class Base(WeakBase):
    pass

Writer Edit

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
#!
# -*- coding: utf-8 -*-
 
import uno
 
from com.sun.star.uno import UnoRuntime
from com.sun.star.frame import XComponentLoader
from com.sun.star.text import XTextDocument
from com.sun.star.text import XSimpleText
from com.sun.star.beans import XPropertySet
from com.sun.star.awt.FontWeight import BOLD as FW_BOLD
from com.sun.star.text import XTextRange
from com.sun.star.awt.FontSlant import ITALIC as FS_ITALIC
 
def test():
    doc = XSCRIPTCONTEXT.getDocument()
    textDoc = uno.query(XTextDocument, doc)
    text = textDoc.getText()
    text.setString(u"にっぽんご")
    simpleText = uno.query(XSimpleText, text)
    cursor = simpleText.createTextCursor()
    cursor.gotoStart(False)
    cursor.goRight(4, True)
    textRange = uno.query(XTextRange, cursor)
    
    prop = uno.query(XPropertySet, cursor)
    prop.setPropertyValue("CharWeightAsian", FW_BOLD)
    prop.setPropertyValue("CharPostureAsian", FS_ITALIC)
    
def writer_test():
    ctx = XSCRIPTCONTEXT.getComponentContext()
    smgr = ctx.getServiceManager()
    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
    xLoader = UnoRuntime.queryInterface(XComponentLoader, desktop)
    doc = xLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, [])
 
    textDoc = uno.query(XTextDocument, doc)
    text = textDoc.getText()
    text.setString("Hello World!")
 
g_exportedScripts = test,

ダイアログ Edit

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
import uno
 
from com.sun.star.awt import (XDialogProvider, XActionListener, XControlContainer, 
    XButton)
from com.sun.star.lang import XComponent
 
class ButtonActionListener(uno.Base, XActionListener):
    def __init__(self):
        pass
    def disposing(self, ev): pass
    def actionPerformed(self, ev):
        print("button pushed.")
 
def test():
    ctx = XSCRIPTCONTEXT.getComponentContext()
    smgr = ctx.getServiceManager()
    dp = uno.query(XDialogProvider, 
        smgr.createInstanceWithContext("com.sun.star.awt.DialogProvider", ctx))
    dlg = dp.createDialog(
        "vnd.sun.star.script:Standard.AddWatch?location=application")
    cont = uno.query(XControlContainer, dlg)
    
    btn_min = cont.getControl("btn_min")
    btn = uno.query(XButton, btn_min)
    btn.addActionListener(ButtonActionListener())
    
    dlg.execute()
    
    uno.query(XComponent, dlg).dispose()

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes