View Single Post
Old 02-01-2024, 09:17 AM   #1262
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
Thanks for the help. I think I figured out the problem. I made the wrong assumption that if no row is selected the result of gui.library_view.currentIndex() will evaluate to None and proceeded with:

Code:
if gui.library_view.currentIndex():
   ....
[...]
Use
Code:
dex = gui.library_view.currentIndex()
if dex.isValid():
    row = dex.row()
    ....
This is easy to test using this python template:
Code:
python:
def evaluate(book, context):
	from calibre.gui2.ui import get_gui
	gui = get_gui()
	dex = gui.library_view.currentIndex()
	print(dex, dex.isValid()) 
	return f'row = {dex.row()}' if dex.isValid() else 'Not valid'
To test it, select a book, open the template tester, then paste the template. It will give you a row number. Then search for authors:false (there aren't any books with no authr), which will give an empty list view. Type something in the template tester to make the template run and you will get "Not valid">
chaley is offline   Reply With Quote