Hi,

I'd like to have a LineBox with text title, like this

----- urwid 0.9.8.1 -------

Hovever I'm not very familiar with this library (I've founded it yesterday 
morning :) and I cannot find anything helpfull in documentation to resolve my 
issue. So I've modified the LineBox class to produce (an optional) title in 
line box.

New __init__ is

__init__(w, title=None, align='center')

And usage

LineBox(widget, Text(urf8decode('urwid 0.9.8.1')), align='center')

But in traditional GUI there's also radio button lists with frame, which has a 
title in left align ...

then LineBox(widget, Text(urf8decode('urwid 0.9.8.1')), align='align') will 
produce

- urwid 0.9.8.1 ------------

I hope, that this path will be useful

BTW: A file line_test.py is modified Conversation object from urwid tutorial, 
which I've used to test of my changes. Lets place it into the same directory, 
as graphics.py.

-- 
best regards
Michal Vyskocil
Index: graphics.py
===================================================================
--- graphics.py	(revision 142)
+++ graphics.py	(working copy)
@@ -90,12 +90,17 @@
 		
 
 class LineBox(WidgetWrap):
-	def __init__(self, w):
-		"""Draw a line around w."""
+	def __init__(self, w, title = None, align='center'):
+		"""
+		Draw a line around w.
+		title -- title of a LineBox
+		align -- determines the position of a title. Use 'center' (default) or 'left'
+		"""
 		
 		tlcorner=None; tline=None; lline=None
 		trcorner=None; blcorner=None; rline=None
 		bline=None; brcorner=None
+		text_title = None; tlchar = None
 		
 		def use_attr( a, t ):
 			if a is not None:
@@ -110,8 +115,22 @@
 		trcorner = use_attr( trcorner, Text(utf8decode("┐")))
 		blcorner = use_attr( blcorner, Text(utf8decode("└")))
 		brcorner = use_attr( brcorner, Text(utf8decode("┘")))
-		top = Columns([ ('fixed', 1, tlcorner),
-			tline, ('fixed', 1, trcorner) ])
+
+		list_top = [('fixed', 1, tlcorner), ]
+		if title is not None:
+			text_title = use_attr(text_title, title); text_title.align_mode = 'center'
+			title_len = len(text_title.get_text()[0]) + 2
+			if align == "left":
+				tlchar = use_attr(tlchar, Text(utf8decode("─")))
+				list_top.extend((('fixed', 1, tlchar), ('fixed', title_len, text_title), tline))
+			else:
+				list_top.extend((tline, ('fixed', title_len, text_title), tline))
+
+		else:
+			list_top.append(tline)
+		list_top.append(('fixed', 1, trcorner))
+
+		top = Columns(list_top)
 		middle = Columns( [('fixed', 1, lline),
 			w, ('fixed', 1, rline)], box_columns = [0,2],
 			focus_column = 1)

Attachment: line_test.py
Description: application/python

_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to