Browse Source

FIX: fixes issue 356 where if an address label contained Unicode it could cause the text UI client (curses) to crash; this fix should work for both the History, Receive, Contacts and Wall tabs

283
Michael Kramlich 11 years ago
parent
commit
724cb06816
  1. 15
      gui/text.py

15
gui/text.py

@ -1,4 +1,4 @@
import curses, datetime
import curses, datetime, locale
from decimal import Decimal
_ = lambda x:x
#from i18n import _
@ -37,6 +37,9 @@ class ElectrumGui:
self.set_cursor(0)
self.w = curses.newwin(10, 50, 5, 5)
locale.setlocale(locale.LC_ALL, '')
self.encoding = locale.getpreferredencoding()
set_verbosity(False)
self.tab = 0
self.pos = 0
@ -140,8 +143,9 @@ class ElectrumGui:
self.print_list(messages, "%19s %25s "%("Address", "Label"))
def print_receive(self):
messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses())
self.print_list(messages, "%19s %25s "%("Address", "Label"))
fmt = "%-35s %-30s"
messages = map(lambda addr: fmt % (addr, self.wallet.labels.get(addr,"")), self.wallet.addresses())
self.print_list(messages, fmt % ("Address", "Label"))
def print_edit_line(self, y, label, text, index, size):
text += " "*(size - len(text) )
@ -160,7 +164,6 @@ class ElectrumGui:
def print_banner(self):
self.print_list( self.network.banner.split('\n'))
def print_list(self, list, firstline = None):
self.maxpos = len(list)
if not self.maxpos: return
@ -170,7 +173,9 @@ class ElectrumGui:
for i in range(self.maxy-4):
msg = list[i] if i < len(list) else ""
msg += " "*(self.maxx - 2 - len(msg))
self.stdscr.addstr( i+2, 1, msg[0:self.maxx - 2], curses.A_REVERSE if i == (self.pos % self.maxpos) else 0)
m = msg[0:self.maxx - 2]
m = m.encode(self.encoding)
self.stdscr.addstr( i+2, 1, m, curses.A_REVERSE if i == (self.pos % self.maxpos) else 0)
def refresh(self):
if self.tab == -1: return

Loading…
Cancel
Save