Control Libreoffice Impress from Python

前端 未结 3 2048
遥遥无期
遥遥无期 2021-01-25 16:17

Im writing an application oriented to speakers and conferences. Im writing it with Python and focused on Linux.

I would like to know if its possible to control LibreOffi

相关标签:
3条回答
  • 2021-01-25 16:52

    Take a look at AOO UNO . You may also check some application projects like docvert. This framework is shared between LO and Apache OO, but perhaps there some minor differences due to separate development of the two projects.

    For a simple tutorial-like code you may take a look at this project. The rest depends on your actual needs and you should study corresponding UNO API, it's (almost) language-neutral.

    0 讨论(0)
  • 2021-01-25 16:53

    The answer from @user3159253 describes how to connect to a presentation file, which is the first part of your question. Then, to control the presentation you will need to use XPresentation2 and XSlideShowController. Here is some code to do this, using the doc variable from the other example:

    def runSlideShow(doc):
        presentation = doc.getPresentation()
        presentation.start()
        while not presentation.isRunning():
            pass
        presentation_controller = presentation.getController()
        presentation_controller.gotoNextSlide()
        print("isRunning() == %s" % presentation_controller.isRunning())
    

    I adapted this code from http://openoffice.2283327.n4.nabble.com/XPresentation2-returns-a-null-XSlideShowController-td2771599.html.

    Responding to your comment: You need to add the following towards the bottom of the code, similar to what is in highlight.py. Did you try running the impress-code-highlighter example?

    def do_runSlideShow(*args):
        ctx = XSCRIPTCONTEXT
        doc = ctx.getDocument()
        runSlideShow(doc)
    
    g_exportedScripts = (do_runSlideShow,)
    if __name__ == "__main__":
        doc = remote_get_doc()
        runSlideShow(doc)
    
    0 讨论(0)
  • 2021-01-25 16:58

    Finally, I found a way to solve this using Python, in an elegant and easy way. Instead of libraries or APIs, Im using a socket to connect to Impress and control it.

    At the end of the post you can read the full-text that indicates how to control Impress this way. It is easy, and amazing.

    You send a message using Python to Impress ( that is listening in some port ), it receives the message and does things based on your request.

    You must enable this "remote control" feeature in the app. I solved my problem using this.

    Thanks for your replies!.

    LibreOffice Impress Remote Protocol Specification

    Communication is over a UTF-8 encoded character stream. (Using RTL_TEXTENCODING_UTF8 in the LibreOffice portion.)

    TCP

    More TCP-specific details on setup and initial handshake to be written, but the actual message protocol is the same as for Bluetooth.

    Message Format

    A message consists of one or more lines. The first line is the message description, further lines can add any necessary data. An empty line concludes the message.

    I.e. "MESSAGE\n\n" or "MESSAGE\nDATA\nDATA2...\n\n"

    You must keep reading a message until an empty line (i.e. double new-line) is reached to allow for future protocol extension.

    Intialisation

    Once connected the server sends "LO_SERVER_SERVER_PAIRED". (I.e. "LO_SERVER_SERVER_PAIRED\n\n" is sent over the stream.)

    Subsequently the server will send either slideshow_started if a slideshow is running, or slideshow_finished if no slideshow is running. (See below for details of.)

    The current server implementation then proceeds to send all slide notes and previews to the client. (This should be changed to prevent memory issues, and a preview request mechanism implemented.)

    Commands (Client to Server)

    The client should not assume that the state of the server has changed when a command has been sent. All changes will be signalled back to the client. (This is to allow for cases such as multiple clients requesting different changes, etc.)

    Any lines in [square brackets] are optional, and should be omitted if not needed.

    • transition_next
    • transition_previous

    • goto_slide slide_number

    • presentation_start

    • presentation_stop

    • presentation_resume // Resumes after a presentation_blank_screen.

    • presentation_blank_screen [Colour String] // Colour the screen will show (default: black). Not // implemented, and format hasn't yet been defined.

    As of gsoc2013, these commands are extended to the existing protocol, since server-end are tolerant with unknown commands, these extensions doesn't break backward compatibility

    • pointer_started // create a red dot on screen at initial position (x,y) initial_x // This should be called when user first touch the screen initial_y // note that x, y are in percentage (from 0.0 to 1.0) with respect to the slideshow size
    • pointer_dismissed // This dismiss the pointer red dot on screen, should be called when user stop touching screen
    • pointer_coordination // This update pointer's position to current (x,y) current_x // note that x, y are in percentage (from 0.0 to 1.0) with respect to the slideshow size current_y // unless screenupdater's performance is significantly improved, we should consider limit the update frequency on the // remote-end

    Status/Data (Server to Client)

    • slideshow_finished // (Also transmitted if no slideshow running when started.)

    • slideshow_started // (Also transmitted if a slideshow is running on startup.) numberOfSlides currentSlideNumber

    • slide_notes slideNumber [Notes] // The notes are an html document, and may also include \n newlines, // i.e. the client should keep reading until a blank line is reached.

    • slide_updated // Slide on server has changed currentSlideNumber

    • slide_preview // Supplies a preview image for a slide. slideNumber image // A Base 64 Encoded png image.

    As of gsoc2013, these commands are extended to the existing protocol, since remote-end also ignore all unknown commands (which is the case of gsoc2012 android implementation), backward compatibility is kept.

    • slideshow_info // once paired, the server-end will send back the title of the current presentation Title
    0 讨论(0)
提交回复
热议问题