View Single Post
Old 02-18-2011, 05:34 PM   #1
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,733
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Can I hold a reference to .model() and .db in a plugin?

To access the data model and database/caches from a plugin, it appears you use self.gui.library_view.model() and self.gui.library_view.model().db respectively.

For coding purposes I usually want to hold a shortcut reference to that such as: self.db = self.gui.library_view.model().db to make the code more readable when doing a bunch of db calls.

Would it be valid to set this reference just once for your InterfaceAction class in initialization_complete()? Currently I re-set it in each connected event in response to a user action. The reason I do this currently is sheer ignorance from not knowing if other code in Calibre at some point would change the object reference returned from either .model() or .model().db.
kiwidude is offline   Reply With Quote