![]() |
#1 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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? ![]() Last edited by ownedbycats; 10-21-2020 at 08:32 PM. |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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','') |
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
if cnt ># 0 then 'question-mark.png' fi |
|
![]() |
![]() |
![]() |
#4 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,188
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
|
Quote:
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 |
|
![]() |
![]() |
![]() |
#5 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Of note:
|
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#7 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#8 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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 |
|
![]() |
![]() |
![]() |
#9 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,745
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
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. |
|
![]() |
![]() |
![]() |
#10 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,188
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#11 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
![]() 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. |
|
![]() |
![]() |
![]() |
#12 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |