Browse Source

kivy: base_unit setting

283
ThomasV 10 years ago
parent
commit
069a6455c7
  1. 66
      gui/kivy/main_window.py
  2. 14
      gui/kivy/uix/screens.py
  3. 12
      gui/kivy/uix/ui_screens/history.kv
  4. 3
      gui/kivy/uix/ui_screens/settings.kv

66
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): class ElectrumWindow(App):
def _get_bu(self): def _get_bu(self):
assert self.decimal_point in (5,8) return self.electrum_config.get('base_unit', 'mBTC')
return "BTC" if self.decimal_point == 8 else "mBTC"
def _set_bu(self, value): def _set_bu(self, value):
try: assert value in base_units.keys()
self.electrum_config.set_key('base_unit', value, True) self.electrum_config.set_key('base_unit', value, True)
except AttributeError: self.update_status()
Logger.error('Electrum: Config not set ' if self.history_screen:
'While trying to save value to config') self.history_screen.update()
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`.
:attr:`decimal_point` is a `AliasProperty` defaults to the value gotten base_unit = AliasProperty(_get_bu, _set_bu)
from electrum config.
'''
electrum_config = ObjectProperty(None) electrum_config = ObjectProperty(None)
'''Holds the electrum config
:attr:`electrum_config` is a `ObjectProperty`, defaults to None.
'''
status = StringProperty(_('Not Connected')) status = StringProperty(_('Not Connected'))
def decimal_point(self):
return base_units[self.base_unit]
def _get_num_zeros(self): def _get_num_zeros(self):
try: try:
@ -129,7 +95,7 @@ class ElectrumWindow(App):
x = Decimal(str(amount_str)) x = Decimal(str(amount_str))
except: except:
return None return None
p = pow(10, self.decimal_point) p = pow(10, self.decimal_point())
return int(p * x) 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 @profiler
def load_wallet(self, wallet): def load_wallet(self, wallet):
self.wallet = wallet self.wallet = wallet
@ -477,7 +437,7 @@ class ElectrumWindow(App):
def format_amount(self, x, is_diff=False, whitespaces=False): def format_amount(self, x, is_diff=False, whitespaces=False):
from electrum.util import format_satoshis from electrum.util import format_satoshis
return format_satoshis(x, is_diff, self.num_zeros, return format_satoshis(x, is_diff, self.num_zeros,
self.decimal_point, whitespaces) self.decimal_point(), whitespaces)
@profiler @profiler
def update_wallet(self, *dt): def update_wallet(self, *dt):

14
gui/kivy/uix/screens.py

@ -113,13 +113,6 @@ class HistoryScreen(CScreen):
else: else:
icon = "atlas://gui/kivy/theming/light/confirmed" 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: if tx_hash:
label, is_default_label = self.app.wallet.get_label(tx_hash) label, is_default_label = self.app.wallet.get_label(tx_hash)
else: else:
@ -130,7 +123,7 @@ class HistoryScreen(CScreen):
rate = self.get_history_rate(value, timestamp) rate = self.get_history_rate(value, timestamp)
quote_text = "..." if rate is None else "{0:.3} {1}".format(rate, quote_currency) 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): def update(self, see_all=False):
if self.app.wallet is None: if self.app.wallet is None:
@ -148,14 +141,13 @@ class HistoryScreen(CScreen):
count = 0 count = 0
for item in history: for item in history:
count += 1 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 = RecentActivityItem()
ri.icon = icon ri.icon = icon
ri.date = date_time ri.date = date_time
ri.address = address ri.address = address
ri.amount = amount ri.value = value
ri.quote_text = quote_text ri.quote_text = quote_text
ri.balance = balance
ri.confirmations = conf ri.confirmations = conf
ri.tx_hash = tx ri.tx_hash = tx
history_add(ri) history_add(ri)

12
gui/kivy/uix/ui_screens/history.kv

@ -54,9 +54,9 @@
<RecentActivityItem@CardItem> <RecentActivityItem@CardItem>
icon: 'atlas://gui/kivy/theming/light/important' icon: 'atlas://gui/kivy/theming/light/important'
address:'no address set' address:'no address set'
amount: '+0.00' value: 0
balance: 'xyz'# balance_after amount: app.format_amount(self.value, True) if self.value is not None else '--'
amount_color: '#DB3627' if float(self.amount) < 0 else '#2EA442' amount_color: '#DB3627' if self.value < 0 else '#2EA442'
confirmations: 0 confirmations: 0
date: '0/0/0' date: '0/0/0'
quote_text: '.' quote_text: '.'
@ -91,15 +91,15 @@
halign: 'right' halign: 'right'
font_size: '13sp' font_size: '13sp'
size_hint: None, 1 size_hint: None, 1
width: '90sp' width: '110sp'
markup: True markup: True
font_name: font_light font_name: font_light
text: 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=#B2B3B3][size=12sp]{qt}[/size]'\
u'[/color]'.format(amount_color=root.amount_color,\ u'[/color]'.format(amount_color=root.amount_color,\
amount=root.amount[1:], qt=root.quote_text, sign=root.amount[0],\ 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 CardSeparator
<CardRecentActivity@Card> <CardRecentActivity@Card>

3
gui/kivy/uix/ui_screens/settings.kv

@ -14,10 +14,11 @@ Popup:
height: '48dp' height: '48dp'
size_hint: 1, None size_hint: 1, None
Spinner: Spinner:
text: 'BTC' text: app.base_unit
values: ('BTC', 'mBTC') values: ('BTC', 'mBTC')
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
on_text: app.base_unit = self.text
Label: Label:
size_hint: 1, None size_hint: 1, None

Loading…
Cancel
Save