Discussion:
[urwid] Question about organizing widgets...
Robert Nesius
2015-12-27 04:16:21 UTC
Permalink
Hello,

I have a list-box UI widget working... the idea is the user scrolls through
the menu, makes his or her choice, and off we go.

I have this working with a widget structure like so:


Padding
ListBox
ListWalker
Text
Divider
Button1
Button2
Button3

I start out by adding the five list items into a generic python list, then
give that to ListWalker, the results of which I give to ListBox, then wrap
with padding, hand to an overlay and off I go. Everything works.

But I don't like that in part because when handling moving the focus around
with tab/shift-tab, I have to constantly account for the text widget and
divider when calculating next focus position so I don't set the focus to
either of those two widgets. But no matter how I try to do this
AttributeError: 'list' object has no attribute 'render'
My latest attempt at this had a widget structure of:

Padding
Pile
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3

But I get the above mentioned error. It struck me that the issue might be
just giving a list to the Pile object is causing problems, so I tried....

Padding
Pile
ListWalker
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3

And that did in fact make the error go away, but another error occurred -
the render loop blew up complaining about too many items to unpack or
something like that.

I also tried the following (and some variations thereof):

Padding
Pile
ListWalker
Text
Divider
ListBox
Pile
Button1
Button2
Button3

That blows up too.

Feels like there is something I'm not conceptually understanding about
layouts in urwid at a fundamental level... so reaching out for advice. I
can follow up with some listings if that would help - thought it feels like
the problem is a conceptual misunderstanding of the rules for gluing these
widgets together.

Thanks in advance! :)

-Rob
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Robert Urban
2015-12-27 11:42:57 UTC
Permalink
show us the code.
Post by Robert Nesius
Hello,
I have a list-box UI widget working... the idea is the user scrolls through
the menu, makes his or her choice, and off we go.
Padding
ListBox
ListWalker
Text
Divider
Button1
Button2
Button3
I start out by adding the five list items into a generic python list, then
give that to ListWalker, the results of which I give to ListBox, then wrap
with padding, hand to an overlay and off I go. Everything works.
But I don't like that in part because when handling moving the focus around
with tab/shift-tab, I have to constantly account for the text widget and
divider when calculating next focus position so I don't set the focus to
either of those two widgets. But no matter how I try to do this differently,
AttributeError: 'list' object has no attribute 'render'
Padding
Pile
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
But I get the above mentioned error. It struck me that the issue might be
just giving a list to the Pile object is causing problems, so I tried....
Padding
Pile
ListWalker
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
And that did in fact make the error go away, but another error occurred - the
render loop blew up complaining about too many items to unpack or something
like that.
Padding
Pile
ListWalker
Text
Divider
ListBox
Pile
Button1
Button2
Button3
That blows up too.
Feels like there is something I'm not conceptually understanding about layouts
in urwid at a fundamental level... so reaching out for advice. I can follow
up with some listings if that would help - thought it feels like the problem
is a conceptual misunderstanding of the rules for gluing these widgets together.
Thanks in advance! :)
-Rob
--
You received this message because you are subscribed to the Google Groups
"Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Robert Nesius
2015-12-28 22:26:20 UTC
Permalink
Here is a link to something that works. Tab/shift-tab work.

https://nopaste.me/view/a6fbf4fd

As mentioned, I didn't like having the text widget and divider in the list
box, so tried some different things. Here's a list of something that gets
the idea of what I'm attempting across. In this particular listing I tried
getting a simple Pile container to display without even including the
listbox and thing still don't work.

https://nopaste.me/view/219fb34b

My ultimate goal is to build some navigable dialog boxes where sometimes
the user chooses form a menu, sometimes fills in a form, sometimes chooses
from a text box, with "Next" and "Go Back" buttons along the bottom to
navigate panes in an Installation UI.

One other thought - I'm a bit surprised I have to implement tab/shift-tab
to navigate focusable objects in a canvas. Looking at the CommandMap
documentation that looks like default behavior really, but I haven't
cracked the coded on CommandMaps yet. :-/

Thanks in advance for any thoughts/advice.

-Rob
Post by Robert Urban
show us the code.
Hello,
I have a list-box UI widget working... the idea is the user scrolls
through the menu, makes his or her choice, and off we go.
Padding
ListBox
ListWalker
Text
Divider
Button1
Button2
Button3
I start out by adding the five list items into a generic python list, then
give that to ListWalker, the results of which I give to ListBox, then wrap
with padding, hand to an overlay and off I go. Everything works.
But I don't like that in part because when handling moving the focus
around with tab/shift-tab, I have to constantly account for the text widget
and divider when calculating next focus position so I don't set the focus
to either of those two widgets. But no matter how I try to do this
AttributeError: 'list' object has no attribute 'render'
Padding
Pile
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
But I get the above mentioned error. It struck me that the issue might be
just giving a list to the Pile object is causing problems, so I tried....
Padding
Pile
ListWalker
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
And that did in fact make the error go away, but another error occurred -
the render loop blew up complaining about too many items to unpack or
something like that.
Padding
Pile
ListWalker
Text
Divider
ListBox
Pile
Button1
Button2
Button3
That blows up too.
Feels like there is something I'm not conceptually understanding about
layouts in urwid at a fundamental level... so reaching out for advice. I
can follow up with some listings if that would help - thought it feels like
the problem is a conceptual misunderstanding of the rules for gluing these
widgets together.
Thanks in advance! :)
-Rob
--
You received this message because you are subscribed to the Google Groups
"Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Robert Nesius
2015-12-28 23:23:43 UTC
Permalink
I managed to finally find the winning formula for my simple use-case...

The simple widgets I was adding to the Pile needed to be added as tuples
with sizing information...

self._frame_contents=[('pack',urwid.Text(title)),
('pack',urwid.Divider())]

Then I added the ListBox object to that that list, dropped it into an
overlay and it worked.

As I re-read the docs, I'm a bit confused as to why I needed to do that.
It seems the answer is "because the Pile widget is not being treated as a
box" and I'm not precisely sure what causes a Pile widget to think it's a
box.

-Rob
Post by Robert Nesius
Here is a link to something that works. Tab/shift-tab work.
https://nopaste.me/view/a6fbf4fd
As mentioned, I didn't like having the text widget and divider in the list
box, so tried some different things. Here's a list of something that gets
the idea of what I'm attempting across. In this particular listing I tried
getting a simple Pile container to display without even including the
listbox and thing still don't work.
https://nopaste.me/view/219fb34b
My ultimate goal is to build some navigable dialog boxes where sometimes
the user chooses form a menu, sometimes fills in a form, sometimes chooses
from a text box, with "Next" and "Go Back" buttons along the bottom to
navigate panes in an Installation UI.
One other thought - I'm a bit surprised I have to implement tab/shift-tab
to navigate focusable objects in a canvas. Looking at the CommandMap
documentation that looks like default behavior really, but I haven't
cracked the coded on CommandMaps yet. :-/
Thanks in advance for any thoughts/advice.
-Rob
Post by Robert Urban
show us the code.
Hello,
I have a list-box UI widget working... the idea is the user scrolls
through the menu, makes his or her choice, and off we go.
Padding
ListBox
ListWalker
Text
Divider
Button1
Button2
Button3
I start out by adding the five list items into a generic python list,
then give that to ListWalker, the results of which I give to ListBox, then
wrap with padding, hand to an overlay and off I go. Everything works.
But I don't like that in part because when handling moving the focus
around with tab/shift-tab, I have to constantly account for the text widget
and divider when calculating next focus position so I don't set the focus
to either of those two widgets. But no matter how I try to do this
AttributeError: 'list' object has no attribute 'render'
Padding
Pile
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
But I get the above mentioned error. It struck me that the issue might
be just giving a list to the Pile object is causing problems, so I
tried....
Padding
Pile
ListWalker
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
And that did in fact make the error go away, but another error occurred -
the render loop blew up complaining about too many items to unpack or
something like that.
Padding
Pile
ListWalker
Text
Divider
ListBox
Pile
Button1
Button2
Button3
That blows up too.
Feels like there is something I'm not conceptually understanding about
layouts in urwid at a fundamental level... so reaching out for advice. I
can follow up with some listings if that would help - thought it feels like
the problem is a conceptual misunderstanding of the rules for gluing these
widgets together.
Thanks in advance! :)
-Rob
--
You received this message because you are subscribed to the Google Groups
"Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Ian Ward
2015-12-29 01:33:34 UTC
Permalink
Right, i forgot to say the simplest way of implementing the next/prev
selectable actions would be to add them to the keys that are handled
by the container widgets' keypress() method.

keypress() is supposed to return keys that a widget can't handle, so
in the ListBox case with the focus at the bottom it would return the
key to the caller, which is the parent container, so if that container
could focus its next child's first selectable widget.
Thanks for the response....
I thought I saw something in the documentation that hinted at a tab-order
solution... It looked like I could invoke a method on some widgets that
would crawl over the children and return a list of "focusable" widgets. If
a widget in a list-box that wasn't visible was focused, I figured that would
trigger the list-box to update its view. However, it wasn't clear if the
method I was reading about would actually perform a full-tree search to
build its list...
Also, in my case, if the last selectable item in a list-box has the focus
and the user presses tab, I'd like to jump to the dialog navigation buttons
(cancel/next).
If I implement the dialogbox in a frame with the buttons in the footer then
I have to manage changing the frame focus when tabbing off the bottom of the
body... (If I read things correctly).
-Rob
CommandMap is just a thing to let you change the keys that are used
for some common actions. tab and shift+tab are in there but the 'next
selectable' and 'prev selectable' actions haven't been implemented
yet.
The main reason is because I'd like to support an ordering for tabbing
through widgets, but I haven't figured out how to make that work for
the general case. A tab order could be implemented as a decoration
widget that knows the focus_path values to set for each of the desired
widgets. It could also be discovered based on what widgets are
visible, but then that depends on the screen being drawn before the
tab key works, and won't work for widgets that need to be scrolled in
to view. The best thing might be to implement a few of these
strategies and let the user choose one that works for their
application.
Ian
Post by Robert Nesius
Here is a link to something that works. Tab/shift-tab work.
https://nopaste.me/view/a6fbf4fd
As mentioned, I didn't like having the text widget and divider in the list
box, so tried some different things. Here's a list of something that gets
the idea of what I'm attempting across. In this particular listing I tried
getting a simple Pile container to display without even including the
listbox and thing still don't work.
https://nopaste.me/view/219fb34b
My ultimate goal is to build some navigable dialog boxes where sometimes
the
user chooses form a menu, sometimes fills in a form, sometimes chooses
from
a text box, with "Next" and "Go Back" buttons along the bottom to
navigate
panes in an Installation UI.
One other thought - I'm a bit surprised I have to implement
tab/shift-tab to
navigate focusable objects in a canvas. Looking at the CommandMap
documentation that looks like default behavior really, but I haven't
cracked
the coded on CommandMaps yet. :-/
Thanks in advance for any thoughts/advice.
-Rob
Post by Robert Urban
show us the code.
Hello,
I have a list-box UI widget working... the idea is the user scrolls
through the menu, makes his or her choice, and off we go.
Padding
ListBox
ListWalker
Text
Divider
Button1
Button2
Button3
I start out by adding the five list items into a generic python list, then
give that to ListWalker, the results of which I give to ListBox, then wrap
with padding, hand to an overlay and off I go. Everything works.
But I don't like that in part because when handling moving the focus
around with tab/shift-tab, I have to constantly account for the text widget
and divider when calculating next focus position so I don't set the
focus to
either of those two widgets. But no matter how I try to do this
AttributeError: 'list' object has no attribute 'render'
Padding
Pile
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
But I get the above mentioned error. It struck me that the issue might be
just giving a list to the Pile object is causing problems, so I tried....
Padding
Pile
ListWalker
Text
Divider
ListBox
ListWalker
Button1
Button2
Button3
And that did in fact make the error go away, but another error occurred -
the render loop blew up complaining about too many items to unpack or
something like that.
Padding
Pile
ListWalker
Text
Divider
ListBox
Pile
Button1
Button2
Button3
That blows up too.
Feels like there is something I'm not conceptually understanding about
layouts in urwid at a fundamental level... so reaching out for advice.
I
can follow up with some listings if that would help - thought it feels like
the problem is a conceptual misunderstanding of the rules for gluing these
widgets together.
Thanks in advance! :)
-Rob
--
You received this message because you are subscribed to the Google Groups
"Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit
https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/a/excess.org/d/optout.
--
You received this message because you are subscribed to the Google Groups "Urwid Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urwid+***@excess.org.
To post to this group, send email to ***@excess.org.
For more options, visit https://groups.google.com/a/excess.org/d/optout.
Loading...