tkivy: simplify fee dialog - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 2e594d2d7a9731f5db1979fa855282dc9e46b186 DIR parent 721dc8cdb9147c3dcbb6b9e7d3034cbe51b77ea8 HTML Author: ThomasV <thomasv@electrum.org> Date: Sat, 3 Mar 2018 14:58:55 +0100 kivy: simplify fee dialog Diffstat: M gui/kivy/uix/dialogs/fee_dialog.py | 74 ++++++++++++++----------------- 1 file changed, 33 insertions(+), 41 deletions(-) --- DIR diff --git a/gui/kivy/uix/dialogs/fee_dialog.py b/gui/kivy/uix/dialogs/fee_dialog.py t@@ -11,13 +11,26 @@ Builder.load_string(''' title: _('Transaction Fees') size_hint: 0.8, 0.8 pos_hint: {'top':0.9} + method: 0 BoxLayout: orientation: 'vertical' BoxLayout: orientation: 'horizontal' size_hint: 1, 0.5 Label: - text: (_('Target') if dynfees.active else _('Fixed rate')) + ':' + text: _('Method') + ':' + Button: + text: _('Mempool based') if root.method == 2 else _('ETA based') if root.method == 1 else _('Static') + background_color: (0,0,0,0) + on_release: + root.method = (root.method + 1) % 3 + root.update_slider() + root.update_text() + BoxLayout: + orientation: 'horizontal' + size_hint: 1, 0.5 + Label: + text: _('Target') + ':' Label: id: fee_target text: '' t@@ -25,7 +38,7 @@ Builder.load_string(''' orientation: 'horizontal' size_hint: 1, 0.5 Label: - text: (_('Current rate') if dynfees.active else _('Estimate')) + ':' + text: (_('Current rate') if root.method > 0 else _('Estimate')) + ':' Label: id: fee_estimate text: '' t@@ -34,22 +47,6 @@ Builder.load_string(''' range: 0, 4 step: 1 on_value: root.on_slider(self.value) - BoxLayout: - orientation: 'horizontal' - size_hint: 1, 0.5 - Label: - text: _('Dynamic Fees') - CheckBox: - id: dynfees - on_active: root.on_dynfees(self.active) - BoxLayout: - orientation: 'horizontal' - size_hint: 1, 0.5 - Label: - text: _('Use mempool') - CheckBox: - id: mempool - on_active: root.on_mempool(self.active) Widget: size_hint: 1, 1 BoxLayout: t@@ -77,10 +74,9 @@ class FeeDialog(Factory.Popup): self.config = config self.fee_rate = self.config.fee_per_kb() self.callback = callback - self.mempool = self.config.use_mempool_fees() - self.dynfees = self.config.is_dynfee() - self.ids.mempool.active = self.mempool - self.ids.dynfees.active = self.dynfees + mempool = self.config.use_mempool_fees() + dynfees = self.config.is_dynfee() + self.method = (2 if mempool else 1) if dynfees else 0 self.update_slider() self.update_text() t@@ -90,28 +86,34 @@ class FeeDialog(Factory.Popup): self.ids.fee_target.text = target self.ids.fee_estimate.text = estimate + def get_method(self): + dynfees = self.method > 0 + mempool = self.method == 2 + return dynfees, mempool + def update_slider(self): slider = self.ids.slider - maxp, pos, fee_rate = self.config.get_fee_slider(self.dynfees, self.mempool) + dynfees, mempool = self.get_method() + maxp, pos, fee_rate = self.config.get_fee_slider(dynfees, mempool) slider.range = (0, maxp) slider.step = 1 slider.value = pos def get_fee_text(self, pos): - dyn = self.dynfees - mempool = self.mempool - if dyn: + dynfees, mempool = self.get_method() + if dynfees: fee_rate = self.config.depth_to_fee(pos) if mempool else self.config.eta_to_fee(pos) else: fee_rate = self.config.static_fee(pos) - return self.config.get_fee_text(pos, dyn, mempool, fee_rate) + return self.config.get_fee_text(pos, dynfees, mempool, fee_rate) def on_ok(self): value = int(self.ids.slider.value) - self.config.set_key('dynamic_fees', self.dynfees, False) - self.config.set_key('mempool_fees', self.mempool, False) - if self.dynfees: - if self.mempool: + dynfees, mempool = self.get_method() + self.config.set_key('dynamic_fees', dynfees, False) + self.config.set_key('mempool_fees', mempool, False) + if dynfees: + if mempool: self.config.set_key('depth_level', value, True) else: self.config.set_key('fee_level', value, True) t@@ -121,13 +123,3 @@ class FeeDialog(Factory.Popup): def on_slider(self, value): self.update_text() - - def on_dynfees(self, b): - self.dynfees = b - self.update_slider() - self.update_text() - - def on_mempool(self, b): - self.mempool = b - self.update_slider() - self.update_text()