Ok. I'm deep into urwid (not so deep). Initially I made some changes to 
urwid sources, then back to original and implemented some widgets to have 
same behaviours.

To get the widget size is easy, it could be implemented for each basic 
widget. To implement into library add *_size* property and *get_size* method 
to urwid.Widget. The *_size* property is a tuple of 2 values: row count and 
column count. The *get_size* method simply return *self._size*. Each basic 
widget implementation (Frame, Filler, Text, ListBox, etc.) update its own 
*_size* property as last operation in *render* method, the *_size* tuple is 
updated with the canvas object created: self._size = (canv.rows (), 
canv.cols ()).
Initially I made chages to the library sources (only for Frame, Filler, Text 
and ListBox) then restored original sources and implemented a new set of 
widget inherited from basic library widgets.
Here are the NewFrame and NewText widgets

    # Class: NewFrame
    class NewFrame (urwid.Frame):

        _size = (0, 0)

        def render (self, size, focus = False):
            canvas = super (NewFrame, self).render (size, focus)
            new_size = (canvas.rows (), canvas.cols ())
            old_size = self._size
            # check if to raise *on_resize* event
            if new_size != old_size:
                self.on_resize (new_size)
            self._size = new_size
            return canvas

        def get_size (self):
            return self._size

        def on_resize (self, new_size):
            pass


    # Calss: NewText
    class NewText (urwid.Text):


        _size = (0, 0)

        def render (self, size, focus = False):
            canvas = super (NewText, self).render (size, focus)
            new_size = (canvas.rows (), canvas.cols ())
            old_size = self._size
            # check if to raise *on_resize* event
            if new_size != old_size:
                self.on_resize (new_size)
            self._size = new_size
            return canvas

        def get_size (self):
            return self._size


        def on_resize (self, new_size):
            pass

I'm new to Python, so I guess there is a better way to implement them. The 
widget size is basically solved and works with 'liquid layout' widgets, it 
is valid after the *render* method is called and will be updated at each 
(implicit or explicit) *render* calls. The event *on_resize* is called only 
if the widget change size.





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

Reply via email to