upgraded to new plugin environment

This commit is contained in:
bitcoinafterlife 2025-04-17 12:44:44 -04:00
parent b23eee0e44
commit 0c10c83f0f
6 changed files with 140 additions and 144 deletions

View File

@ -1,20 +0,0 @@
from electrum.i18n import _
import subprocess
from . import bal_resources
BUILD_NUMBER = 0
REVISION_NUMBER = 1
VERSION_NUMBER = 0
def _version():
return f'{VERSION_NUMBER}.{REVISION_NUMBER}-{BUILD_NUMBER}'
version = _version()
author = "Bal Enterprise inc."
fullname = _('B.A.L.')
description = ''.join([
"<img src='",bal_resources.icon_path('bal16x16.png'),"'>", _("Bitcoin After Life"), '<br/>',
_("For more information, visit"),
" <a href=\"https://bitcoin-after.life/\">https://bitcoin-after.life/</a><br/>",
"<p style='font-size:8pt;vertialAlign:bottom'>Version: ", _version(),"</p>"
])
#available_for = ['qt', 'cmdline', 'qml']
available_for = ['qt']

4
bal.py
View File

@ -102,8 +102,10 @@ class BalPlugin(BasePlugin):
def config_get(self,key): def config_get(self,key):
v = self.config.get(key,None) v = self.config.get(key,None)
print("config get",key,v)
if v is None: if v is None:
self.config.set_key(key,self.DEFAULT_SETTINGS[key],save=True) self.config.set_key(key,self.DEFAULT_SETTINGS[key])
print("config setkey",key)
v = self.DEFAULT_SETTINGS[key] v = self.DEFAULT_SETTINGS[key]
return v return v

View File

@ -95,25 +95,8 @@ class bal_checkbox(QCheckBox):
def __init__(self, plugin,variable,window=None): def __init__(self, plugin,variable,window=None):
QCheckBox.__init__(self) QCheckBox.__init__(self)
self.setChecked(plugin.config_get(variable)) self.setChecked(plugin.config_get(variable))
window=window
def on_check(v): def on_check(v):
plugin.config.set_key(variable, v == Qt.CheckState.Checked, save=True) plugin.config.set_key(variable, v == 2)
if window: plugin.config_get(variable)
plugin._hide_invalidated= plugin.config_get(plugin.HIDE_INVALIDATED)
plugin._hide_replaced= plugin.config_get(plugin.HIDE_REPLACED)
window.update_all()
self.stateChanged.connect(on_check) self.stateChanged.connect(on_check)
#TODO IMPLEMENT PREVIEW DIALOG
#tx list display txid, willexecutor, qrcode, button to sign
# :def preview_dialog(self, txs):
def preview_dialog(self, txs):
w=PreviewDialog(self,txs)
w.exec()
return w
def add_info_from_will(self,tx):
for input in tx.inputs():
pass

View File

@ -225,7 +225,7 @@ class BalCloseDialog(BalDialog):
#self._stopping=True #self._stopping=True
#self.on_success_phase2() #self.on_success_phase2()
# return # return
_logger.debug("have to sign",self.have_to_sign) _logger.debug("have to sign {}".format(self.have_to_sign))
password=None password=None
if self.have_to_sign is None: if self.have_to_sign is None:
self.msg_set_invalidating() self.msg_set_invalidating()

View File

@ -199,7 +199,6 @@ class WillExecutorDialog(BalDialog,MessageBoxMixin):
def __init__(self, bal_window): def __init__(self, bal_window):
BalDialog.__init__(self,bal_window.window) BalDialog.__init__(self,bal_window.window)
self.bal_plugin = bal_window.bal_plugin self.bal_plugin = bal_window.bal_plugin
self.gui_object = self.bal_plugin.gui_object
self.config = self.bal_plugin.config self.config = self.bal_plugin.config
self.window = bal_window.window self.window = bal_window.window
self.bal_window = bal_window self.bal_window = bal_window

236
qt.py
View File

@ -81,22 +81,29 @@ class Plugin(BalPlugin,Logger):
@hook @hook
def init_qt(self,gui_object): def init_qt(self,gui_object):
print("********************************************************************************************************************")
self.logger.info("HOOK init qt") self.logger.info("HOOK init qt")
print("logger")
try: try:
self.gui_object=gui_object self.gui_object=gui_object
print(dir(gui_object))
for window in gui_object.windows: for window in gui_object.windows:
wallet = window.wallet wallet = window.wallet
if wallet: if wallet:
window.show_warning(_('Please restart Electrum to activate the BAL plugin'), title=_('Success')) window.show_warning(_('Please restart Electrum to activate the BAL plugin'), title=_('Success'))
return return
w = BalWindow(self,window) w = BalWindow(self,window)
print("windows.winid",window.winid)
self.bal_windows[window.winId]= w self.bal_windows[window.winId]= w
for child in window.children(): for child in window.children():
if isinstance(child,QMenuBar): if isinstance(child,QMenuBar):
print("found menubar")
for menu_child in child.children(): for menu_child in child.children():
if isinstance(menu_child,QMenu): if isinstance(menu_child,QMenu):
print("found qmenu")
try: try:
if menu_child.title()==_("&Tools"): if menu_child.title()==_("&Tools"):
print("found tools")
w.init_menubar_tools(menu_child) w.init_menubar_tools(menu_child)
except Exception as e: except Exception as e:
@ -104,8 +111,8 @@ class Plugin(BalPlugin,Logger):
self.logger.error(("except:",menu_child.text())) self.logger.error(("except:",menu_child.text()))
except Exception as e: except Exception as e:
raise e
self.logger.error("Error loading plugini {}".format(e)) self.logger.error("Error loading plugini {}".format(e))
raise e
@ -118,15 +125,16 @@ class Plugin(BalPlugin,Logger):
sb.addPermanentWidget(b) sb.addPermanentWidget(b)
@hook @hook
def init_menubar_tools(self,window,tools_menu): def init_menubar(self,window):
self.logger.info("HOOK init_menubar") self.logger.info("HOOK init_menubar")
w = self.get_window(window) w = self.get_window(window)
w.init_menubar_tools(tools_menu) w.init_menubar_tools(window.tools_menu)
@hook @hook
def load_wallet(self,wallet, main_window): def load_wallet(self,wallet, main_window):
self.logger.info("HOOK load wallet") self.logger.info("HOOK load wallet")
w = self.get_window(main_window) w = self.get_window(main_window)
print(dir(w))
w.wallet = wallet w.wallet = wallet
w.init_will() w.init_will()
w.willexecutors = Willexecutors.get_willexecutors(self, update=False, bal_window=w) w.willexecutors = Willexecutors.get_willexecutors(self, update=False, bal_window=w)
@ -170,8 +178,116 @@ class Plugin(BalPlugin,Logger):
return return
self.extension = bool(keystore.get_passphrase(password)) self.extension = bool(keystore.get_passphrase(password))
return keystore.get_seed(password) return keystore.get_seed(password)
def settings_dialog(self,window,wallet):
d = BalDialog(window, self.get_window_title("Settings"))
d.setMinimumSize(100, 200)
qicon=qt_resources.read_QPixmap("bal32x32.png")
lbl_logo = QLabel()
lbl_logo.setPixmap(qicon)
#heir_locktime_time = QSpinBox()
#heir_locktime_time.setMinimum(0)
#heir_locktime_time.setMaximum(3650)
#heir_locktime_time.setValue(int(self.config_get(BalPlugin.LOCKTIME_TIME)))
#def on_heir_locktime_time():
# value = heir_locktime_time.value()
# self.config.set_key(BalPlugin.LOCKTIME_TIME,value,save=True)
#heir_locktime_time.valueChanged.connect(on_heir_locktime_time)
##heir_locktimedelta_time = QSpinBox()
#heir_locktimedelta_time.setMinimum(0)
#heir_locktimedelta_time.setMaximum(3650)
#heir_locktimedelta_time.setValue(int(self.config_get(BalPlugin.LOCKTIMEDELTA_TIME)))
#def on_heir_locktime_time():
#value = heir_locktime_time.value
#self.config.set_key(BalPlugin.LOCKTIME_TIME,value,save=True)
#heir_locktime_time.valueChanged.connect(on_heir_locktime_time)
#heir_locktime_blocks = QSpinBox()
#heir_locktime_blocks.setMinimum(0)
#heir_locktime_blocks.setMaximum(144*3650)
#heir_locktime_blocks.setValue(int(self.config_get(BalPlugin.LOCKTIME_BLOCKS)))
#def on_heir_locktime_blocks():
#value = heir_locktime_blocks.value()
#self.config.set_key(BalPlugin.LOCKTIME_BLOCKS,value,save=True)
#heir_locktime_blocks.valueChanged.connect(on_heir_locktime_blocks)
#heir_locktimedelta_blocks = QSpinBox()
#heir_locktimedelta_blocks.setMinimum(0)
#heir_locktimedelta_blocks.setMaximum(144*3650)
#heir_locktimedelta_blocks.setValue(int(self.config_get(BalPlugin.LOCKTIMEDELTA_BLOCKS)))
#def on_heir_locktimedelta_blocks():
#value = heir_locktimedelta_blocks.value()
#self.config.set_key(BalPlugin.LOCKTIMEDELTA_TIME,value,save=True)
#heir_locktimedelta_blocks.valueChanged.connect(on_heir_locktimedelta_blocks)
#heir_tx_fees = QSpinBox()
#heir_tx_fees.setMinimum(1)
#heir_tx_fees.setMaximum(10000)
#heir_tx_fees.setValue(int(self.config_get(BalPlugin.TX_FEES)))
#def on_heir_tx_fees():
#value = heir_tx_fees.value()
#self.config.set_key(BalPlugin.TX_FEES,value,save=True)
#heir_tx_fees.valueChanged.connect(on_heir_tx_fees)
#heir_broadcast = bal_checkbox(self, BalPlugin.BROADCAST)
#heir_ask_broadcast = bal_checkbox(self, BalPlugin.ASK_BROADCAST)
#heir_invalidate = bal_checkbox(self, BalPlugin.INVALIDATE)
#heir_ask_invalidate = bal_checkbox(self, BalPlugin.ASK_INVALIDATE)
#heir_preview = bal_checkbox(self, BalPlugin.PREVIEW)
heir_ping_willexecutors = bal_checkbox(self, BalPlugin.PING_WILLEXECUTORS)
heir_ask_ping_willexecutors = bal_checkbox(self, BalPlugin.ASK_PING_WILLEXECUTORS)
#print("setkey broadcast")
#self.config.set_key(BalPlugin.BROADCAST,True)
heir_no_willexecutor = bal_checkbox(self, BalPlugin.NO_WILLEXECUTOR)
heir_hide_replaced = bal_checkbox(self,BalPlugin.HIDE_REPLACED,self)
heir_hide_invalidated = bal_checkbox(self,BalPlugin.HIDE_INVALIDATED,self)
#heir_allow_repush = bal_checkbox(self,BalPlugin.ALLOW_REPUSH,self)
heir_repush = QPushButton("Rebroadcast transactions")
heir_repush.clicked.connect(partial(self.broadcast_transactions,True))
grid=QGridLayout(d)
#add_widget(grid,"Refresh Time Days",heir_locktime_time,0,"Delta days for inputs to be invalidated and transactions resubmitted")
#add_widget(grid,"Refresh Blocks",heir_locktime_blocks,1,"Delta blocks for inputs to be invalidated and transaction resubmitted")
#add_widget(grid,"Transaction fees",heir_tx_fees,1,"Default transaction fees")
#add_widget(grid,"Broadcast transactions",heir_broadcast,3,"")
#add_widget(grid," - Ask before",heir_ask_broadcast,4,"")
#add_widget(grid,"Invalidate transactions",heir_invalidate,5,"")
#add_widget(grid," - Ask before",heir_ask_invalidate,6,"")
#add_widget(grid,"Show preview before sign",heir_preview,7,"")
#grid.addWidget(lbl_logo,0,0)
add_widget(grid,"Hide Replaced",heir_hide_replaced, 1, "Hide replaced transactions from will detail and list")
add_widget(grid,"Hide Invalidated",heir_hide_invalidated ,2,"Hide invalidated transactions from will detail and list")
add_widget(grid,"Ping Willexecutors",heir_ping_willexecutors,3,"Ping willexecutors to get payment info before compiling will")
add_widget(grid," - Ask before",heir_ask_ping_willexecutors,4,"Ask before to ping willexecutor")
add_widget(grid,"Backup Transaction",heir_no_willexecutor,5,"Add transactions without willexecutor")
grid.addWidget(heir_repush,6,0)
grid.addWidget(HelpButton("Broadcast all transactions to willexecutors including those already pushed"),6,2)
#add_widget(grid,"Max Allowed TimeDelta Days",heir_locktimedelta_time,8,"")
#add_widget(grid,"Max Allowed BlocksDelta",heir_locktimedelta_blocks,9,"")
if ret := bool(d.exec()):
try:
self.update_all()
return ret
except:
pass
return False
def broadcast_transactions(self,force):
for k,w in self.bal_windows.items():
print(dir(w))
w.broadcast_transactions(force)
def update_all(self):
for k,w in self.bal_windows.items():
w.update_all()
def get_window_title(self,title):
return _('BAL - ') + _(title)
class shown_cv(): class shown_cv():
_type= bool _type= bool
def __init__(self,value): def __init__(self,value):
@ -212,11 +328,22 @@ class BalWindow(Logger):
tab.tab_pos = len(tabs) tab.tab_pos = len(tabs)
if tab.is_shown_cv: if tab.is_shown_cv:
tabs.addTab(tab, icon, description.replace("&", "")) tabs.addTab(tab, icon, description.replace("&", ""))
def add_toggle_action(tab):
is_shown = tab.is_shown_cv.get()
tab.menu_action = self.window.view_menu.addAction(tab.tab_description, lambda: self.window.toggle_tab(tab))
tab.menu_action.setCheckable(True)
tab.menu_action.setChecked(is_shown)
print("add tab heir",self.heirs_tab);
add_optional_tab(self.window.tabs, self.heirs_tab, qt_resources.read_QIcon("heir.png"), _("&Heirs")) add_optional_tab(self.window.tabs, self.heirs_tab, qt_resources.read_QIcon("heir.png"), _("&Heirs"))
add_optional_tab(self.window.tabs, self.will_tab, qt_resources.read_QIcon("will.png"), _("&Will")) add_optional_tab(self.window.tabs, self.will_tab, qt_resources.read_QIcon("will.png"), _("&Will"))
tools_menu.addSeparator() tools_menu.addSeparator()
self.tools_menu.willexecutors_action = tools_menu.addAction(_("&Will-Executors"), self.show_willexecutor_dialog) self.tools_menu.willexecutors_action = tools_menu.addAction(_("&Will-Executors"), self.show_willexecutor_dialog)
self.window.view_menu.addSeparator()
add_toggle_action(self.heirs_tab)
add_toggle_action(self.will_tab)
def load_willitems(self): def load_willitems(self):
self.willitems={} self.willitems={}
@ -262,8 +389,6 @@ class BalWindow(Logger):
self.bal_plugin.validate_will_settings(self.will_settings) self.bal_plugin.validate_will_settings(self.will_settings)
self.heir_list.update_will_settings() self.heir_list.update_will_settings()
def get_window_title(self,title):
return _('BAL - ') + _(title)
def show_willexecutor_dialog(self): def show_willexecutor_dialog(self):
self.willexecutor_dialog = WillExecutorDialog(self) self.willexecutor_dialog = WillExecutorDialog(self)
@ -271,6 +396,8 @@ class BalWindow(Logger):
def create_heirs_tab(self): def create_heirs_tab(self):
self.heir_list = l = HeirList(self) self.heir_list = l = HeirList(self)
print("heir_list",l)
tab = self.window.create_list_tab(l) tab = self.window.create_list_tab(l)
tab.is_shown_cv = shown_cv(True) tab.is_shown_cv = shown_cv(True)
return tab return tab
@ -829,101 +956,6 @@ class BalWindow(Logger):
self.dw=WillDetailDialog(self) self.dw=WillDetailDialog(self)
self.dw.show() self.dw.show()
def settings_dialog(self,window):
d = BalDialog(window, self.get_window_title("Settings"))
d.setMinimumSize(100, 200)
qicon=qt_resources.read_QPixmap("bal32x32.png")
lbl_logo = QLabel()
lbl_logo.setPixmap(qicon)
heir_locktime_time = QSpinBox()
heir_locktime_time.setMinimum(0)
heir_locktime_time.setMaximum(3650)
heir_locktime_time.setValue(int(self.bal_plugin.config_get(BalPlugin.LOCKTIME_TIME)))
def on_heir_locktime_time():
value = heir_locktime_time.value()
self.bal_plugin.config.set_key(BalPlugin.LOCKTIME_TIME,value,save=True)
heir_locktime_time.valueChanged.connect(on_heir_locktime_time)
heir_locktimedelta_time = QSpinBox()
heir_locktimedelta_time.setMinimum(0)
heir_locktimedelta_time.setMaximum(3650)
heir_locktimedelta_time.setValue(int(self.bal_plugin.config_get(BalPlugin.LOCKTIMEDELTA_TIME)))
def on_heir_locktime_time():
value = heir_locktime_time.value
self.bal_plugin.config.set_key(BalPlugin.LOCKTIME_TIME,value,save=True)
heir_locktime_time.valueChanged.connect(on_heir_locktime_time)
heir_locktime_blocks = QSpinBox()
heir_locktime_blocks.setMinimum(0)
heir_locktime_blocks.setMaximum(144*3650)
heir_locktime_blocks.setValue(int(self.bal_plugin.config_get(BalPlugin.LOCKTIME_BLOCKS)))
def on_heir_locktime_blocks():
value = heir_locktime_blocks.value()
self.bal_plugin.config.set_key(BalPlugin.LOCKTIME_BLOCKS,value,save=True)
heir_locktime_blocks.valueChanged.connect(on_heir_locktime_blocks)
heir_locktimedelta_blocks = QSpinBox()
heir_locktimedelta_blocks.setMinimum(0)
heir_locktimedelta_blocks.setMaximum(144*3650)
heir_locktimedelta_blocks.setValue(int(self.bal_plugin.config_get(BalPlugin.LOCKTIMEDELTA_BLOCKS)))
def on_heir_locktimedelta_blocks():
value = heir_locktimedelta_blocks.value()
self.bal_plugin.config.set_key(BalPlugin.LOCKTIMEDELTA_TIME,value,save=True)
heir_locktimedelta_blocks.valueChanged.connect(on_heir_locktimedelta_blocks)
heir_tx_fees = QSpinBox()
heir_tx_fees.setMinimum(1)
heir_tx_fees.setMaximum(10000)
heir_tx_fees.setValue(int(self.bal_plugin.config_get(BalPlugin.TX_FEES)))
def on_heir_tx_fees():
value = heir_tx_fees.value()
self.bal_plugin.config.set_key(BalPlugin.TX_FEES,value,save=True)
heir_tx_fees.valueChanged.connect(on_heir_tx_fees)
heir_broadcast = bal_checkbox(self.bal_plugin, BalPlugin.BROADCAST)
heir_ask_broadcast = bal_checkbox(self.bal_plugin, BalPlugin.ASK_BROADCAST)
heir_invalidate = bal_checkbox(self.bal_plugin, BalPlugin.INVALIDATE)
heir_ask_invalidate = bal_checkbox(self.bal_plugin, BalPlugin.ASK_INVALIDATE)
heir_preview = bal_checkbox(self.bal_plugin, BalPlugin.PREVIEW)
heir_ping_willexecutors = bal_checkbox(self.bal_plugin, BalPlugin.PING_WILLEXECUTORS)
heir_ask_ping_willexecutors = bal_checkbox(self.bal_plugin, BalPlugin.ASK_PING_WILLEXECUTORS)
heir_no_willexecutor = bal_checkbox(self.bal_plugin, BalPlugin.NO_WILLEXECUTOR)
heir_hide_replaced = bal_checkbox(self.bal_plugin,BalPlugin.HIDE_REPLACED,self)
heir_hide_invalidated = bal_checkbox(self.bal_plugin,BalPlugin.HIDE_INVALIDATED,self)
heir_allow_repush = bal_checkbox(self.bal_plugin,BalPlugin.ALLOW_REPUSH,self)
heir_repush = QPushButton("Rebroadcast transactions")
heir_repush.clicked.connect(partial(self.broadcast_transactions,True))
grid=QGridLayout(d)
#add_widget(grid,"Refresh Time Days",heir_locktime_time,0,"Delta days for inputs to be invalidated and transactions resubmitted")
#add_widget(grid,"Refresh Blocks",heir_locktime_blocks,1,"Delta blocks for inputs to be invalidated and transaction resubmitted")
#add_widget(grid,"Transaction fees",heir_tx_fees,1,"Default transaction fees")
#add_widget(grid,"Broadcast transactions",heir_broadcast,3,"")
#add_widget(grid," - Ask before",heir_ask_broadcast,4,"")
#add_widget(grid,"Invalidate transactions",heir_invalidate,5,"")
#add_widget(grid," - Ask before",heir_ask_invalidate,6,"")
#add_widget(grid,"Show preview before sign",heir_preview,7,"")
#grid.addWidget(lbl_logo,0,0)
add_widget(grid,"Hide Replaced",heir_hide_replaced, 1, "Hide replaced transactions from will detail and list")
add_widget(grid,"Hide Invalidated",heir_hide_invalidated ,2,"Hide invalidated transactions from will detail and list")
add_widget(grid,"Ping Willexecutors",heir_ping_willexecutors,3,"Ping willexecutors to get payment info before compiling will")
add_widget(grid," - Ask before",heir_ask_ping_willexecutors,4,"Ask before to ping willexecutor")
add_widget(grid,"Backup Transaction",heir_no_willexecutor,5,"Add transactions without willexecutor")
grid.addWidget(heir_repush,6,0)
grid.addWidget(HelpButton("Broadcast all transactions to willexecutors including those already pushed"),6,2)
#add_widget(grid,"Max Allowed TimeDelta Days",heir_locktimedelta_time,8,"")
#add_widget(grid,"Max Allowed BlocksDelta",heir_locktimedelta_blocks,9,"")
if ret := bool(d.exec()):
try:
self.update_all()
return ret
except:
pass
return False
def update_all(self): def update_all(self):
self.will_list.update_will(self.willitems) self.will_list.update_will(self.willitems)