To do this in Writer in Python, here is an adaptation from the HelloWorld.py script included in the standard LO distribution:
def HelloWorldPython( ):
#get the doc from the scripting context which is made available to all scripts
desktop = XSCRIPTCONTEXT.getDesktop()
model = desktop.getCurrentComponent()
#get the cursor
ctrllr = model.CurrentController
curview = ctrllr.ViewCursor
curview.String = "Hello World (in Python at cursor)"
return None
With the head start in the standard HelloWorld macro, it was easy to fill in the rest knowing how to do this in LO Basic is:
cntrllr = ThisComponent.CurrentController
vcur = cntrllr.ViewCursor
vcur.String = "Hello World "
Other useful methods of ViewCursor
, which presumably are the same in Python are:
SbxSTRING getString ( void ) ; SbxVOID setString ( SbxSTRING ) ;
SbxVOID collapseToStart ( void ) ; SbxVOID collapseToEnd ( void ) ;
SbxBOOL isCollapsed ( void ) ; SbxBOOL goLeft ( SbxINTEGER, SbxBOOL ) ;
SbxBOOL goRight ( SbxINTEGER, SbxBOOL ) ; SbxVOID gotoStart ( SbxBOOL ) ;
SbxVOID gotoEnd ( SbxBOOL ) ; SbxVOID gotoRange ( SbxOBJECT, SbxBOOL ) ;
SbxBOOL isVisible ( void ) ; SbxVOID setVisible ( SbxBOOL ) ; SbxOBJECT getPosition ( void );
SbxBOOL jumpToFirstPage ( void ) ; SbxBOOL jumpToLastPage ( void ) ;
SbxBOOL jumpToPage ( SbxINTEGER ) ; SbxINTEGER getPage ( void ) ;
SbxBOOL jumpToNextPage ( void ) ; SbxBOOL jumpToPreviousPage ( void ) ;
SbxBOOL jumpToEndOfPage ( void ) ; SbxBOOL jumpToStartOfPage ( void ) ;
SbxBOOL screenDown ( void ) ; SbxBOOL screenUp ( void ) ;
SbxBOOL goDown ( SbxINTEGER, SbxBOOL ) ; SbxBOOL goUp ( SbxINTEGER, SbxBOOL ) ;
SbxBOOL goLeft ( SbxINTEGER, SbxBOOL ) ; SbxBOOL goRight ( SbxINTEGER, SbxBOOL ) ;
SbxBOOL isAtStartOfLine ( void ) ; SbxBOOL isAtEndOfLine ( void ) ;
SbxVOID gotoEndOfLine ( SbxBOOL ) ; SbxVOID gotoStartOfLine ( SbxBOOL ) ;
Other useful properties of ViewCursor
: many formatting options and,
SbxOBJECT Start; SbxOBJECT End; SbxSTRING String;
SbxOBJECT Position; SbxBOOL Visible; SbxINTEGER Page;