add a hook at the end of the gui constructor

This commit is contained in:
thomasv 2013-03-12 18:40:21 +01:00
parent 06315dd911
commit 2c1ae1ba18
2 changed files with 25 additions and 9 deletions

View File

@ -325,6 +325,9 @@ class ElectrumWindow(QMainWindow):
# set initial message
self.console.showMessage(self.wallet.banner)
# plugins that need to change the GUI do it here
self.run_hook('init')
# plugins
def init_plugins(self):

View File

@ -103,6 +103,7 @@ def init(gui):
gui.requested_amounts = config.get('requested_amounts',{})
gui.merchant_name = config.get('merchant_name', 'Invoice')
gui.qr_window = None
do_enable(gui, is_enabled())
def is_enabled():
return config.get('pointofsale') is True
@ -110,35 +111,47 @@ def is_enabled():
def is_available():
return True
def toggle(gui):
if not is_enabled():
def toggle(gui):
enabled = not is_enabled()
config.set_key('pointofsale', enabled, True)
do_enable(gui, enabled)
update_gui(gui)
return enabled
def do_enable(gui, enabled):
if enabled:
gui.expert_mode = True
gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Request')])
gui.set_hook('item_changed', item_changed)
gui.set_hook('current_item_changed', recv_changed)
gui.set_hook('receive_menu', receive_menu)
gui.set_hook('update_receive_item', update_receive_item)
gui.set_hook('timer_actions', timer_actions)
gui.set_hook('close_main_window', close_main_window)
enabled = True
gui.set_hook('init', update_gui)
else:
gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')])
gui.unset_hook('item_changed', item_changed)
gui.unset_hook('current_item_changed', recv_changed)
gui.unset_hook('receive_menu', receive_menu)
gui.unset_hook('update_receive_item', update_receive_item)
gui.unset_hook('timer_actions', timer_actions)
gui.unset_hook('close_main_window', close_main_window)
enabled = False
gui.unset_hook('init', update_gui)
def update_gui(gui):
enabled = is_enabled()
if enabled:
gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Request')])
else:
gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')])
config.set_key('pointofsale', enabled, True)
toggle_QR_window(gui, enabled)
return enabled
def toggle_QR_window(self, show):
if show and not self.qr_window:
self.qr_window = QR_Window(self.exchanger)