plugins settings widget
This commit is contained in:
parent
f5b54391d7
commit
87a8bfda47
|
@ -2083,19 +2083,27 @@ class ElectrumWindow(QMainWindow):
|
|||
grid.setColumnStretch(0,1)
|
||||
w.setLayout(grid)
|
||||
|
||||
def mk_toggle(cb, p):
|
||||
return lambda: cb.setChecked(p.toggle())
|
||||
def do_toggle(cb, p, w):
|
||||
r = p.toggle()
|
||||
cb.setChecked(r)
|
||||
if w: w.setEnabled(r)
|
||||
|
||||
def mk_toggle(cb, p, w):
|
||||
return lambda: do_toggle(cb,p,w)
|
||||
|
||||
for i, p in enumerate(plugins):
|
||||
try:
|
||||
cb = QCheckBox(p.fullname())
|
||||
cb.setDisabled(not p.is_available())
|
||||
cb.setChecked(p.is_enabled())
|
||||
cb.clicked.connect(mk_toggle(cb,p))
|
||||
grid.addWidget(cb, i, 0)
|
||||
if p.requires_settings():
|
||||
b = EnterButton(_('Settings'), p.settings_dialog)
|
||||
b.setEnabled( p.is_enabled() )
|
||||
grid.addWidget(b, i, 1)
|
||||
w = p.settings_widget(self)
|
||||
w.setEnabled( p.is_enabled() )
|
||||
grid.addWidget(w, i, 1)
|
||||
else:
|
||||
w = None
|
||||
cb.clicked.connect(mk_toggle(cb,p,w))
|
||||
grid.addWidget(HelpButton(p.description()), i, 2)
|
||||
except:
|
||||
print_msg(_("Error: cannot display plugin"), p)
|
||||
|
|
|
@ -49,10 +49,11 @@ class Exchanger(threading.Thread):
|
|||
quote_currencies[r] = self._lookup_rate(response, r)
|
||||
with self.lock:
|
||||
self.quote_currencies = quote_currencies
|
||||
self.parent.emit(SIGNAL("refresh_balance()"))
|
||||
self.parent.set_currencies(quote_currencies)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
def get_currencies(self):
|
||||
return [] if self.quote_currencies == None else sorted(self.quote_currencies.keys())
|
||||
|
||||
|
@ -68,20 +69,28 @@ class Plugin(BasePlugin):
|
|||
def description(self):
|
||||
return """exchange rates, retrieved from blockchain.info"""
|
||||
|
||||
|
||||
def __init__(self,a,b):
|
||||
BasePlugin.__init__(self,a,b)
|
||||
self.currencies = [self.config.get('currency', "EUR")]
|
||||
|
||||
def init(self):
|
||||
self.win = self.gui.main_window
|
||||
self.exchanger = Exchanger(self.win)
|
||||
self.win.connect(self.win, SIGNAL("refresh_balance()"), self.win.update_wallet)
|
||||
self.win.connect(self.win, SIGNAL("refresh_currencies()"), self.win.update_status)
|
||||
# Do price discovery
|
||||
self.exchanger = Exchanger(self)
|
||||
self.exchanger.start()
|
||||
self.gui.exchanger = self.exchanger
|
||||
|
||||
def set_currencies(self, quote_currencies):
|
||||
self.currencies = sorted(quote_currencies.keys())
|
||||
self.win.emit(SIGNAL("refresh_currencies()"))
|
||||
self.win.emit(SIGNAL("refresh_currencies_combo()"))
|
||||
|
||||
def set_quote_text(self, btc_balance, r):
|
||||
r[0] = self.create_quote_text(Decimal(btc_balance) / 100000000)
|
||||
|
||||
def create_quote_text(self, btc_balance):
|
||||
quote_currency = self.config.get("currency", "None")
|
||||
quote_currency = self.config.get("currency", "EUR")
|
||||
quote_balance = self.exchanger.exchange(btc_balance, quote_currency)
|
||||
if quote_balance is None:
|
||||
quote_text = ""
|
||||
|
@ -94,37 +103,37 @@ class Plugin(BasePlugin):
|
|||
return True
|
||||
|
||||
|
||||
def settings_dialog(self):
|
||||
d = QDialog(self.win)
|
||||
def toggle(self):
|
||||
out = BasePlugin.toggle(self)
|
||||
self.win.update_status()
|
||||
return out
|
||||
|
||||
vbox = QVBoxLayout(d)
|
||||
|
||||
grid = QGridLayout()
|
||||
vbox.addLayout(grid)
|
||||
def settings_widget(self, window):
|
||||
combo = QComboBox()
|
||||
|
||||
currencies = self.exchanger.get_currencies()
|
||||
currencies.insert(0, "None")
|
||||
def on_change(x):
|
||||
cur_request = str(self.currencies[x])
|
||||
if cur_request != self.config.get('currency', "EUR"):
|
||||
self.config.set_key('currency', cur_request, True)
|
||||
self.win.update_status()
|
||||
|
||||
cur_label=QLabel(_('Currency') + ':')
|
||||
grid.addWidget(cur_label , 2, 0)
|
||||
cur_combo = QComboBox()
|
||||
cur_combo.addItems(currencies)
|
||||
def set_currencies(combo):
|
||||
try:
|
||||
index = currencies.index(self.config.get('currency', "None"))
|
||||
combo.clear()
|
||||
except:
|
||||
return
|
||||
combo.addItems(self.currencies)
|
||||
try:
|
||||
index = self.currencies.index(self.config.get('currency', "EUR"))
|
||||
except:
|
||||
index = 0
|
||||
cur_combo.setCurrentIndex(index)
|
||||
grid.addWidget(cur_combo, 2, 1)
|
||||
grid.addWidget(HelpButton(_('Select which currency is used for quotes.') + ' '), 2, 2)
|
||||
combo.setCurrentIndex(index)
|
||||
|
||||
vbox.addLayout(ok_cancel_buttons(d))
|
||||
|
||||
if d.exec_():
|
||||
|
||||
cur_request = str(currencies[cur_combo.currentIndex()])
|
||||
if cur_request != self.config.get('currency', "None"):
|
||||
self.config.set_key('currency', cur_request, True)
|
||||
self.win.update_wallet()
|
||||
set_currencies(combo)
|
||||
combo.currentIndexChanged.connect(on_change)
|
||||
combo.connect(window, SIGNAL('refresh_currencies_combo()'), lambda: set_currencies(combo))
|
||||
return combo
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ from electrum import bmp, pyqrnative
|
|||
from electrum.plugins import BasePlugin
|
||||
from electrum.i18n import _
|
||||
|
||||
from electrum_gui.qt import HelpButton
|
||||
from electrum_gui.qt import HelpButton, EnterButton
|
||||
|
||||
class Plugin(BasePlugin):
|
||||
|
||||
|
@ -95,6 +95,9 @@ class Plugin(BasePlugin):
|
|||
print_error('Error connecting to service: %s ' % e)
|
||||
return False
|
||||
|
||||
def settings_widget(self, window):
|
||||
return EnterButton(_('Settings'), self.settings_dialog)
|
||||
|
||||
def settings_dialog(self):
|
||||
def check_for_api_key(api_key):
|
||||
if api_key and len(api_key) > 12:
|
||||
|
|
Loading…
Reference in New Issue