kivy: fee_dialog
This commit is contained in:
parent
c0295c767e
commit
fa7fba53fc
|
@ -3,14 +3,27 @@ from kivy.factory import Factory
|
|||
from kivy.properties import ObjectProperty
|
||||
from kivy.lang import Builder
|
||||
|
||||
from electrum.bitcoin import RECOMMENDED_FEE
|
||||
|
||||
Builder.load_string('''
|
||||
<FeeDialog@Popup>
|
||||
id: popup
|
||||
title: ''
|
||||
title: _('Transaction Fees')
|
||||
size_hint: 0.8, 0.8
|
||||
pos_hint: {'top':0.9}
|
||||
BoxLayout:
|
||||
orientation: 'vertical'
|
||||
BoxLayout:
|
||||
orientation: 'horizontal'
|
||||
size_hint: 1, 0.5
|
||||
Label:
|
||||
id: fee_per_kb
|
||||
text: ''
|
||||
Slider:
|
||||
id: slider
|
||||
range: 0, 100
|
||||
on_value: root.on_slider(self.value)
|
||||
|
||||
BoxLayout:
|
||||
orientation: 'horizontal'
|
||||
size_hint: 1, 0.5
|
||||
|
@ -18,6 +31,10 @@ Builder.load_string('''
|
|||
text: _('Dynamic fees')
|
||||
CheckBox:
|
||||
id: dynfees
|
||||
on_active: root.on_checkbox(self.active)
|
||||
Widget:
|
||||
size_hint: 1, 1
|
||||
|
||||
BoxLayout:
|
||||
orientation: 'horizontal'
|
||||
size_hint: 1, 0.5
|
||||
|
@ -37,12 +54,55 @@ Builder.load_string('''
|
|||
|
||||
class FeeDialog(Factory.Popup):
|
||||
|
||||
def __init__(self, config, callback):
|
||||
def __init__(self, app, config, callback):
|
||||
Factory.Popup.__init__(self)
|
||||
self.app = app
|
||||
self.config = config
|
||||
self.callback = callback
|
||||
self.ids.dynfees.active = bool(self.config.get('dynamic_fees'))
|
||||
|
||||
self.dynfees = self.config.get('dynamic_fees', False)
|
||||
self.fee_factor = self.config.get('fee_factor', 50)
|
||||
self.static_fee = self.config.get('fee_per_kb', RECOMMENDED_FEE)
|
||||
|
||||
self.ids.dynfees.active = self.dynfees
|
||||
self.update_slider()
|
||||
self.update_text()
|
||||
|
||||
|
||||
def update_text(self):
|
||||
self.ids.fee_per_kb.text = self.get_fee_text()
|
||||
|
||||
def update_slider(self):
|
||||
slider = self.ids.slider
|
||||
if self.dynfees:
|
||||
slider.value = self.fee_factor
|
||||
slider.range = (0, 100)
|
||||
else:
|
||||
slider.value = self.static_fee
|
||||
slider.range = (0, 2*RECOMMENDED_FEE)
|
||||
|
||||
def get_fee_text(self):
|
||||
if self.ids.dynfees.active:
|
||||
return 'Recommendation x %d%%'%(self.fee_factor + 50)
|
||||
else:
|
||||
return self.app.format_amount_and_units(self.static_fee) + '/kB'
|
||||
|
||||
def on_ok(self):
|
||||
self.config.set_key('dynamic_fees', self.ids.dynfees.active, True)
|
||||
self.config.set_key('dynamic_fees', self.dynfees, False)
|
||||
if self.dynfees:
|
||||
self.config.set_key('fee_factor', self.fee_factor, True)
|
||||
else:
|
||||
self.config.set_key('fee_per_kb', self.static_fee, True)
|
||||
self.callback()
|
||||
|
||||
def on_slider(self, value):
|
||||
if self.dynfees:
|
||||
self.fee_factor = int(value)
|
||||
else:
|
||||
self.static_fee = int(value)
|
||||
self.update_text()
|
||||
|
||||
def on_checkbox(self, b):
|
||||
self.dynfees = b
|
||||
self.update_slider()
|
||||
self.update_text()
|
||||
|
|
|
@ -162,13 +162,13 @@ class SettingsDialog(Factory.Popup):
|
|||
return 'Dynamic, %d%%'%f
|
||||
else:
|
||||
F = self.config.get('fee_per_kb', RECOMMENDED_FEE)
|
||||
return self.app.format_amount(F) + ' ' + self.app.base_unit + '/kB'
|
||||
return self.app.format_amount_and_units(F) + '/kB'
|
||||
|
||||
def fee_dialog(self, label, dt):
|
||||
from fee_dialog import FeeDialog
|
||||
def cb():
|
||||
label.status = self.fee_status()
|
||||
d = FeeDialog(self.config, cb)
|
||||
d = FeeDialog(self.app, self.config, cb)
|
||||
d.open()
|
||||
|
||||
def fx_status(self):
|
||||
|
|
Loading…
Reference in New Issue