Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

PyClient

Categories: Tools
<< | Page list | >>

Python interface to the LyXServer

Goal

An easy to use interface for external scripts enhancing LyX

Solution

A Python package with functions and classes to connect to LyX via the LyXServer and make LyxFunctions available to python scripts.

  • start_lyx() start a LyX session in a separate process
  • lyxpipe() open a lyxpipe for nonblocking access
  • LyXServer basic class for communication with the LyXServer. (provides a file-type like object)
  • LyXClient more high level LyX client using the serverpipes
  • lfuns.py a module wrapping lyx functions (LFUNS) to python functions

And the example "end-user" scripts

  • lyx-remote: Open a file in a running LyX or start LyX with the file
  • lyx-Mx: LyX with an interactive lyxclient ('minibuffer-console')
  • lyx-python: LyX with an interactive Python client
  • bindings help on keybindings and lyxfunctions

Tested on Linux only!

Files

uploads:/Tools/PyClient/pylyx0.1.tar.bz2 python LyX package

Installation

  • Unpack to somewhere in your PYTHONPATH (will create the package directory LyX/).
  • Optionally copy/link the example scripts in LyX/examples to somewhere in your PATH (e.g. /usr/local/bin)
  • You can browse the embedded documentation with pydoc, e.g.:
    pydoc -p 1200 &; firefox http://localhost:1200 # or any browser of your choice

Configuration

    Set Edit>Preferences>Paths>Server-pipe to "~/.lyx/lyxpipe"
For a different path, change the global variable SERVERPIPE.
  • At import time, the LyX package looks for a file ~/.lyx/scripts/python/config.py that can be used to override the defaults in LyX.constants.py

Usage

  • To use the new classes in a python script, do e.g.
from LyX.lyxclient import LyXClient
client = LyXClient()
  • or run LyX via one of the scripts in pyclient/examples/ to make use of enhancements.

Example

Word count

Needs the `xclip` command line tool.

  • Start lyx-python [file]
(This will connect to a runnign LyX session or open up a new one if there is no LyX running.)
  • at the Python prompt write count_words()
  • Read the word count in the statusbar or at the terminal.

See also the scripts in LyX/examples/

History

2005-01-26 First public release (Python module),

2005-01-31 Bugfix release 0.2,

2005-05-06 First release of the LyX package.

Comments, Bugs

  • Testing is only partially done (and only on a Debian Linux system)
  • For some strange reason, LyX closes and reopens the serverpipes with every read/save operation. Polling the pipes will therefore be fooled and the LyXclient.listen method breaks with every buffer-save or buffer-read.

Send bugreports, feature wishes and comments to one of the LyX lists.

Copyright

Copyright (c) 2005 Günter Milde

Released under the terms of the GNU General Public License (ver. 2 or later)

Tools

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2008-09-27 14:49 UTC