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 10-21-2020, 08:28 PM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,745
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Custom column icons question

I'm setting up a bunch of "composed icons w/ no text" column icons in a Formats column.

So far I've set up rules to show the images for my most used types and they all work as expected. However I'm stuck on the last one. I want it to show a question mark image if there's a format that's not one of these common types.

I set up a "does not match pattern - (epub|pdf|azw3|mobi|cbz|paperbook)" which sort of works, unless there's a common type available.

Any suggestions?
Attached Thumbnails
Click image for larger version

Name:	2020-10-21 21_27_55-calibre - Preferences - Look & feel.png
Views:	209
Size:	53.7 KB
ID:	182925  

Last edited by ownedbycats; 10-21-2020 at 08:32 PM.
ownedbycats is online now   Reply With Quote
Old 10-22-2020, 08:57 AM   #2
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,188
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Maybe try using an advanced rule with this template

Code:
program:
    fmts = field('formats');
    common = 'epub, pdf, azw3, mobi, cbz, paperbook';
    diff = list_difference(fmts, common, ', ');
    cnt = count(diff, ',');
    test(cmp(cnt,0,'','','gt'),'question-mark.png','')
replace 'question-mark.png' with the name of your icon. Also note that the multiple assignments here make the template slower, but more readable.
capink is offline   Reply With Quote
Advert
Old 10-22-2020, 11:41 AM   #3
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,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
Maybe try using an advanced rule with this template

Code:
program:
    fmts = field('formats');
    common = 'epub, pdf, azw3, mobi, cbz, paperbook';
    diff = list_difference(fmts, common, ', ');
    cnt = count(diff, ',');
    test(cmp(cnt,0,'','','gt'),'question-mark.png','')
replace 'question-mark.png' with the name of your icon. Also note that the multiple assignments here make the template slower, but more readable.
FWIW: that last line can now be written
Code:
if cnt ># 0 then 'question-mark.png' fi
chaley is offline   Reply With Quote
Old 10-22-2020, 01:53 PM   #4
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,188
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
FWIW: that last line can now be written
Code:
if cnt ># 0 then 'question-mark.png' fi
That does make things look better, I saw you using it but have not checked the docs on it.

Now that I think of it, the count step is redundant, and using chaley's new if statement the template can be further simplified as follows:

Code:
program:
    if list_difference(field('formats'), 'epub, pdf, azw3, mobi, cbz, paperbook', ', ') then 'question-mark.png' fi
This does not use assignments and should have better performance. I wonder whether putting this in a custom column instead might be better performance wise?
capink is offline   Reply With Quote
Old 10-22-2020, 02:07 PM   #5
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,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
This does not use assignments and should have better performance. I wonder whether putting this in a custom column instead might be better performance wise?
No. Color and icon rules cache the compiled template, as does a composite column, so there is no difference in execution time. Calibre also caches the results of rule evaluation, so a rule is reevaluated only if calibre thinks the data might have changed. This is roughly the same as the process used to cache composite column evaluation results.

Of note:
  • calibre generates GPM templates for all color/icon rules. There is no additional overhead in using advanced rules.
  • If your rules use stored templates then the compiled stored template is also included in the cache.
  • The new GPM template parser 'compiles' the template into an interpretable tree. The old parser 'compiled' the template into a stream of lexical tokens. The new scheme will be faster than the old one, especially for complex templates.
  • The "test" function used to evaluate both the "true" and the "false" branches then pick the right one. The function is now inlined as "if-then-else" where the unused branch is not evaluated.
chaley is offline   Reply With Quote
Advert
Old 10-22-2020, 02:38 PM   #6
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,188
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
That's interesting. Can I somehow use this cache in my own custom functions? I have a function that opens a json file and reads a dict and then it does a lookup based on a column value. I would like to be able to cache that dictionary instead of repeating this step for each row.
capink is offline   Reply With Quote
Old 10-22-2020, 02:39 PM   #7
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,745
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I used the template in post #4. It worked as expected. Thank you

Last edited by ownedbycats; 10-22-2020 at 02:49 PM.
ownedbycats is online now   Reply With Quote
Old 10-22-2020, 02:57 PM   #8
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,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
That's interesting. Can I somehow use this cache in my own custom functions? I have a function that opens a json file and reads a dict and then it does a lookup based on a column value. I would like to be able to cache that dictionary instead of repeating this step for each row.
You have a custom (Python) template function? If so, then yes you can cache results. The reason: each function is compiled into its own persistent class. You can store stuff as class attributes, which will persist until the next time calibre restarts, you change the library, or are running the function in a separate job.

The approach is to check if the desired cache class attribute exists. If so, use it. If not then fetch and store it, then use it. Sample code:
Code:
	x = getattr(self, 'foobar', None)
	if x is None:
		self.foobar = {'element': 'value'} # do what it takes to set foobar's value
	# use self.foobar in whatever way you want
It is up to you to invalidate the attribute (the 'cache') when needed. Simply restarting calibre will do it.
chaley is offline   Reply With Quote
Old 10-22-2020, 02:57 PM   #9
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,745
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by chaley View Post
No. Color and icon rules cache the compiled template, as does a composite column, so there is no difference in execution time. Calibre also caches the results of rule evaluation, so a rule is reevaluated only if calibre thinks the data might have changed. This is roughly the same as the process used to cache composite column evaluation results.
Is that part of the reason why an icon based on a composite template doesn't always immediately update when a column is modified by a plugin instead of the user?

For example: A #lastread date column, which is used for a composite psuedobool #currentlyreading. (It also checks the #read bool for a 'false' value.)

Column icons are set to display an icon if #currentlyreading returns a "true."

If the user manually edits the #lastread date, the icon appears immediately.

If the Job Spy plugin autopopulates the #lastread, the icon doesn't appear until the list is resorted (or occasionally until a new search is done, not sure why).

Last edited by ownedbycats; 10-22-2020 at 03:58 PM.
ownedbycats is online now   Reply With Quote
Old 10-22-2020, 03:07 PM   #10
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,188
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
You have a custom (Python) template function? If so, then yes you can cache results. The reason: each function is compiled into its own persistent class. You can store stuff as class attributes, which will persist until the next time calibre restarts, you change the library, or are running the function in a separate job.

The approach is to check if the desired cache class attribute exists. If so, use it. If not then fetch and store it, then use it. Sample code:
Code:
	x = getattr(self, 'foobar', None)
	if x is None:
		self.foobar = {'element': 'value'} # do what it takes to set foobar's value
	# use self.foobar in whatever way you want
It is up to you to invalidate the attribute (the 'cache') when needed. Simply restarting calibre will do it.
That should do it.
capink is offline   Reply With Quote
Old 10-22-2020, 03:54 PM   #11
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,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Is that part of the reason why an icon based on a composite template doesn't always immediately update when a column is modified by a plugin instead of the user?

For example: A #lastread date column, which is used for a composite text psuedobool #currentlyreading. (It also checks the #read bool for a 'false' value.)

Column icons are set to display an icon if #currentlyreading returns a "true."

If the user manually edits the #lastread date, the icon appears immediately.

If the Job Spy plugin autopopulates the #lastread, the icon doesn't appear until the list is resorted (though occasionally it won't show up until a new search is done, not sure why).
Its complicated.

First, simply updating a field using db.set_field doesn't clear the composite column cache. As far as I can tell, one must call db.clear_caches() to do that.

In addition, if data is changed then the GUI must be told so it can clear the various caches (rule, icon, emblem, covers, etc) , using get_gui().library_view.model().refresh_ids().

Sorting in the GUI *should* refresh the GUI cache. It doesn't refresh the DB search/composite cache so you can still get "old" results.

Searching in the GUI will (as far as I can see) refresh the GUI cache. The AFAICS comes from the fact that the GUI search has the option of not refreshing and I don't know where that option is used. It doesn't refresh the DB caches.

Does doing a bulk metadata edit, changing nothing, then pressing OK cause the icons to show correctly?

I would guess that switching between list and cover view would also clear caches.
chaley is offline   Reply With Quote
Old 10-22-2020, 04:02 PM   #12
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,745
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
When it fails to update icons after a resort, either doing a new search or editing a metadata cell on any book (even if no actual changes are made) tends to fix it. I figure it's just some sort of weird Qt glitch.
ownedbycats is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
added custom column icons render larger than original icons masp Library Management 12 01-22-2019 04:07 PM
How do I create a icons only custom column? pleiadesc Library Management 3 09-24-2017 08:58 PM
Custom Column Question Vallora Library Management 4 10-13-2014 10:57 PM
Custom Column Icons? tarisea Library Management 90 01-17-2014 06:12 PM
Custom column question ice_cracked Library Management 1 11-10-2012 04:54 PM


All times are GMT -4. The time now is 01:57 PM.


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