electrum-bitcoinprivate/gui/kivy/uix/dialogs/settings.py

237 lines
8.7 KiB
Python
Raw Normal View History

2015-12-16 02:53:37 -08:00
from kivy.app import App
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from electrum.util import base_units
from electrum.i18n import languages
from electrum_gui.kivy.i18n import _
2016-01-19 03:37:40 -08:00
from electrum.plugins import run_hook
2016-01-22 01:50:24 -08:00
from electrum.bitcoin import RECOMMENDED_FEE
2015-12-16 02:53:37 -08:00
from choice_dialog import ChoiceDialog
2015-12-16 02:53:37 -08:00
Builder.load_string('''
#:import partial functools.partial
#:import _ electrum_gui.kivy.i18n._
2015-12-18 01:53:50 -08:00
<SettingsItem@ButtonBehavior+BoxLayout>
orientation: 'vertical'
title: ''
description: ''
2016-01-21 03:12:55 -08:00
size_hint: 1, None
height: '60dp'
canvas.before:
Color:
rgba: (0.192, .498, 0.745, 1) if self.state == 'down' else (0.3, 0.3, 0.3, 0)
Rectangle:
size: self.size
pos: self.pos
on_release:
Clock.schedule_once(self.action)
Widget
TopLabel:
2015-12-18 01:53:50 -08:00
id: title
text: self.parent.title
bold: True
halign: 'left'
TopLabel:
2016-01-19 03:37:40 -08:00
text: self.parent.description
2015-12-18 01:53:50 -08:00
color: 0.8, 0.8, 0.8, 1
halign: 'left'
Widget
2015-12-18 01:53:50 -08:00
2015-12-16 02:53:37 -08:00
<SettingsDialog@Popup>
id: settings
2016-01-19 03:57:18 -08:00
title: _('Electrum Settings')
watching_only: False
use_encryption: False
2015-12-16 02:53:37 -08:00
BoxLayout:
orientation: 'vertical'
2016-01-21 03:12:55 -08:00
ScrollView:
GridLayout:
id: scrollviewlayout
cols:1
2016-01-21 03:12:55 -08:00
size_hint: 1, None
height: self.minimum_height
padding: '10dp'
2016-01-21 03:12:55 -08:00
SettingsItem:
lang: settings.get_language_name()
title: 'Language' + ': ' + str(self.lang)
description: _('Language')
action: partial(root.language_dialog, self)
CardSeparator
2016-01-21 03:12:55 -08:00
SettingsItem:
status: 'watching-only' if root.watching_only else ('ON' if root.use_encryption else 'OFF')
disabled: root.watching_only
2016-01-21 03:12:55 -08:00
title: _('PIN code') + ': ' + self.status
description: _("Change your PIN code.")
action: partial(root.change_password, self)
CardSeparator
2016-01-21 03:12:55 -08:00
SettingsItem:
bu: app.base_unit
title: _('Denomination') + ': ' + self.bu
description: _("Base unit for Bitcoin amounts.")
action: partial(root.unit_dialog, self)
CardSeparator
2016-01-22 01:50:24 -08:00
SettingsItem:
status: root.fee_status()
title: _('Fees') + ': ' + self.status
description: _("Fees paid to the Bitcoin miners.")
action: partial(root.fee_dialog, self)
CardSeparator
2016-01-21 03:12:55 -08:00
SettingsItem:
status: root.fx_status()
2016-01-21 03:12:55 -08:00
title: _('Fiat Currency') + ': ' + self.status
description: _("Display amounts in fiat currency.")
action: partial(root.fx_dialog, self)
CardSeparator
SettingsItem:
status: root.network_status()
title: _('Network') + ': ' + self.status
description: _("Network status and server selection.")
action: partial(root.network_dialog, self)
CardSeparator
2016-01-21 03:12:55 -08:00
SettingsItem:
status: 'ON' if bool(app.plugins.get('labels')) else 'OFF'
title: _('Labels Sync') + ': ' + self.status
2016-02-22 01:53:08 -08:00
description: _("Save and synchronize your labels.")
action: partial(root.plugin_dialog, 'labels', self)
CardSeparator
SettingsItem:
status: root.coinselect_status()
title: _('Coin selection') + ': ' + self.status
description: "Coin selection method"
action: partial(root.coinselect_dialog, self)
2015-12-16 02:53:37 -08:00
''')
2016-03-06 02:46:09 -08:00
2015-12-16 02:53:37 -08:00
class SettingsDialog(Factory.Popup):
def __init__(self, app):
self.app = app
2016-01-19 03:37:40 -08:00
self.plugins = self.app.plugins
self.config = self.app.electrum_config
2015-12-16 02:53:37 -08:00
Factory.Popup.__init__(self)
2016-01-21 03:12:55 -08:00
layout = self.ids.scrollviewlayout
layout.bind(minimum_height=layout.setter('height'))
2016-03-06 02:46:09 -08:00
# cached dialogs
self._fx_dialog = None
self._fee_dialog = None
self._network_dialog = None
self._language_dialog = None
self._unit_dialog = None
self._coinselect_dialog = None
2015-12-16 02:53:37 -08:00
def update(self):
self.wallet = self.app.wallet
self.watching_only = self.wallet.is_watching_only()
self.use_encryption = self.wallet.use_encryption
2015-12-16 02:53:37 -08:00
def get_language_name(self):
2016-01-19 03:37:40 -08:00
return languages.get(self.config.get('language', 'en_UK'), '')
2015-12-16 02:53:37 -08:00
2016-03-06 02:46:09 -08:00
def change_password(self, item, dt):
self.app.change_password(self.update)
def language_dialog(self, item, dt):
2016-03-06 02:46:09 -08:00
if self._language_dialog is None:
l = self.config.get('language', 'en_UK')
def cb(key):
self.config.set_key("language", key, True)
item.lang = self.get_language_name()
self.app.language = key
self._language_dialog = ChoiceDialog(_('Language'), languages, l, cb)
self._language_dialog.open()
2015-12-16 02:53:37 -08:00
def unit_dialog(self, item, dt):
2016-03-06 02:46:09 -08:00
if self._unit_dialog is None:
def cb(text):
self._set_bu(text)
item.bu = self.app.base_unit
self._unit_dialog = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb)
self._unit_dialog.open()
2015-12-16 02:53:37 -08:00
def coinselect_status(self):
return self.app.wallet.coin_chooser_name(self.app.electrum_config)
def coinselect_dialog(self, item, dt):
2016-03-06 02:46:09 -08:00
if self._coinselect_dialog is None:
from electrum import COIN_CHOOSERS
choosers = sorted(COIN_CHOOSERS.keys())
chooser_name = self.app.wallet.coin_chooser_name(self.config)
def cb(text):
self.config.set_key('coin_chooser', text)
item.status = text
self._coinselect_dialog = ChoiceDialog(_('Coin selection'), choosers, chooser_name, cb)
self._coinselect_dialog.open()
2016-02-22 02:49:37 -08:00
def network_dialog(self, item, dt):
2016-03-06 02:46:09 -08:00
if self._network_dialog is None:
server, port, protocol, proxy, auto_connect = self.app.network.get_parameters()
def cb(popup):
server = popup.ids.host.text
auto_connect = popup.ids.auto_connect.active
self.app.network.set_parameters(server, port, protocol, proxy, auto_connect)
item.status = self.network_status()
popup = Builder.load_file('gui/kivy/uix/ui_screens/network.kv')
popup.ids.host.text = server
popup.ids.auto_connect.active = auto_connect
popup.on_dismiss = lambda: cb(popup)
self._network_dialog = popup
self._network_dialog.open()
def network_status(self):
server, port, protocol, proxy, auto_connect = self.app.network.get_parameters()
return 'auto-connect' if auto_connect else server
def plugin_dialog(self, name, label, dt):
2016-01-19 03:37:40 -08:00
from checkbox_dialog import CheckBoxDialog
def callback(status):
2016-01-21 03:12:55 -08:00
self.plugins.enable(name) if status else self.plugins.disable(name)
2016-01-19 03:37:40 -08:00
label.status = 'ON' if status else 'OFF'
2016-01-22 01:50:24 -08:00
2016-01-21 03:12:55 -08:00
status = bool(self.plugins.get(name))
dd = self.plugins.descriptions.get(name)
descr = dd.get('description')
fullname = dd.get('fullname')
d = CheckBoxDialog(fullname, descr, status, callback)
2016-01-19 03:37:40 -08:00
d.open()
2016-01-22 01:50:24 -08:00
def fee_status(self):
if self.config.get('dynamic_fees'):
f = self.config.get('fee_factor', 50) + 50
return 'Dynamic, %d%%'%f
else:
F = self.config.get('fee_per_kb', RECOMMENDED_FEE)
2016-01-25 03:25:09 -08:00
return self.app.format_amount_and_units(F) + '/kB'
2016-01-22 01:50:24 -08:00
def fee_dialog(self, label, dt):
2016-03-06 02:46:09 -08:00
if self._fee_dialog is None:
from fee_dialog import FeeDialog
def cb():
label.status = self.fee_status()
self._fee_dialog = FeeDialog(self.app, self.config, cb)
self._fee_dialog.open()
def fx_status(self):
p = self.plugins.get('exchange_rate')
if p:
source = p.exchange.name()
ccy = p.get_currency()
return '%s [%s]' %(ccy, source)
else:
return 'Disabled'
def fx_dialog(self, label, dt):
2016-03-06 02:46:09 -08:00
if self._fx_dialog is None:
from fx_dialog import FxDialog
def cb():
label.status = self.fx_status()
self._fx_dialog = FxDialog(self.app, self.plugins, self.config, cb)
self._fx_dialog.open()