from WikiPlugin import * from AppData import * def getName(): # # This is the name that appears on the 'plugin' menu. # It should be unique # return "Lesson 04 - Create Book" def getVendorName(): # # The name of the person who developed the plugin # return "Dogmelon" def getVendorVersionString(): # # A version string for this plugin # return "1.0" def getDescription(): # # A brief, helpful description of the plugin # return "Lesson 04 - Learn how to create a book" def preExecute(): # # Do anything you need to do before running the plugin. # This could include popping up a dialog to collect parameters. # returns a list of parameters, which will be passed to the execute() method # STAGE_NAME = "preExecute" return [] def lesson04_createBrandNewBook( outputFile ): # create a brand new book, and add it to the first collection newBookName = "Lesson 4 - Newly Created Book" collection = theAppData.library.getDataSource( 0 ) book = WikiBook( collection ) book.setDisplayName( newBookName ) ret = theAppData.library.addBook( book, collection ) if ret: outputFile.write( "adding book '%s' was successful\n"%( newBookName ) ) else: outputFile.write( "adding book '%s' was NOT successful\n"%( newBookName ) ) homePageName = "My Home Page" homePageText = "This is my home page. It worked!" book.addPageWithNameAndContents( homePageName, homePageText ) book.setHomePage(homePageName) return book def lesson04_getAndSetProperties( outputFile, book ): displayName = book.getDisplayName() description = book.getDescription() publisher = book.getPublisher() isReadOnly = book.getReadOnly() isLocked = book.isLocked() outputFile.write( "\nBook Properties (initial)\n" ) outputFile.write( "Name: '%s'\n"%(displayName) ) outputFile.write( "Description: '%s'\n"%(description) ) outputFile.write( "Publisher: '%s'\n"%(publisher) ) outputFile.write( "isReadOnly: '%d'\n"%(isReadOnly) ) outputFile.write( "isLocked (encrypted): '%d'\n"%(isLocked) ) book.setDisplayName( "Renamed: Lesson 4 Book" ) book.setDescription( "A book created and modified by Plugin Lesson 04" ) book.setPublisher( "Dogmelon Plugin Tutorial" ) displayName = book.getDisplayName() description = book.getDescription() publisher = book.getPublisher() isReadOnly = book.getReadOnly() isLocked = book.isLocked() outputFile.write( "\nBook Properties (after modification)\n" ) outputFile.write( "Name: '%s'\n"%(displayName) ) outputFile.write( "Description: '%s'\n"%(description) ) outputFile.write( "Publisher: '%s'\n"%(publisher) ) outputFile.write( "isReadOnly: '%d'\n"%(isReadOnly) ) outputFile.write( "isLocked (encrypted): '%d'\n"%(isLocked) ) def execute( parameterList ): # # Here is where you actually do the plugin tasks. # # If anything goes wrong, you can throw a WikiPluginException # as follows: # STAGE_NAME = "execute" bThrowException = False outputFile = open( "C:/lesson04.txt", "w" ) outputFile.write( "Lesson 04\n\n" ) numCollections = theAppData.library.getNumDataSources() outputFile.write( "Number of Collections: %d\n\n"%numCollections ) outputFile.write( "#, Collection Name:\n" ) for i in range( numCollections ): name = theAppData.library.getDataSourceFriendlyName( i ) outputFile.write( "%d, '%s'\n"%(i, name) ) outputFile.write( "\n" ) if numCollections == 0: outputFile.close() return newBook = lesson04_createBrandNewBook( outputFile ) lesson04_getAndSetProperties( outputFile, newBook ) # Note: newBook is valid theAppData.appFrame.onRefresh() # Note: newBook is no longer valid - trying to use it # would cause a crash searchName = "Renamed: Lesson 4 Book" book = theAppData.library.findBook( searchName ) if( book == None ): outputFile.write( "\n\nAfter refresh. Something wrong. Couldn't find book: '%s'\n"%(searchName) ) else: outputFile.write( "\n\nAfter refresh. Found the book again. Name: '%s'\n"%(book.getDisplayName()) ) outputFile.write( "\nFinished.\n" ) outputFile.close() if bThrowException: raise WikiPluginException( STAGE_NAME, "Some error string describing the problem" ) def postExecute(): # # Do anything you need to clean up after running the plugin. # STAGE_NAME = "postExecute" pass