Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 07-21-2023, 11:43 PM   #1
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,611
Karma: 7891011
Join Date: Sep 2020
Device: none
Convert GPM to PTM - Emblem Rule

Hi!

I have some emblem rules like these, for the cover grid:

Code:
program:
test($#last_viewed, 'lastop-dark.png', '');
and
Code:
program:
test(contains(field('formats'), "EPUB", '1', ''), 'logo epub.png', '');
Is it possible and advisable to convert them to PTM?
Comfy.n is offline   Reply With Quote
Old 07-22-2023, 07:25 AM   #2
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,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Possible? certainly.

Advisable? depends.
  • PTM templates will be faster, but in the case of emblems it probably doesn't matter all that much. The template is evaluated when a cover is shown, with the result cached until metadata is changed. You might see a performance difference scrolling at full speed through the covers, but I doubt it. However, even very small performance improvements can matter if the template can be used when sorting or searching.
  • The first template is simple enough where we are talking about nanoseconds of difference, perhaps a 100 or so. The second will see more improvement because PTM can deal directly with the list of formats without converting it to a comma-separated list, and because it avoids using a regular expression search.
  • You should understand the template well enough to maintain it.

As for the templates themselves ...

Code:
program:
test($#last_viewed, 'lastop-dark.png', '');
What column type is #last_viewed? The template below works if it is a date. Tags-like fields would use a different return statement because for empty values book.get() returns an empty list instead of 'None'.
Code:
python:
def evaluate(book, context):
	date = book.get('#mydate')
	return 'lastop-dark.png' if date is not None else ''
As for
Code:
program:
test(contains(field('formats'), "EPUB", '1', ''), 'logo epub.png', '');
This is the equivalent PTM template:
Code:
python:
def evaluate(book, context):
	formats = book.get('formats')
	return 'logo epub.png' if formats is not None and 'EPUB' in formats else ''
chaley is offline   Reply With Quote
Advert
Old 07-22-2023, 12:31 PM   #3
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,611
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by chaley View Post
What column type is #last_viewed? The template below works if it is a date.
Exactly, it's a date column updated by Job Spy plugin upon 'viewing' a title. Thanks so much for the templates! I just installed them and the second seems to work faster for the formats' emblems.


Quote:
  • You should understand the template well enough to maintain it.
Noted.

I've attached the icons I'm using for emblems, maybe someone finds them useful.
Attached Files
File Type: zip calibre share icons.zip (367.5 KB, 85 views)
Comfy.n is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running PTM/PythonTemplateContexts in Job, not GUI DaltonST Library Management 3 12-26-2022 08:30 AM
Math functions in GPM sweth Library Management 4 05-31-2021 07:05 PM
Custom column GPM foobarius Library Management 3 09-04-2016 07:20 PM
Emblem overlay in Covergrid? rlugojr Calibre 7 08-09-2014 03:48 AM
The Demon Emblem TheDemonEmblem Self-Promotions by Authors and Publishers 1 07-11-2014 09:01 PM


All times are GMT -4. The time now is 03:24 AM.


MobileRead.com is a privately owned, operated and funded community.