from WikiPlugin import * from AppData import * def getName(): # # This is the name that appears on the 'plugin' menu. # It should be unique # return "Lesson 06 - Remove 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 06 - Learn how to remove a book from your library" 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 lesson06_setupBook( outputFile, newBookName ): 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) 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:/lesson06.txt", "w" ) outputFile.write( "Lesson 06\n\n" ) newBookName = "Lesson 6 Removable Book" # don't run the plugin if we don't have any collections numCollections = theAppData.library.getNumDataSources() if numCollections == 0: outputFile.write( "No collections! Exiting.\n" ) outputFile.close() return # create the book lesson06_setupBook( outputFile, newBookName ) theAppData.appFrame.onRefresh() # now remove the book book = theAppData.library.findBook( newBookName ) if( book == None ): outputFile.write( "\n\nSomething wrong. Couldn't find book: '%s'\nExiting."%(newBookName) ) outputFile.close() exit outputFile.write( "Removing book '%s'...\n"%(book.getDisplayName()) ) theAppData.library.removeBook( book ) outputFile.write( "done.\n" ) outputFile.write( "\nFinished.\n" ) outputFile.close() # update library panel again theAppData.appFrame.onRefresh() 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