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 06-04-2011, 09:22 AM   #61
jesscat
Groupie
jesscat has a complete set of Star Wars action figures.jesscat has a complete set of Star Wars action figures.jesscat has a complete set of Star Wars action figures.jesscat has a complete set of Star Wars action figures.
 
Posts: 156
Karma: 354
Join Date: Mar 2009
Location: US
Device: iPad mini, iPad 2, Kindle 3
Is it possible to construct more complex if-else statements in the template language? Like - if #unread and ondevice() then title red; elseif #unread and not ondevice() then green, else black? Would switch work - or does switch have to operate on a field?

I can't figure out how to make this work with the template language if-else-then operators (contains, ifempty, test...); they all seem to allow for only one condition. (I guess this kind of relates to the comment a few pages back trying to set two rules for one column...)

One other thing: I did appreciate having the link to the tutorial on the template language; might there be any way to put that back in the "advanced" rule section? (Easier than having to go look for it when I find myself needing it...)
jesscat is offline   Reply With Quote
Old 06-04-2011, 09:24 AM   #62
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by beckywc View Post
I have a composite column that shows 95=date read, Reading: (percent read), Not Read in this column. This composite column information comes from the comments column, where the fetch annotations information is displayed.

I'm trying to color code this column, so far I can get the Not Read to show a color, but can't seem to get the others to change color. I hope I'm making sense.
Give some real examples of the first two cases, especially the first one. Does it look something like like "95=01/12/2011"?

The bottom line is that because the column does not have fixed content, you will need to match using regular expressions. What those expressions are will depend on what the column can contain.
chaley is offline   Reply With Quote
Advert
Old 06-04-2011, 09:38 AM   #63
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 272
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
It looks like 95=1/30/2011 or 95=4/9/2011

Reading: 33%

Last edited by beckywc; 06-04-2011 at 09:40 AM.
beckywc is offline   Reply With Quote
Old 06-04-2011, 09:57 AM   #64
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by jesscat View Post
Is it possible to construct more complex if-else statements in the template language? Like - if #unread and ondevice() then title red; elseif #unread and not ondevice() then green, else black? Would switch work - or does switch have to operate on a field?
First, you can do this with the wizard. Rules for a column are applied in order until one of them matches. In your case I see three rules, all for title. The first would test unread and ondevice, the second unread and not ondevice, and the third something like title is not empty (which is always true).

Now to the template, which is how I would do this. Use the 'and' function to combine the terms. If you think
Code:
if X and Y then Z else Q
you write
Code:
test(and(X, Y), Z, Q)
Use first_non_empty to sequence through a set of ands. For example,
Code:
if X and Y then Z1 elseif X and not Y then Z2 else Z3
becomes
Code:
first_non_empty(test(and(X, Y), Z, ''), test(and(X, not(Y)), Z2, ''), Z3)
A template that might work after you fix the column names is
Code:
program:
  first_non_empty(
    test(and(
      	        ondevice(),
                switch(field('#mybool'), 'Yes', '1', '')), 
        'red', ''),
    test(and(
                test(ondevice(), '', '1'),
                switch(field('#mybool'), 'Yes', '1', '')),
        'green', ''),
    'black')
Note that the not function is not working, which is why I used test in the second arm. I will fix the not function for the next release.
Quote:
One other thing: I did appreciate having the link to the tutorial on the template language; might there be any way to put that back in the "advanced" rule section? (Easier than having to go look for it when I find myself needing it...)
Good idea. I will do that.
chaley is offline   Reply With Quote
Old 06-04-2011, 10:03 AM   #65
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by beckywc View Post
It looks like 95=1/30/2011 or 95=4/9/2011

Reading: 33%
Make three rules.
For the first rule, the condition is "#column matches pattern ^95="
For the second rule, the condition is "#column matches pattern ^Reading:
For the third rule, the condition is "#column has Not Read"

All three rules will color #column with the color of your choice.
chaley is offline   Reply With Quote
Advert
Old 06-04-2011, 10:21 AM   #66
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 272
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
Thanks Chaley,

I was able to get all but the 95 to work.
beckywc is offline   Reply With Quote
Old 06-04-2011, 10:25 AM   #67
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by beckywc View Post
I was able to get all but the 95 to work.
My guess is that there is a space somewhere that isn't in what you typed for me. Try changing the condition, removing the initial ^ character. If that doesn't work, put a space before the equals. If that doesn't work, then try the single character =.
chaley is offline   Reply With Quote
Old 06-04-2011, 10:41 AM   #68
beckywc
Addict
beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.beckywc ought to be getting tired of karma fortunes by now.
 
beckywc's Avatar
 
Posts: 272
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
I just did this:

#pct_read is not and left the value blank and the date changed color.
beckywc is offline   Reply With Quote
Old 06-04-2011, 11:14 AM   #69
jesscat
Groupie
jesscat has a complete set of Star Wars action figures.jesscat has a complete set of Star Wars action figures.jesscat has a complete set of Star Wars action figures.jesscat has a complete set of Star Wars action figures.
 
Posts: 156
Karma: 354
Join Date: Mar 2009
Location: US
Device: iPad mini, iPad 2, Kindle 3
Quote:
Originally Posted by chaley View Post
First, you can do this with the wizard. Rules for a column are applied in order until one of them matches. In your case I see three rules, all for title. The first would test unread and ondevice, the second unread and not ondevice, and the third something like title is not empty (which is always true).

Now to the template, which is how I would do this. .... Use first_non_empty to sequence through a set of ands.
I didn't even consider first_non_empty. I considered trying it with the wizard, but I'd rather try to do it with the language, which is hard for me to get a grip on. I played with switches for a while, but that wasn't getting me there.

So thanks for this - it works perfectly and I can tweak things how I want. When "not" is restored I'll give that a try just to see how it works, but the test function gets by that very nicely.

Thank you!
jesscat is offline   Reply With Quote
Old 06-04-2011, 11:48 AM   #70
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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Quote:
Originally Posted by GRiker View Post
One more minor matter:
If you disable a condition by blanking all of its boxes, upon clearing the first field (the column field) the following exception occurs:
Fixed.
kovidgoyal is offline   Reply With Quote
Old 06-08-2011, 04:52 PM   #71
Noughty
Addict
Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.
 
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
This is simple, but I just don't know how to work with columns Yes/No. I have custom column #read. How to make it color title in green if the book is read (Y)?

I would also like to color in read books which metadata is missing. Fields comments (false), and custom column #tagsshelf (false, it is combined column of tags and shelves), cover (false). If any of these are missing it should be in red.
I guess those two can overlap, so maybe for the second it could color format column or author column.

Is there any other useful material, other than this http://manual.calibre-ebook.com/template_lang.html ? I'd really like to learn template language, but I need to begin from complete basics.
TIA
Noughty is offline   Reply With Quote
Old 06-08-2011, 05:05 PM   #72
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,801
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by Noughty View Post
This is simple, but I just don't know how to work with columns Yes/No. I have custom column #read. How to make it color title in green if the book is read (Y)?

I would also like to color in read books which metadata is missing. Fields comments (false), and custom column #tagsshelf (false, it is combined column of tags and shelves), cover (false). If any of these are missing it should be in red.
I guess those two can overlap, so maybe for the second it could color format column or author column.

Is there any other useful material, other than this http://manual.calibre-ebook.com/template_lang.html ? I'd really like to learn template language, but I need to begin from complete basics.
TIA
The new tool is almost self explanatory as yo go.
Add a rule button
Set the color of Column <pick> to <pick color>
Only if the conditions are satisfied
If the <pick column to test>
<pick type of test (depends on column type)

At the bottom you can click and add a second condition that must be met...
OK

In your case, you probably want 2 separate rules

Just return to the Tool and ADD another rule.
True and Yes are the same for a Yes/No column
theducks is online now   Reply With Quote
Old 06-08-2011, 05:20 PM   #73
Noughty
Addict
Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.
 
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
I haven't updated calibre yet, maybe the tool is new as I don't see anything like that. Although I succeeded with program:test(field('#tagsshelf'), '', 'red').

Will try the Tool for the first question, since I managed the second one.

Thanks for such a quick answer

Last edited by Noughty; 06-08-2011 at 05:35 PM.
Noughty is offline   Reply With Quote
Old 06-08-2011, 05:58 PM   #74
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,801
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by Noughty View Post
I haven't updated calibre yet, maybe the tool is new as I don't see anything like that. Although I succeeded with program:test(field('#tagsshelf'), '', 'red').

Will try the Tool for the first question, since I managed the second one.

Thanks for such a quick answer
8.4 has the new tool on the Color Columns tab in Look and Feel
theducks is online now   Reply With Quote
Old 06-09-2011, 05:44 AM   #75
Noughty
Addict
Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.
 
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
Thanks, updated and used it. Great tool. Very useful for those who have trouble with template languages (like me )

Ok, after update other rules got messed up or they weren't working even before (although it looked ok). With columns you can use tool, but I need rules for comments and covers. I have
program:test(field('comments'), 'black', 'red') (as I understand first color is for true, second for false, how to make it to do something only then it is false? If I remove black, it colors everything in red)
With tool I made rule to color red if there is nothing in the column.
So it checks comments and tagsshelf. I also want to add covers:
and another rule
program:test(field('cover'), '', 'red')
But it isn't working.

I need it to color in red if there is no cover, comments or tagsshelf (tags separated comma, combined column). If any is missing it should color.

TIA

Last edited by Noughty; 06-09-2011 at 07:38 AM. Reason: question
Noughty is offline   Reply With Quote
Reply

Tags
calibre, template


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 01:35 PM.


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