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