Skip to content
Snippets Groups Projects
Commit bbac6295 authored by Vincent Texier's avatar Vincent Texier
Browse files

Merge remote-tracking branch 'origin/dev0113' into dev0113

Conflicts:
	src/sakia/core/money/quant_zerosum.py
	src/sakia/core/money/relative_zerosum.py
parents 067f2964 82047ee3
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,11 @@ class QuantitativeZSum:
def localized(self, units=False, international_system=False):
value = yield from self.value()
localized_value = QLocale().toString(float(value), 'f', 0)
prefix = ""
if international_system:
localized_value, prefix = Quantitative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', 0)
if units:
return QCoreApplication.translate("QuantitativeZSum",
......
......@@ -40,8 +40,15 @@ class Quantitative():
value = yield from self.value()
return value
def _to_si(self, value):
@staticmethod
def to_si(value, digits):
prefixes = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'z', 'y']
if value < 0:
value = -value
multiplier = -1
else:
multiplier = 1
scientific_value = value
prefix_index = 0
prefix = ""
......@@ -52,10 +59,9 @@ class Quantitative():
if prefix_index < len(prefixes):
prefix = prefixes[prefix_index]
localized_value = QLocale().toString(float(scientific_value), 'f',
self.app.preferences['digits_after_comma'])
localized_value = QLocale().toString(float(scientific_value * multiplier), 'f', digits)
else:
localized_value = QLocale().toString(float(value), 'f', 0)
localized_value = QLocale().toString(float(value * multiplier), 'f', 0)
return localized_value, prefix
......@@ -64,7 +70,7 @@ class Quantitative():
value = yield from self.value()
prefix = ""
if international_system:
localized_value, prefix = self._to_si(value)
localized_value, prefix = Quantitative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', 0)
......@@ -82,7 +88,7 @@ class Quantitative():
value = yield from self.differential()
prefix = ""
if international_system:
localized_value, prefix = self._to_si(value)
localized_value, prefix = Quantitative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', 0)
......
......@@ -43,8 +43,14 @@ class Relative:
value = yield from self.value()
return value
def _to_si(self, value):
@staticmethod
def to_si(value, digits):
prefixes = ['', 'd', 'c', 'm', 'µ', 'n', 'p', 'f', 'a', 'z', 'y']
if value < 0:
value = -value
multiplier = -1
else:
multiplier = 1
scientific_value = value
prefix_index = 0
prefix = ""
......@@ -58,11 +64,9 @@ class Relative:
if prefix_index < len(prefixes):
prefix = prefixes[prefix_index]
localized_value = QLocale().toString(float(scientific_value), 'f',
self.app.preferences['digits_after_comma'])
localized_value = QLocale().toString(float(scientific_value * multiplier), 'f', digits)
else:
localized_value = QLocale().toString(float(value), 'f',
self.app.preferences['digits_after_comma'])
localized_value = QLocale().toString(float(value * multiplier), 'f', digits)
return localized_value, prefix
......@@ -71,7 +75,7 @@ class Relative:
value = yield from self.value()
prefix = ""
if international_system:
localized_value, prefix = self._to_si(value)
localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
......@@ -88,7 +92,7 @@ class Relative:
value = yield from self.differential()
prefix = ""
if international_system and value != 0:
localized_value, prefix = self._to_si(value)
localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
......
......@@ -2,6 +2,7 @@ from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale
from .relative import Relative
import asyncio
class RelativeZSum:
_NAME_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', 'Relat Z-sum')
_REF_STR_ = QT_TRANSLATE_NOOP('RelativeZSum', "{0} R0 {1}")
......@@ -59,7 +60,11 @@ class RelativeZSum:
def localized(self, units=False, international_system=False):
value = yield from self.value()
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
prefix = ""
if international_system:
localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units:
return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\
......@@ -71,7 +76,11 @@ class RelativeZSum:
def diff_localized(self, units=False, international_system=False):
value = yield from self.differential()
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
prefix = ""
if international_system and value != 0:
localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units:
return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\
......
......@@ -235,8 +235,6 @@ class Wallet(QObject):
time = block['medianTime']
txid = len(block['transactions'])
key = None
logging.debug("Key : {0} : {1}".format(salt, password))
if self.walletid == 0:
key = SigningKey(salt, password)
else:
......
......@@ -36,8 +36,8 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
for community in self.account.communities:
self.combo_community.addItem(community.currency)
for contact in certifier.contacts:
self.combo_contact.addItem(contact['name'])
for contact_name in sorted([c['name'] for c in certifier.contacts], key=str.lower):
self.combo_contact.addItem(contact_name)
if len(certifier.contacts) == 0:
self.radio_pubkey.setChecked(True)
self.radio_contact.setEnabled(False)
......@@ -55,8 +55,10 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
@asyncio.coroutine
def accept(self):
if self.radio_contact.isChecked():
index = self.combo_contact.currentIndex()
pubkey = self.account.contacts[index]['pubkey']
for contact in self.account.contacts:
if contact['name'] == self.combo_contact.currentText():
pubkey = contact['pubkey']
break
else:
pubkey = self.edit_pubkey.text()
......
......@@ -13,6 +13,8 @@ from ..models.communities import CommunitiesListModel
from ..tools.exceptions import KeyAlreadyUsed, Error, NoPeerAvailable
from PyQt5.QtWidgets import QDialog, QMessageBox
from PyQt5.QtCore import QRegExp
from PyQt5.QtGui import QRegExpValidator
class Step():
......@@ -144,6 +146,9 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
# Set up the user interface from Designer.
super().__init__()
self.setupUi(self)
regexp = QRegExp('[A-Za-z0-9_-]*')
validator = QRegExpValidator(regexp)
self.edit_account_name.setValidator(validator)
self.account = account
self.password_asker = None
self.app = app
......
......@@ -51,8 +51,8 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
for wallet in self.account.wallets:
self.combo_wallets.addItem(wallet.name)
for contact in sender.contacts:
self.combo_contact.addItem(contact['name'])
for contact_name in sorted([c['name'] for c in sender.contacts], key=str.lower):
self.combo_contact.addItem(contact_name)
if len(self.account.contacts) == 0:
self.combo_contact.setEnabled(False)
......@@ -96,8 +96,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
comment = self.edit_message.text()
if self.radio_contact.isChecked():
index = self.combo_contact.currentIndex()
recipient = self.account.contacts[index]['pubkey']
for contact in self.account.contacts:
if contact['name'] == self.combo_contact.currentText():
recipient = contact['pubkey']
break
else:
recipient = self.edit_pubkey.text()
amount = self.spinbox_amount.value()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment