def Find( attribute ): """ Search for methods and attributes """ print( "\nSearching for attribute '{}'...".format( attribute ) ) found = False AA = attribute.upper() for thing in dir(Sword): BB = thing.upper() if BB.startswith(AA): print( " Have {} in Sword".format( thing ) ); found = True for thing in dir(Sword.SWVersion()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWVersion".format( thing ) ); found = True for thing in dir(Sword.SWMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWMgr".format( thing ) ); found = True module = library.getModule( "KJV" ) for thing in dir(module): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWModule".format( thing ) ); found = True for thing in dir(Sword.SWKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWKey".format( thing ) ); found = True for thing in dir(Sword.VerseKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in VerseKey".format( thing ) ); found = True #for thing in dir(Sword.InstallMgr()): #BB = thing.upper() #if BB.startswith(AA): print( " Have {} in InstallMgr".format( thing ) ); found = True for thing in dir(Sword.LocaleMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in LocaleMgr".format( thing ) ); found = True for thing in dir(Sword.SWFilterMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWFilterMgr".format( thing ) ); found = True if not found: print( " Sorry, '{}' not found.".format( attribute ) )
def demo(): """ Sword """ if Globals.verbosityLevel > 0: print( ProgNameVersion ) #print( "\ndir Sword", dir(Sword) ) if SwordType == "CrosswireLibrary": print( "\ndir Sword.SWVersion()", dir(Sword.SWVersion()) ) print( "Version", Sword.SWVersion().getText() ) print( "Versions", Sword.SWVersion().major, Sword.SWVersion().minor, Sword.SWVersion().minor2, Sword.SWVersion().minor3 ) # ints library = Sword.SWMgr() #print( "\ndir library", dir(library) ) #print( "\nlibrary getHomeDir", library.getHomeDir().getRawData() ) def Find( attribute ): """ Search for methods and attributes """ print( "\nSearching for attribute '{}'...".format( attribute ) ) found = False AA = attribute.upper() for thing in dir(Sword): BB = thing.upper() if BB.startswith(AA): print( " Have {} in Sword".format( thing ) ); found = True for thing in dir(Sword.SWVersion()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWVersion".format( thing ) ); found = True for thing in dir(Sword.SWMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWMgr".format( thing ) ); found = True module = library.getModule( "KJV" ) for thing in dir(module): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWModule".format( thing ) ); found = True for thing in dir(Sword.SWKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWKey".format( thing ) ); found = True for thing in dir(Sword.VerseKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in VerseKey".format( thing ) ); found = True #for thing in dir(Sword.InstallMgr()): #BB = thing.upper() #if BB.startswith(AA): print( " Have {} in InstallMgr".format( thing ) ); found = True for thing in dir(Sword.LocaleMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in LocaleMgr".format( thing ) ); found = True for thing in dir(Sword.SWFilterMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWFilterMgr".format( thing ) ); found = True if not found: print( " Sorry, '{}' not found.".format( attribute ) ) # end of Find if 0: # Install manager print( "\nINSTALL MANAGER" ) im = Sword.InstallMgr() # FAILS print( "\ndir im", im, dir(im) ) if 0: # Locale manager print( "\nLOCALE MANAGER" ) lm = Sword.LocaleMgr() print( "dir lm", lm, dir(lm) ) print( "default {}".format( lm.getDefaultLocaleName() ) ) print( "available {}".format( lm.getAvailableLocales() ) ) # Gives weird result: "available ()" print( "locale {}".format( lm.getLocale( "en" ) ) ) # Needs a string parameter but why does it return None? if 0: # try filters print( "\nFILTER MANAGER" ) fm = Sword.SWFilterMgr() print( "\ndir filters", dir(fm) ) if SwordType == "CrosswireLibrary": # Get a list of available module names and types print( "\n{} modules are installed.".format( len(library.getModules()) ) ) for j,moduleBuffer in enumerate(library.getModules()): moduleID = moduleBuffer.getRawData() module = library.getModule( moduleID ) if 0: print( "{} {} ({}) {} '{}'".format( j, module.getName(), module.getType(), module.getLanguage(), module.getEncoding() ) ) try: print( " {} '{}' {} {}".format( module.getDescription(), module.getMarkup(), module.getDirection(), "" ) ) except UnicodeDecodeError: print( " Description is not Unicode!" ) #print( "\n", j, "dir module", dir(module) ) # Try some modules mod1 = library.getModule( "KJV" ) print( "\nmod1 {} ({}) '{}'".format( mod1.getName(), mod1.getType(), mod1.getDescription() ) ) mod2 = library.getModule( "ASV" ) print( "\nmod2 {} ({}) '{}'".format( mod2.getName(), mod2.getType(), mod2.getDescription() ) ) mod3 = library.getModule( "WEB" ) print( "\nmod3 {} ({}) '{}'".format( mod3.getName(), mod3.getType(), mod3.getDescription() ) ) strongsGreek = library.getModule( "StrongsGreek" ) print( "\nSG {} ({}) '{}'\n".format( strongsGreek.getName(), strongsGreek.getType(), strongsGreek.getDescription() ) ) strongsHebrew = library.getModule( "StrongsHebrew" ) print( "\nSH {} ({}) '{}'\n".format( strongsHebrew.getName(), strongsHebrew.getType(), strongsHebrew.getDescription() ) ) print() # Try a sword key sk = Sword.SWKey( "H0430" ) #print( "\ndir sk", dir(sk) ) # Try a verse key vk = Sword.VerseKey( "Jn 3:16" ) #print( "\ndir vk", dir(vk) ) #print( "val", vk.validateCurrentLocale() ) # gives None print( "getInfo", vk.getLocale(), vk.getBookCount(), vk.getBookMax(), vk.getIndex(), vk.getVersificationSystem() ) print( "getBCV {}({}/{}) {}/{}:{} in '{}'({})/{}".format( vk.getBookName(), vk.getBookAbbrev(), vk.getOSISBookName(), vk.getChapter(), vk.getChapterMax(), vk.getVerse(), repr(vk.getTestament()), vk.getTestamentIndex(), vk.getTestamentMax() ) ) print( "getText {} {} {} {} '{}'".format( vk.getOSISRef(), vk.getText(), vk.getRangeText(), vk.getShortText(), vk.getSuffix() ) ) #print( "bounds {} {}".format( vk.getLowerBound(), vk.getUpperBound() ) ) if 0: # Set a filter HOW DO WE DO THIS??? rFs = mod1.getRenderFilters() print( mod1.getRenderFilters() ) mod1.setRenderFilter() print( "\n{} {}: {}".format( mod1.getName(), "Jonny 1:1", mod1.renderText( Sword.VerseKey("Jn 1:1") ) ) ) mod1.increment() print( "\n{} {}: {}".format( mod1.getName(), mod1.getKey().getText(), mod1.stripText( ) ) ) mod1.increment() print( "\n{} {}: {}".format( mod1.getName(), mod1.getKey().getText(), mod1.renderText( ) ) ) print( "\n{} {}: {}".format( mod2.getName(), vk.getText(), mod2.renderText( vk ) ) ) print( "\n{} {}: {}".format( mod3.getName(), vk.getText(), mod3.renderText( vk ) ) ) print( "\n{} {}: {}".format( mod3.getName(), vk.getText(), mod3.renderText( vk ) ) ) print( "\n{} {}: {}".format( strongsGreek.getName(), sk.getText(), strongsGreek.renderText( Sword.SWKey("G746") ) ) ) print( "\n{} {}: {}".format( strongsHebrew.getName(), sk.getText(), strongsHebrew.renderText( sk ) ) ) if 0: # Get all vernacular booknames # VerseKey vk; while (!vk.Error()) { cout << vk.getBookName(); vk.setBook(vk.getBook()+1); } vk = Sword.VerseKey() while vk.popError()=='\x00': print( "bookname", vk.getBookName() ) booknumber = int( bytes( vk.getBook(),'utf-8' )[0] ) vk.setBook( booknumber + 1 ) if 0: # Get booknames by testament (from http://www.crosswire.org/wiki/DevTools:Code_Examples) vk = Sword.VerseKey() for t in range( 1, 2+1 ): vk.setTestament( t ) for i in range( 1, vk.getBookMax()+1 ): vk.setBook( i ) print( t, i, vk.getBookName() ) # Try a tree key on a GenBook module = library.getModule( "Westminster" ) print( "\nmodule {} ({}) '{}'".format( module.getName(), module.getType(), module.getDescription() ) ) def getGenBookTOC( tk, parent ): if tk is None: # obtain one from the module tk = Sword.TreeKey_castTo( module.getKey() ) # Only works for gen books if tk and tk.firstChild(): while True: print( " ", tk.getText() ) # Keep track of the information for custom implementation #Class *item = storeItemInfoForLaterUse(parent, text); item = (parent) # temp .................... if tk.hasChildren(): print( " Getting children..." ) getGenBookTOC( tk, item ) if not tk.nextSibling(): break # end of getGenBookTOC getGenBookTOC( None, None )