Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 06-12-2011, 04:45 PM   #76
Sparkling
Member
Sparkling began at the beginning.
 
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.
Sparkling is offline   Reply With Quote
Old 06-12-2011, 07:04 PM   #77
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 34,410
Karma: 10323934
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.
kovidgoyal is online now   Reply With Quote
Advert
Old 06-13-2011, 05:35 AM   #78
Sparkling
Member
Sparkling began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Jun 2010
Device: SONY PRS-600
Had not, but downloaded it and now it works perfectly!
Sparkling is offline   Reply With Quote
Old 06-18-2011, 07:19 AM   #79
nynaevelan
eBook Junkie
nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.
 
nynaevelan's Avatar
 
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 6 2014, Kindle PW2, Galaxy Note 3
Question

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
nynaevelan is offline   Reply With Quote
Old 06-18-2011, 07:36 AM   #80
chaley
CC Android & calibre dev
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: 8,945
Karma: 2737706
Join Date: Jan 2010
Location: UK
Device: Many android devices
Quote:
Originally Posted by nynaevelan View Post
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??
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.
chaley is offline   Reply With Quote
Advert
Old 06-18-2011, 07:59 AM   #81
nynaevelan
eBook Junkie
nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.nynaevelan ought to be getting tired of karma fortunes by now.
 
nynaevelan's Avatar
 
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 6 2014, Kindle PW2, Galaxy Note 3
Quote:
Originally Posted by chaley View Post
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.
Thanks
nynaevelan is offline   Reply With Quote
Old 07-02-2011, 03:51 AM   #82
mezme
Connoisseur
mezme began at the beginning.
 
Posts: 52
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')
)
mezme is offline   Reply With Quote
Old 07-02-2011, 05:38 AM   #83
chaley
CC Android & calibre dev
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: 8,945
Karma: 2737706
Join Date: Jan 2010
Location: UK
Device: Many android devices
Quote:
Originally Posted by mezme View Post
Okay... I've pretty much got the coloring working the way I want it... with a few "exceptions" that I cannot figure out. Help?
Nice to see someone attempting complicated stuff.
Quote:
Basically this is what I'm wanting to happen:
Code:
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)
First: given your specification (a series of elses), you don't want to use switch. That function looks inside the content of a single field (in your case, rating) and compares that contents to a series of test regular expressions, returning the value of the first regular expression that matches. As written, your code is checking the result of the outermost test against the content of rating. EDIT: The last sentence is wrong. Looking more carefully, I note that the test is the default of the switch, so it stands alone and is definitely a correct usage.

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'
)
The first argument to first_non_empty, cmp, returns 'silver' if rating == 5, otherwise '' (the empty value). The second argument returns 'red' of formats is empty, otherwise ''. The third argument returns 'fuschia' of comments is empty, otherwise ''. The last argument always returns '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
chaley is offline   Reply With Quote
Old 07-02-2011, 06:18 AM   #84
chaley
CC Android & calibre dev
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: 8,945
Karma: 2737706
Join Date: Jan 2010
Location: UK
Device: Many android devices
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'
)
Also, should someone want to make a yes/no column that indicates whether or not a book has a cover, create a column made from other columns (a composite column), check the 'use checkmarks' box, then enter the following as the template.
Code:
program: ifempty(has_cover(), 'No')
chaley is offline   Reply With Quote
Old 07-03-2011, 12:10 AM   #85
mezme
Connoisseur
mezme began at the beginning.
 
Posts: 52
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!
mezme is offline   Reply With Quote
Old 07-03-2011, 03:32 AM   #86
chaley
CC Android & calibre dev
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: 8,945
Karma: 2737706
Join Date: Jan 2010
Location: UK
Device: Many android devices
Quote:
Originally Posted by mezme View Post
That said... I hope they will include the has_cover() function.
"They" is me, via Kovid.

Already done in source, ready to go out in the next release.

And you are welcome.
Quote:
So thank you for the heads up on the CMP()... this one itty bitty command solved another issue I was trying to figure out!
Have you noticed the (relatively) new section in the manual that classifies the template functions? (http://manual.calibre-ebook.com/template_ref.html) This documentation shows you both how to use the template functions and the underlying python source for the function. That might be helpful on several levels.
chaley is offline   Reply With Quote
Old 07-03-2011, 11:46 PM   #87
mezme
Connoisseur
mezme began at the beginning.
 
Posts: 52
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!
mezme is offline   Reply With Quote
Reply

Tags
calibre, template

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 09:48 PM.


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