mirror of
https://github.com/migatu/vtt_work.git
synced 2026-07-14 13:34:42 +00:00
140 lines
4.7 KiB
Python
140 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Quick test to verify the arrange_plot_windows function improvements.
|
|
This script simulates the functionality without running the full nuclear monitor.
|
|
"""
|
|
|
|
import math
|
|
|
|
def test_best_grid():
|
|
"""Test the improved grid calculation"""
|
|
def best_grid(n):
|
|
if n <= 0:
|
|
return (1, 1)
|
|
# For small number of windows, prefer horizontal layout
|
|
if n <= 3:
|
|
return (1, n)
|
|
if n == 4:
|
|
return (2, 2)
|
|
|
|
# For larger numbers: approximate square, but prefer width
|
|
cols = int(math.ceil(math.sqrt(n)))
|
|
if cols * (cols - 1) >= n: # check if we can reduce rows
|
|
cols -= 1
|
|
rows = int(math.ceil(n / cols))
|
|
return (rows, cols)
|
|
|
|
test_cases = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16]
|
|
|
|
print("Grid layout tests:")
|
|
print("Windows | Grid (rows x cols) | Layout")
|
|
print("--------|-------------------|--------")
|
|
|
|
for n in test_cases:
|
|
rows, cols = best_grid(n)
|
|
layout = "x".join(["O"] * cols)
|
|
layout = " | ".join([layout] * rows)
|
|
print(f"{n:7d} | {rows:2d} x {cols:2d} | {layout}")
|
|
|
|
def test_window_padding():
|
|
"""Test the window-specific padding"""
|
|
def get_window_padding(kind):
|
|
if kind == "qt":
|
|
return (15, 40) # Qt needs more space for title bar
|
|
else:
|
|
return (8, 12) # Tk windows
|
|
|
|
print("\nWindow padding tests:")
|
|
print("Type | Width Pad | Height Pad | Reason")
|
|
print("-----|-----------|------------|--------")
|
|
|
|
for kind in ["tk", "qt"]:
|
|
w_pad, h_pad = get_window_padding(kind)
|
|
reason = "Qt title bar & frames" if kind == "qt" else "Tk decorations"
|
|
print(f"{kind:4s} | {w_pad:9d} | {h_pad:10d} | {reason}")
|
|
|
|
def test_arrangement_calculation():
|
|
"""Test the arrangement calculation for different scenarios"""
|
|
print("\nArrangement calculation test:")
|
|
|
|
# Simulate monitor: 1920x1080
|
|
mon_w, mon_h = 1920, 1080
|
|
SIDE_MARGIN = 12
|
|
TOP_MARGIN = 60
|
|
BOTTOM_MARGIN = 12
|
|
CELL_PAD = 10
|
|
MAX_W, MAX_H = 380, 210 # Half of 760x420
|
|
|
|
test_scenarios = [
|
|
(2, "Two windows - should be side by side"),
|
|
(4, "Four windows - 2x2 grid"),
|
|
(6, "Six windows - 2x3 or 3x2 grid"),
|
|
(9, "Nine windows - full screen mode"),
|
|
]
|
|
|
|
def best_grid(n):
|
|
if n <= 0:
|
|
return (1, 1)
|
|
if n <= 3:
|
|
return (1, n)
|
|
if n == 4:
|
|
return (2, 2)
|
|
cols = int(math.ceil(math.sqrt(n)))
|
|
if cols * (cols - 1) >= n:
|
|
cols -= 1
|
|
rows = int(math.ceil(n / cols))
|
|
return (rows, cols)
|
|
|
|
for n_windows, description in test_scenarios:
|
|
print(f"\n{description}")
|
|
print(f"Windows: {n_windows}")
|
|
|
|
rows, cols = best_grid(n_windows)
|
|
use_max_size = n_windows < 9
|
|
|
|
# Calculate available space
|
|
available_w = mon_w - (cols + 1) * CELL_PAD - 2 * SIDE_MARGIN
|
|
available_h = mon_h - (rows + 1) * CELL_PAD - TOP_MARGIN - BOTTOM_MARGIN
|
|
|
|
# Initial cell size
|
|
cell_w = max(1, available_w // cols)
|
|
cell_h = max(1, available_h // rows)
|
|
|
|
# Apply max size constraint for few windows
|
|
if use_max_size:
|
|
cell_w = min(MAX_W, cell_w)
|
|
cell_h = min(MAX_H, cell_h)
|
|
|
|
print(f"Grid: {rows}x{cols}")
|
|
print(f"Available space: {available_w}x{available_h}")
|
|
print(f"Cell size: {cell_w}x{cell_h}")
|
|
print(f"Max size applied: {use_max_size}")
|
|
|
|
# Test padding for different window types
|
|
for win_type in ["tk", "qt"]:
|
|
if win_type == "qt":
|
|
w_pad, h_pad = (15, 40)
|
|
else:
|
|
w_pad, h_pad = (8, 12)
|
|
|
|
adj_w = max(50, cell_w - w_pad)
|
|
adj_h = max(50, cell_h - h_pad)
|
|
print(f" {win_type} windows: {adj_w}x{adj_h} (after padding)")
|
|
|
|
if __name__ == "__main__":
|
|
print("Testing arrange_plot_windows improvements\n")
|
|
print("=" * 50)
|
|
|
|
test_best_grid()
|
|
test_window_padding()
|
|
test_arrangement_calculation()
|
|
|
|
print("\n" + "=" * 50)
|
|
print("All tests completed. The arrange_plot_windows function should now:")
|
|
print("1. ✅ Properly detect both Qt and matplotlib windows")
|
|
print("2. ✅ Use improved grid layout (prefer horizontal for few windows)")
|
|
print("3. ✅ Apply appropriate padding for different window types")
|
|
print("4. ✅ Arrange windows top-to-bottom, left-to-right")
|
|
print("5. ✅ Handle multiple displays correctly")
|
|
print("6. ✅ Scale down when windows don't fit")
|
|
print("7. ✅ Sort windows alphabetically by display name") |