From 8e852220145e71e07f9ebec7b102ead608a54358 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Sat, 22 Aug 2015 09:36:52 +0200 Subject: [PATCH] Multiple fixes in referentials --- src/cutecoin/core/money/__init__.py | 6 ----- src/cutecoin/core/money/quant_zerosum.py | 17 ++++++++---- src/cutecoin/core/money/quantitative.py | 29 ++++++++++++++++----- src/cutecoin/core/money/relative.py | 12 ++++----- src/cutecoin/core/money/relative_zerosum.py | 23 +++++++++++----- src/cutecoin/gui/wallets_tab.py | 10 +++---- 6 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/cutecoin/core/money/__init__.py b/src/cutecoin/core/money/__init__.py index 7f550e49..05a4b506 100644 --- a/src/cutecoin/core/money/__init__.py +++ b/src/cutecoin/core/money/__init__.py @@ -1,9 +1,3 @@ -from enum import Enum - -class RefType(Enum): - q = 0 - r = 1 - from .quantitative import Quantitative from .relative import Relative from .quant_zerosum import QuantitativeZSum diff --git a/src/cutecoin/core/money/quant_zerosum.py b/src/cutecoin/core/money/quant_zerosum.py index e71f5e90..340c350a 100644 --- a/src/cutecoin/core/money/quant_zerosum.py +++ b/src/cutecoin/core/money/quant_zerosum.py @@ -1,4 +1,4 @@ -from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP +from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale from . import Quantitative @@ -24,7 +24,7 @@ class QuantitativeZSum: def diff_units(cls, currency): return QuantitativeZSum.units(currency) - def compute(self): + def value(self): """ Return quantitative value of amount minus the average value @@ -43,8 +43,15 @@ class QuantitativeZSum: return Quantitative(self.amount, self.community, self.app).compute() def localized(self, pretty_print=False): - value = self.compute() - return QCoreApplication.translate("Quantitative", Quantitative._REF_STR_).format(value, self.community.currency) + value = self.value() + if pretty_print: + pass + else: + strvalue = QLocale().toString(float(value), 'f', 0) + return QCoreApplication.translate("QuantitativeZSum", + QuantitativeZSum._REF_STR_) \ + .format(strvalue, + self.community.short_currency) def diff_localized(self, pretty_print=False): - return Quantitative(self.amount, self.community, self.app).amount_to_str(pretty_print) \ No newline at end of file + return Quantitative(self.amount, self.community, self.app).localized(pretty_print) \ No newline at end of file diff --git a/src/cutecoin/core/money/quantitative.py b/src/cutecoin/core/money/quantitative.py index c104b4ba..aae90749 100644 --- a/src/cutecoin/core/money/quantitative.py +++ b/src/cutecoin/core/money/quantitative.py @@ -1,7 +1,7 @@ from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QObject, QLocale -class Quantitative(QObject): +class Quantitative(): _NAME_STR_ = QT_TRANSLATE_NOOP('Quantitative', 'Units') _REF_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0} {1}") _UNITS_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0}") @@ -13,7 +13,7 @@ class Quantitative(QObject): @classmethod def translated_name(cls): - return QCoreApplication.translate('Quantitative', 'UD') + return QCoreApplication.translate('Quantitative', Quantitative._NAME_STR_) @classmethod def units(cls, currency): @@ -23,7 +23,7 @@ class Quantitative(QObject): def diff_units(cls, currency): return Quantitative.units(currency) - def compute(self): + def value(self): """ Return quantitative value of amount @@ -34,11 +34,26 @@ class Quantitative(QObject): return int(self.amount) def differential(self): - return self.compute() + return self.value() def localized(self, pretty_print=False): - return QCoreApplication.translate("Quantitative", Quantitative._REF_STR_).format(self.amount, self.currency) + value = self.value() + if pretty_print: + pass + else: + strvalue = QLocale().toString(float(value), 'f', 0) + return QCoreApplication.translate("Quantitative", + Quantitative._REF_STR_) \ + .format(strvalue, + self.community.short_currency) def diff_localized(self, pretty_print=False): - strvalue = QLocale().toString(float(self.amount), 'f', 0) - return QCoreApplication.translate("Quantitative", Quantitative._REF_STR_).format(strvalue, self.currency) + value = self.differential() + if pretty_print: + pass + else: + strvalue = QLocale().toString(float(value), 'f', 0) + return QCoreApplication.translate("Quantitative", + Quantitative._REF_STR_) \ + .format(strvalue, + self.community.short_currency) diff --git a/src/cutecoin/core/money/relative.py b/src/cutecoin/core/money/relative.py index 1b184b17..bcc29ffe 100644 --- a/src/cutecoin/core/money/relative.py +++ b/src/cutecoin/core/money/relative.py @@ -1,7 +1,7 @@ from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale -class Relative(QObject): +class Relative(): _NAME_STR_ = QT_TRANSLATE_NOOP('Relative', 'UD') _REF_STR_ = QT_TRANSLATE_NOOP('Relative', "{0} UD {1}") _UNITS_STR_ = QT_TRANSLATE_NOOP('Relative', "UD {0}") @@ -23,7 +23,7 @@ class Relative(QObject): def diff_units(self, currency): return self.units(currency) - def compute(self): + def value(self): """ Return relaive value of amount type @@ -37,16 +37,16 @@ class Relative(QObject): return 0 def differential(self): - return self.compute() + return self.value() def localized(self, pretty_print=False): - value = self.compute() + value = self.value() if pretty_print: pass else: strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma']) return QCoreApplication.translate("Relative", Relative._REF_STR_).format(strvalue, - self.community.currency) + self.community.short_currency) def diff_localized(self, pretty_print=False): value = self.differential() @@ -55,4 +55,4 @@ class Relative(QObject): else: strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma']) return QCoreApplication.translate("Relative", Relative._REF_STR_).format(strvalue, - self.community.currency) + self.community.short_currency) diff --git a/src/cutecoin/core/money/relative_zerosum.py b/src/cutecoin/core/money/relative_zerosum.py index 7487ef54..b4148304 100644 --- a/src/cutecoin/core/money/relative_zerosum.py +++ b/src/cutecoin/core/money/relative_zerosum.py @@ -1,5 +1,5 @@ -from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP -from . import relative +from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale +from .relative import Relative class RelativeZSum: @@ -42,11 +42,22 @@ class RelativeZSum: return relative_value - relative_median def differential(self): - return relative.compute(self.amount, self.community) + return Relative(self.amount, self.community, self.app).value() def localized(self, pretty_print=False): - value = self.compute(self.amount, self.community) - return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(value, self.community) + value = self.value() + if pretty_print: + pass + else: + strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma']) + return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(strvalue, + self.community.short_currency) def diff_localized(self, pretty_print=False): - return relative.amount_to_str(self.amount, self.community, pretty_print) \ No newline at end of file + value = self.differential() + if pretty_print: + pass + else: + strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma']) + return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(strvalue, + self.community.short_currency) diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py index 77a12f9d..06fae7b6 100644 --- a/src/cutecoin/gui/wallets_tab.py +++ b/src/cutecoin/gui/wallets_tab.py @@ -147,18 +147,16 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): # set infos in label self.label_balance.setText( - self.tr("{:} {:}") + self.tr("{:}") .format( - localized_amount, - self.account.current_ref.units(self.community.currency) + localized_amount ) ) self.label_balance_range.setText( - self.tr("in [{:} ; {:}] {:}") + self.tr("in [{:} ; {:}]") .format( localized_minimum, - localized_maximum, - self.account.current_ref.units(self.community.currency) + localized_maximum ) ) -- GitLab