Arcadie M. Cracan wrote on 2010-01-28 17:24:
> Sorry, I forgot to actually attach the file...
> 
> Hello,
> 
> I'm trying to implement a generic class for a dialog popup. I'm attaching the 
> code for the implementation. I don't know the reason why it gives me an error 
> at some point. To trigger the error one must:
> - click on browse
> - click on whatever OK or Cancel

That problem is coming up because you're overriding WidgetWrap's
__init__ method without calling it from your subclass.  Adding:
    self.__super.__init__(view)
to the end of the function "fixes" the problem for me.

The error only comes up at the end because you never use the actual
AddToolDisplay instance as a widget until the moment it is closed.

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.

> Would someone please review the code and comment on it...

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


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, ...), ...)


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)


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.


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.

Ian

_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to