[sword-devel] Python and swig
Ben Morgan
benpmorgan at gmail.com
Sun Jan 28 01:18:31 MST 2007
Hi.
Glad you got it to build.
Examples:
For example, to output the text of a verse from the ESV
>>> import Sword
>>> markup=Sword.MarkupFilterMgr(Sword.FMT_HTMLHREF) #Html markup
>>> markup.thisown=False #Tell SWIG not to bother cleaning this up
>>> mgr=Sword.SWMgr(markup) #new mgr
>>> mod=mgr.getModule("ESV") #get esv
>>> vk=Sword.VerseKey("Matthew 1:1")
>>> mod.setKey(vk) #set key for mod
'\x00'
>>> mod.RenderText() #render the text
'<a href="passagestudy.jsp
?action=showNote&type=x&value=1&module=ESV&passage=Mat
thew+1%3A1"><small><sup>*x</sup></small></a> The book of the genealogy of
Jesus
Christ, <a href="passagestudy.jsp
?action=showNote&type=x&value=2&module=ESV&pass
age=Matthew+1%3A1"><small><sup>*x</sup></small></a> the son of David, <a
href="p
assagestudy.jsp
?action=showNote&type=x&value=3&module=ESV&passage=Matthew+1%3A1"
><small><sup>*x</sup></small></a> the son of Abraham.'
To output, for all modules installed, their names and types:
>>> import Sword
>>> mgr=Sword.SWMgr()
>>> for mod in mgr.getModules().values(): #mgr.getModules is a map, keys are
type SWBuf, values are SWModules
... print mod.Name() + " is a '" + mod.Type()+"'" #name of mod and type
ESV is a 'Biblical Texts'
MHC is a 'Commentaries'
etc.
For longer examples, look at my Gospel Harmony Viewer. The files
BibleInterface.py, Book.py and Dictionary.py are from a larger project I am
doing, and have much more than the gospel harmony viewer needs. This code
isn't well commented, I'm afraid, nor pythonic.
If you have any specific questions on how to do something, just email me.
God Bless,
Ben
On 1/28/07, Pierre Amadio <pierre.amadio at libertysurf.fr> wrote:
>
> Hi there.
>
> After chatting a bit on #maemo, i installed a version of python2.5
> (instead of 2.3) on the scratchbox environment.
>
> I was happy to realise the sword python module was working with this
> version of python: the import _Sword did not complain.
>
> However, in this specific version of python, the help keyword is not
> implemented, so i cannot ask for help(_Sword)
>
>
> On Thu, Jan 25, 2007 at 01:43:20PM +1100, Ben Morgan wrote:
> > This should build the extension. I'm not sure whether you need to
> install it
> > (if you do, just type cd python && python setup.py install
> >
> > If you would like any examples of how to use SWORD under python, just
> email
> > me
>
> Those example would be greatly appreciated :)
>
> Have a nice day.
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
>
--
God Bless,
Ben
-------------------------------------------------------------------------------------------
"Glory is fleeting, but obscurity is forever" Napoleon Bonaparte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.crosswire.org/pipermail/sword-devel/attachments/20070128/1f1fa2d6/attachment.html
More information about the sword-devel
mailing list