|
|
#16 | |
|
Member
![]() Posts: 11
Karma: 10
Join Date: Oct 2013
Device: Kindle
|
Quote:
Right now I populate this column manually, but I will either write a script or a plugin to do that for me. Just not sure when I will find the time to do so. I have a concept, but I will have to look into plugin development in more detail. If you are interested, here is my format_index function: Code:
def evaluate(self, formatter, kwargs, mi, locals, val, template):
# Check if the argument is empty. If so, return the empty string
if val == '':
return ''
# Return the input as is, if template is empty
if template == '':
return val
# Not empty. Must be a number. If it isn't, bad things will happen.
# split the strings in integer and fractional parts
v = val.split('.')
t = template.split('.')
if len(v) == 1:
v.extend('0')
# trim leading and trailing zeros
v_int = v[0].lstrip( '0' )
if len(t) != 1:
v_frac = v[1].rstrip( '0' )
# determine the number of digits for the integer and fractional part of the template
digits_int = len(t[0].lstrip('0'))
if len(t) != 1:
digits_frac = len(t[1].rstrip('0'))
# pad the input val according to the template
val_int = v_int.rjust(digits_int, '0')
if len(t) != 1 and digits_frac != 0:
val_frac = v_frac.ljust(digits_frac, '0')
retval = val_int + '.' + val_frac
else:
retval = val_int
return retval
Code:
program: format_index(field('series_index'), field('#seriestemplate'))
|
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Customize series_index value | luoman | Calibre | 3 | 08-23-2013 05:11 AM |
| dynamic content manipulation | maze | ePub | 1 | 02-16-2013 12:01 AM |
| [Kindle Touch] LocalStorage manipulation | tommytomtom | Kindle Developer's Corner | 1 | 05-12-2012 12:16 PM |
| PDF annotation and manipulation? | mr_ed | enTourage eDGe | 10 | 06-27-2011 06:23 PM |
| Section for content manipulation and issues? POLL | Alexander Turcic | iRex | 3 | 09-14-2006 05:43 AM |