Private
Public Access
refactor(gui_2): migrate L1222 _show_menus is_max to Result[T] (Phase 3)
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3. Adds _show_menus_is_max_result(app, hwnd) -> Result[bool] helper that wraps the win32gui.GetWindowPlacement try/except from App._show_menus. The data field carries the is_max value (True iff window is maximized, False on failure) so the legacy wrapper can use it without an additional instance attribute. App._show_menus becomes a thin wrapper that drains errors to _last_request_errors when GetWindowPlacement fails. Audit: BROAD_CATCH count 20 -> 19, COMPLIANT count 17 -> 18. Tests: 2/2 pass.
This commit is contained in:
+32
-3
@@ -1211,9 +1211,11 @@ class App:
|
||||
win32gui.SendMessage(hwnd, win32con.WM_NCLBUTTONDOWN, win32con.HTCAPTION, 0)
|
||||
|
||||
imgui.push_style_color(imgui.Col_.button, imgui.ImVec4(0, 0, 0, 0))
|
||||
#Note(Ed): Exception(Thirdparty)
|
||||
try: is_max = win32gui.GetWindowPlacement(hwnd)[1] == win32con.SW_SHOWMAXIMIZED
|
||||
except Exception: is_max = False
|
||||
result = _show_menus_is_max_result(self, hwnd)
|
||||
if not result.ok:
|
||||
if not hasattr(self, '_last_request_errors'): self._last_request_errors = []
|
||||
self._last_request_errors.append(("_show_menus.is_max", result.errors[0]))
|
||||
is_max = result.data
|
||||
# Explicitly set Y to 0 and match button height to bar height for perfect alignment
|
||||
imgui.set_cursor_pos((right_x, 0))
|
||||
if imgui.button("_", (btn_w, bar_h)): win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
|
||||
@@ -7554,6 +7556,33 @@ def _show_menus_hwnd_result(app: "App") -> Result[int]:
|
||||
original=e,
|
||||
)])
|
||||
|
||||
def _show_menus_is_max_result(app: "App", hwnd) -> Result[bool]:
|
||||
"""Drain-aware variant of L1222 _show_menus GetWindowPlacement try/except.
|
||||
|
||||
Extracts the win32gui.GetWindowPlacement try/except from App._show_menus
|
||||
into a Result-returning helper. On success, returns Result(data=is_max)
|
||||
where is_max is True iff the window is currently maximized. On
|
||||
failure, returns Result(data=False, errors=[ErrorInfo]) - the data
|
||||
defaults to False (not maximized) matching the original except
|
||||
branch behavior.
|
||||
|
||||
[C: src/gui_2.py:App._show_menus (L1222 legacy wrapper)]
|
||||
"""
|
||||
global win32gui, win32con
|
||||
try:
|
||||
if win32gui is None:
|
||||
import win32gui
|
||||
import win32con
|
||||
is_max = win32gui.GetWindowPlacement(hwnd)[1] == win32con.SW_SHOWMAXIMIZED
|
||||
return Result(data=is_max)
|
||||
except Exception as e:
|
||||
return Result(data=False, errors=[ErrorInfo(
|
||||
kind=ErrorKind.INTERNAL,
|
||||
message=f"GetWindowPlacement failed for hwnd={hwnd}: {e}",
|
||||
source="gui_2._show_menus_is_max_result",
|
||||
original=e,
|
||||
)])
|
||||
|
||||
#endregion: Phase 3 Render-Loop Result Helpers
|
||||
|
||||
#endregion: MMA
|
||||
|
||||
Reference in New Issue
Block a user