tMerge branch 'kyuupichan-commas' - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 6646b7a43f46dc73d89a3a83e05fdc7ff3e34823 DIR parent 4bed294ddd8fd4e95ebc19ca56731ed536ed8826 HTML Author: ThomasV <thomasv@gitorious> Date: Wed, 29 Apr 2015 09:26:48 +0200 Merge branch 'kyuupichan-commas' Diffstat: M gui/qt/history_widget.py | 2 +- M gui/qt/history_widget_lite.py | 2 +- M gui/qt/main_window.py | 19 +++++++++---------- M gui/qt/util.py | 12 ++++-------- M lib/util.py | 36 ++++++++++++++----------------- 5 files changed, 31 insertions(+), 40 deletions(-) --- DIR diff --git a/gui/qt/history_widget.py b/gui/qt/history_widget.py t@@ -28,7 +28,7 @@ from electrum.plugins import run_hook class HistoryWidget(MyTreeWidget): def __init__(self, parent=None): - MyTreeWidget.__init__(self, parent, self.create_menu, [ '', _('Date'), _('Description') , _('Amount'), _('Balance')], [40, 140, None, 140, 140]) + MyTreeWidget.__init__(self, parent, self.create_menu, [ '', _('Date'), _('Description') , _('Amount'), _('Balance')], 2) self.config = self.parent.config self.setSortingEnabled(False) DIR diff --git a/gui/qt/history_widget_lite.py b/gui/qt/history_widget_lite.py t@@ -20,6 +20,6 @@ class HistoryWidget(QTreeWidget): if date is None: date = _("Unknown") item = QTreeWidgetItem([amount, address, date]) - if float(amount) < 0: + if amount.find('-') != -1: item.setForeground(0, QBrush(QColor("#BC1E1E"))) self.insertTopLevelItem(0, item) DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py t@@ -629,7 +629,7 @@ class ElectrumWindow(QMainWindow): buttons.addWidget(self.new_request_button) self.receive_requests_label = QLabel(_('My Requests')) - self.receive_list = MyTreeWidget(self, self.receive_list_menu, [_('Date'), _('Account'), _('Address'), _('Description'), _('Amount'), _('Status')], []) + self.receive_list = MyTreeWidget(self, self.receive_list_menu, [_('Date'), _('Account'), _('Address'), _('Description'), _('Amount'), _('Status')], 3) self.receive_list.currentItemChanged.connect(self.receive_item_changed) self.receive_list.itemClicked.connect(self.receive_item_changed) self.receive_list.setSortingEnabled(True) t@@ -901,7 +901,7 @@ class ElectrumWindow(QMainWindow): self.from_label = QLabel(_('From')) grid.addWidget(self.from_label, 3, 0) - self.from_list = MyTreeWidget(self, self.from_list_menu, ['',''], [350, 50]) + self.from_list = MyTreeWidget(self, self.from_list_menu, ['','']) self.from_list.setHeaderHidden(True) self.from_list.setMaximumHeight(80) grid.addWidget(self.from_list, 3, 1, 1, 3) t@@ -968,12 +968,11 @@ class ElectrumWindow(QMainWindow): self.fee_e.textChanged.connect(entry_changed) self.invoices_label = QLabel(_('Invoices')) - self.invoices_list = MyTreeWidget( - self, - self.create_invoice_menu, - [_('Date'), _('Requestor'), _('Description'), _('Amount'), _('Status')], - [150, 150, None, 150, 100] - ) + self.invoices_list = MyTreeWidget(self, self.create_invoice_menu, + [_('Date'), _('Requestor'), _('Description'), _('Amount'), _('Status')], 2) + self.invoices_list.header().setResizeMode(1, QHeaderView.Interactive) + self.invoices_list.setColumnWidth(1, 200) + vbox0 = QVBoxLayout() vbox0.addLayout(grid) vbox0.addLayout(buttons) t@@ -1309,14 +1308,14 @@ class ElectrumWindow(QMainWindow): return w def create_addresses_tab(self): - l = MyTreeWidget(self, self.create_receive_menu, [ _('Address'), _('Label'), _('Balance'), _('Tx')], [370, None, 130]) + l = MyTreeWidget(self, self.create_receive_menu, [ _('Address'), _('Label'), _('Balance'), _('Tx')], 1) l.setSelectionMode(QAbstractItemView.ExtendedSelection) l.setSortingEnabled(False) self.address_list = l return self.create_list_tab(l) def create_contacts_tab(self): - l = MyTreeWidget(self, self.create_contact_menu, [_('Key'), _('Value'), _('Type')], [250, None, 130]) + l = MyTreeWidget(self, self.create_contact_menu, [_('Key'), _('Value'), _('Type')], 1) self.contacts_list = l return self.create_list_tab(l) DIR diff --git a/gui/qt/util.py b/gui/qt/util.py t@@ -260,7 +260,7 @@ def filename_field(parent, config, defaultname, select_msg): class MyTreeWidget(QTreeWidget): - def __init__(self, parent, create_menu, headers, column_width): + def __init__(self, parent, create_menu, headers, stretch_column=0): QTreeWidget.__init__(self, parent) self.parent = parent self.setColumnCount(len(headers)) t@@ -277,13 +277,9 @@ class MyTreeWidget(QTreeWidget): self.edit_column = None self.itemDoubleClicked.connect(self.edit_label) self.itemChanged.connect(self.label_changed) - # set column width - for i, width in enumerate(column_width): - if width is None: - self.header().setResizeMode(i, QHeaderView.Stretch) - self.edit_column = i - else: - self.setColumnWidth(i, width) + # stretch + for i in range(len(headers)): + self.header().setResizeMode(i, QHeaderView.Stretch if i == stretch_column else QHeaderView.ResizeToContents) self.setSortingEnabled(True) def on_activated(self, item): DIR diff --git a/lib/util.py b/lib/util.py t@@ -108,28 +108,24 @@ def user_dir(): def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False): - from decimal import Decimal - if x is None: - return 'unknown' - s = Decimal(x) - sign, digits, exp = s.as_tuple() - digits = map(str, digits) - while len(digits) < decimal_point + 1: - digits.insert(0,'0') - digits.insert(-decimal_point,'.') - s = ''.join(digits).rstrip('0') - if sign: - s = '-' + s + from locale import localeconv + x = int(x) # Some callers pass Decimal + scale_factor = pow (10, decimal_point) + integer_part = "{:n}".format(int(abs(x) / float(scale_factor))) + if x < 0: + integer_part = '-' + integer_part elif is_diff: - s = "+" + s - - p = s.find('.') - s += "0"*( 1 + num_zeros - ( len(s) - p )) + integer_part = '+' + integer_part + dp = localeconv()['decimal_point'] + fract_part = ("{:0" + str(decimal_point) + "}").format(abs(x) % scale_factor) + fract_part = fract_part.rstrip('0') + if len(fract_part) < num_zeros: + fract_part += "0" * (num_zeros - len(fract_part)) + result = integer_part + dp + fract_part if whitespaces: - s += " "*( 1 + decimal_point - ( len(s) - p )) - s = " "*( 13 - decimal_point - ( p )) + s - return s - + result += " " * (decimal_point - len(fract_part)) + result = " " * (15 - len(result)) + result + return result def format_time(timestamp): import datetime