Quote:
Originally Posted by chaley
You are welcome. It is fun to work with people who do their homework. 
|
Quote:
You should combine the test into the function ...
|
Yes! (

) Done.
Quote:
Given that it returns 'color' without change, you could use the same function for an icon simply by passing 'foo.png' instead of 'red'.
|
Oooh, that got me cooking! Here's what I've got so far:
Code:
program:
strcat(
icon_if_set('series', 'series'),
':',
icon_if_fmt('LNK', 'folder'),
)
Code:
name: icon_if_set
arg count: 2
doc: icon_if_set(field, icon) -- if 'field' value is set, returns icon filename ('icon' + '.png:'), else returns 'blank.png'
program code:
def evaluate(self, formatter, kwargs, mi, locals, field, icon):
if mi.get(field):
return icon + '.png'
return 'blank.png'
Code:
name: icon_if_fmt
arg count: 2
doc: icon_if_fmt(format, icon) -- if format is found, returns icon filename ('icon' + '.png'), else returns 'blank.png'
program code:
def evaluate(self, formatter, kwargs, mi, locals, format, icon):
import re
fmt_data = mi._proxy_metadata.db_approx_formats
fmt_data = ','.join(v.upper() for v in fmt_data)
if re.search(format, fmt_data):
return icon + '.png'
return 'blank.png'
But I'm stuck on this one:
Code:
name: icon_if_val
arg count: 3
doc: icon_if_val(field, val, icon) -- if 'field' contains 'val', returns icon filename ('icon' + '.png'), else returns 'blank.png'
program code:
def evaluate(self, formatter, kwargs, mi, locals, field, val, icon):
import re
if re.search(val, mi.get(field)):
return icon + '.png'
return 'blank.png'
Result:
EXCEPTION: expected string or buffer