dark compact theme

This commit is contained in:
2025-07-26 00:02:25 -04:00
parent d77dd386f3
commit e9573d0e5f
6 changed files with 1244 additions and 387 deletions

View File

@@ -288,7 +288,9 @@ class Chapter10SignalDecoder:
data_array = data_array * gain + offset
# Generate timestamps (would be more sophisticated in real implementation)
sample_rate = self.tmats_metadata.sample_rate if self.tmats_metadata else 1000.0
sample_rate = 1000.0 # Default sample rate
if self.tmats_metadata and self.tmats_metadata.sample_rate and self.tmats_metadata.sample_rate > 0:
sample_rate = self.tmats_metadata.sample_rate
timestamps = np.arange(len(data_array)) / sample_rate
channel_name = f"CH{channel_id}"
@@ -320,7 +322,10 @@ class Chapter10SignalDecoder:
data_array = np.array(samples, dtype=np.float32)
sample_rate = self.tmats_metadata.sample_rate if self.tmats_metadata else 1000.0
# Use default sample rate if TMATS doesn't provide one
sample_rate = 1000.0 # Default sample rate
if self.tmats_metadata and self.tmats_metadata.sample_rate and self.tmats_metadata.sample_rate > 0:
sample_rate = self.tmats_metadata.sample_rate
timestamps = np.arange(len(data_array)) / sample_rate
channel_name = f"PCM_CH{channel_id}"
@@ -350,17 +355,16 @@ class SignalVisualizer:
def visualize_flow_signals(self, flow: 'FlowStats', packets: List['Packet'], gui_mode: bool = False) -> None:
"""Visualize signals from a Chapter 10 flow"""
# Lazy load matplotlib with appropriate backend
# IMPORTANT: For GUI mode with embedded plots, this method should NOT be called
# Embedded plots should use the _extract methods directly
if gui_mode:
# For GUI mode, use Qt backend for embedded plots
if not _ensure_matplotlib_loaded('Qt5Agg'):
print("Matplotlib not available - cannot visualize signals")
return
else:
# For TUI mode, use Agg backend to avoid GUI windows
if not _ensure_matplotlib_loaded():
print("Matplotlib not available - cannot visualize signals")
return
print("WARNING: visualize_flow_signals called in GUI mode - should use embedded plots instead")
return # Don't create floating windows in GUI mode
# For TUI mode, use Agg backend to avoid GUI windows
if not _ensure_matplotlib_loaded():
print("Matplotlib not available - cannot visualize signals")
return
flow_key = f"{flow.src_ip}->{flow.dst_ip}"
@@ -482,7 +486,9 @@ class SignalVisualizer:
else:
# Subsequent signals - add time offset to create continuous timeline
if len(all_timestamps) > 0:
time_offset = all_timestamps[-1] + (1.0 / signal_data.sample_rate)
# Use safe sample rate (avoid division by None or zero)
safe_sample_rate = signal_data.sample_rate if signal_data.sample_rate and signal_data.sample_rate > 0 else 1000.0
time_offset = all_timestamps[-1] + (1.0 / safe_sample_rate)
# Add offset timestamps
offset_timestamps = signal_data.timestamps + time_offset
@@ -596,9 +602,10 @@ class SignalVisualizer:
print(f"Signal plot saved to {filename}")
plt.close(fig)
else:
# Store reference and show interactively (GUI mode)
# Store reference but DO NOT show for GUI mode embedded plots
# GUI mode should only use embedded widgets, not floating windows
self.active_windows[flow_key] = fig
plt.show()
# Do not call plt.show() - this should only be used for TUI mode file output
except Exception as e:
print(f"Signal visualization error: {e}")