PyAbiWord

From AbiWiki

(Difference between revisions)
Jump to: navigation, search
Line 57: Line 57:
<H4> A very simple program - test.py </H4>
<H4> A very simple program - test.py </H4>
<code>
<code>
-
#!/usr/bin/python
+
#!/usr/bin/python<br>
-
 
+
<br>
-
import sys
+
import sys<br>
-
import pygtk
+
import pygtk<br>
-
pygtk.require(''2.0'')
+
pygtk.require(''2.0'')<br>
-
import gtk
+
import gtk<br>
-
import abiword
+
import abiword<br>
-
 
+
<br>
-
window = gtk.Window()
+
window = gtk.Window() <br>
-
window.set_default_size(640, 480)
+
window.set_default_size(640, 480)<br>
-
window.connect(''delete-event'', gtk.main_quit)
+
window.connect(''delete-event'', gtk.main_quit) <br>
-
 
+
<br>
-
abi = abiword.Canvas()
+
abi = abiword.Canvas() <br>
-
window.add(abi)
+
window.add(abi)<br>
-
window.show_all()
+
window.show_all()<br>
-
abi.load_file("test.abw")
+
abi.load_file("test.abw")<br>
-
 
+
<br>
-
gtk.main()
+
gtk.main()<br>
</code>
</code>

Revision as of 02:31, 14 June 2008


Contents

PyAbiWord

PyAbiWord is a set of wrappers around AbiWidget that enable python programmers to use AbiWord in their PyGtk applications.

This set of code is available from the AbiWord cvs server with module name "pyabiword". To build it, you must first build libabiword as described in AbiWordSDK. After that make sure that the

PKG_CONFIG_PATH

evironment varia ble is set so that abiword-2.5.pc is discoverable.

After that configure pyabiword with:

./configure --prefix=/Path/To/Install

and "make" it.

The appropriate packages will be placed in:

/Path/To/Install/lib/python2.4/site-packages

Then make sure your

PYTHONPATH

environment variable is set so that /Path/To/Install/lib/python2.4/site-packages is discoverable.

To use the AbiWidget from within python call the "Canvas()" method on the abiword object. This returns the AbiWidget object which can be used like any other PyGtk GtkWidget in addition to its own methods.

Like the C version of AbiWidget, by default, PyAbiWord starts in "OLPC" mode, which is "Normal View", with a small left border, zoom set to page widget and selections are made on per word granularity.

You can turn this behaviour off with the:

set_show_margin(False)

and

set_word_selections(False)

Methods.

You can find a complete listing of all the methods available to the python AbiWidget at PyAbiWordMethods.

The Python wrapper supports all the [[[AbiWordSignals|AbiWordSignals]] signals] emitted by AbiWidget.

TableCreator

In addition to AbiWidget, PyAbiWord also wraps a useful little widget TableCreator. This widget allows users to interactively insert a table of specified size by dragging a mouse.

Follow the link to TableCreator to learn how to use this.

Example Code

A very simple program - test.py

  1. !/usr/bin/python


import sys
import pygtk
pygtk.require(2.0)
import gtk
import abiword

window = gtk.Window()
window.set_default_size(640, 480)
window.connect(delete-event, gtk.main_quit)

abi = abiword.Canvas()
window.add(abi)
window.show_all()
abi.load_file("test.abw")

gtk.main()


Contributors

Personal tools