Discussion:
[Urwid] New pull down widget
Keith Dart
2012-11-15 07:14:34 UTC
Permalink
Hello urwid people,

Here is a widget I recently created for a project. I needed something
like a pull-down that GUIs have. It enables you to select from a list
of options, without taking up much screen space.

Attached is the widget file and demo program.


Keith Dart
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Dart <keith at dartworks.biz>
public key: ID: 19017044
<http://www.dartworks.biz/>
=====================================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lsstest.py
Type: text/x-python
Size: 4110 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20121114/7a658d7b/attachment.py
Keith Dart
2012-11-15 07:23:30 UTC
Permalink
On Wed, 14 Nov 2012 23:14:34 -0800
Post by Keith Dart
Here is a widget I recently created for a project.
Oops, forgot to add this helper function.

I guess this should be a method.

def prefix_index(thelist, prefix, index=0):
while index < len(thelist):
if thelist[index].startswith(prefix):
return index
index += 1
return None
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Dart <keith at dartworks.biz>
public key: ID: 19017044
<http://www.dartworks.biz/>
=====================================================================
Keith Dart
2012-11-15 07:27:55 UTC
Permalink
On Wed, 14 Nov 2012 23:14:34 -0800
Post by Keith Dart
Attached is the widget file and demo program.
Ok, new, fixed version. Sorry about the last one.
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Dart <keith at dartworks.biz>
public key: ID: 19017044
<http://www.dartworks.biz/>
=====================================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lsstest.py
Type: text/x-python
Size: 4284 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20121114/466aca5d/attachment.py
Ian Ward
2012-11-17 16:56:42 UTC
Permalink
Post by Keith Dart
Ok, new, fixed version. Sorry about the last one.
Thanks Keith.

There are a few issues I notice: You assume the length of a string is
the same as its width on screen (not true for wide or combining
characters), render fails if the screen is too narrow, and there's no
handling of mouse events.

For the last two It would be better to let existing widgets handle
your rendering and mouse events (like Columns, Text and Button) by
subclassing WidgetWrap. Have you seen the new tutorial examples?

For the first you can use Text.pack() to calculate the "ideal" width
of a piece of text.

Ian

Loading...