[Urwid] urwid.Pile() - ValueError: too many values to unpack

Bernardo Torres bernardojts at gmail.com
Wed Apr 26 15:39:22 EDT 2006


Just fixed. Apparently, ui.get_cols_rows() is only available under the
wrapper. New code:

class Interface:
  def __init__(self):
    server = xmlrpclib.ServerProxy("http://localhost:8082/")
    modules = server.list_modules()
    self.ui = urwid.curses_display.Screen()
    self.ui.register_palette([
      ('header', 'white', 'black', 'standout'),
      ('module', 'white', 'dark green'),
      ('text', 'black', 'dark blue'),
      ('title', 'white', 'dark blue', 'standout'),
      ('tip', 'dark red', 'dark cyan', 'standout'),
      ('bg', 'black', 'dark blue'),
    ])
    mods = []
    for mod in modules:
      mods.append(urwid.AttrWrap(urwid.Text(mod), 'module'))
    mods = urwid.ListBox(mods)
    title = urwid.AttrWrap(urwid.Text(('header', "Diag\n"),
align="center"), 'title')
    footer = urwid.Text(('tip', "ESC - Sair"))
    help = ""
    for module in modules:
      for method in server.module_methods(module):
        doc = docextract.DocString(server.system.methodHelp(module+'.'+method))
        help += module+'.'+method+': '+doc.description+"\n"
    play = urwid.ListBox([urwid.Text(('header', help))])
    self.body = urwid.Columns([('weight', 1, mods), ('weight', 4,
play)], dividechars=1, focus_column=0)
    self.box = urwid.AttrWrap(urwid.Frame(self.body, title, footer,
focus_part='body'), 'bg')
    self.ui.run_wrapper(self.main)

  def main(self):
    self.size = self.ui.get_cols_rows()
    self.canvas = self.box.render(self.size)
    while True:
      self.ui.draw_screen(self.size, self.canvas)
      time.sleep(1)
i = Interface()

On 4/26/06, Bernardo Torres <bernardojts at gmail.com> wrote:
> Hi, worked wonders. Thanks a lot!
>
> Now, I'm making a class with it, but having a little problem with the
> following code:
> #!/usr/bin/python
> import time, xmlrpclib, urwid, urwid.curses_display, docextract
>
> class Interface:
>   def __init__(self):
>     server = xmlrpclib.ServerProxy("http://localhost:8082/")
>     modules = server.list_modules()
>     self.ui = urwid.curses_display.Screen()
>     self.ui.register_palette([
>       ('header', 'white', 'black', 'standout'),
>       ('module', 'white', 'dark green'),
>       ('text', 'black', 'dark blue'),
>       ('title', 'white', 'dark blue', 'standout'),
>       ('tip', 'dark red', 'dark cyan', 'standout'),
>       ('bg', 'black', 'dark blue'),
>     ])
>     mods = []
>     for mod in modules:
>       mods.append(urwid.AttrWrap(urwid.Text(mod), 'module'))
>     mods = urwid.ListBox(mods)
>     title = urwid.AttrWrap(urwid.Text(('header', "Diag\n"),
> align="center"), 'title')
>     footer = urwid.Text(('tip', "ESC - Sair"))
>     play = urwid.ListBox([urwid.Text(('header', "Aperte F8 para sair" * 200))])
>     self.body = urwid.Columns([('weight', 1, mods), ('weight', 4,
> play)], dividechars=1, focus_column=1)
>     box = urwid.AttrWrap(urwid.Frame(self.body, title, footer,
> focus_part='body'), 'bg')
>     self.size = self.ui.get_cols_rows()
>     self.canvas = box.render(self.size)
>     ui.run_wrapper(main)
>
>   def main():
>     while True:
>       self.ui.draw_screen(self.size, self.canvas)
>       time.sleep(1)
> i = Interface()
>
> And the result is this:
> bernardo at iraque:~/codes/dialogger$ ./diag
> Traceback (most recent call last):
>   File "./diag", line 34, in ?
>     i = Interface()
>   File "./diag", line 26, in __init__
>     self.size = self.ui.get_cols_rows()
>   File "/usr/lib/python2.4/site-packages/urwid/curses_display.py",
> line 437, in get_cols_rows
>     rows,cols = self.s.getmaxyx()
> AttributeError: 'NoneType' object has no attribute 'getmaxyx'
>
> Any ideas?
> Cya,
>
> Bernardo
>
> On 4/18/06, Ian Ward <ian at excess.org> wrote:
> > Bernardo Torres wrote:
> > > Hi,
> > >
> > > I'm starting to use Urwid and I have a little doubt about this program I made:
> > ...
> > >   mods = []
> > >   for mod in modules:
> > >     mods.append(urwid.AttrWrap(urwid.Text(mod["name"]), 'header'))
> > >   mods = urwid.ListBox(mods)
> > >   title = urwid.Text(('header', "Diag"))
> > >   footer = urwid.Text(('header', "Aperte F8 para sair"))
> > >   body = mods
> > >   box = urwid.Pile([title, body, footer])
> >
> > This last line is the problem.  ListBox widgets are box widgets, but
> > Pile widgets may only contain flow widgets.
> >
> > You could replace the line above with:
> >      box = urwid.Frame( body, header=title, footer=footer )
> >
> > Frame widgets have one box widget in the middle and may have header and
> > footer flow widgets on the top and bottom.
> >
> > ...
> > > What I wanted to do is something like what's in the attachment.
> > >
> > > Any idea would be nice.
> > > Thanks,
> >
> > In your diagram you are also showing two columns.  To create columns you
> > use the Columns widget.  Something like this would work:
> >
> > left_list = [urwid.Text("blablab\nOther text\n\nAnother txt")]
> > left_col = urwid.ListBox( left_list )
> > right_list = [urwid.Text("Some widgets here:"),urwid.Edit("Edits","")]
> > right_col = urwid.ListBox( right_list )
> > body = urwid.Columns([ ('weight',1,left_col), ('weight',3,right_col) ])
> >
> > This creates two seperate ListBox widgets, one using 1/4 of the
> > available space and the other using 3/4.
> >
> > Hope this helps!
> >
> > Ian
> >
> >
> > _______________________________________________
> > Urwid mailing list
> > Urwid at lists.excess.org
> > http://lists.excess.org/mailman/listinfo/urwid
> >
> >
>




More information about the Urwid mailing list