tolto connect da ppi
This commit is contained in:
parent
03ac1c2ce5
commit
329d468794
@ -104,17 +104,39 @@ class MainView(tk.Tk):
|
||||
self.h_pane = ttk.PanedWindow(v_pane, orient=tk.HORIZONTAL)
|
||||
v_pane.add(self.h_pane, weight=4)
|
||||
|
||||
# --- Right Pane (PPI) ---
|
||||
self.ppi_widget = PPIDisplay(
|
||||
self.h_pane, max_range_nm=self.max_range, scan_limit_deg=self.scan_limit
|
||||
)
|
||||
self.h_pane.add(self.ppi_widget, weight=2)
|
||||
# --- Right Pane (connection panel + PPI) ---
|
||||
right_container = ttk.Frame(self.h_pane)
|
||||
self.h_pane.add(right_container, weight=2)
|
||||
|
||||
# Wire the PPI's built-in connect toggle to the MainView connect handler
|
||||
# Connection panel sits above the PPI on the right side and shows
|
||||
# current connection parameters and a centralized Connect/Disconnect button.
|
||||
conn_panel = ttk.LabelFrame(right_container, text="Connection")
|
||||
conn_panel.pack(side=tk.TOP, fill=tk.X, padx=5, pady=(5, 2))
|
||||
|
||||
# Display current connection summary (type / brief params)
|
||||
self.conn_type_var = tk.StringVar(value=self.connection_config.get("target", {}).get("type", "-"))
|
||||
self.conn_info_var = tk.StringVar(value=self._format_connection_summary(self.connection_config.get("target", {})))
|
||||
|
||||
ttk.Label(conn_panel, text="Type:").pack(side=tk.LEFT, padx=(6, 2))
|
||||
ttk.Label(conn_panel, textvariable=self.conn_type_var, width=10).pack(side=tk.LEFT)
|
||||
ttk.Label(conn_panel, textvariable=self.conn_info_var).pack(side=tk.LEFT, padx=(8, 4))
|
||||
|
||||
# Connect / Disconnect button centralised here
|
||||
self.connect_button = ttk.Button(conn_panel, text="Connect", command=self._on_connect_button)
|
||||
self.connect_button.pack(side=tk.RIGHT, padx=(4, 6))
|
||||
|
||||
# Open settings quick button
|
||||
self.conn_settings_button = ttk.Button(conn_panel, text="Settings...", command=self._open_settings)
|
||||
self.conn_settings_button.pack(side=tk.RIGHT, padx=(4, 0))
|
||||
|
||||
# Now the PPI widget below the connection panel
|
||||
self.ppi_widget = PPIDisplay(
|
||||
right_container, max_range_nm=self.max_range, scan_limit_deg=self.scan_limit
|
||||
)
|
||||
self.ppi_widget.pack(side=tk.TOP, fill=tk.BOTH, expand=True, padx=2, pady=(2, 5))
|
||||
|
||||
# Reflect initial connection state (likely disconnected)
|
||||
try:
|
||||
if hasattr(self.ppi_widget, "set_connect_callback"):
|
||||
self.ppi_widget.set_connect_callback(self._on_connect_button)
|
||||
# Reflect initial connection state (likely disconnected)
|
||||
if hasattr(self.ppi_widget, "update_connect_state"):
|
||||
self.ppi_widget.update_connect_state(False)
|
||||
except Exception:
|
||||
@ -363,6 +385,34 @@ class MainView(tk.Tk):
|
||||
else:
|
||||
self.title(base_title)
|
||||
|
||||
def _format_connection_summary(self, cfg: dict) -> str:
|
||||
"""Return a short human-readable summary of the target connection config.
|
||||
|
||||
This is used by the connection panel to show relevant info without
|
||||
opening the full settings dialog.
|
||||
"""
|
||||
try:
|
||||
t = cfg.get("type")
|
||||
if not t:
|
||||
return "-"
|
||||
if t == "sfp":
|
||||
sfp = cfg.get("sfp", {})
|
||||
ip = sfp.get("ip") or sfp.get("host") or "?"
|
||||
port = sfp.get("port") or sfp.get("remote_port") or "?"
|
||||
return f"{ip}:{port}"
|
||||
if t == "serial":
|
||||
s = cfg.get("serial", {})
|
||||
port = s.get("port") or s.get("device") or "?"
|
||||
baud = s.get("baudrate") or s.get("baud") or "?"
|
||||
return f"{port} @{baud}"
|
||||
if t == "tftp":
|
||||
tftp = cfg.get("tftp", {})
|
||||
host = tftp.get("host") or tftp.get("server") or "?"
|
||||
return f"{host}"
|
||||
return "-"
|
||||
except Exception:
|
||||
return "-"
|
||||
|
||||
def _update_communicator_status(self, comm_name: str, is_connected: bool):
|
||||
canvas = (
|
||||
self.target_status_canvas
|
||||
@ -377,9 +427,20 @@ class MainView(tk.Tk):
|
||||
self.logger.info(f"MainView received connection state change: Connected={is_connected}")
|
||||
self._update_communicator_status("Target", is_connected)
|
||||
|
||||
if hasattr(self.ppi_widget, 'update_connect_state'):
|
||||
self.ppi_widget.update_connect_state(is_connected)
|
||||
|
||||
# Update the PPI's internal state (visual only) and the debug window
|
||||
try:
|
||||
if hasattr(self.ppi_widget, 'update_connect_state'):
|
||||
self.ppi_widget.update_connect_state(is_connected)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Update centralized connect button text and status indicator
|
||||
try:
|
||||
if hasattr(self, 'connect_button') and self.connect_button:
|
||||
self.connect_button.config(text="Disconnect" if is_connected else "Connect")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Also update the debug window if it's open
|
||||
if self.sfp_debug_window and self.sfp_debug_window.winfo_exists():
|
||||
if hasattr(self.sfp_debug_window, 'update_toggle_state'):
|
||||
@ -440,6 +501,14 @@ class MainView(tk.Tk):
|
||||
self.logger.info(f"Updating connection settings: {new_config}")
|
||||
self.connection_config = new_config
|
||||
self.config_manager.save_connection_settings(new_config)
|
||||
# Refresh connection summary in the connection panel
|
||||
try:
|
||||
if hasattr(self, 'conn_type_var'):
|
||||
self.conn_type_var.set(self.connection_config.get("target", {}).get("type", "-"))
|
||||
if hasattr(self, 'conn_info_var'):
|
||||
self.conn_info_var.set(self._format_connection_summary(self.connection_config.get("target", {})))
|
||||
except Exception:
|
||||
pass
|
||||
self._initialize_communicators()
|
||||
|
||||
def _open_settings(self):
|
||||
|
||||
@ -84,11 +84,12 @@ class PPIDisplay(ttk.Frame):
|
||||
self.range_selector.pack(side=tk.LEFT, padx=5)
|
||||
self.range_selector.bind("<<ComboboxSelected>>", self._on_range_selected)
|
||||
|
||||
# Connection toggle (Connect / Disconnect) for SFP
|
||||
# NOTE: Connection controls were removed from the PPI display to
|
||||
# keep this widget purely visual. Connection state is still
|
||||
# exposed via the API below so MainView or other windows can
|
||||
# register callbacks or push state changes here.
|
||||
self._connect_callback = None
|
||||
self._is_connected = False
|
||||
self.connect_btn = ttk.Button(self.controls_frame, text="Connect", command=self._on_connect_btn)
|
||||
self.connect_btn.pack(side=tk.RIGHT, padx=10)
|
||||
|
||||
# --- Display Options ---
|
||||
options_frame = ttk.LabelFrame(top_frame, text="Display Options")
|
||||
@ -230,56 +231,23 @@ class PPIDisplay(ttk.Frame):
|
||||
|
||||
self.canvas.draw_idle()
|
||||
|
||||
# --- Connection toggle API ---
|
||||
def _on_connect_btn(self):
|
||||
if callable(self._connect_callback):
|
||||
try:
|
||||
self._connect_callback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# --- Connection state API (PPI remains visual only) ---
|
||||
def set_connect_callback(self, cb):
|
||||
"""Register a callback to be executed when the PPI Connect button is pressed.
|
||||
"""Register a callback. Kept for backward compatibility.
|
||||
|
||||
The callback should handle connecting/disconnecting logic at the application level.
|
||||
Note: the PPI no longer exposes a connect button. This method
|
||||
only stores the callback so higher-level UI can reuse the same
|
||||
handler if desired.
|
||||
"""
|
||||
self._connect_callback = cb
|
||||
|
||||
def update_connect_state(self, is_connected: bool):
|
||||
"""Update the Connect button label/state to reflect current connection status."""
|
||||
try:
|
||||
self._is_connected = bool(is_connected)
|
||||
if self._is_connected:
|
||||
self.connect_btn.config(text="Disconnect")
|
||||
else:
|
||||
self.connect_btn.config(text="Connect")
|
||||
except Exception:
|
||||
pass
|
||||
"""Update the internal connection state. Does not alter any widgets.
|
||||
|
||||
# --- Connection toggle API ---
|
||||
def _on_connect_btn(self):
|
||||
if callable(self._connect_callback):
|
||||
try:
|
||||
self._connect_callback()
|
||||
except Exception:
|
||||
# Allow caller to handle exceptions and update state
|
||||
pass
|
||||
|
||||
def set_connect_callback(self, cb):
|
||||
"""Register a callback to be executed when the PPI Connect button is pressed.
|
||||
|
||||
The callback should handle connecting/disconnecting logic at the application level.
|
||||
MainView is responsible for showing connect/disconnect controls.
|
||||
"""
|
||||
self._connect_callback = cb
|
||||
|
||||
def update_connect_state(self, is_connected: bool):
|
||||
"""Update the Connect button label/state to reflect current connection status."""
|
||||
try:
|
||||
self._is_connected = bool(is_connected)
|
||||
if self._is_connected:
|
||||
self.connect_btn.config(text="Disconnect")
|
||||
else:
|
||||
self.connect_btn.config(text="Connect")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user