[Urwid] Generic dialog popup implementation...

Arcadie Cracan acracan at gmail.com
Sat Jan 30 09:36:33 EST 2010


Hello Ian,

Thank you for your reply and suggestions.

În data de Sîmbătă 30 Ianuarie 2010 04:49:27 am Ian Ward a scris:

> That might me partly my fault, the dialog.py example is quite old and
> creates classes that manage widgets instead of just creating new widgets
> that manage themselves (as you might do with a WidgetWrap subclass.)  So
> it really isn't a great example anymore.
>

It was for me :)

I made the changes you suggested. I'm attaching the new file.

> The definitive "empty space" widget is SolidFill.  You can replace this:
>     body = urwid.Filler(urwid.Divider(),'top')
> with this:
>     body = urwid.SolidFill(' ')

Done.

> A shadow effect can be better created with a second Overlay, but you
> need it shifted slightly off from the first.  Here's how to do that:
>
> class OffsetOverlay(urwid.Overlay):
>     def calculate_padding_filler(self, size, focus):
>         l, r, t, b = self.__super.calculate_padding_filler(size, focus)
> 	return l+1, max(0, r-1), t+1, max(0, b-1)
>
> and then use Overlay(dialog_fg, OffsetOverlay(shadow, bg, ...), ...)
>

Well, that wasn't really clear for me, I'll take a look at it later...

>
> For MyCheckBox you're trying to stop enter from causing the state to
> change, so you could change your keypress method to:
>     if key == 'enter': return key
>     self.__super.keypress(size, key)
>

Done.

>
> You're using unhandled_input to add special handling of enter in one of
> your listboxes.  A better approach would be to extend ListBox and put
> that special handling in a new keypress() method.  That way it won't
> affect enter being pressed when other widgets are in focus.  Also, if
> you grab 'enter' before passing it to the contents of the ListBox
> (calling self.__super.keypress) then you wouldn't need MyCheckBox at all.
>

Done

>
> Finally it would also be better to separate the loop handling from the
> dialog itself and make the dialog just another widget.  I'll post again
> when I have time to update the example to do this.
>

Done (sort of...). Look at the implementation of DialogDisplay.show(). The 
dialog now raises 2 kinds of exceptions: ChildDialogExit and MainDialogExit. 
If a ChildDialogExit is encountered, then the loop is "re-run" (is it correct 
to do this?).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: deftool.py
Type: text/x-python
Size: 7617 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20100130/14052e95/attachment.py 


More information about the Urwid mailing list