Discussion:
[Urwid] Draw a table widget
Oscar
2013-08-01 13:08:44 UTC
Permalink
Hi,

Does anyone know the best way to create a table widget? I just need a
simple table (6 columns x 20 rows) like those you can do with HTML.

Thanks!
Abhinav Singh
2013-08-01 13:13:50 UTC
Permalink
I am myself new to urwid, but I assume Gridflow widget might help you here:

http://excess.org/urwid/docs/manual/widgets.html#included-widgets
http://excess.org/urwid/docs/reference/widget.html#urwid.GridFlow
Post by Oscar
Hi,
Does anyone know the best way to create a table widget? I just need a
simple table (6 columns x 20 rows) like those you can do with HTML.
Thanks!
_______________________________________________
Urwid mailing list
Urwid at lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.excess.org/pipermail/urwid/attachments/20130801/55a07f5e/attachment.htm
Oscar
2013-08-01 14:56:56 UTC
Permalink
That was my first thought, but after looking at it closer I have
some problems with that widget. I would appreciate if someone knows what
can I do to solve them!:

- It arranges each widget in a cell from left
to right and top to bottom, not it columns and rows.
- The width of
each cell is fixed. That means that the entire width of the table is
also fixed in the code. I would prefer to be automatically adjusted
based on the available rows of the terminal.
- I don't see a (easy) way
of adding a LineBox to each cell.

Thanks!

El 2013-08-01 15:13,
Post by Abhinav Singh
I am myself new to urwid, but I assume
Gridflow widget might help you here:
http://excess.org/urwid/docs/manual/widgets.html#included-widgets [2]
http://excess.org/urwid/docs/reference/widget.html#urwid.GridFlow [3]
Hi,
Post by Abhinav Singh
Post by Oscar
Does anyone know the best way to create a table widget? I
just need a
Post by Abhinav Singh
Post by Oscar
simple table (6 columns x 20 rows) like those you can do
with HTML.
Post by Abhinav Singh
Post by Oscar
Thanks!
_______________________________________________
Post by Abhinav Singh
Post by Oscar
Urwid mailing list
Urwid at lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
_______________________________________________
Post by Abhinav Singh
Urwid mailing list
Urwid at lists.excess.org
Post by Abhinav Singh
http://lists.excess.org/mailman/listinfo/urwid
[1]



Links:
------
[1]
http://lists.excess.org/mailman/listinfo/urwid
[2]
http://excess.org/urwid/docs/manual/widgets.html#included-widgets
[3]
http://excess.org/urwid/docs/reference/widget.html#urwid.GridFlow
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.excess.org/pipermail/urwid/attachments/20130801/2337ebad/attachment-0001.htm
Ian Ward
2013-08-04 18:50:30 UTC
Permalink
I would use a ListBox or Pile of Columns widgets with equal given
widths or weights for each column to make a table.

Ian
Oscar
2013-08-05 19:38:57 UTC
Permalink
Post by Ian Ward
I would use a ListBox or Pile of Columns widgets with equal given
widths or weights for each column to make a table.
Ian
Thanks Ian. The following piece of code based on your suggestion does
what I want. However, I'm not sure if the way of getting the width of
the fixed columns, using the pack() method of the Text widget in each
column, is the correct way of doing it (IMHO, looks quite ugly!). Am I
getting it right?

________________________
import urwid as u

htxt1 = u.Text("Header1", "center")
htxt2 = u.Text("Header2", "center")
htxt3 = u.Text("Header3", "center")
htxt4 = u.Text("Header4", "center")
htxt5 = u.Text("Header5", "center")

header1 = u.Pile((htxt1, u.Divider("=")))
header2 = u.Pile((htxt2, u.Divider("=")))
header3 = u.Pile((htxt3, u.Divider("=")))
header4 = u.Pile((htxt4, u.Divider("=")))
header5 = u.Pile((htxt5, u.Divider("=")))

txt11 = txt21 = u.Text("X")
txt12 = txt23 = u.Text("FoBar")
txt13 = txt24 = u.Text("Foooo Bar")
txt14 = txt25 = u.Text("Foooooo Baaar")
txt15 = txt22 = u.Text("Fooo Bar")

row1 = u.Columns(((htxt1.pack()[0], header1), header2, header3,
(txt14.pack()[0], header4), header5), 1)
row2 = u.Columns(((htxt1.pack()[0], txt11), txt12, txt13,
(txt14.pack()[0], txt14), txt15), 1)
row3 = u.Columns(((htxt1.pack()[0], txt21), txt22, txt23,
(txt14.pack()[0], txt24), txt25), 1)

table = u.Pile((row1, row2, row3))

Cheers,
Oscar

Continue reading on narkive:
Loading...