Hi,

For a start, using help isn't all that useful. Output for help of Versekey
is contained in attached help.txt. Using dir will usually be just as much
use. If I want to know how something works, I look at the c++ source code
(which is quite an opaque mess, I think :) If you have doxygen generated,
look at that. That may help a bit. A few of the methods are renamed, I
think. ie SWModule.search becomes SWModule.doSearch

Also, I do not know that there is any way to check whether a module contains
a certain book (though it probably doesn't if you go through a whole chapter
and it is empty)

To get all book names and chapter counts in old and new testaments:
__________________
#!/usr/bin/python2.5
import Sword
vk=Sword.VerseKey()

def GetBooks():
   for i in range(2):
       for j in range(vk.bookCount(i+1)):
           print vk.bookName(i+1, j+1),
           print "has %d chapters" % vk.chapterCount(i+1, j+1)

def GetChapters(i, j):
   bookname=vk.bookName(i, j)
   for k in range(vk.chapterCount(i, j)):
       print "%s %d has %d verses" %  (bookname, k+1, \
           vk.verseCount(i,j,k+1))

print GetBooks()
print GetChapters(1, 3) #old testament, 3rd book = Leviticus
print GetChapters(2, 3) #new testament, 3rd book = Luke
__________________

An updated version of your script with my comments added on certain points:
__________________
#!/usr/bin/python2.5
import Sword
import sys
#mgr=Sword.SWMgr()
#mgr.getModule('KJV')
vk=Sword.VerseKey()
error=0
cnt=1
while 1:
  print "cnt=%d" % cnt
  # use the following instead of a count as when the counter gets to
Matthew,
  # it automatically increments the testament and sets vk.Book() to 1
  # ie
  # >>> vk=Sword.VerseKey()
  # >>> vk.Book(1)
  # '\x00'
  # >>> vk.Testament()
  # '\x01'
  # >>> vk.Book(40)
  # '\x01'
  # >>> vk.Book()
  # '\x01'
  # >>> vk.Testament()
  # '\x02'
  # So we do this below:
  test=vk.Book(ord(vk.Book())+1) #use ord to change char -> int
  cnt+=1
  error=ord(vk.Error()) #with error, do error=ord(vk.Error()), this will
output a number instead of a char
  if(error):break
  name=vk.getBookName()
  abr=vk.getBookAbbrev()
#    count=vk.bookCount()
  print "%s -> %s " %(abr,name)
  print "error=",error
  print vk.Index()
  #print vk.UpperBound().Index() #This is only for keys with bounds set
  #print vk.LowerBound().Index() #ditto
__________________

If you would like any other help, just ask.

God Bless,
Ben
-------------------------------------------------------------------------------------------
He has made everything beautiful in its time. Also, he has put eternity into
mans heart, yet so that he cannot find out what God has done from the
beginning to the end.
Ecclesiastes 3:11 (ESV)

On 1/30/07, Pierre Amadio <[EMAIL PROTECTED]> wrote:

Hi there.

On Sun, Jan 28, 2007 at 07:18:31PM +1100, Ben Morgan wrote:
>
> If you have any specific questions on how to do something, just email
me.

I m copying the list as well as the answer may be interesting to have on
the archive of the list.

I do not understand how to get a list of book that one can use in a
given module.

Using the following code, i have a sort of list of existing bible book:

__________________
#!/usr/bin/python2.5
import Sword
import sys
#mgr=Sword.SWMgr()
#mgr.getModule('KJV')
vk=Sword.VerseKey()
error=0
cnt=0
while 1:
    print "cnt=%d" % cnt
    test=vk.Book(cnt)
    cnt+=1
    error=vk.Error()
    name=vk.getBookName()
    abr=vk.getBookAbbrev()
#    count=vk.bookCount()
    print "%s -> %s " %(abr,name)
    print "error=",error
    print vk.Index()
    print vk.UpperBound().Index()
    print vk.LowerBound().Index()
__________________

However, as my verse key does not know wich module i m interested in, i
cannot be sure all the book will be available for a given module (i
think tere are some translation that are not complete).

Plus, I do not see any new testament book (except for revelation).

I cannot understand how to detect i reach the end of the books.

Bear in mind that, as my python version does not seem to implement
help(), i guess what is available in the modules and object i have
with dir().

Before trying to understand every things related to text rendering, i
would be happy knowing how to:

-get a list of books in a module
-get a list of chapter in a book
-get a list of verses in a chapter

I hope the 3 mechanism are similar :)

Best regards


_______________________________________________
sword-devel mailing list: sword-devel@crosswire.org
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page

Help on class VerseKey in module Sword:

class VerseKey(SWKey)
 |  Method resolution order:
 |      VerseKey
 |      SWKey
 |      SWObject
 |      __builtin__.object
 |
 |  Methods defined here:
 |
 |  AutoNormalize(*args)
 |
 |  Book(*args)
 |
 |  Chapter(*args)
 |
 |  ClearBounds(*args)
 |
 |  Headings(*args)
 |
 |  Index(*args)
 |
 |  LowerBound(*args)
 |
 |  NewIndex(*args)
 |
 |  Normalize(*args)
 |
 |  ParseVerseList(*args)
 |
 |  Testament(*args)
 |
 |  UpperBound(*args)
 |
 |  Verse(*args)
 |
 |  __del__ lambda self
 |
 |  __getattr__ lambda self, name
 |
 |  __init__(self, *args)
 |
 |  __repr__ = _swig_repr(self)
 |
 |  __setattr__ lambda self, name, value
 |
 |  bookCount(*args)
 |
 |  bookName(*args)
 |
 |  chapterCount(*args)
 |
 |  clone(*args)
 |
 |  compare(*args)
 |
 |  copyFrom(*args)
 |
 |  decrement(*args)
 |
 |  getBookAbbrev(*args)
 |
 |  getBookName(*args)
 |
 |  getLocale(*args)
 |
 |  getOSISRef(*args)
 |
 |  getRangeText(*args)
 |
 |  getShortText(*args)
 |
 |  getText(*args)
 |
 |  increment(*args)
 |
 |  isTraversable(*args)
 |
 |  setPosition(*args)
 |
 |  setText(*args)
 |
 |  verseCount(*args)
 |
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |
 |  castTo = VerseKey_castTo(...)
 |
 |  convertToOSIS = VerseKey_convertToOSIS(...)
 |
 |  getOSISBookNum = VerseKey_getOSISBookNum(...)
 |
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |
 |  __swig_destroy__ = <built-in function delete_VerseKey>
 |
 |
 |  __swig_getmethods__ = {'castTo': <function <lambda> at 0x00BD8DB0>, 'c...
 |
 |  __swig_setmethods__ = {}
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from SWKey:
 |
 |  Error(*args)
 |
 |  Persist(*args)
 |
 |  Traversable(*args)
 |
 |  equals(*args)
 |
 |  isBoundSet(*args)
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from SWObject:
 |
 |  getClass(*args)
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from SWObject:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)

_______________________________________________
sword-devel mailing list: sword-devel@crosswire.org
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page

Reply via email to