[Urwid] problems with overlay widget

zerx at prochas.net zerx at prochas.net
Mon May 21 09:14:35 EDT 2007


hi!

i have some problems getting an overlay widget to work.
can you help me please and have a quick look at the following code?

this is the error if i press 'h' which triggers the code:
"ValueError: need more than 1 value to unpack"

i looked at the examples but didn't find any hint why my code doesn't work 
but
the example's one does.

thank your for this good piece of software!

regards
thomas prochaska

-------------- next part --------------
#!/usr/bin/env python
##      gajimnox.py
##
##
## Copyright (C) 2007 Thomas Prochaska <zanshin at prochas.net>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##

import urwid.curses_display
import urwid

class Gajimnox:
	palette = [
		('header', 'white', 'dark blue', 'standout'),
		('footer', 'black', 'light gray', 'standout'),
		('body', 'white', 'black'),
		('help', 'white', 'black')]

	def popRoster(self, nickname):
		w = urwid.Edit(nickname)
		self.roster.append(w)

	def setup_views(self):
		# main interface
		# header bauen
		headertxt = urwid.Text('Gajim 0.11.1 :: online with account zanshin at prochas.net :: 21:30', align='left')
		headertxt = urwid.AttrWrap(headertxt, 'header')

		# footer bauen
		footertxt = urwid.Text('STATUS - Press "ALT+q" to exit or "h" for help', align='center')
		footertxt = urwid.AttrWrap(footertxt, 'footer')

		# body bauen
		roster = urwid.ListBox(urwid.SimpleListWalker(self.roster))
		accounts = urwid.ListBox(urwid.SimpleListWalker([urwid.Edit(('body', 'Accounts\n'))]))
		body = urwid.Columns([roster, accounts], 2, 'roster')

		# frame bauen
		topframe = urwid.Frame(body, headertxt, footertxt)

		# help overlay message
		# FIXME: overlay funktioniert ned.
		help = urwid.Text('Help\n----\n"h"\t ... this help screen\n"ESC"\t ... exit this help screen\n"ALT+q"\t ... exit the programm', align='center')
		help = urwid.AttrWrap(help, 'help')
		help = urwid.Overlay(help, topframe, 'center', None, 'middle', None)
		#help = urwid.Overlay(help, topframe, 'center', 1, 'middle', None)

		return topframe, help

	def main(self):
		self.roster = []
		a = urwid.Edit('a')
		b = urwid.Edit('b')
		self.roster.append(a)
		self.roster.append(b)
		self.ui = urwid.curses_display.Screen()
		self.ui.register_palette(self.palette)
		self.view, self.help_view = self.setup_views()
		self.ui.run_wrapper(self.run)

	def run(self):
		size = self.ui.get_cols_rows()
		canvas = self.view.render(size)
		self.ui.draw_screen(size, canvas)

		while True:
			canvas = self.view.render(size, focus=True)
			self.ui.draw_screen(size, canvas)
			keys = self.ui.get_input()
			if 'meta q' in keys:
				break
			for k in keys:
				if k == 'window resize':
					size = self.ui.get_cols_rows()
					continue
				elif k == 'h':
					canvas = self.help_view.render(size)
					self.ui.draw_screen(size, canvas)
					while True:
						canvas = self.help_view.render(size)
						self.ui.draw_screen(size, canvas)
						keys = self.ui.get_input()
						if 'esc' in keys:
							break
						for k in keys:
							if k == 'window resize':
								size = self.ui.get_cols_rows()
							elif k == 'x':
								print 'x'
								break
				elif k == 'r':
					self.popRoster('r')
					self.view, self.help_view = self.setup_views()
				elif k == 'a':
					self.popRoster('a')
					self.view, self.help_view = self.setup_views()

def main():
	Gajimnox().main()

if '__main__' == __name__:
	main()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20070521/c72b520e/attachment.pgp 


More information about the Urwid mailing list