Manual de Calibre | Page 196

Manual de usuario de calibre, Publicación 2.73.0
self. marked _ button = QPushButton(
' Show books with only one format in the calibre GUI ', self) self. marked _ button. clicked. connect( self. marked) self. l. addWidget( self. marked _ button)
self. view _ button = QPushButton(
' View the most recently added book ', self) self. view _ button. clicked. connect( self. view) self. l. addWidget( self. view _ button)
self. update _ metadata _ button = QPushButton(
' Update metadata in a book \' s files ', self) self. update _ metadata _ button. clicked. connect( self. update _ metadata) self. l. addWidget( self. update _ metadata _ button)
self. conf _ button = QPushButton( ' Configure this plugin ', self) self. conf _ button. clicked. connect( self. config) self. l. addWidget( self. conf _ button)
self. resize( self. sizeHint())
def about( self): # Get the about text from a file inside the plugin zip file # The get _ resources function is a builtin function defined for all your # plugin code. It loads files from the plugin zip file. It returns # the bytes from the specified file. # # Note that if you are loading more than one file, for performance, you # should pass a list of names to get _ resources. In this case, # get _ resources will return a dictionary mapping names to bytes. Names that # are not found in the zip file will not be in the returned dictionary. text = get _ resources(' about. txt ') QMessageBox. about( self, ' About the Interface Plugin Demo ', text. decode(' utf-8 '))
def marked( self): ''' Show books with only one format ''' db = self. db. new _ api matched _ ids = { book _ id for book _ id in db. all _ book _ ids() if len( db.
˓→formats( book _ id)) == 1 } # Mark the records with the matching ids # new _ api does not know anything about marked books, so we use the full # db object self. db. set _ marked _ ids( matched _ ids)
# Tell the GUI to search for all marked records self. gui. search. setEditText(' marked: true ') self. gui. search. do _ search()
def view( self): ''' View the most recently added book ''' most _ recent = most _ recent _ id = None db = self. db. new _ api for book _ id, timestamp in db. all _ field _ for(' timestamp ', db. all _ book _ ids()).
˓→iteritems(): if most _ recent is None or timestamp > most _ recent: most _ recent = timestamp
192 Capítulo 1. Secciones