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 05-28-2011, 01:01 PM   #1
kenreiss
Junior Member
kenreiss began at the beginning.
 
Posts: 5
Karma: 10
Join Date: May 2011
Device: ipad
Custom Coloring

Hi-

I'm hoping someone can help me come up with a template that does something simple, but appears to be beyond my understanding of the template language (which isn't hard).

I'm trying to get the title to turn red if the tags field is empty. I've tried all sorts of variations that I can think of with the ifempty operator, but I'm not finding the right combination.

Any help would be appreciated.

Thanks!
kenreiss is offline   Reply With Quote
Old 05-28-2011, 01:08 PM   #2
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,842
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
{tags:'test($, "red", "black")'}
kovidgoyal is online now   Reply With Quote
Advert
Old 05-28-2011, 02:09 PM   #3
Loeffel
Connoisseur
Loeffel began at the beginning.
 
Loeffel's Avatar
 
Posts: 58
Karma: 10
Join Date: Mar 2011
Device: Kindle 3 3G
The new coloring is really useful. Is there a possibility to color the line background instead of the text or even color the text of the whole line not only one column?
Loeffel is offline   Reply With Quote
Old 05-28-2011, 02:33 PM   #4
phenomshel
ZCD BombShel
phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.phenomshel ought to be getting tired of karma fortunes by now.
 
phenomshel's Avatar
 
Posts: 4,793
Karma: 8293322
Join Date: Jan 2009
Location: The Frozen North (aka Illinois, USA)
Device: iPad, STB Kindle Oasis
Well, you got further than I did, anyway, Ken. I took one look at the editor and decided my calibre could just stay one color! For the record, I AM NOT COMPLAINING!! Just observing that the feature sounds great but is apparently beyond me.
phenomshel is offline   Reply With Quote
Old 05-28-2011, 04:27 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: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Loeffel View Post
The new coloring is really useful. Is there a possibility to color the line background instead of the text or even color the text of the whole line not only one column?
No, and no.
chaley is offline   Reply With Quote
Advert
Old 05-28-2011, 04:28 PM   #6
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,842
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
phenomshel: The next calibre release should have two modes for specifying coloring a "Basic" mode and an advanced mode (you should find the basic mode usable).
kovidgoyal is online now   Reply With Quote
Old 05-28-2011, 04:40 PM   #7
Loeffel
Connoisseur
Loeffel began at the beginning.
 
Loeffel's Avatar
 
Posts: 58
Karma: 10
Join Date: Mar 2011
Device: Kindle 3 3G
Too bad, I hoped a little script could manage this.
Loeffel is offline   Reply With Quote
Old 05-28-2011, 05:46 PM   #8
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
Continuing this thread rather than starting a new one: what if you want the title to be red if (for example) tags are empty *and* the #read field is "no." I'm perplexed about how to use the template language when you want to test two different fields; I keep looking for an "and" operator, but I'm pretty certain that's not the right way to go about it!
jesscat is offline   Reply With Quote
Old 05-28-2011, 06:12 PM   #9
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,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by jesscat View Post
Continuing this thread rather than starting a new one: what if you want the title to be red if (for example) tags are empty *and* the #read field is "no." I'm perplexed about how to use the template language when you want to test two different fields; I keep looking for an "and" operator, but I'm pretty certain that's not the right way to go about it!
There is an 'and' function. It returns a non-empty value if all its arguments are non-empty (true), otherwise empty (false).

What you want is something like:
Code:
program:
  test(and(
      test(field('tags'), '', '1'),
      switch(field('#read'), 'No', '1', '')),
    'red',
    'black')
In this case the and() checks if two things are true: the tags field is empty (the test() inside the and) and the #read field is no (the switch() inside the and). The first (outermost) test checks if the and() is true, and if so returns 'red', otherwise 'black'.

There are other ways to do this. For example, you can construct a string by concatenating tags and #read, then check if it is 'no' with something like
Code:
program: switch(strcat(field('tags'), field('#read')), '^No$', 'red', 'black')
The concatenated string can be 'no' only if tags are empty and #read is no.

A third way is similar to the second, but using comparison instead of switch.
Code:
program: strcmp(strcat(field('tags'), field('#read')), 'no', 'black', 'red', 'black')

Last edited by chaley; 05-28-2011 at 06:27 PM. Reason: Add a third option
chaley is offline   Reply With Quote
Old 05-28-2011, 07:34 PM   #10
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
Oh wow, perfect, thank you so much! Seeing those three models really helps me better understand how to actually use the template language - it's so helpful, I really appreciate it.

Another question for you: can you test on the ondevice field? If so, what happens if there is no device connected? Or do you first have to check to see if that field exists?
jesscat is offline   Reply With Quote
Old 05-28-2011, 10:40 PM   #11
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 2020, Kindle PW2
If you all do not mind me asking, what reasons would you want to use the coloring, what benefit are you expecting??
nynaevelan is offline   Reply With Quote
Old 05-29-2011, 12:15 AM   #12
kenreiss
Junior Member
kenreiss began at the beginning.
 
Posts: 5
Karma: 10
Join Date: May 2011
Device: ipad
Red and Black

Quote:
Originally Posted by kovidgoyal View Post
{tags:'test($, "red", "black")'}
Thank for the quick reply... now the question is where to enter this. I thought it would go in the tags wizard in column coloring, but apparently not.

I don't remember seeing any info on the test command, but I never would have gotten there anyway

Thanks again!

Ken
kenreiss is offline   Reply With Quote
Old 05-29-2011, 01:16 AM   #13
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,842
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Put it into one of the white boxes and change the combobox next to it to read title. You cant use the Tag Wizard for this template.
kovidgoyal is online now   Reply With Quote
Old 05-29-2011, 06:08 AM   #14
Loeffel
Connoisseur
Loeffel began at the beginning.
 
Loeffel's Avatar
 
Posts: 58
Karma: 10
Join Date: Mar 2011
Device: Kindle 3 3G
@nynaevelan
I use the coloring for marking 2 types of books in my bibliothek.
  • I mark english books as I am german and most of the books are in german, I would like to know while scanning the whole bibliothek which book is in english. It is right, when you say, you can see it in the tag, but while searching/scanning I switch of the tag or it isn't in the visible range of screen.
  • New books "just" added are in a somehow raw form. They get marked by 2 tags, one for showing the entry is raw and the second one for marking that the cover isn't added by now. These entries I mark red and darkred, so I can easily see whats the matter.
Loeffel is offline   Reply With Quote
Old 05-29-2011, 09:10 AM   #15
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,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by jesscat View Post
Another question for you: can you test on the ondevice field? If so, what happens if there is no device connected? Or do you first have to check to see if that field exists?
Currently the ondevice field cannot be used in templates. There are issues with making it a normal template field.

However, it is clearly useful to be able to use ondevice in color templates, so I have added a new template function, ondevice(), to fetch its value. This function should appear in the next release, earlier if you run from source. The function returns 'Yes' (translated if not running in English) if a device is connected and the book is on that device. It returns the empty string if the book is not on the device or if a device is not connected.

You can use the ondevice function where you would use field('ondevice') if only ondevice were a real field. You can also use it in template function mode as {:'ondevice()'} (the field name is omitted).
chaley 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 02:41 AM.


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