OO-Snippets: fetching services from desktop

Commons

Keywords
LanguagePython
ApplicationOffice
AuthorsDarragh Sherwin (initial)
Tom Schindl (initial)
Supported Versions
Supported OS
QuestionHow can I fetch all services from the desktop?
Answer

Code-Snippet-Listing (snippet-source)

# Get all the required services for the current open document
def getDesktopDict( ctx ):

        desktop = ctx.ServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", ctx )

        #Get the current controller and viewCursor

        document = desktop.getCurrentComponent()
        controller = document.getCurrentController()
        viewCursor = controller.getViewCursor()

        document.RecordChanges = False

        return { 'desktop'    : desktop,
                 'document'  : document,
                 'controller' : controller,
                 'viewcursor' : viewCursor }

if __name__=="__main__":
        # For a connection example see Office.ConnectViaPipe.snip
        remoteContext = connect()
        deskDict = getDesktopDict( ctx )

Changelog

DateUserModification
2005-10-15tomsontomInitial version

and