from WikiPlugin import * from AppData import * from wxPython.wx import * class DlgDisplayBook(wxDialog): def __init__( self ): wxDialog.__init__(self, None, -1, "List of Books", wxDefaultPosition, wxSize(352, 200)) self.SetAutoLayout(true) topSizer = wxBoxSizer( wxVERTICAL ) buttonSizer = wxBoxSizer( wxHORIZONTAL ) DEFAULT_LB_HEIGHT = 200 txtCtrl = wxStaticText(self, -1, "Here are your books") topSizer.Add( txtCtrl, 0, wxEXPAND | wxEAST | wxWEST, 10 ) topSizer.Add(wxSize( 0, 5) ) self.lb1 = wxListBox(self, -1, wxDefaultPosition,wxSize(350, DEFAULT_LB_HEIGHT), style=wxLB_SINGLE ) self.populateListBox() topSizer.Add( self.lb1, 0, wxEXPAND | wxEAST | wxWEST, 10 ) okButton = wxButton(self, wxID_OK, "OK", wxDefaultPosition, wxDefaultSize) okButton.SetDefault() buttonSizer.Add( okButton, 0, wxEAST|wxWEST,20 ) cancelButton = wxButton(self, wxID_CANCEL, "Cancel", wxDefaultPosition, wxDefaultSize) buttonSizer.Add( cancelButton, 0, wxEAST|wxWEST,20 ) topSizer.Add( wxSize(0, 10) ) topSizer.Add( buttonSizer, 0, wxALIGN_CENTRE ) topSizer.Add( wxSize(0, 5) ) self.SetSizer( topSizer ) topSizer.Fit( self ) self.Layout() self.Centre() def populateListBox( self ): self.lb1.Clear() sampleList = [] for i in range( theAppData.library.getNumBooks() ): book = theAppData.library.getBook(i) sampleList.append( book.getDisplayName() ) self.lb1.InsertItems( sampleList, 0 ) def getName(): # # This is the name that appears on the 'plugin' menu. # It should be unique # return "Lesson 08 - Show Dialog" 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 08 - Show a dialog using the wxPython interface" 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" # announce that we're in preExecute() dlg = wxMessageDialog( None, "We're in preExecute()", "Progress Report", wxOK | wxICON_EXCLAMATION ) dlg.ShowModal() #ask a yes-no question shouldRunPlugin = False dlg = wxMessageDialog( None, "Do you really want to run this plugin?", "Are you sure?", wxYES_NO | wxICON_QUESTION ) userChoice = dlg.ShowModal() if userChoice == wxID_YES: shouldRunPlugin = True else: shouldRunPlugin = False if shouldRunPlugin: return [] return None 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 # announce that we're in execute() dlg = wxMessageDialog( None, "We're in execute()", "Progress Report", wxOK | wxICON_EXCLAMATION ) dlg.ShowModal() # now show a list of our books dlg = DlgDisplayBook() dlg.ShowModal() 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" # announce that we're in preExecute() dlg = wxMessageDialog( None, "We're in postExecute(). Plugin is finished.", "Progress Report", wxOK | wxICON_EXCLAMATION ) dlg.ShowModal()