On Mon, Nov 23, 2009 at 5:46 AM, Ian Ward <[email protected]> wrote: > Dominic LoBue wrote: >> Ian, >> >> Urwid is not behaving as I expected with the collapsible widgets I >> created for reading email conversations. In short, when a widget is >> expanded or made more "detailed" (which makes one widget go from one >> line to multi-line), the enlarged widget (or series or widgets, as >> they case may be), displaces the widgets above it. Focus doesn't move, >> nor does the widget in focus move at all, but I had expected the below >> widgets to be displaced instead. > > If your focus is below the widget that is expanding, then yes, the > expanding widget will push the others upward. The ListBox stores the > widget in focus and its offset, so that if the screen is resized the > widget in focus will maintain the same approximate position. The > alternative is what happens with most web-browsers: once you resize the > window and all the text re-flows you are left at some random unrelated > position within the content (likely the same pixel offset from the top > of the page) > >> The best example I can give you is the header widget. The header >> widget has two modes: summary and detailed. In summary mode the widget >> says something along the lines of "Sent <date> from <sender>". In >> detailed mode the widget is 5 lines, one line each for From, To, Cc, >> Sent, Subject. Each individual message in a conversation is made up of >> several widgets. From any of these widgets when you press the >> appropriate key, you can expand the header widget. Getting to the >> point, I open a conversation, move the focus down to the body of the >> message, and toggle the header detail widget. When the header widget >> is toggled to detailed, the widget expands upwards offscreen and all >> that is visible is the last line. > > You might try putting the header and content inside a Pile widget. That > way they look like a single widget to the ListBox and you will likely > get the behaviour you are looking for. > > >> I think I can use the listbox shift_focus() method to yank everything >> down, but I'm not sure to go about doing it. More details and examples >> on both the shift_focus and change_focus methods would be greatly >> appreciated. > > shift_focus and change_focus are the harder to use interfaces (really > just for the ListBox's own keypress handling code to use) You can use > set_focus_valign to change the focus widget's position in the ListBox. > >> Ideally a method where you specify the index of the topmost widget you >> want displayed, and focus is automatically shifted or dragged along >> (if the specified index would put the originally selected index >> off-screen) to compensate would be _perfect_. > > In this case the Pile solution may be better for you. You are trying to > set the position within the ListBox relative to a widget that is not in > focus, and that's not very easy to do at the moment. > > Ian > > _______________________________________________ > Urwid mailing list > [email protected] > http://lists.excess.org/mailman/listinfo/urwid >
I'll play with set_focus_valign and see what I get, thanks. As to using pile, I need multiple widgets. I cut the message body up into several pieces and so I can collapse replies and whatnot. I need the multiple widgets so I can use focus's keypress context. So in order to use the set_focus_valign, I take it I need to calculate the number of rows all the widgets between the widget I want to be the "top" widget, and the currently focues widget, and feed that value to set_focus_valign right? Dominic _______________________________________________ Urwid mailing list [email protected] http://lists.excess.org/mailman/listinfo/urwid
