From 9d59ef34c780fa8324afbdaf1d9771767f10bca4 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Sun, 22 Jan 2017 00:54:20 +0000 Subject: [PATCH] Ensure popup windows are on-screen on Windows --- prefs.py | 9 +++++++++ stats.py | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/prefs.py b/prefs.py index 282ec41e..51db8c16 100644 --- a/prefs.py +++ b/prefs.py @@ -52,6 +52,8 @@ elif platform=='win32': class BROWSEINFO(ctypes.Structure): _fields_ = [("hwndOwner", HWND), ("pidlRoot", LPVOID), ("pszDisplayName", LPWSTR), ("lpszTitle", LPCWSTR), ("ulFlags", UINT), ("lpfn", BrowseCallbackProc), ("lParam", LPCWSTR), ("iImage", ctypes.c_int)] + CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition + CalculatePopupWindowPosition.argtypes = [ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT)] class PreferencesDialog(tk.Toplevel): @@ -311,6 +313,13 @@ class PreferencesDialog(tk.Toplevel): self.wait_visibility() self.grab_set() + # Ensure fully on-screen + if platform == 'win32': + position = RECT() + if CalculatePopupWindowPosition(POINT(parent.winfo_rootx(), parent.winfo_rooty()), + SIZE(self.winfo_width(), self.winfo_height()), + 0x10000, None, position): + self.geometry("+%d+%d" % (position.left, position.top)) def outvarchanged(self): self.displaypath(self.outdir, self.outdir_entry) diff --git a/stats.py b/stats.py index ae42394f..998b8afc 100644 --- a/stats.py +++ b/stats.py @@ -13,6 +13,11 @@ import companion from companion import ship_map import prefs +if platform=='win32': + import ctypes + from ctypes.wintypes import * + CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition + CalculatePopupWindowPosition.argtypes = [ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT)] RANKS = [ # in output order (_('Combat') , 'combat'), # Ranking @@ -257,6 +262,14 @@ class StatsResults(tk.Toplevel): self.wait_visibility() self.grab_set() + # Ensure fully on-screen + if platform == 'win32': + position = RECT() + if CalculatePopupWindowPosition(POINT(parent.winfo_rootx(), parent.winfo_rooty()), + SIZE(self.winfo_width(), self.winfo_height()), + 0x10000, None, position): + self.geometry("+%d+%d" % (position.left, position.top)) + def addpage(self, parent, header=[], align=None): page = nb.Frame(parent) page.grid(pady=10, sticky=tk.NSEW)