[Urwid] run_wrapper doesn't accept arguments

Iñigo Serna inigoserna at gmail.com
Mon Apr 9 09:37:45 EDT 2007


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_wrapper.py
Type: text/x-python
Size: 1064 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20070409/571e3f9e/attachment-0001.py 


More information about the Urwid mailing list