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

109 lines
3.0 KiB
Python
Raw Normal View History

2016-01-22 01:50:24 -08:00
from kivy.app import App
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.lang import Builder
2016-01-25 03:25:09 -08:00
from electrum.bitcoin import RECOMMENDED_FEE
2016-01-22 01:50:24 -08:00
Builder.load_string('''
<FeeDialog@Popup>
id: popup
2016-01-25 03:25:09 -08:00
title: _('Transaction Fees')
2016-01-22 01:50:24 -08:00
size_hint: 0.8, 0.8
pos_hint: {'top':0.9}
BoxLayout:
orientation: 'vertical'
2016-01-25 03:25:09 -08:00
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)
2016-01-22 01:50:24 -08:00
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Label:
text: _('Dynamic fees')
CheckBox:
id: dynfees
2016-01-25 03:25:09 -08:00
on_active: root.on_checkbox(self.active)
Widget:
size_hint: 1, 1
2016-01-22 01:50:24 -08:00
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Button:
text: 'Cancel'
size_hint: 0.5, None
height: '48dp'
on_release: popup.dismiss()
Button:
text: 'OK'
size_hint: 0.5, None
height: '48dp'
on_release:
root.on_ok()
root.dismiss()
''')
class FeeDialog(Factory.Popup):
2016-01-25 03:25:09 -08:00
def __init__(self, app, config, callback):
2016-01-22 01:50:24 -08:00
Factory.Popup.__init__(self)
2016-01-25 03:25:09 -08:00
self.app = app
2016-01-22 01:50:24 -08:00
self.config = config
self.callback = callback
2016-01-25 03:25:09 -08:00
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'
2016-01-22 01:50:24 -08:00
def on_ok(self):
2016-01-25 03:25:09 -08:00
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)
2016-01-22 01:50:24 -08:00
self.callback()
2016-01-25 03:25:09 -08:00
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()