Browse Source

option to display zeros after decimal point

master
thomasv 14 years ago
parent
commit
fc7c9acd4d
  1. 33
      gui.py
  2. 28
      gui_qt.py
  3. 5
      wallet.py

33
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,10 +277,20 @@ def run_settings_dialog(wallet, parent):
except:
show_message("error")
return
if wallet.fee != fee:
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 )

28
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,9 +909,23 @@ class ElectrumWindow(QMainWindow):
QMessageBox.warning(self, 'Error', 'Invalid value:%s'%fee, 'OK')
return
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):
interface = wallet.interface

5
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")

Loading…
Cancel
Save