123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- def InsertText(text):
- """Inserts the argument string into the current document.
- If there is a selection, the selection is replaced by it.
- """
-
-
- desktop = XSCRIPTCONTEXT.getDesktop()
- model = desktop.getCurrentComponent()
-
- if not hasattr(model, "Text"):
- return
-
-
- xModel = XSCRIPTCONTEXT.getDocument()
-
-
- xSelectionSupplier = xModel.getCurrentController()
-
- xIndexAccess = xSelectionSupplier.getSelection()
- count = xIndexAccess.getCount()
- if count >= 1:
- i = 0
- while i < count:
- xTextRange = xIndexAccess.getByIndex(i)
- theString = xTextRange.getString()
- if not len(theString):
-
- xText = xTextRange.getText()
- xWordCursor = xText.createTextCursorByRange(xTextRange)
- xWordCursor.setString(text)
- xSelectionSupplier.select(xWordCursor)
- else:
-
- xTextRange.setString(text)
- xSelectionSupplier.select(xTextRange)
- i += 1
- def InsertHello(event=None):
-
- InsertText("Hello")
- g_exportedScripts = (InsertHello, )
|