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
This commit is contained in:
@@ -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 """
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user