From da95b4c7abde5db1125bbcb68aba217f8c624090 Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Fri, 17 Oct 2025 11:00:11 +0200 Subject: [PATCH] sistemata visualizzazione dump Hex nella tab corretta --- target_simulator/gui/sfp_debug_window.py | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/target_simulator/gui/sfp_debug_window.py b/target_simulator/gui/sfp_debug_window.py index 8cbd461..1d8e226 100644 --- a/target_simulator/gui/sfp_debug_window.py +++ b/target_simulator/gui/sfp_debug_window.py @@ -875,6 +875,8 @@ class SfpDebugWindow(tk.Toplevel): desc = legend_map.get(name, "") out_lines.append(f" {name:12s}: {desc}\n") + # Build hex dump but do not insert it into the Raw tab; + # always show binary/body hex in the dedicated Binary tab. out_lines.append("\nBODY (hex):\n") hex_dump = self._format_hex_dump(body) out_lines.append(hex_dump) @@ -889,16 +891,23 @@ class SfpDebugWindow(tk.Toplevel): # Don't fail display on logging problems # pass - # Now display in the widget with visual tags where helpful. + # Display header/parsed fields in the Raw tab, but move the + # full hex/body dump into the Binary tab to centralize binary data. self.raw_tab_text.config(state=tk.NORMAL) self.raw_tab_text.delete("1.0", tk.END) - # Insert header block with hdr_field tag - header_block, _, rest = full_text.partition("\nBODY (hex):\n") + header_block, _, _ = full_text.partition("\nBODY (hex):\n") self.raw_tab_text.insert(tk.END, header_block + "\n", "hdr_field") - # For flags, re-insert with colored tags: simple approach, append the rest - self.raw_tab_text.insert(tk.END, "BODY (hex):\n") - self.raw_tab_text.insert(tk.END, hex_dump) self.raw_tab_text.config(state=tk.DISABLED) + + # Put the hex dump into the Binary tab + try: + self._display_hex_data(body, self.bin_tab) + except Exception: + # fallback: ensure binary tab contains something + self.bin_tab.config(state=tk.NORMAL) + self.bin_tab.delete("1.0", tk.END) + self.bin_tab.insert("1.0", hex_dump) + self.bin_tab.config(state=tk.DISABLED) return except Exception as e: text = f"Failed to format raw packet: {e}\n\nRaw dump:\n" @@ -985,7 +994,16 @@ class SfpDebugWindow(tk.Toplevel): ) setattr(self, photo_attr, None) - self._display_hex_data(payload, tab_widgets["hex_view"]) + # Always show binary/body hex in the dedicated Binary tab instead of + # attaching it to individual image tabs. + try: + self._display_hex_data(payload, self.bin_tab) + except Exception: + # best-effort fallback to the image tab hex_view if Binary tab isn't available + try: + self._display_hex_data(payload, tab_widgets["hex_view"]) + except Exception: + pass def _resize_pil_to_label( self, img: "Image.Image", label_widget: ttk.Label