|
|
#1 |
|
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,208
Karma: 30317706
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Template function for current book
I'd like to put an Up arrow emblem under the current book in the upcoming shelf view - i.e. the one that's highlighted - which can be hard to see - but I can't fathom how to finagle the equivalent of an is_current template function.
Any ideas? BR |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,911
Karma: 29228280
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Here is the code for a python template:
Code:
python:
def evaluate(book, context):
from calibre.gui2.ui import get_gui
v = get_gui().library_view
row = v.currentIndex().row()
if row < 0:
return 'no'
try:
return 'yes' if v.model().db.data.index_to_id(row) == book.id else 'no'
except Exception:
return 'no'
Last edited by kovidgoyal; Yesterday at 04:19 AM. |
|
|
|
|
|
#3 |
|
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,208
Karma: 30317706
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Thanks, but it returns 'no' for selected book
I just copied and pasted (I'm good at that) but I've attached the saved python function. BR |
|
|
|
|
|
#4 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,911
Karma: 29228280
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yeah actually thinking about it some more, I doubt this whole approach will work, template results are cached and the cache isnt invalidated when the current book changes. So it will give stale results anyway.
|
|
|
|
|
|
#5 |
|
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,208
Karma: 30317706
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Oh well, back to the drawing board
![]() Thanks anyway |
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with template function | JohnAndJane | Library Management | 1 | 03-16-2025 02:35 PM |
| Template function to strip HTML? | halloleo | Library Management | 6 | 11-16-2023 04:20 AM |
| BuiltinAdd template language function | DyckBook | Editor | 4 | 10-19-2021 05:21 PM |
| Using built-in template functions in a custom template function | ilovejedd | Library Management | 4 | 01-28-2018 01:20 PM |
| how to use re() function in Template Program Mode? | msciwoj | Library Management | 3 | 07-07-2016 04:55 PM |