06-12-2011, 04:45 PM | #76 |
Member
Posts: 13
Karma: 10
Join Date: Jun 2010
Device: SONY PRS-600
|
Thank you so much for this feature (and the rest of calibre!), this especially has enabled me to do a lot of fancy customizing I didn't imagine before.
I have one problem though, it seems as if the colouring option does not work when I try to colour my custom column #reread (integers). I tried the option "equals to" which worked, but "less than" and "greater than" seemed to get same result as equals. Right now I have the rule "#reread to crimson if #reread is less than 3" and while 3 turns crimson, 2 does not. Also, but this is only a cosmetic issue, it would be nice if the colouring options looked like the "add custom column" with the add and remove buttons to the side (still keeping the red minus rather than a recycle sign), for consistency throughout the program. And, please, please, add an edit button! ^^ Took slow-brained me some time to find out that double-click worked. |
06-12-2011, 07:04 PM | #77 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@Sparkling: Are you using calibre 0.8.5 it has various fixes related to coloring?
The buttons stay, however I have made the help text above where it says "You can change an existing rule by double clicking it" in bold. |
Advert | |
|
06-13-2011, 05:35 AM | #78 |
Member
Posts: 13
Karma: 10
Join Date: Jun 2010
Device: SONY PRS-600
|
Had not, but downloaded it and now it works perfectly!
|
06-18-2011, 07:19 AM | #79 |
eBook Junkie
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 2020, Kindle PW2
|
Hi:
How do you set up a custom column coloring if you want to have it select between four different values, as if it was an OR statement?? Nyn |
06-18-2011, 07:36 AM | #80 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Use four separate rules specifying same target column (column to be colored). The rules will be tried in order, stopping at the first one that provides a color.
|
Advert | |
|
06-18-2011, 07:59 AM | #81 |
eBook Junkie
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 2020, Kindle PW2
|
|
07-02-2011, 03:51 AM | #82 |
Connoisseur
Posts: 58
Karma: 10
Join Date: Dec 2009
Device: PRS700
|
Okay... I've pretty much got the coloring working the way I want it... with a few "exceptions" that I cannot figure out. Help?
Basically this is what I'm wanting to happen: If rating = 5 then rating is silver else if format is false then rating is red else if comments are false then rating is fuchsia else if cover is false then rating is fuchsia else rating is black (format=true / cover=true / comments=true) The code I am using right now is: switch(field('rating'), '5', 'silver', test(field('format'), test(first_non_empty(field('comments'),field('cove r')), 'black', 'fuchsia'), 'red') ) This code DOES work for the following conditions: if rating = 5 then rating is silver if there is no format then rating is red if cover is true and comments are false then rating is fuchsia if cover and comments are false then rating is fuchsia Error occures here: if cover is false and comments are true then rating is black .... when it should be fuchsia It appears to not be recognizing when the cover is true/false and is only registering the comments. On a side note... I did try the following to see if it made a difference testing comments and cover seperately... the result was that if the first two conditions (format=false or rating=5) were not met then rating became fuchsia regardless of whether comments where true/false or cover was true/false. switch(field('rating'), '5', 'silver', test(field('format'), test(first_non_empty(field('comments')), test(first_non_empty(field('cover')), 'black', 'fuchsia'), 'fuchsia'), 'red') ) |
07-02-2011, 05:38 AM | #83 | ||
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
Instead of switch, you should use the more general iteration function 'first_non_empty', which is designed to implement a series of else clauses like you have. This function evaluates the arguments in sequence, stopping when one of them has a value. Second: unfortunately, for performance reasons you cannot test for the presence of a cover in templates. Adding that possibility would slow calibre to an acceptable level. If you really want to test for the presence/absence of a cover, then you will need to create your own yes/no column and populate it using search+bulk metadata edit, refreshing it from time to time. So, removing the 'cover' else, the following code implements the sequence of elses. Code:
program: first_non_empty( cmp(field('rating'), 5, '', 'silver', ''), test(field('formats'), '', 'red'), test(field('comments'), '', 'fuchsia'), 'black' ) Note that first_non_empty does not need to find a non-empty value. It will happily return '' if no argument returns a value. For coloring, the value '' means 'apply no color', which is sometimes what one wants. You could also do this with a series of tests, but that is much harder to read because of the required nesting. Sub-tests would go into the false or true arm of the enclosing test. Makes my brain hurt to think about it. Last edited by chaley; 07-02-2011 at 08:03 AM. Reason: correction of statement about switch |
||
07-02-2011, 06:18 AM | #84 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Followup: thinking about the 'cover' issue, I realized that I can add new code to calibre to indicate presence or absence of a cover, with no performance impact. What I cannot do is provide the path to the cover file.
I added a new template function, has_cover() that returns 'Yes' if the book has a cover, otherwise '', making it ideal for a 'test' condition. I have submitted the code for inclusion in the next release (0.8.9). Once that function is available, then the coloring code will look like Code:
program: first_non_empty( cmp(field('rating'), 5, '', 'silver', ''), test(field('formats'), '', 'red'), test(field('comments'), '', 'fuchsia'), test(has_cover(), '', 'fuchsia'), 'black' ) Code:
program: ifempty(has_cover(), 'No') |
07-03-2011, 12:10 AM | #85 |
Connoisseur
Posts: 58
Karma: 10
Join Date: Dec 2009
Device: PRS700
|
Charles... you, my friend, are a godsend! I know just enough to be scary but not enough to be truly useful when it comes to python coding. I stick with PHP/SQL coding with a little bit of VMS coding just because work still has archaic equipment!!!
That said... I hope they will include the has_cover() function. I don't need the path... just to test if it has one or not. This makes it easy, at a glance, to know what is missing from a library entry. I knew testing for first_non_empty() would work for the coding... I just couldn't figure out the right command for testing the rating field without using switch. So thank you for the heads up on the CMP()... this one itty bitty command solved another issue I was trying to figure out! |
07-03-2011, 03:32 AM | #86 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
"They" is me, via Kovid.
Already done in source, ready to go out in the next release. And you are welcome. Quote:
|
|
07-03-2011, 11:46 PM | #87 |
Connoisseur
Posts: 58
Karma: 10
Join Date: Dec 2009
Device: PRS700
|
Actually I recently found it... I'm in the middle of a project that is requiring me to learn TCL... so as soon as I tackle that and the new AJAX coding schema the client is torturing me with *lol* I'll eventually get around to playing with python! I did notice in the newer calibre version that there is a drop down command info section which is very helpful as well!
|
Tags |
calibre, template |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can custom book data be displayed in a custom column? | kiwidude | Development | 9 | 03-02-2011 05:35 AM |
Custom charge? | daoshi | iRex | 3 | 10-06-2008 06:47 PM |