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