electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 069a6455c7ba909bdf216bdcb29c8ec5ff9d2fbe
parent d70948f74f1e48ce37cded68a292444516ec2481
Author: ThomasV <thomasv@electrum.org>
Date:   Thu, 15 Oct 2015 11:18:10 +0200

kivy: base_unit setting

Diffstat:
Mgui/kivy/main_window.py | 66+++++++++++++-----------------------------------------------------
Mgui/kivy/uix/screens.py | 14+++-----------
Mgui/kivy/uix/ui_screens/history.kv | 12++++++------
Mgui/kivy/uix/ui_screens/settings.kv | 3++-
4 files changed, 24 insertions(+), 71 deletions(-)

diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py @@ -48,62 +48,28 @@ Factory.register('TabbedCarousel', module='electrum_gui.kivy.uix.screens') +base_units = {'BTC':8, 'mBTC':5, 'uBTC':2} + class ElectrumWindow(App): def _get_bu(self): - assert self.decimal_point in (5,8) - return "BTC" if self.decimal_point == 8 else "mBTC" + return self.electrum_config.get('base_unit', 'mBTC') def _set_bu(self, value): - try: - self.electrum_config.set_key('base_unit', value, True) - except AttributeError: - Logger.error('Electrum: Config not set ' - 'While trying to save value to config') - - base_unit = AliasProperty(_get_bu, _set_bu, bind=('decimal_point',)) - '''BTC or UBTC or mBTC... - - :attr:`base_unit` is a `AliasProperty` defaults to the unit set in - electrum config. - ''' - - currencies = ListProperty(['EUR', 'GBP', 'USD']) - '''List of currencies supported by the current exchanger plugin. - - :attr:`currencies` is a `ListProperty` default to ['Eur', 'GBP'. 'USD']. - ''' - - def _get_decimal(self): - try: - return self.electrum_config.get('decimal_point', 8) - except AttributeError: - return 8 - - def _set_decimal(self, value): - try: - self.electrum_config.set_key('decimal_point', value, True) - except AttributeError: - Logger.error('Electrum: Config not set ' - 'While trying to save value to config') - - decimal_point = AliasProperty(_get_decimal, _set_decimal) - '''This defines the decimal point to be used determining the - :attr:`decimal_point`. + assert value in base_units.keys() + self.electrum_config.set_key('base_unit', value, True) + self.update_status() + if self.history_screen: + self.history_screen.update() - :attr:`decimal_point` is a `AliasProperty` defaults to the value gotten - from electrum config. - ''' + base_unit = AliasProperty(_get_bu, _set_bu) electrum_config = ObjectProperty(None) - '''Holds the electrum config - - :attr:`electrum_config` is a `ObjectProperty`, defaults to None. - ''' status = StringProperty(_('Not Connected')) - + def decimal_point(self): + return base_units[self.base_unit] def _get_num_zeros(self): try: @@ -129,7 +95,7 @@ class ElectrumWindow(App): x = Decimal(str(amount_str)) except: return None - p = pow(10, self.decimal_point) + p = pow(10, self.decimal_point()) return int(p * x) @@ -416,12 +382,6 @@ class ElectrumWindow(App): - def set_currencies(self, quote_currencies): - self.currencies = sorted(quote_currencies.keys()) - self._trigger_update_status() - - - @profiler def load_wallet(self, wallet): self.wallet = wallet @@ -477,7 +437,7 @@ class ElectrumWindow(App): def format_amount(self, x, is_diff=False, whitespaces=False): from electrum.util import format_satoshis return format_satoshis(x, is_diff, self.num_zeros, - self.decimal_point, whitespaces) + self.decimal_point(), whitespaces) @profiler def update_wallet(self, *dt): diff --git a/gui/kivy/uix/screens.py b/gui/kivy/uix/screens.py @@ -113,13 +113,6 @@ class HistoryScreen(CScreen): else: icon = "atlas://gui/kivy/theming/light/confirmed" - if value is not None: - v_str = self.app.format_amount(value, True).replace(',','.') - else: - v_str = '--' - - balance_str = self.app.format_amount(balance).replace(',','.') - if tx_hash: label, is_default_label = self.app.wallet.get_label(tx_hash) else: @@ -130,7 +123,7 @@ class HistoryScreen(CScreen): rate = self.get_history_rate(value, timestamp) quote_text = "..." if rate is None else "{0:.3} {1}".format(rate, quote_currency) - yield (conf, icon, time_str, label, v_str, balance_str, tx_hash, quote_text) + yield (conf, icon, time_str, label, value, tx_hash, quote_text) def update(self, see_all=False): if self.app.wallet is None: @@ -148,14 +141,13 @@ class HistoryScreen(CScreen): count = 0 for item in history: count += 1 - conf, icon, date_time, address, amount, balance, tx, quote_text = item + conf, icon, date_time, address, value, tx, quote_text = item ri = RecentActivityItem() ri.icon = icon ri.date = date_time ri.address = address - ri.amount = amount + ri.value = value ri.quote_text = quote_text - ri.balance = balance ri.confirmations = conf ri.tx_hash = tx history_add(ri) diff --git a/gui/kivy/uix/ui_screens/history.kv b/gui/kivy/uix/ui_screens/history.kv @@ -54,9 +54,9 @@ <RecentActivityItem@CardItem> icon: 'atlas://gui/kivy/theming/light/important' address:'no address set' - amount: '+0.00' - balance: 'xyz'# balance_after - amount_color: '#DB3627' if float(self.amount) < 0 else '#2EA442' + value: 0 + amount: app.format_amount(self.value, True) if self.value is not None else '--' + amount_color: '#DB3627' if self.value < 0 else '#2EA442' confirmations: 0 date: '0/0/0' quote_text: '.' @@ -91,15 +91,15 @@ halign: 'right' font_size: '13sp' size_hint: None, 1 - width: '90sp' + width: '110sp' markup: True font_name: font_light text: - u'[color={amount_color}]{sign}{symbol}{amount}[/color]\n'\ + u'[color={amount_color}]{sign}{amount} {unit}[/color]\n'\ u'[color=#B2B3B3][size=12sp]{qt}[/size]'\ u'[/color]'.format(amount_color=root.amount_color,\ amount=root.amount[1:], qt=root.quote_text, sign=root.amount[0],\ - symbol=btc_symbol if app.base_unit == 'BTC' else mbtc_symbol) + unit=app.base_unit) CardSeparator <CardRecentActivity@Card> diff --git a/gui/kivy/uix/ui_screens/settings.kv b/gui/kivy/uix/ui_screens/settings.kv @@ -14,10 +14,11 @@ Popup: height: '48dp' size_hint: 1, None Spinner: - text: 'BTC' + text: app.base_unit values: ('BTC', 'mBTC') size_hint: 1, None height: '48dp' + on_text: app.base_unit = self.text Label: size_hint: 1, None