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()