PyAbiWord

From AbiWiki

(Difference between revisions)
Jump to: navigation, search
 
(14 intermediate revisions not shown)
Line 1: Line 1:
-
<!--Modify this as appropriate, especially if it''s not an FAQ-->
+
=PyAbiWord=
-
<!--Aside: using H2 and H3 is a trick for old TWikis to keep headings out of the [[ToC|ToC]]-->
+
-
<!--Delete this line and those above, and anything else that is not needed when you create the page, leave the [[ToC|ToC]] commented out if you don''t use it-->
+
-
 
+
-
<H2>[[PyAbiWord|PyAbiWord]]</H2>
+
-
 
+
[[PyAbiWord|PyAbiWord]] is a set of wrappers around [[AbiWidget|AbiWidget]] that enable python programmers to use [[AbiWord|AbiWord]] in their [[PyGtk|PyGtk]] applications.
[[PyAbiWord|PyAbiWord]] is a set of wrappers around [[AbiWidget|AbiWidget]] that enable python programmers to use [[AbiWord|AbiWord]] in their [[PyGtk|PyGtk]] applications.
-
===Getting the Source Code from SVN===
+
==Getting the Source Code from SVN==
-
This set of code is available from the [[AbiWord|AbiWord]] cvs server with module name "pyabiword".
+
This set of code is available from the [[AbiWord|AbiWord]] cvs server with module name &amp;quot;pyabiword&amp;quot;.
-
For version 2.6 (the current stable version of AbiWord) do:
+
For version 2.8 (the current stable version of AbiWord) do:
-
   svn co http://svn.abisource.com/pyabiword/branches/ABI-2-6-0-STABLE/ pyabiword
+
   svn co http://svn.abisource.com/pyabiword/branches/ABI-2-8-0-STABLE/ pyabiword
You get the current development version with:
You get the current development version with:
Line 20: Line 15:
   svn co http://svn.abisource.com/pyabiword/trunk pyabiword
   svn co http://svn.abisource.com/pyabiword/trunk pyabiword
-
===Building pyabiword===
 
-
To build it, you must first build libabiword as described in [[AbiWordSDK|AbiWordSDK]]. Note that for post 2.6, libabiword should be built with the "--enable-dynamic" configure option.  
+
==Building pyabiword==
 +
 
 +
To build it, you must first build libabiword as described in [[AbiWordSDK|AbiWordSDK]]. Make sure to build libabiword with the &quot;--enable-dynamic&quot; configure option.  
After that make sure that the  
After that make sure that the  
Line 28: Line 24:
   PKG_CONFIG_PATH  
   PKG_CONFIG_PATH  
-
environment variable is set so that abiword-2.6.pc or abiword-2.7.pc is discoverable.
+
environment variable is set so that abiword-2.8.pc or abiword-2.9.pc is discoverable.
After that configure pyabiword with:
After that configure pyabiword with:
Line 34: Line 30:
   ./configure --prefix=/Path/To/Install
   ./configure --prefix=/Path/To/Install
-
and "make" it.
+
and &quot;make&quot; it.
The appropriate packages will be placed in:
The appropriate packages will be placed in:
Line 50: Line 46:
environment variable is set so that /Path/To/Install/lib/python2.4/site-packages or Path/To/Install/lib/python2.5/site-packages is discoverable.
environment variable is set so that /Path/To/Install/lib/python2.4/site-packages or Path/To/Install/lib/python2.5/site-packages is discoverable.
-
To use the [[AbiWidget|AbiWidget]] from within python call the "Canvas()" method on the abiword object. This returns the [[AbiWidget|AbiWidget]] object which can be used like any other [[PyGtk|PyGtk]] [[GtkWidget|GtkWidget]] in addition to it''s own methods.
+
To use the [[AbiWidget]] from within python call the &quot;Canvas()&quot; method on the abiword object. This returns the [[AbiWidget]] object which can be used like any other [[PyGtk|PyGtk]] [[GtkWidget|GtkWidget]] in addition to it''s own methods.
-
Like the C version of [[AbiWidget|AbiWidget]], by default, [[PyAbiWord|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.
+
Like the C version of [[AbiWidget|AbiWidget]], by default, [[PyAbiWord|PyAbiWord]] starts in &quot;OLPC&quot; mode, which is &quot;Normal View&quot;, 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:
You can turn this behaviour off with the:
Line 68: Line 64:
The Python wrapper supports all the [[[AbiWordSignals|AbiWordSignals]] signals] emitted by [[AbiWidget|AbiWidget]].
The Python wrapper supports all the [[[AbiWordSignals|AbiWordSignals]] signals] emitted by [[AbiWidget|AbiWidget]].
-
<H2> [[TableCreator|TableCreator]] </H2>
+
= TableCreator =
In addition to [[AbiWidget|AbiWidget]], [[PyAbiWord|PyAbiWord]] also wraps a useful little widget [[TableCreator|TableCreator]]. This widget allows users to interactively insert a table of specified size by dragging a mouse.
In addition to [[AbiWidget|AbiWidget]], [[PyAbiWord|PyAbiWord]] also wraps a useful little widget [[TableCreator|TableCreator]]. This widget allows users to interactively insert a table of specified size by dragging a mouse.
Follow the link to [[TableCreator|TableCreator]] to learn how to use this.  
Follow the link to [[TableCreator|TableCreator]] to learn how to use this.  
-
<H3> Example Code </H3>
+
= Example Code =
 +
 
 +
== A very simple program - test.py ==
 +
<pre>
 +
 
 +
#!/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)
 +
 
 +
box = gtk.VBox()
 +
window.add(box)
 +
box.show()
 +
 
 +
abi = abiword.Canvas()
 +
box.add(abi)
 +
abi.show()
 +
 
 +
window.show()
 +
 
 +
b = gtk.Button('render page')
 +
box.add(b)
 +
b.show()
 +
 
 +
i = gtk.Image()
 +
box.add(i)
 +
i.show()
 +
 
 +
def _clicked_cb(widget, abi, i):
 +
    i.props.pixbuf = abi.render_page_to_image(1)
 +
 
 +
b.connect('clicked', lambda widget: _clicked_cb(widget, abi, i))
-
<H4> A very simple program - test.py </H4>
+
gtk.main()
-
<code>
+
-
#!/usr/bin/python<br>
+
-
<br>
+
-
import sys<br>
+
-
import pygtk<br>
+
-
pygtk.require(''2.0'')<br>
+
-
import gtk<br>
+
-
import abiword<br>
+
-
<br>
+
-
window = gtk.Window() <br>
+
-
window.set_default_size(640, 480)<br>
+
-
window.connect(''delete-event'', gtk.main_quit) <br>
+
-
<br>
+
-
abi = abiword.Canvas() <br>
+
-
window.add(abi)<br>
+
-
window.show_all()<br>
+
-
abi.load_file("test.abw")<br>
+
-
<br>
+
-
gtk.main()<br>
+
-
</code>
 
-
<!--
+
</pre>
-
<H3>Contents</H3>
+
-
-->
 
-
==== Contributors ====
+
[[Category:Developer]]
-
* Main.[[MartinSevior|MartinSevior]] - 04 Jan 2007
+
[[Category:Python]]
-
[[Category:To Convert]]
+

Current revision as of 13:50, 27 November 2010

Contents

PyAbiWord

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

Getting the Source Code from SVN

This set of code is available from the AbiWord cvs server with module name &quot;pyabiword&quot;.

For version 2.8 (the current stable version of AbiWord) do:

  svn co http://svn.abisource.com/pyabiword/branches/ABI-2-8-0-STABLE/ pyabiword

You get the current development version with:

  svn co http://svn.abisource.com/pyabiword/trunk pyabiword


Building pyabiword

To build it, you must first build libabiword as described in AbiWordSDK. Make sure to build libabiword with the "--enable-dynamic" configure option.

After that make sure that the

  PKG_CONFIG_PATH 

environment variable is set so that abiword-2.8.pc or abiword-2.9.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

or

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

depending on your version of python. Then make sure your

  PYTHONPATH 

environment variable is set so that /Path/To/Install/lib/python2.4/site-packages or Path/To/Install/lib/python2.5/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


#!/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)

box = gtk.VBox()
window.add(box)
box.show()

abi = abiword.Canvas()
box.add(abi)
abi.show()

window.show()

b = gtk.Button('render page')
box.add(b)
b.show()

i = gtk.Image()
box.add(i)
i.show()

def _clicked_cb(widget, abi, i):
    i.props.pixbuf = abi.render_page_to_image(1)

b.connect('clicked', lambda widget: _clicked_cb(widget, abi, i))

gtk.main()


Personal tools