tmake fee_slider thread safe - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 6055d4b2fd145052247d55ff30f0c80168ebceff DIR parent 0a31acbdf222ab25adb48a7e2092e4204f426582 HTML Author: ThomasV <thomasv@electrum.org> Date: Mon, 9 Jan 2017 14:05:43 +0100 make fee_slider thread safe Diffstat: M gui/qt/fee_slider.py | 42 +++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) --- DIR diff --git a/gui/qt/fee_slider.py b/gui/qt/fee_slider.py t@@ -5,6 +5,8 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * import PyQt4.QtCore as QtCore +import threading + class FeeSlider(QSlider): def __init__(self, window, config, callback): t@@ -13,31 +15,43 @@ class FeeSlider(QSlider): self.fee_step = self.config.max_fee_rate() / 10 self.window = window self.callback = callback - self.setToolTip('') + self.dyn = False + self.lock = threading.RLock() self.update() self.valueChanged.connect(self.moved) def moved(self, pos): + with self.lock: + fee_rate = self.config.dynfee(pos) if self.dyn else pos * self.fee_step + tooltip = self.get_tooltip(pos, fee_rate) + QToolTip.showText(QCursor.pos(), tooltip, self) + self.setToolTip(tooltip) + self.callback(self.dyn, pos, fee_rate) + + def get_tooltip(self, pos, fee_rate): from electrum.util import fee_levels - dyn = self.config.is_dynfee() - fee_rate = self.config.dynfee(pos) if dyn else pos * self.fee_step rate_str = self.window.format_amount(fee_rate) + ' ' + self.window.base_unit() + '/kB' - if dyn: + if self.dyn: tooltip = fee_levels[pos] + '\n' + rate_str else: tooltip = rate_str if self.config.has_fee_estimates(): i = self.config.reverse_dynfee(fee_rate) tooltip += '\n' + (_('low fee') if i < 0 else 'Within %d blocks'%i) - QToolTip.showText(QCursor.pos(), tooltip, self) - self.callback(dyn, pos, fee_rate) + return tooltip def update(self): - if self.config.is_dynfee(): - self.setRange(0, 4) - self.setValue(self.config.get('fee_level', 2)) - else: - self.setRange(1, 10) - fee_rate = self.config.fee_per_kb() - pos = min(fee_rate / self.fee_step, 10) - self.setValue(pos) + with self.lock: + self.dyn = self.config.is_dynfee() + if self.dyn: + pos = self.config.get('fee_level', 2) + fee_rate = self.config.dynfee(pos) + self.setRange(0, 4) + self.setValue(pos) + else: + fee_rate = self.config.fee_per_kb() + pos = min(fee_rate / self.fee_step, 10) + self.setRange(1, 10) + self.setValue(pos) + tooltip = self.get_tooltip(pos, fee_rate) + self.setToolTip(tooltip)