Discussion:
[Urwid] [proposal] new Tree API
Patrick Totzke
2012-11-03 13:08:11 UTC
Permalink
Hi all!

I finally got around to polish my efforts for a new tree api a bit.
You can find the result here: https://github.com/pazz/urwidtrees .

In short, it allows you to define trees of widgets based on local
position movements like in urwids ListWalker API.

The proof-of-concept implementation also features a ListBox based
widget to display these beasts, a SimpleTreeWalker for ease of use,
customizable and fancy? decoration and lots of examples.

Have fun,
/p
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://lists.excess.org/pipermail/urwid/attachments/20121103/0749f34d/attachment.pgp
Ian Ward
2012-11-04 18:56:58 UTC
Permalink
Thanks Patrick!

It's much nicer than what we have right now.

Any chance of a licence change to LGPL2+?
Post by Patrick Totzke
Hi all!
I finally got around to polish my efforts for a new tree api a bit.
You can find the result here: https://github.com/pazz/urwidtrees .
In short, it allows you to define trees of widgets based on local
position movements like in urwids ListWalker API.
The proof-of-concept implementation also features a ListBox based
widget to display these beasts, a SimpleTreeWalker for ease of use,
customizable and fancy? decoration and lots of examples.
Have fun,
/p
_______________________________________________
Urwid mailing list
Urwid at lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Keith Dart
2012-12-01 08:11:16 UTC
Permalink
On Sun, 4 Nov 2012 13:56:58 -0500
Post by Ian Ward
It's much nicer than what we have right now.
I'm about to write some tree navigation functionality to my app. So now
I'm wondering if this is the future direction of the urwid API? Should
I get this code now and start using it, or use the original API?
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Dart <keith at dartworks.biz>
public key: ID: 19017044
<http://www.dartworks.biz/>
=====================================================================
Patrick Totzke
2012-12-01 13:01:08 UTC
Permalink
Quoting Keith Dart (2012-12-01 08:11:16)
Post by Keith Dart
On Sun, 4 Nov 2012 13:56:58 -0500
Post by Ian Ward
It's much nicer than what we have right now.
I'm about to write some tree navigation functionality to my app. So now
I'm wondering if this is the future direction of the urwid API? Should
I get this code now and start using it, or use the original API?
This API is definitely not set in stone. I am hacking on it right now to improve the
way stacking of treeboxes can be done. If I were you i'd do other parts of my app
first. I'd definitely not spend the time learning about the current Tree API.

Also, you can always use it as its now and ship it with your app to ensure a stable API :)

@Ian: I am fumbling around with your NestedTreeWalker. The idea is to allow
ListBox and TreeBox widgets as nodes and to transparently use only their respective walkers
to make a single, outer tree. Keypresses can still be first send to the widgets to make sure
customized keypress method in tree/listBoxes are respected..
/p
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://lists.excess.org/pipermail/urwid/attachments/20121201/b30a09e2/attachment.pgp
Patrick Totzke
2012-12-01 13:50:57 UTC
Permalink
Quoting Patrick Totzke (2012-12-01 13:01:08)
Post by Patrick Totzke
@Ian: I am fumbling around with your NestedTreeWalker. The idea is to allow
ListBox and TreeBox widgets as nodes and to transparently use only their respective walkers
to make a single, outer tree. Keypresses can still be first send to the widgets to make sure
customized keypress method in tree/listBoxes are respected..
This is how far I got:
https://github.com/pazz/urwidtrees/tree/nested

I have trouble debugging this TreeBox stuff.
Its somehow got to do with the way listbox sets its focus..
suggestions?

--------------------
./sandbox.nested.py

Traceback (most recent call last):
File "./sandbox.nested.py", line 30, in <module>
urwid.MainLoop(rootwidget, palette).run() # go
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 272, in run
self.screen.run_wrapper(self._run)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/raw_display.py", line 242, in run_wrapper
return fn()
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 312, in _run
self.draw_screen()
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/main_loop.py", line 563, in draw_screen
canvas = self._topmost_widget.render(self.screen_size, focus=True)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/widget.py", line 141, in cached_render
canv = fn(self, size, focus=focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/decoration.py", line 225, in render
canv = self._original_widget.render(size, focus=focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/widget.py", line 141, in cached_render
canv = fn(self, size, focus=focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/widget.py", line 1751, in render
canv = get_delegate(self).render(size, focus=focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/widget.py", line 141, in cached_render
canv = fn(self, size, focus=focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/listbox.py", line 457, in render
(maxcol, maxrow), focus=focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/listbox.py", line 339, in calculate_visible
self._set_focus_complete( (maxcol, maxrow), focus )
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/listbox.py", line 704, in _set_focus_complete
(maxcol,maxrow), focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/listbox.py", line 674, in _set_focus_first_selectable
(maxcol, maxrow), focus=focus)
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/listbox.py", line 406, in calculate_visible
n_rows = next.rows( (maxcol,) )
File "/home/pazz/.local/lib/python2.7/site-packages/urwid-1.2.0_dev-py2.7-linux-x86_64.egg/urwid/widget.py", line 1761, in <lambda>
rows = property(lambda self:get_delegate(self).rows)
AttributeError: 'ListBox' object has no attribute 'rows'
---------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://lists.excess.org/pipermail/urwid/attachments/20121201/11a4e239/attachment.pgp
Ian Ward
2012-12-02 01:37:13 UTC
Permalink
Post by Patrick Totzke
Quoting Patrick Totzke (2012-12-01 13:01:08)
Post by Patrick Totzke
@Ian: I am fumbling around with your NestedTreeWalker. The idea is to allow
ListBox and TreeBox widgets as nodes and to transparently use only their respective walkers
to make a single, outer tree. Keypresses can still be first send to the widgets to make sure
customized keypress method in tree/listBoxes are respected..
https://github.com/pazz/urwidtrees/tree/nested
...
Post by Patrick Totzke
AttributeError: 'ListBox' object has no attribute 'rows'
---------------------------------------------------------------
ListBoxes as widgets within other ListBoxes really can't work well.

AttributeError: 'ListBox' object has no attribute 'rows'
^that means a wiget (ListBox) is being treated as a flow widget when
it doesn't support that.

My NestedTreeWalker code avoids this by unrolling the content of a
tree or list walker into another list walker. That list walker is
then the one the ListBox uses.

Ian
Patrick Totzke
2012-12-02 11:48:12 UTC
Permalink
Quoting Ian Ward (2012-12-02 01:37:13)
Post by Ian Ward
Post by Patrick Totzke
Quoting Patrick Totzke (2012-12-01 13:01:08)
Post by Patrick Totzke
@Ian: I am fumbling around with your NestedTreeWalker. The idea is to allow
ListBox and TreeBox widgets as nodes and to transparently use only their respective walkers
to make a single, outer tree. Keypresses can still be first send to the widgets to make sure
customized keypress method in tree/listBoxes are respected..
https://github.com/pazz/urwidtrees/tree/nested
...
Post by Patrick Totzke
AttributeError: 'ListBox' object has no attribute 'rows'
---------------------------------------------------------------
ListBoxes as widgets within other ListBoxes really can't work well.
AttributeError: 'ListBox' object has no attribute 'rows'
^that means a wiget (ListBox) is being treated as a flow widget when
it doesn't support that.
I wonder why it is treated as a widget!
In my proposal, a NestedTreeWalker detects if a widget is ListBox or TreeBox
and returns its interna accordingly, never the widget itself..
The idea is that you use `isinstance` a lot to transparently
use internal walker (the way you did before) only.
From a users point of view this looks exactly like stacking list/treeboxes..

/p
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://lists.excess.org/pipermail/urwid/attachments/20121202/f526afad/attachment.pgp
Patrick Totzke
2013-01-23 14:10:52 UTC
Permalink
Hi all,

as mentioned on IRC, i updated my POC tree API for urwid:
https://github.com/pazz/urwidtrees-V2

It contains a couple of examples and probably a lot more bugs
but for me, it solves the important issue of allowing
nesting of trees and all in all it shoulbe be easier to use than the
previous approach.

Before this is completely ready for consumption, it needs some more
documentation and I'd also like to have the ability to nest ListWalkers.
Anyhow, feedback welcome..
/p
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://lists.excess.org/pipermail/urwid/attachments/20130123/94203f64/attachment.pgp
Loading...