Browse Source

Merge pull request #1255 from kyuupichan/amountedit2

Fix nasty bug in amount editors
283
ThomasV 10 years ago
parent
commit
8e6e4f1b92
  1. 8
      gui/qt/amountedit.py
  2. 11
      lib/util.py

8
gui/qt/amountedit.py

@ -4,6 +4,7 @@ from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
from decimal import Decimal from decimal import Decimal
from electrum.util import format_satoshis_plain
class MyLineEdit(QLineEdit): class MyLineEdit(QLineEdit):
frozen = pyqtSignal() frozen = pyqtSignal()
@ -93,8 +94,5 @@ class BTCAmountEdit(AmountEdit):
def setAmount(self, amount): def setAmount(self, amount):
if amount is None: if amount is None:
self.setText("") self.setText("")
return else:
self.setText(format_satoshis_plain(amount, self.decimal_point()))
p = pow(10, self.decimal_point())
x = amount / Decimal(p)
self.setText(str(x))

11
lib/util.py

@ -2,6 +2,7 @@ import os, sys, re, json
import platform import platform
import shutil import shutil
from datetime import datetime from datetime import datetime
from decimal import Decimal
import urlparse import urlparse
import urllib import urllib
import threading import threading
@ -104,10 +105,11 @@ def user_dir():
#raise Exception("No home directory found in environment variables.") #raise Exception("No home directory found in environment variables.")
return return
def format_satoshis_plain(x): def format_satoshis_plain(x, decimal_point = 8):
'''Display a satoshi amount in BTC with 8 decimal places. Always '''Display a satoshi amount scaled. Always uses a '.' as a decimal
uses a '.' as a decimal point and has no thousands separator''' point and has no thousands separator'''
return "{:.8f}".format(x / 100000000.0) scale_factor = pow(10, decimal_point)
return "{:.8f}".format(Decimal(x) / scale_factor).rstrip('0').rstrip('.')
def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False): def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False):
from locale import localeconv from locale import localeconv
@ -223,7 +225,6 @@ def block_explorer_URL(config, kind, item):
def parse_URI(uri): def parse_URI(uri):
import bitcoin import bitcoin
from decimal import Decimal
if ':' not in uri: if ':' not in uri:
assert bitcoin.is_address(uri) assert bitcoin.is_address(uri)

Loading…
Cancel
Save