View Single Post
Old 02-19-2011, 07:28 PM   #1
Rie142 began at the beginning.
Posts: 17
Karma: 24
Join Date: Dec 2009
Location: Just outside of Seattle, WA
Device: Kindle2
Exclamation Need help with this custom Column.

I am trying to put this into Calibre. I am not sure what all the leading spaces are? I think I deleted them all.

Custom column:
Name: #special_title
Template: (the following with all leading spaces removed) program:
#compute the equivalent of the composite fields and store them in local variables

stripped = re(field('series'), '^(A|The|An)\s+', '');
shortened = shorten(stripped, 4, '-' ,4);
initials = re(stripped, '[^\w]*(\w?)[^\s]+(\s|$)', '\1');

# Format the series index. Ends up as empty if there is no series index.
# Note that leading and trailing spaces will be removed by the formatter,
# so we cannot add them here. We will do that in the strcat below.
# Also note that because we are in 'program' mode, we can freely use
# curly brackets in strings, something we cannot do in template mode.

s_index = template('{series_index:0>2.0f}');

# print(stripped, shortened, initials, s_index);
# Now concatenate all the bits together. The switch picks between
# initials and shortened, depending on whether there is a space
# in stripped. We then add the brackets around s_index if it is
# not empty. Finally, add the title. As this is the last function in
# the program, its value will be returned.

strcat( switch( stripped, '.\s', initials, '.', shortened, field('series')), test(s_index, strcat(' [', s_index, '] '), ''), field('title'));

When I enter all this into the correct places I get this error.

calibre, version 0.7.46
Traceback (most recent call last):
File "site-packages\calibre\gui2\preferences\create_custom_co", line 161, in accept
AttributeError: 'QString' object has no attribute 'strip'

Can you tell me what I am doing wrong? No matter what type of custom column I try to make using any of the recipes from the Calibre User Manual or the Calibre Forum I get the same Attribute Error.

I am not a programmer, I am an old dog who is trying to learn a new trick. This trick would be so nice for me and easier to keep the kindles organized.

Thanks for all the help you can give me.
Rie142 is offline   Reply With Quote