[kupfer] uiutils: Hard-wrap text for when showing as Large Type



commit 42a0e594a7a33c0020e0eb5d070c4e4a291d9972
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Fri Oct 30 16:51:55 2009 +0100

    uiutils: Hard-wrap text for when showing as Large Type
    
    We handle really long lines in Large Type by hard-wrapping text (by
    paragraphs).

 kupfer/uiutils.py |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/uiutils.py b/kupfer/uiutils.py
index 06a9f5b..5008c97 100644
--- a/kupfer/uiutils.py
+++ b/kupfer/uiutils.py
@@ -111,13 +111,20 @@ def show_text_result(text, title=None):
 	window.resize(hsize, vsize)
 	window.present()
 
+def _wrap_paragraphs(text):
+	"""
+	Return @text with linewrapped paragraphs
+	"""
+	import textwrap
+	return u"\n\n".join(textwrap.fill(par) for par in text.split("\n\n"))
+
 def show_large_type(text):
 	"""
 	Show @text, large, in a result window.
 	"""
 	import math
-	import textwrap
 
+	text = text.strip()
 	window = gtk.Window()
 	label = gtk.Label()
 	label.set_text(text)
@@ -137,9 +144,11 @@ def show_large_type(text):
 	maxhei = gtk.gdk.screen_height() - 100
 	wid, hei = label.size_request()
 
-	# Try wrapping a long line
-	if (wid > maxwid or hei > maxhei) and len(text.splitlines()) < 2:
-		label.set_text(textwrap.fill(text))
+	# If the text contains long lines, we try to
+	# hard-wrap the text
+	if ((wid > maxwid or hei > maxhei) and
+			any(len(L) > 100 for L in text.splitlines())):
+		label.set_text(_wrap_paragraphs(text))
 
 	wid, hei = label.size_request()
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]