Ian Ward wrote: > > It looks pretty good, but I wonder if there is a way to do it in a more > duck-typing style. > > Instead of isinstance() perhaps we could check for a size_hint attribute > and use it if it's there. That way people that know they are only using > "my_widget" in one container could just do something like: > my_widget.size_hint = 'weight' > my_widget.size_hint_weight = 5 > Good idea, but why not just my_widget.size_hint_weight, or perhaps my_widget.hint_weight? The size_hint attribute enforces a limit of a single hint, but perhaps it might be neater to rely on precedence and convention?
For instance, the precedence of the hints could go: 1. hint_flow 2. hint_fixed 3. hint_weight With flow taking precedence over fixed size, and fixed size taking precedence over weight. > I would prefer to name the classes FlowHint, WeightHint and FixedHint > and make them part of the urwid namespace (not a separate submodule), so > the same thing as above without modifying my_widget would be: > my_hinted_widget = urwid.WeightHint(my_widget, 5) > Funnily enough, that's exactly what I originally named them :) - then I started worrying about brevity and shipped them off to their own module. Keeping them in the urwid namespace is probably more consistent, though. > The hint classes could inherit from a new base class I'm planning to add > "DecoratorWidget". See: http://excess.org/urwid/wiki/NewBaseClasses > I think that's a pretty good idea. On another note, I was thinking about keybindings, largely because I've been customising them a lot since I switched to the Dvorak keyboard layout. The signal system you have is really quite neat, and perhaps underused. Instead of giving default keybindings to widgets like the Columns and Pile widgets, maybe instead you could give them a set of standard signals, such as "pile-down" and "column-left", that would perform the same job. So you could do something like: keybindings.register("up", "pile-up") keybindings.register("left", "column-left") keybindings.register("down", "pile-down") keybindings.register("right", "column-right") That way, if someone wanted to use emacs-like keybindings, but keep the default focus-swapping behaviour of the Columns and Pile widgets, he could do: keybindings.register("ctrl-p", "pile-up") keybindings.register("ctrl-p", "column-left") keybindings.register("ctrl-n", "pile-down") keybindings.register("ctrl-n", "column-right") I dunno; just a thought... I might be overcomplicating things. -- James Reeves _______________________________________________ Urwid mailing list [email protected] http://lists.excess.org/mailman/listinfo/urwid
