electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit fc7c9acd4d140b298a0aab1dc43cb6d2800ff038
parent f389cd6ad5f7a9233544aba76355db52fd40a80d
Author: thomasv <thomasv@gitorious>
Date:   Wed,  2 May 2012 17:40:39 +0200

option to display zeros after decimal point

Diffstat:
Mgui.py | 35++++++++++++++++++++++++++++++-----
Mgui_qt.py | 32++++++++++++++++++++++++++------
Mwallet.py | 5++++-
3 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/gui.py b/gui.py @@ -249,9 +249,24 @@ def run_settings_dialog(wallet, parent): fee.show() vbox.pack_start(fee, False,False, 5) + nz = gtk.HBox() + nz_entry = gtk.Entry() + nz_label = gtk.Label('Display zeros:') + nz_label.set_size_request(150,10) + nz_label.show() + nz.pack_start(nz_label,False, False, 10) + nz_entry.set_text( str( wallet.num_zeros )) + nz_entry.connect('changed', numbify, True) + nz_entry.show() + nz.pack_start(nz_entry,False,False, 10) + add_help_button(nz, "Number of zeros displayed after the decimal point.\nFor example, if this number is 2, then '5.' is displayed as '5.00'") + nz.show() + vbox.pack_start(nz, False,False, 5) + dialog.show() r = dialog.run() fee = fee_entry.get_text() + nz = nz_entry.get_text() dialog.destroy() if r==gtk.RESPONSE_CANCEL: @@ -262,9 +277,19 @@ def run_settings_dialog(wallet, parent): except: show_message("error") return + if wallet.fee != fee: + wallet.fee = fee + wallet.save() - wallet.fee = fee - wallet.save() + try: + nz = int( nz ) + if nz>8: nz = 8 + except: + show_message("error") + return + if wallet.num_zeros != nz: + wallet.num_zeros = nz + wallet.save() @@ -1104,8 +1129,8 @@ class ElectrumWindow: self.status_image.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks\nresponse time: %f"%(interface.host, interface.port, self.wallet.blocks, interface.rtime)) c, u = self.wallet.get_balance() - text = "Balance: %s "%( format_satoshis(c) ) - if u: text += "[%s unconfirmed]"%( format_satoshis(u,True).strip() ) + text = "Balance: %s "%( format_satoshis(c,False,self.wallet.num_zeros) ) + if u: text += "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() ) else: self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU) self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(interface.host, self.wallet.blocks)) @@ -1187,7 +1212,7 @@ class ElectrumWindow: self.history_list.prepend( [tx_hash, conf_icon, time_str, label, is_default_label, - format_satoshis(v,True), format_satoshis(balance), tooltip, details] ) + format_satoshis(v,True,self.wallet.num_zeros), format_satoshis(balance,False,self.wallet.num_zeros), tooltip, details] ) if cursor: self.history_treeview.set_cursor( cursor ) diff --git a/gui_qt.py b/gui_qt.py @@ -208,8 +208,8 @@ class ElectrumWindow(QMainWindow): icon = QIcon(":icons/status_waiting.png") else: c, u = self.wallet.get_balance() - text = "Balance: %s "%( format_satoshis(c) ) - if u: text += "[%s unconfirmed]"%( format_satoshis(u,True).strip() ) + text = "Balance: %s "%( format_satoshis(c,False,self.wallet.num_zeros) ) + if u: text += "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() ) icon = QIcon(":icons/status_connected.png") else: text = "Not connected" @@ -337,7 +337,7 @@ class ElectrumWindow(QMainWindow): is_default_label = (label == '') or (label is None) if is_default_label: label = tx['default_label'] - item = QTreeWidgetItem( [ '', time_str, label, format_satoshis(v,True), format_satoshis(balance)] ) + item = QTreeWidgetItem( [ '', time_str, label, format_satoshis(v,True,self.wallet.num_zeros), format_satoshis(balance,False,self.wallet.num_zeros)] ) item.setFont(2, QFont(MONOSPACE_FONT)) item.setFont(3, QFont(MONOSPACE_FONT)) item.setFont(4, QFont(MONOSPACE_FONT)) @@ -883,14 +883,20 @@ class ElectrumWindow(QMainWindow): grid = QGridLayout() grid.setSpacing(8) + vbox.addLayout(grid) fee_e = QLineEdit() fee_e.setText("%s"% str( Decimal( self.wallet.fee)/100000000 ) ) grid.addWidget(QLabel('Fee per tx. input'), 2, 0) grid.addWidget(fee_e, 2, 1) - vbox.addLayout(grid) fee_e.textChanged.connect(lambda: numbify(fee_e,False)) + nz_e = QLineEdit() + nz_e.setText("%d"% self.wallet.num_zeros) + grid.addWidget(QLabel('Zeros displayed after decimal point'), 3, 0) + grid.addWidget(nz_e, 3, 1) + nz_e.textChanged.connect(lambda: numbify(nz_e,True)) + vbox.addLayout(ok_cancel_buttons(d)) d.setLayout(vbox) @@ -903,8 +909,22 @@ class ElectrumWindow(QMainWindow): QMessageBox.warning(self, 'Error', 'Invalid value:%s'%fee, 'OK') return - self.wallet.fee = fee - self.wallet.save() + if self.wallet.fee != fee: + self.wallet.fee = fee + self.wallet.save() + + nz = unicode(nz_e.text()) + try: + nz = int( nz ) + if nz>8: nz=8 + except: + QMessageBox.warning(self, 'Error', 'Invalid value:%s'%nz, 'OK') + return + + if self.wallet.num_zeros != nz: + self.wallet.num_zeros = nz + self.update_history_tab() + self.wallet.save() @staticmethod def network_dialog(wallet, parent=None): diff --git a/wallet.py b/wallet.py @@ -223,13 +223,14 @@ def raw_tx( inputs, outputs, for_sig = None ): -def format_satoshis(x, is_diff=False): +def format_satoshis(x, is_diff=False, num_zeros = 0): from decimal import Decimal s = str( Decimal(x) /100000000 ) if is_diff and x>0: s = "+" + s if not '.' in s: s += '.' p = s.find('.') + s += "0"*( 1 + num_zeros - ( len(s) - p )) s += " "*( 9 - ( len(s) - p )) s = " "*( 5 - ( p )) + s return s @@ -558,6 +559,7 @@ class Wallet: 'aliases':self.aliases, 'authorities':self.authorities, 'receipts':self.receipts, + 'num_zeros':self.num_zeros, } f = open(self.path,"w") f.write( repr(s) ) @@ -593,6 +595,7 @@ class Wallet: self.aliases = d.get('aliases',{}) self.authorities = d.get('authorities',{}) self.receipts = d.get('receipts',{}) + self.num_zeros = d.get('num_zeros',0) except: raise BaseException("cannot read wallet file")