def eventHandler(self, dlg, event, name):
  result=self.lst_results.GetSelection()
  if lbc.IsCloseEvent(event) or (name==self.btn_close.GetName() and lbc.IsButtonEvent(event)): return globals.destroy(self, self.lst_results.GetName(), [self.lst_results.GetName()])
  elif name==self.lst_results.GetName() and (lbc.IsFocusEvent(event) or lbc.IsListChangeEvent(event)):
   #update info box with current item when user changes selection or lands on list
   self.memo_info.SetValue(self.getInfo(self, self.results[result], ["longSynopsis"]))
  elif self.favoriteable and name==self.btn_favorite.GetName() and lbc.IsButtonEvent(event): #save this search to the favorites section of config
   globals.config['favorites'][self.searchName]=[str(self.searchTerms), self.searchType, self.category, self.grade]
   try:
    globals.config.write()
    return AlertDialog("Success", "The favorite has been saved.")
   except:
    return ErrorDialog("Error", "There was an error trying to save the favorite. Please try closing the program and re-launching it, then search again.")
  elif name==self.btn_download.GetName() and lbc.IsButtonEvent(event):
   if globals.config['settings']['format']!=str(globals.prompt[1]): #download book in preferred format
    globals.download(self.results[result])
   else: return DownloadDialog(self.results[result])
  elif name==self.btn_moreInfo.GetName() and lbc.IsButtonEvent(event): #use an api call to show all info about the book
   return BookInfoDialog(self.results[result])
  elif name==self.btn_prev.GetName() and lbc.IsButtonEvent(event):
   if globals.canSpeak: globals.output("Loading previous "+str(globals.limit)+" results, please wait.", 1)
   self.results.prevPage()
   self.Destroy()
   return SearchResultsDialog(searchTerms=self.searchTerms, searchType=self.searchType, results=self.results, category=self.category, grade=self.grade)
  elif name==self.btn_next.GetName() and lbc.IsButtonEvent(event):
   if globals.canSpeak: globals.output("Loading next "+str(globals.limit)+" results, please wait.", 1)
   self.results.nextPage()
   self.Destroy()
   return SearchResultsDialog(searchTerms=self.searchTerms, searchType=self.searchType, results=self.results, category=self.category, grade=self.grade)
  elif name==self.btn_first.GetName() and lbc.IsButtonEvent(event):
   if globals.canSpeak: globals.output("Loading first "+str(globals.limit)+" results, please wait.", 1)
   self.results.getPage(1, True)
   self.Destroy()
   return SearchResultsDialog(searchTerms=self.searchTerms, searchType=self.searchType, results=self.results, category=self.category, grade=self.grade)
  elif name==self.btn_last.GetName() and lbc.IsButtonEvent(event):
   if globals.canSpeak: globals.output("Loading final results, please wait.", 1)
   self.results.getPage(self.results.pages, True)
   self.Destroy()
   return SearchResultsDialog(searchTerms=self.searchTerms, searchType=self.searchType, results=self.results, category=self.category, grade=self.grade)
  elif name==self.btn_author.GetName() and lbc.IsButtonEvent(event):
   if len(self.results[result].authorList)>1: author=lbc.DialogPick(title="Choose Author", names=self.results[result].authorList, values=self.results[result].authorList)
   else: author=self.results[result].authorList[0]
   if globals.canSpeak: globals.output("Searching for all books by "+author+", please wait.", 1)
   try:
    results=globals.searchTypes[globals.search_author](author, category=self.category, grade=self.grade) #search for the text
   except pybookshare.ApiError, e:
    return ErrorDialog("Error!", e)
   return SearchResultsDialog(searchTerms=author, searchType=globals.searchTypes.keys()[1], results=results, category=self.category, grade=self.grade)
 def eventHandler(self, dlg, event, name):
  if lbc.IsCloseEvent(event) or (name==self.btn_cancel.GetName() and lbc.IsButtonEvent(event)): return globals.destroy(self)
  if name==self.btn_brf.GetName(): format=0
  if name==self.btn_daisy.GetName(): format=1
  if lbc.IsButtonEvent(event): #must be one of the formats available
   globals.download(self.result, format)
   return self.Destroy()
 def eventHandler(self, dlg, event, name):
  if lbc.IsCloseEvent(event) or (name==self.btn_cancel.GetName() and lbc.IsButtonEvent(event)): return globals.destroy(self, self.txt_search.GetName(), [self.txt_search.GetName()])
  elif name==self.lst_searchTypes.GetName() and lbc.IsListChangeEvent(event): #show/hide category/grades depending on search type
   if self.lst_searchTypes.GetStringSelection() in globals.uncategorizedSearch:
    self.lst_categories.Hide()
    self.lst_grades.Hide()
   else: #show them in case they were hidden by passing over a search type that would hide them
    self.lst_categories.Show()
    self.lst_grades.Show()
   self.Layout()
  elif name==self.btn_search.GetName() and lbc.IsButtonEvent(event): #do the search
   text=self.txt_search.GetValue()
   grade=None
   category=None
   typeIndex=self.lst_searchTypes.GetSelection()
   categoryIndex=self.lst_categories.GetSelection()
   gradeIndex=self.lst_grades.GetSelection()
   if typeIndex<0: typeIndex=0
   #the next 2 say >0 because selection 0 is for leaving the option unspecified
   if categoryIndex>0: category=globals.categories[categoryIndex]
   if gradeIndex>0: grade=globals.grades[gradeIndex]
   searchType=globals.searchTypes.keys()[typeIndex]
   if text=="" and searchType!=globals.search_getBooksInCategory: #only category searches can be blank, since they just list all books in that category
    return ErrorDialog("No Search Terms", "You did not enter anything to search for. Please enter your search terms and try again.")
   if searchType==globals.search_getBooksInCategory:
    if categoryIndex==0: return ErrorDialog("No Category Selected", "You must select a category before the books in that category can be retrieved. Please choose a category and try again.")
    text="all books in "+category+" category"
   if globals.canSpeak: globals.output("Searching, please wait.", 1)
   try:
    results=globals.searchTypes[searchType](text, category=category, grade=grade) #search for the text
   except pybookshare.ApiError, e:
    return ErrorDialog("Error!", e.message)
   SearchResultsDialog(searchTerms=text, searchType=globals.searchTypes.keys()[typeIndex], results=results, category=category, grade=grade)
   return self.Destroy()