1
0

Create a Plugins class

Encapsulates plugin logic and removes global variable ugliness.
This commit is contained in:
Neil Booth
2015-09-03 12:02:03 +09:00
parent 2c67de8f64
commit 49797c3094
10 changed files with 208 additions and 203 deletions

View File

@@ -12,7 +12,7 @@ import tty, sys
class ElectrumGui:
def __init__(self, config, network):
def __init__(self, config, network, plugins):
self.config = config
self.network = network
@@ -51,8 +51,8 @@ class ElectrumGui:
self.str_amount = ""
self.str_fee = ""
self.history = None
if self.network:
if self.network:
self.network.register_callback('updated', self.update)
self.network.register_callback('connected', self.refresh)
self.network.register_callback('disconnected', self.refresh)
@@ -73,7 +73,7 @@ class ElectrumGui:
def verify_seed(self):
pass
def get_string(self, y, x):
self.set_cursor(1)
curses.echo()
@@ -85,7 +85,7 @@ class ElectrumGui:
def update(self):
self.update_history()
if self.tab == 0:
if self.tab == 0:
self.print_history()
self.refresh()
@@ -105,7 +105,7 @@ class ElectrumGui:
delta = (self.maxx - sum(width) - 4)/3
format_str = "%"+"%d"%width[0]+"s"+"%"+"%d"%(width[1]+delta)+"s"+"%"+"%d"%(width[2]+delta)+"s"+"%"+"%d"%(width[3]+delta)+"s"
b = 0
b = 0
self.history = []
for item in self.wallet.get_history():
@@ -130,7 +130,7 @@ class ElectrumGui:
elif self.network.is_connected():
if not self.wallet.up_to_date:
msg = _("Synchronizing...")
else:
else:
c, u, x = self.wallet.get_balance()
msg = _("Balance")+": %f "%(Decimal(c) / COIN)
if u:
@@ -139,12 +139,12 @@ class ElectrumGui:
msg += " [%f unmatured]"%(Decimal(x) / COIN)
else:
msg = _("Not connected")
self.stdscr.addstr( self.maxy -1, 3, msg)
for i in range(self.num_tabs):
self.stdscr.addstr( 0, 2 + 2*i + len(''.join(self.tab_names[0:i])), ' '+self.tab_names[i]+' ', curses.A_BOLD if self.tab == i else 0)
self.stdscr.addstr( self.maxy -1, self.maxx-30, ' '.join([_("Settings"), _("Network"), _("Quit")]))
@@ -221,7 +221,7 @@ class ElectrumGui:
def run_history_tab(self, c):
if c == 10:
out = self.run_popup('',["blah","foo"])
def edit_str(self, target, c, is_num=False):
# detect backspace
@@ -246,11 +246,11 @@ class ElectrumGui:
elif self.pos%6==5:
if c == 10: self.do_clear()
def run_receive_tab(self, c):
if c == 10:
out = self.run_popup('Address', ["Edit label", "Freeze", "Prioritize"])
def run_contacts_tab(self, c):
if c == 10 and self.contacts:
out = self.run_popup('Adress', ["Copy", "Pay to", "Edit label", "Delete"]).get('button')
@@ -263,7 +263,7 @@ class ElectrumGui:
s = self.get_string(6 + self.pos, 18)
if s:
self.wallet.labels[address] = s
def run_banner_tab(self, c):
self.show_message(repr(c))
pass
@@ -318,8 +318,8 @@ class ElectrumGui:
except Exception as e:
self.show_message(str(e))
return
if self.str_description:
if self.str_description:
self.wallet.labels[tx.hash()] = self.str_description
h = self.wallet.send_tx(tx)
@@ -375,7 +375,7 @@ class ElectrumGui:
proxy = None
self.network.set_parameters(host, port, protocol, proxy, auto_connect)
def settings_dialog(self):
@@ -396,11 +396,11 @@ class ElectrumGui:
{'label':'Password', 'type':'password', 'value':''}
], buttons = 1)
return out.get('Password')
def run_dialog(self, title, items, interval=2, buttons=None, y_pos=3):
self.popup_pos = 0
self.w = curses.newwin( 5 + len(items)*interval + (2 if buttons else 0), 50, y_pos, 5)
w = self.w
out = {}
@@ -441,7 +441,7 @@ class ElectrumGui:
if buttons:
w.addstr( 5+interval*i, 10, "[ ok ]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-2) else curses.color_pair(2))
w.addstr( 5+interval*i, 25, "[cancel]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-1) else curses.color_pair(2))
w.refresh()
c = self.stdscr.getch()
@@ -480,10 +480,9 @@ class ElectrumGui:
new_choice = choices[(j + 1)% len(choices)]
item['value'] = new_choice
out[item.get('label')] = item.get('value')
elif _type == 'button':
out['button'] = item.get('label')
break
return out