Hi again,
"curses.wrapper" allows to pass arguments to the supplied function.
<code>
def wrapper(func, *args, **kwds):
...
func(*args, **kwds)
...
</code>
Urwid doesn't accept args:
<code>
def run_wrapper(self, fn, alternate_buffer=True):
try:
self.start(alternate_buffer)
return fn()
finally:
self.stop()
</code>
That "alternate_buffer=True" eliminates the posibility to add "*args"
So I propose next solution:
<code>
def run_wrapper(fn, *args, **kwds):
alternate_buffer = kwds.get('alternate_buffer', True)
if 'alternate_buffer' in kwds.keys():
del(kwds['alternate_buffer'])
...
fn(*args, **kwds)
...
</code>
COMMENTS:
-alternate_buffer should be added as run_wrapper last argument or, at
least, always behind non keyword arguments. This is a Python issue.
- Another limitation of this method is that alternate_buffer *must be*
a keyword argument.
Look the attached file for more info.
Best regards,
Iñigo Serna
def print_alt(alternate_buffer):
print 'Alternate buffer', alternate_buffer
def run(*args, **kwds):
print 'Arguments:', str(args)
print 'Keywords:', str(kwds)
def run_wrapper(fn, *args, **kwds):
alternate_buffer = kwds.get('alternate_buffer', True)
if 'alternate_buffer' in kwds.keys():
del(kwds['alternate_buffer'])
print_alt(alternate_buffer)
fn(*args, **kwds)
##### COMMENTS:
# alternate_buffer should be added as run_wrapper last argument or,
# at least, always behind non keyword arguments. This is a Python issue.
# F.e.: this will fail:
# run_wrapper(run, alternate_buffer=False, 'aaaa', 'bbbb', a=0, b=0)
# Another limitation of this method is that alternate_buffer *must be*
# a keyword argument, so this will also fail:
# run_wrapper(run, False, 'aaaa', 'bbbb', a=0, b=0)
print '#' * 50
run_wrapper(run, 'aaaa', 'bbbb', a=0, b=0)
print '#' * 50
run_wrapper(run, 'aaaa', 'bbbb', a=0, b=0, alternate_buffer=True)
print '#' * 50
run_wrapper(run, 'aaaa', 'bbbb', a=0, b=0, alternate_buffer=False)
print '#' * 50
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid