fix(gui): window z-order + lifecycle (B1-B10) (#2)

* fix(gui): correct window z-order and lifecycle bugs (B1-B10)

Sintomi risolti:
- S1: le finestre del plugin sparivano dietro Electrum
- S2: alcuni meccanismi funzionavano solo dopo chiusura+pulizia di Electrum

La logica di business resta BYTE-IDENTICA (nessuna modifica a bal/core/*):
cambiano solo parent, modalità, ciclo di vita, cleanup e presentazione.

Nuovo modulo bal/gui/qt/window_utils.py con helper centralizzati:
- top_level_of, bring_to_front, stop_thread, show_modal, show_on_top

Fix per bug:
- B1: self.parent -> self._bal_parent (dialogs/lists/widgets); parent = top_level_of(parent)
- B2/B9: .show() -> show_on_top()/show_modal()/bring_to_front()
- B3: init a caldo _setup_window() replica load_wallet (niente 'restart Electrum')
- B4: chiave finestra stabile _window_key() = id(window)
- B5: on_close riscritto (no except:pass, log per-step, reset stato)
- B6: BalBlockingWaitingDialog ripristina processEvents()
- B7/B8: closeEvent/hideEvent -> stop_thread() (stop+wait) + super()
- B10: uso di window.tools_menu (no ricerca per titolo localizzato '&Tools')

Test: smoke + gui_fixes (regressione B1-B10) + external_zip tutti verdi.
Doc aggiornata: DIAGNOSI_GUI.md marca B1-B10 come FIXED.

* fix(gui): do not kill task thread on dialog close (download list regression)

The B7/B8 change added stop_thread() to BalDialog.closeEvent/hideEvent.
But Electrum's TaskThread.on_done runs cb_done (often self.accept, which
closes the waiting dialog) BEFORE cb_result (on_success, which updates the
will-executor list). Stopping/joining the thread inside closeEvent therefore
tore the thread down before on_success ran, silently dropping the downloaded
will-executor list ('Download List' appeared to do nothing).

Restore the original safe behavior: the base BalDialog no longer stops the
thread on close/hide (matching the original plugin, which deliberately left
this commented out). Long-lived dialogs that own a thread still stop it
explicitly in their own handlers.

Adds a regression test asserting BalDialog.closeEvent/hideEvent never call
stop_thread.

* fix(gui): restore modal exec for waiting dialog + surface download failures

Two changes to fix 'Download List' doing nothing:

1) BalWaitingDialog.exe() now keeps the original application-modal exec()
   (only adding raise/activate for visibility). The earlier switch to
   window-modal could interfere with how the TaskThread result (on_success,
   which populates the will-executor list) is delivered via a queued signal
   while the modal loop is spinning.

2) BalWindow.download_list now logs how many entries were received and, when
   the result is empty (the core download_list swallows errors and returns {}),
   shows a warning to the user instead of failing silently. This makes any
   future network/parse failure visible in the Electrum log and to the user.

Business logic in bal/core/* is unchanged.

* fix(gui): show the real download error reason in the warning popup

When 'Download List' fails, the core download_list returns {} and the cause
was only visible in the Electrum log (which is hard to capture). The GUI now
re-issues the same raw request when the result is empty and shows the actual
exception/reason in the warning popup (e.g. SSL error, timeout, empty server
response). Pure GUI-side diagnostics; bal/core/* logic unchanged.

* fix(gui): download will-executor list synchronously like the original

ROOT CAUSE: the original plugin's 'Download List' button called
Willexecutors.download_list() DIRECTLY on the GUI thread
(qt.py: WillExecutorWidget.download_list). The refactor instead routed the
button through BalWaitingDialog + TaskThread. Electrum's
Network.send_http_on_proxy behaves differently depending on the calling
thread, and on the user's setup the TaskThread path timed out ('No response
from the server'), while the original direct call worked fine.

FIX: WillExecutorWidget.download_list now performs the same direct,
synchronous download as the original, updates and saves the list, and shows a
warning only on genuine failure. The wizard download path (which the original
also ran via TaskThread) is left unchanged.

Compared against upstream original source (kaibot/bal-electrum-plugin):
send_request, handle_response, download_list core logic are byte-identical;
only the GUI call site is restored to the original behaviour.

* diag(gui): detailed download diagnostics + hardcoded-URL fallback

The will-executor download still times out on the user's setup even with the
direct (original-style) GUI-thread call, and the URL/request are byte-identical
to the working original. To pinpoint the real cause, the Download List button
now:
- logs whether a Network instance is present;
- tries the configured WELIST_SERVER URL AND falls back to the original
  hardcoded https://welist.bitcoin-after.life/ endpoint (so a stale/bad config
  value can't break it);
- shows the EXACT URL(s) tried and the precise exception per attempt in the
  warning popup instead of a generic timeout message.

bal/core networking remains unchanged.

* diag(gui): add direct-HTTPS control probe to download diagnostics

When the Electrum-network download fails, also run a plain urllib HTTPS GET
(bypassing Electrum's Network/proxy layer) and show its result in the popup.
This distinguishes a real connectivity/DNS/firewall problem from an
Electrum-network-state problem, so we can finally pinpoint why the request
times out only in this build.

* fix(gui): unify wizard + button download on one synchronous path with diagnostics

The 'No response from the server (timeout?)' popup was coming from the WIZARD
download path in window.py (BalWaitingDialog + TaskThread), which was never
switched to the original direct call - only the list button had been.

Both paths now share BalWindow.fetch_will_executors_list(): a direct,
synchronous GUI-thread download (like the original), trying the configured
server then the hardcoded fallback, with full diagnostics (exact URL/error per
attempt + a direct-HTTPS control probe) shown in the failure popup.

This both fixes the wizard timeout and guarantees the same diagnostic popup
('Details (via Electrum network)' + 'Direct connection test') regardless of
which UI entry point is used.

* fix(gui): clean up will-executor download (waiting dialog + simple message)

Root cause of the 'download not working' reports was environmental (the user's
network/ISP was resetting the connection to the IPv6/IPv4 host; a VPN fixes
it), NOT a plugin bug. Final cleanup of the diagnostic code:

- download_list (button + wizard) again uses BalWaitingDialog + TaskThread so
  the GUI is not frozen and shows a 'Downloading will-executors list...' dialog.
- Keep the configured + hardcoded-fallback server URLs and detailed per-attempt
  diagnostics, but write them to the Electrum log only.
- On failure the user now sees a simple English message explaining it is most
  likely a connection/firewall issue (a VPN often helps), instead of a technical
  timeout/exception dump.
- Removed the urllib control probe from the user-facing popup.

bal/core networking unchanged.

---------

Co-authored-by: GenSpark AI Developer <ai@genspark.dev>
This commit is contained in:
genspark-ai-developer[bot]
2026-06-13 14:04:52 +00:00
committed by steal
parent 4711f7de62
commit c8a9cbfc0a
9 changed files with 536 additions and 119 deletions

View File

@@ -254,7 +254,7 @@ class PreviewList(MyTreeView, MessageBoxMixin):
main_window=bal_window.window,
stretch_column=self.Columns.TXID,
)
# self.parent = parent
# self._bal_parent = parent
self.bal_window = bal_window
self.decimal_point = bal_window.window.get_decimal_point
@@ -528,7 +528,7 @@ class PreviewList(MyTreeView, MessageBoxMixin):
# class PreviewDialog(BalDialog, MessageBoxMixin):
# def __init__(self, bal_window, will):
# self.parent = bal_window.window
# self._bal_parent = bal_window.window
# BalDialog.__init__(
# self, bal_window=bal_window, bal_plugin=bal_window.bal_plugin
# )
@@ -644,7 +644,7 @@ class WillExecutorListWidget(MyTreeView):
self.Columns.INFO,
],
)
self.parent = parent
self._bal_parent = parent
try:
self.setModel(QStandardItemModel(self))
self.sortByColumn(self.Columns.SELECTED, Qt.SortOrder.AscendingOrder)
@@ -672,7 +672,7 @@ class WillExecutorListWidget(MyTreeView):
# self.model().itemFromIndex(s_idx).text()
# for s_idx in self.selected_in_column(column)
# )
if Willexecutors.is_selected(self.parent.willexecutors_list[sel_key]):
if Willexecutors.is_selected(self._bal_parent.willexecutors_list[sel_key]):
menu.addAction(
_("deselect").format(column_title),
lambda: self.deselect(selected_keys),
@@ -704,10 +704,10 @@ class WillExecutorListWidget(MyTreeView):
def ping_willexecutors(self, selected_keys):
wout = {}
for k in selected_keys:
wout[k] = self.parent.willexecutors_list[k]
self.parent.update_willexecutors(wout)
wout[k] = self._bal_parent.willexecutors_list[k]
self._bal_parent.update_willexecutors(wout)
self.parent.save_willexecutors()
self._bal_parent.save_willexecutors()
self.update()
def get_edit_key_from_coordinate(self, row, col):
@@ -717,49 +717,49 @@ class WillExecutorListWidget(MyTreeView):
def delete(self, selected_keys):
for key in selected_keys:
del self.parent.willexecutors_list[key]
del self._bal_parent.willexecutors_list[key]
self.parent.save_willexecutors()
self._bal_parent.save_willexecutors()
self.update()
def select(self, selected_keys):
for wid, w in self.parent.willexecutors_list.items():
for wid, w in self._bal_parent.willexecutors_list.items():
if wid in selected_keys:
w["selected"] = True
self.parent.save_willexecutors()
self._bal_parent.save_willexecutors()
self.update()
def deselect(self, selected_keys):
for wid, w in self.parent.willexecutors_list.items():
for wid, w in self._bal_parent.willexecutors_list.items():
if wid in selected_keys:
w["selected"] = False
self.parent.save_willexecutors()
self._bal_parent.save_willexecutors()
self.update()
def on_edited(self, idx, edit_key, *, text):
# prior_name = self.parent.willexecutors_list[edit_key]
# prior_name = self._bal_parent.willexecutors_list[edit_key]
col = idx.column()
try:
if col == self.Columns.URL:
self.parent.willexecutors_list[text] = self.parent.willexecutors_list[
self._bal_parent.willexecutors_list[text] = self._bal_parent.willexecutors_list[
edit_key
]
del self.parent.willexecutors_list[edit_key]
del self._bal_parent.willexecutors_list[edit_key]
if col == self.Columns.BASE_FEE:
self.parent.willexecutors_list[edit_key]["base_fee"] = (
self._bal_parent.willexecutors_list[edit_key]["base_fee"] = (
Util.encode_amount(text, self.get_decimal_point())
)
if col == self.Columns.ADDRESS:
self.parent.willexecutors_list[edit_key]["address"] = text
self._bal_parent.willexecutors_list[edit_key]["address"] = text
if col == self.Columns.INFO:
self.parent.willexecutors_list[edit_key]["info"] = text
self.parent.save_willexecutors()
self._bal_parent.willexecutors_list[edit_key]["info"] = text
self._bal_parent.save_willexecutors()
self.update()
except Exception:
pass
def update(self):
if self.parent.willexecutors_list is None:
if self._bal_parent.willexecutors_list is None:
return
try:
current_key = self.get_role_data_for_current_item(
@@ -770,14 +770,14 @@ class WillExecutorListWidget(MyTreeView):
set_current = None
for url, value in self.parent.willexecutors_list.items():
for url, value in self._bal_parent.willexecutors_list.items():
labels = [""] * len(self.Columns)
labels[self.Columns.URL] = url
if Willexecutors.is_selected(value):
labels[self.Columns.SELECTED] = [
read_QIcon_from_bytes(
self.parent.bal_plugin.read_file("icons/confirmed.png")
self._bal_parent.bal_plugin.read_file("icons/confirmed.png")
),
"",
]
@@ -789,7 +789,7 @@ class WillExecutorListWidget(MyTreeView):
if str(value.get("status", 0)) == "200":
labels[self.Columns.STATUS] = [
read_QIcon_from_bytes(
self.parent.bal_plugin.read_file(
self._bal_parent.bal_plugin.read_file(
"icons/status_connected.png"
)
),
@@ -798,7 +798,7 @@ class WillExecutorListWidget(MyTreeView):
else:
labels[self.Columns.STATUS] = [
read_QIcon_from_bytes(
self.parent.bal_plugin.read_file("icons/unconfirmed.png")
self._bal_parent.bal_plugin.read_file("icons/unconfirmed.png")
),
"",
]
@@ -850,7 +850,7 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
def __init__(self, parent, bal_window, willexecutors=None):
self.bal_window = bal_window
self.bal_plugin = bal_window.bal_plugin
self.parent = parent
self._bal_parent = parent
MessageBoxMixin.__init__(self)
QWidget.__init__(self, parent)
if willexecutors:
@@ -911,10 +911,17 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
self.will_executor_list_widget.update()
def download_list(self, wes=None):
if not wes:
wes = self.willexecutors_list
self.bal_window.download_list(wes, self.save_willexecutors)
self.update()
# Both this button and the wizard go through the same code path on
# BalWindow, which shows a "Downloading..." dialog (non-blocking GUI),
# tries the configured + fallback servers, logs the technical details
# and shows a simple message on failure.
def on_success(result):
self.willexecutors_list.update(result)
self.will_executor_list_widget.update()
Willexecutors.save(self.bal_window.bal_plugin, self.willexecutors_list)
self.update()
self.bal_window.download_list(self.bal_window.willexecutors, on_success)
def export_file(self, path):
export_meta_gui(