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
|
|
|
|
|
2018-03-17 04:42:38 -07:00
|
|
|
from electrum_zcash.util import base_units
|
|
|
|
from electrum_zcash.i18n import languages
|
|
|
|
from electrum_zcash_gui.kivy.i18n import _
|
|
|
|
from electrum_zcash.plugins import run_hook
|
|
|
|
from electrum_zcash import coinchooser
|
|
|
|
from electrum_zcash.util import fee_levels
|
2015-12-16 02:53:37 -08:00
|
|
|
|
2017-02-16 01:54:24 -08:00
|
|
|
from .choice_dialog import ChoiceDialog
|
2016-02-22 01:50:27 -08:00
|
|
|
|
2015-12-16 02:53:37 -08:00
|
|
|
Builder.load_string('''
|
2016-01-23 10:28:01 -08:00
|
|
|
#:import partial functools.partial
|
2018-03-17 04:42:38 -07:00
|
|
|
#:import _ electrum_zcash_gui.kivy.i18n._
|
2016-01-23 10:28:01 -08:00
|
|
|
|
2015-12-16 02:53:37 -08:00
|
|
|
<SettingsDialog@Popup>
|
|
|
|
id: settings
|
2018-03-17 04:42:38 -07:00
|
|
|
title: _('Electrum-Zcash Settings')
|
2016-03-10 07:43:15 -08:00
|
|
|
disable_pin: False
|
2016-03-06 03:57:21 -08:00
|
|
|
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
|
2016-03-06 00:50:45 -08:00
|
|
|
cols:1
|
2016-01-21 03:12:55 -08:00
|
|
|
size_hint: 1, None
|
2016-03-06 00:50:45 -08:00
|
|
|
height: self.minimum_height
|
|
|
|
padding: '10dp'
|
2016-01-21 03:12:55 -08:00
|
|
|
SettingsItem:
|
|
|
|
lang: settings.get_language_name()
|
2016-02-04 01:49:51 -08:00
|
|
|
title: 'Language' + ': ' + str(self.lang)
|
|
|
|
description: _('Language')
|
2016-01-23 10:28:01 -08:00
|
|
|
action: partial(root.language_dialog, self)
|
2016-03-06 00:50:45 -08:00
|
|
|
CardSeparator
|
2016-01-21 03:12:55 -08:00
|
|
|
SettingsItem:
|
2016-03-10 07:43:15 -08:00
|
|
|
status: '' if root.disable_pin else ('ON' if root.use_encryption else 'OFF')
|
|
|
|
disabled: root.disable_pin
|
2016-01-21 03:12:55 -08:00
|
|
|
title: _('PIN code') + ': ' + self.status
|
|
|
|
description: _("Change your PIN code.")
|
2016-01-23 10:28:01 -08:00
|
|
|
action: partial(root.change_password, self)
|
2016-03-06 00:50:45 -08:00
|
|
|
CardSeparator
|
2016-01-21 03:12:55 -08:00
|
|
|
SettingsItem:
|
|
|
|
bu: app.base_unit
|
|
|
|
title: _('Denomination') + ': ' + self.bu
|
2018-03-17 04:42:38 -07:00
|
|
|
description: _("Base unit for Zcash amounts.")
|
2016-01-23 10:28:01 -08:00
|
|
|
action: partial(root.unit_dialog, self)
|
2016-03-06 00:50:45 -08:00
|
|
|
CardSeparator
|
2016-01-22 01:50:24 -08:00
|
|
|
SettingsItem:
|
|
|
|
status: root.fee_status()
|
|
|
|
title: _('Fees') + ': ' + self.status
|
2018-03-17 04:42:38 -07:00
|
|
|
description: _("Fees paid to the Zcash miners.")
|
2016-01-23 10:28:01 -08:00
|
|
|
action: partial(root.fee_dialog, self)
|
2016-03-06 00:50:45 -08:00
|
|
|
CardSeparator
|
2016-01-21 03:12:55 -08:00
|
|
|
SettingsItem:
|
2016-01-23 00:54:26 -08:00
|
|
|
status: root.fx_status()
|
2016-01-21 03:12:55 -08:00
|
|
|
title: _('Fiat Currency') + ': ' + self.status
|
2016-01-23 00:54:26 -08:00
|
|
|
description: _("Display amounts in fiat currency.")
|
2016-01-23 10:28:01 -08:00
|
|
|
action: partial(root.fx_dialog, self)
|
2016-03-06 00:50:45 -08:00
|
|
|
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.")
|
2016-01-23 10:28:01 -08:00
|
|
|
action: partial(root.plugin_dialog, 'labels', self)
|
2016-03-06 00:50:45 -08:00
|
|
|
CardSeparator
|
2017-07-10 04:51:13 -07:00
|
|
|
SettingsItem:
|
|
|
|
status: _('Yes') if app.use_unconfirmed else _('No')
|
|
|
|
title: _('Spend unconfirmed') + ': ' + self.status
|
|
|
|
description: _("Use unconfirmed coins in transactions.")
|
|
|
|
message: _('Spend unconfirmed coins')
|
|
|
|
action: partial(root.boolean_dialog, 'use_unconfirmed', _('Use unconfirmed'), self.message)
|
|
|
|
CardSeparator
|
|
|
|
SettingsItem:
|
|
|
|
status: _('Yes') if app.use_change else _('No')
|
|
|
|
title: _('Use change addresses') + ': ' + self.status
|
|
|
|
description: _("Send your change to separate addresses.")
|
|
|
|
message: _('Send excess coins to change addresses')
|
|
|
|
action: partial(root.boolean_dialog, 'use_change', _('Use change addresses'), self.message)
|
2016-06-09 20:49:22 -07:00
|
|
|
CardSeparator
|
2016-02-22 01:50:27 -08:00
|
|
|
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
|
2017-03-27 09:59:48 -07:00
|
|
|
self._proxy_dialog = None
|
2016-03-06 02:46:09 -08:00
|
|
|
self._language_dialog = None
|
|
|
|
self._unit_dialog = None
|
|
|
|
self._coinselect_dialog = None
|
2015-12-16 02:53:37 -08:00
|
|
|
|
2016-03-06 03:57:21 -08:00
|
|
|
def update(self):
|
|
|
|
self.wallet = self.app.wallet
|
2016-03-10 07:43:15 -08:00
|
|
|
self.disable_pin = self.wallet.is_watching_only() if self.wallet else True
|
2016-08-19 04:10:39 -07:00
|
|
|
self.use_encryption = self.wallet.has_password() if self.wallet else False
|
2016-03-06 03:57:21 -08:00
|
|
|
|
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):
|
2016-03-06 03:57:21 -08:00
|
|
|
self.app.change_password(self.update)
|
2016-01-23 10:28:01 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-01-23 10:28:01 -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):
|
2016-03-06 05:49:50 -08:00
|
|
|
self.app._set_bu(text)
|
2016-03-06 02:46:09 -08:00
|
|
|
item.bu = self.app.base_unit
|
2017-11-04 07:50:49 -07:00
|
|
|
self._unit_dialog = ChoiceDialog(_('Denomination'), list(base_units.keys()), self.app.base_unit, cb)
|
2016-03-06 02:46:09 -08:00
|
|
|
self._unit_dialog.open()
|
2015-12-16 02:53:37 -08:00
|
|
|
|
2016-02-22 01:50:27 -08:00
|
|
|
def coinselect_status(self):
|
2016-03-10 07:37:45 -08:00
|
|
|
return coinchooser.get_name(self.app.electrum_config)
|
2016-02-22 01:50:27 -08:00
|
|
|
|
|
|
|
def coinselect_dialog(self, item, dt):
|
2016-03-06 02:46:09 -08:00
|
|
|
if self._coinselect_dialog is None:
|
2016-03-10 07:37:45 -08:00
|
|
|
choosers = sorted(coinchooser.COIN_CHOOSERS.keys())
|
|
|
|
chooser_name = coinchooser.get_name(self.config)
|
2016-03-06 02:46:09 -08:00
|
|
|
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 01:50:27 -08:00
|
|
|
|
2017-03-27 09:59:48 -07:00
|
|
|
def proxy_status(self):
|
|
|
|
server, port, protocol, proxy, auto_connect = self.app.network.get_parameters()
|
|
|
|
return proxy.get('host') +':' + proxy.get('port') if proxy else _('None')
|
|
|
|
|
|
|
|
def proxy_dialog(self, item, dt):
|
|
|
|
if self._proxy_dialog is None:
|
|
|
|
server, port, protocol, proxy, auto_connect = self.app.network.get_parameters()
|
|
|
|
def callback(popup):
|
|
|
|
if popup.ids.mode.text != 'None':
|
|
|
|
proxy = {
|
|
|
|
'mode':popup.ids.mode.text,
|
|
|
|
'host':popup.ids.host.text,
|
|
|
|
'port':popup.ids.port.text,
|
|
|
|
'user':popup.ids.user.text,
|
|
|
|
'password':popup.ids.password.text
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
proxy = None
|
|
|
|
self.app.network.set_parameters(server, port, protocol, proxy, auto_connect)
|
|
|
|
item.status = self.proxy_status()
|
|
|
|
popup = Builder.load_file('gui/kivy/uix/ui_screens/proxy.kv')
|
|
|
|
popup.ids.mode.text = proxy.get('mode') if proxy else 'None'
|
|
|
|
popup.ids.host.text = proxy.get('host') if proxy else ''
|
|
|
|
popup.ids.port.text = proxy.get('port') if proxy else ''
|
|
|
|
popup.ids.user.text = proxy.get('user') if proxy else ''
|
|
|
|
popup.ids.password.text = proxy.get('password') if proxy else ''
|
|
|
|
popup.on_dismiss = lambda: callback(popup)
|
|
|
|
self._proxy_dialog = popup
|
|
|
|
self._proxy_dialog.open()
|
|
|
|
|
2016-01-23 10:28:01 -08:00
|
|
|
def plugin_dialog(self, name, label, dt):
|
2017-10-21 02:00:56 -07:00
|
|
|
from .checkbox_dialog import CheckBoxDialog
|
2016-01-19 03:37:40 -08:00
|
|
|
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-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):
|
2016-06-09 20:49:22 -07:00
|
|
|
if self.config.get('dynamic_fees', True):
|
2016-05-26 00:23:42 -07:00
|
|
|
return fee_levels[self.config.get('fee_level', 2)]
|
2016-01-22 01:50:24 -08:00
|
|
|
else:
|
2017-01-22 02:22:16 -08:00
|
|
|
return self.app.format_amount_and_units(self.config.fee_per_kb()) + '/kB'
|
2016-01-22 01:50:24 -08:00
|
|
|
|
2016-01-23 10:28:01 -08:00
|
|
|
def fee_dialog(self, label, dt):
|
2016-03-06 02:46:09 -08:00
|
|
|
if self._fee_dialog is None:
|
2017-10-21 02:00:56 -07:00
|
|
|
from .fee_dialog import FeeDialog
|
2016-03-06 02:46:09 -08:00
|
|
|
def cb():
|
|
|
|
label.status = self.fee_status()
|
|
|
|
self._fee_dialog = FeeDialog(self.app, self.config, cb)
|
|
|
|
self._fee_dialog.open()
|
2016-01-23 00:54:26 -08:00
|
|
|
|
2017-07-10 04:51:13 -07:00
|
|
|
def boolean_dialog(self, name, title, message, dt):
|
2017-10-21 02:00:56 -07:00
|
|
|
from .checkbox_dialog import CheckBoxDialog
|
2017-07-10 04:51:13 -07:00
|
|
|
CheckBoxDialog(title, message, getattr(self.app, name), lambda x: setattr(self.app, name, x)).open()
|
2016-06-09 20:49:22 -07:00
|
|
|
|
2016-01-23 00:54:26 -08:00
|
|
|
def fx_status(self):
|
2017-01-03 00:02:26 -08:00
|
|
|
fx = self.app.fx
|
|
|
|
if fx.is_enabled():
|
|
|
|
source = fx.exchange.name()
|
|
|
|
ccy = fx.get_currency()
|
2016-01-23 00:54:26 -08:00
|
|
|
return '%s [%s]' %(ccy, source)
|
|
|
|
else:
|
2017-01-24 01:45:49 -08:00
|
|
|
return _('None')
|
2016-01-23 00:54:26 -08:00
|
|
|
|
2016-01-23 10:28:01 -08:00
|
|
|
def fx_dialog(self, label, dt):
|
2016-03-06 02:46:09 -08:00
|
|
|
if self._fx_dialog is None:
|
2017-10-21 02:00:56 -07:00
|
|
|
from .fx_dialog import FxDialog
|
2016-03-06 02:46:09 -08:00
|
|
|
def cb():
|
|
|
|
label.status = self.fx_status()
|
|
|
|
self._fx_dialog = FxDialog(self.app, self.plugins, self.config, cb)
|
|
|
|
self._fx_dialog.open()
|