File: readme.md

package info (click to toggle)
ipe-tools 1%3A7.2.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 840 kB
  • sloc: cpp: 2,677; python: 2,109; ansic: 1,053; sh: 224; makefile: 88; xml: 39
file content (72 lines) | stat: -rw-r--r-- 1,825 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Ipe Python module

This is an extension module that will let you read and write Ipe
documents from Python 3.

It makes the Ipe Lua-bindings available using a Python-Lua bridge
based on code written by [Gustavo
Niemeyer](http://labix.org/lunatic-python).

## Installation

You'll need to fill in the arguments to find the Lua and Ipe header
files and library in `setup.py`.  Then say
```
python3 setup.py build
python3 setup.py install --user
```

## Documentation

After loading the module:

```
import ipe
```

you can use the functions documented in the [Lua
bindings](http://ipe.otfried.org/manual/lua.html). For instance, load
an Ipe document by saying:

```
doc = ipe.Document("filename.pdf")
```

Have a look at `test.py` for an example.


**Tables:** Several methods in the module return *Lua tables*.  These
are similar to Python dictionaries, but are a distinct type.

For instance,

```
props = doc.properties()
```

will set `props` to be a table with keys such as `author`, `title`,
`created`, etc.  

You can access the elements of a table using either
attribute syntax (`props.title`) or dictionary syntax
(`props['title']`).  You can also can iterate over the elements of a
table in a `for` loop:

```
for k in props:
  print(k, props[k])
```

**Sequences:** A document is a sequence of pages, a page is a sequence
of graphical objects.  In Lua, indices **start with one**, not zero!
You can use Python's `len` function to determine the length of a
sequence.  For instance, loop over the pages of a document like this:

```
for pageNo in range(1, len(doc) + 1):
  print("Page %d has %d objects" % (pageNo, len(doc[pageNo])))
```

**Iterators:** The Lua documentation shows loops using
`page:objects()` and `document:pages()`.  This does not work from
Python.  You should use a loop over the indices instead.