Browse Source

Merge pull request #358 from mkramlich/master

fix for issue 356: unicode labels cause the text/curses UI to crash
283
ThomasV 11 years ago
parent
commit
18c2dba9b8
  1. 5
      .gitignore
  2. 17
      gui/text.py

5
.gitignore

@ -1,8 +1,13 @@
####-*.patch ####-*.patch
lib/icons_rc.py lib/icons_rc.py
*.pyc *.pyc
*.swp
build/ build/
dist/ dist/
*.egg/ *.egg/
/electrum.py /electrum.py
contrib/pyinstaller/ contrib/pyinstaller/
Electrum.egg-info/
gui/qt/icons_rc.py
locale/
.devlocaltmp/

17
gui/text.py

@ -1,4 +1,4 @@
import curses, datetime import curses, datetime, locale
from decimal import Decimal from decimal import Decimal
_ = lambda x:x _ = lambda x:x
#from i18n import _ #from i18n import _
@ -24,6 +24,9 @@ class ElectrumGui:
self.wallet = Wallet(storage) self.wallet = Wallet(storage)
self.wallet.start_threads(network) self.wallet.start_threads(network)
locale.setlocale(locale.LC_ALL, '')
self.encoding = locale.getpreferredencoding()
self.stdscr = curses.initscr() self.stdscr = curses.initscr()
curses.noecho() curses.noecho()
curses.cbreak() curses.cbreak()
@ -54,7 +57,7 @@ class ElectrumGui:
self.network.register_callback('disconnecting', self.refresh) self.network.register_callback('disconnecting', self.refresh)
self.tab_names = [_("History"), _("Send"), _("Receive"), _("Contacts"), _("Wall")] self.tab_names = [_("History"), _("Send"), _("Receive"), _("Contacts"), _("Wall")]
self.num_tabs = len(self.tab_names) self.num_tabs = len(self.tab_names)
def set_cursor(self, x): def set_cursor(self, x):
try: try:
@ -140,8 +143,9 @@ class ElectrumGui:
self.print_list(messages, "%19s %25s "%("Address", "Label")) self.print_list(messages, "%19s %25s "%("Address", "Label"))
def print_receive(self): def print_receive(self):
messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses()) fmt = "%-35s %-30s"
self.print_list(messages, "%19s %25s "%("Address", "Label")) 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): def print_edit_line(self, y, label, text, index, size):
text += " "*(size - len(text) ) text += " "*(size - len(text) )
@ -160,7 +164,6 @@ class ElectrumGui:
def print_banner(self): def print_banner(self):
self.print_list( self.network.banner.split('\n')) self.print_list( self.network.banner.split('\n'))
def print_list(self, list, firstline = None): def print_list(self, list, firstline = None):
self.maxpos = len(list) self.maxpos = len(list)
if not self.maxpos: return if not self.maxpos: return
@ -170,7 +173,9 @@ class ElectrumGui:
for i in range(self.maxy-4): for i in range(self.maxy-4):
msg = list[i] if i < len(list) else "" msg = list[i] if i < len(list) else ""
msg += " "*(self.maxx - 2 - len(msg)) 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): def refresh(self):
if self.tab == -1: return if self.tab == -1: return

Loading…
Cancel
Save