Skip to content

Commit 5a762a4

Browse files
committed
Updated main window and tests
1 parent 71df89c commit 5a762a4

2 files changed

Lines changed: 46 additions & 34 deletions

File tree

dna2graph/gui/main_window.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def __init__(self):
4646
self.stop_event = mp.Event()
4747

4848
self._build_ui()
49+
self.update_idletasks()
50+
required_width = max(720, self.winfo_reqwidth())
51+
required_height = max(570, self.winfo_reqheight() + 10)
52+
self.geometry(f'{required_width}x{required_height}')
4953

5054
def _build_ui(self):
5155
# === Path Selectors ====
@@ -324,4 +328,4 @@ def _start_analysis(self):
324328
def open_feedback_email(self, event=None):
325329
webbrowser.open(
326330
f'mailto:{DEVELOPER_EMAIL}?subject=Feedback {APP_NAME}'
327-
)
331+
)

tests/test_gui.py

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,41 @@ def _find_button(parent, text):
2121
return None
2222

2323

24+
def _capture_window(window, output_path):
25+
try:
26+
window.deiconify()
27+
window.lift()
28+
window.attributes("-topmost", True)
29+
window.focus_force()
30+
window.update_idletasks()
31+
window.update()
32+
window.after(250)
33+
window.update()
34+
35+
left = window.winfo_rootx()
36+
top = window.winfo_rooty()
37+
right = left + window.winfo_width()
38+
bottom = top + window.winfo_height()
39+
40+
grab_options = {}
41+
if "DISPLAY" in os.environ:
42+
grab_options["xdisplay"] = os.environ["DISPLAY"]
43+
44+
screenshot = ImageGrab.grab(
45+
bbox=(left, top, right, bottom),
46+
**grab_options,
47+
)
48+
screenshot.save(output_path)
49+
window.attributes("-topmost", False)
50+
except Exception as error:
51+
warnings.warn(
52+
f"Unable to capture {output_path.name} on {sys.platform}: "
53+
f"{error}",
54+
RuntimeWarning,
55+
stacklevel=1,
56+
)
57+
58+
2459
def test_gui_opens(tmp_path):
2560
window = MainWindow()
2661

@@ -43,6 +78,11 @@ def test_gui_opens(tmp_path):
4378
assert advanced_window.winfo_exists()
4479
assert advanced_window.title() == "Advanced Preferences"
4580

81+
_capture_window(
82+
advanced_window,
83+
tmp_path / "dna2graph_advanced_preferences.png",
84+
)
85+
4686
cancel_button = _find_button(advanced_window, "Cancel")
4787
assert cancel_button is not None
4888

@@ -51,38 +91,6 @@ def test_gui_opens(tmp_path):
5191
window.update()
5292

5393
assert not advanced_window.winfo_exists()
54-
55-
try:
56-
window.deiconify()
57-
window.lift()
58-
window.attributes("-topmost", True)
59-
window.focus_force()
60-
window.update_idletasks()
61-
window.update()
62-
window.after(250)
63-
window.update()
64-
65-
left = window.winfo_rootx()
66-
top = window.winfo_rooty()
67-
right = left + window.winfo_width()
68-
bottom = top + window.winfo_height()
69-
70-
grab_options = {}
71-
if "DISPLAY" in os.environ:
72-
grab_options["xdisplay"] = os.environ["DISPLAY"]
73-
74-
screenshot = ImageGrab.grab(
75-
bbox=(left, top, right, bottom),
76-
**grab_options,
77-
)
78-
screenshot.save(tmp_path / "dna2graph_gui.png")
79-
window.attributes("-topmost", False)
80-
except Exception as error:
81-
warnings.warn(
82-
f"Unable to capture the GUI screenshot on {sys.platform}: "
83-
f"{error}",
84-
RuntimeWarning,
85-
stacklevel=1,
86-
)
94+
_capture_window(window, tmp_path / "dna2graph_gui.png")
8795
finally:
8896
window.destroy()

0 commit comments

Comments
 (0)