forked from bitcoinafterlife/bal-electrum-plugin
fix(gui): restore BAL status-bar icon (bottom-right) + open settings on click
Regression: create_status_bar had been turned into a no-op while chasing the "condensed menu/tabs" bug. The real cause of that bug was a Windows OverflowError (year 2038), already fixed separately -- so the no-op wrongly removed the BAL icon from the status bar. Restore the original (Gitea) behaviour: - Build a StatusBarButton with the bal32x32 icon and add it via addPermanentWidget, so the icon shows the plugin is installed. - Clicking the icon opens settings_dialog (quick access to plugin settings). - Track buttons in self._statusbar_buttons keyed by id(sb.window()); remove the stale button before creating a new one to avoid a duplicated icon on restart / wallet switch. Also: - import StatusBarButton from electrum.gui.qt.main_window; ensure read_QIcon_from_bytes is imported; init self._statusbar_buttons in __init__. - Update tests/gui_fixes_test.py: the regression check now asserts the icon IS added (StatusBarButton + addPermanentWidget + settings_dialog + _statusbar_buttons book-keeping), instead of the previous wrong no-op check. Tests: 182 official tests pass; smoke/windows_overflow/parallel/external_zip OK. Note: from now on all code and code-comments are in English.
This commit is contained in:
committed by
steal
parent
03985a2566
commit
f28f1502e2
@@ -14,8 +14,11 @@ One :class:`bal.gui.qt.window.BalWindow` is created per top-level wallet window
|
|||||||
and cached in ``self.bal_windows``.
|
and cached in ``self.bal_windows``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from electrum.gui.qt.main_window import StatusBarButton
|
||||||
|
|
||||||
from .common import *
|
from .common import *
|
||||||
from .common import _, _logger # underscore names are not re-exported by "import *"
|
from .common import _, _logger # underscore names are not re-exported by "import *"
|
||||||
|
from .common import read_QIcon_from_bytes
|
||||||
from .widgets import BalCheckBox, BalLineEdit, BalTextEdit
|
from .widgets import BalCheckBox, BalLineEdit, BalTextEdit
|
||||||
from .window import BalWindow
|
from .window import BalWindow
|
||||||
from .dialogs import BalDialog
|
from .dialogs import BalDialog
|
||||||
@@ -38,6 +41,10 @@ class Plugin(BalPlugin):
|
|||||||
_logger.info("INIT BALPLUGIN")
|
_logger.info("INIT BALPLUGIN")
|
||||||
BalPlugin.__init__(self, parent, config, name)
|
BalPlugin.__init__(self, parent, config, name)
|
||||||
self.bal_windows = {}
|
self.bal_windows = {}
|
||||||
|
# Status-bar buttons, keyed by id(sb.window()). Tracking them lets us
|
||||||
|
# remove a stale button before creating a fresh one when a wallet is
|
||||||
|
# switched / Electrum is restarted, so the icon is never duplicated.
|
||||||
|
self._statusbar_buttons = {}
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def init_qt(self, gui_object):
|
def init_qt(self, gui_object):
|
||||||
@@ -88,15 +95,34 @@ class Plugin(BalPlugin):
|
|||||||
|
|
||||||
@hook
|
@hook
|
||||||
def create_status_bar(self, sb):
|
def create_status_bar(self, sb):
|
||||||
# NOTE: intentionally a no-op, matching the original plugin. The
|
# Show the BAL icon in the status bar (bottom-right): it signals that
|
||||||
# original code had an early ``return`` before building the
|
# the Bitcoin After Life plugin is installed and, when clicked, quickly
|
||||||
# StatusBarButton, i.e. the button was deliberately disabled. Adding
|
# opens the plugin settings (settings_dialog).
|
||||||
# the button here caused a stray, condensed icon+text element to be
|
#
|
||||||
# rendered in the wrong place (near the top, under the Electrum logo)
|
# NOTE: this was NOT the "condensed menu/tabs" bug under the Electrum
|
||||||
# after a restart / wallet switch. Settings are already reachable via
|
# logo -- that one was a Windows OverflowError (year 2038), fixed
|
||||||
# Tools -> Plugins, so we keep the original behaviour.
|
# separately. The icon must therefore be kept.
|
||||||
_logger.info("HOOK create status bar (no-op)")
|
#
|
||||||
return
|
# To avoid a duplicated icon on restart / wallet switch, we track the
|
||||||
|
# button by id(sb.window()) and remove the stale one before creating a
|
||||||
|
# fresh one.
|
||||||
|
_logger.info("HOOK create status bar")
|
||||||
|
key = id(sb.window())
|
||||||
|
old = self._statusbar_buttons.pop(key, None)
|
||||||
|
if old is not None:
|
||||||
|
try:
|
||||||
|
old.setParent(None)
|
||||||
|
old.deleteLater()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
b = StatusBarButton(
|
||||||
|
read_QIcon_from_bytes(self.read_file("icons/bal32x32.png")),
|
||||||
|
"Bal " + _("Bitcoin After Life"),
|
||||||
|
lambda: self.settings_dialog(sb.window()),
|
||||||
|
sb.height(),
|
||||||
|
)
|
||||||
|
sb.addPermanentWidget(b)
|
||||||
|
self._statusbar_buttons[key] = b
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def init_menubar(self, window):
|
def init_menubar(self, window):
|
||||||
|
|||||||
@@ -115,22 +115,31 @@ def main(pkg: str) -> int:
|
|||||||
"on_close must reset _menubar_initialized so the window can be reused")
|
"on_close must reset _menubar_initialized so the window can be reused")
|
||||||
print("[OK] init_menubar_tools is idempotent (no duplicate tabs/menu)")
|
print("[OK] init_menubar_tools is idempotent (no duplicate tabs/menu)")
|
||||||
|
|
||||||
# REGRESSION: create_status_bar must stay a no-op, like the original plugin
|
# REGRESSION: create_status_bar MUST add the BAL status-bar icon (bottom
|
||||||
# (whose body had an early ``return`` before building the StatusBarButton).
|
# right of the Electrum window). It signals that the plugin is installed
|
||||||
# Re-adding the status-bar button made a stray condensed icon+text element
|
# and, when clicked, opens the plugin settings. An earlier change wrongly
|
||||||
# appear in the wrong place after restart / wallet switch.
|
# turned this into a no-op while chasing the "condensed menu" bug (whose
|
||||||
csb_src = inspect.getsource(plugin_mod.Plugin.create_status_bar)
|
# real cause was a Windows OverflowError, fixed elsewhere), which made the
|
||||||
csb_active = _active_source_without_strings(plugin_mod) # whole module sans strings
|
# icon disappear. The icon must stay, and must not be duplicated on
|
||||||
|
# restart / wallet switch (hence the _statusbar_buttons book-keeping).
|
||||||
csb_body = inspect.getsource(plugin_mod.Plugin.create_status_bar)
|
csb_body = inspect.getsource(plugin_mod.Plugin.create_status_bar)
|
||||||
# The executable body must not add a permanent widget / build the button.
|
|
||||||
# Strip comments to avoid matching the explanatory note.
|
|
||||||
csb_code = "\n".join(
|
csb_code = "\n".join(
|
||||||
line for line in csb_body.splitlines()
|
line for line in csb_body.splitlines()
|
||||||
if not line.lstrip().startswith("#")
|
if not line.lstrip().startswith("#")
|
||||||
)
|
)
|
||||||
assert "addPermanentWidget" not in csb_code, (
|
assert "StatusBarButton" in csb_code, (
|
||||||
"create_status_bar must not add a status-bar widget (original is a no-op)")
|
"create_status_bar must build a StatusBarButton (the BAL icon)")
|
||||||
print("[OK] create_status_bar is a no-op (matches original)")
|
assert "addPermanentWidget" in csb_code, (
|
||||||
|
"create_status_bar must add the BAL icon to the status bar")
|
||||||
|
assert "settings_dialog" in csb_code, (
|
||||||
|
"clicking the BAL icon must open settings_dialog")
|
||||||
|
assert "_statusbar_buttons" in csb_code, (
|
||||||
|
"create_status_bar must track buttons to avoid duplicate icons")
|
||||||
|
# __init__ must initialise the tracking dict.
|
||||||
|
init_code = inspect.getsource(plugin_mod.Plugin.__init__)
|
||||||
|
assert "_statusbar_buttons" in init_code, (
|
||||||
|
"Plugin.__init__ must initialise self._statusbar_buttons")
|
||||||
|
print("[OK] create_status_bar adds the BAL icon + opens settings on click")
|
||||||
|
|
||||||
print(f"\n[OK] all GUI-fix checks passed for package {pkg!r}")
|
print(f"\n[OK] all GUI-fix checks passed for package {pkg!r}")
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user