From 0061145f3955259ea977a513ddaff51e64b8426b Mon Sep 17 00:00:00 2001 From: oepen Date: Thu, 5 Aug 2010 13:55:26 +0000 Subject: [PATCH] Added new method to break text into several lines of a maximum length. This is neccessary because pygtk.set_width_chars doesn't work correctly on the Moko git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@242 96b47cad-a561-4643-ad3b-153ac7d7599c --- eID_gui/src/eid/logic.py | 23 +++++++++++++++++++++++ eID_gui/src/eid/windows.py | 8 ++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/eID_gui/src/eid/logic.py b/eID_gui/src/eid/logic.py index 88c1b0a..43ac773 100644 --- a/eID_gui/src/eid/logic.py +++ b/eID_gui/src/eid/logic.py @@ -4,6 +4,29 @@ import subprocess from threading import Thread, Event from eid_gui_globals import STR_CARD_FOUND, STR_NO_CARD, IMAGES +def break_text(text, line_len): + """Inject newlines into a string, so that no line is longer than + line_len characters""" + pos = line_len + chr_lst = list(text) + lst_len = len(text) + + while(pos < lst_len): + #Search for a whitespace + while(chr_lst[pos] != ' '): + pos -= 1 + #If we don't find a whitespace, we inject a newline into the text + if(chr_lst[pos] == '\n' or pos == 0): + pos += line_len + chr_lst.insert(pos, '\n') + line_len += 1 + break + chr_lst[pos] = '\n' + + pos += line_len + + return "".join(chr_lst) + class cardChecker(Thread): """ This class searches for a card with a given ATR and displays wether or not using a label and an image """ diff --git a/eID_gui/src/eid/windows.py b/eID_gui/src/eid/windows.py index 465e071..2e82c51 100644 --- a/eID_gui/src/eid/windows.py +++ b/eID_gui/src/eid/windows.py @@ -16,7 +16,7 @@ except ImportError: from eid_gui_globals import IMAGES, GLADE_FILE, EPA_ATR from widgets import customCheckButton -from logic import cardChecker +from logic import cardChecker, break_text class MokoWindow(gtk.Window): """ @@ -123,9 +123,9 @@ class MsgBox(gtk.Dialog): self.set_size_request(480, 160) hbox_top = gtk.HBox() - lbl = gtk.Label(msg) - lbl.set_width_chars(20) - lbl.set_line_wrap(True) + lbl = gtk.Label(break_text(msg, 35)) + #lbl.set_width_chars(20) + #lbl.set_line_wrap(True) btn = gtk.Button("Ok") btn.connect("clicked", self.__destroy) img = gtk.Image()