From a6ce9edc1d0be4e2d9cedb1efe2837631832cb1f Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Wed, 19 Jun 2019 12:09:26 +0100 Subject: [PATCH] Fix running under Wine --- prefs.py | 17 ++++++++++------- protocol.py | 14 ++++++++++---- stats.py | 18 ++++++++++-------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/prefs.py b/prefs.py index 0512dabb..5096d194 100644 --- a/prefs.py +++ b/prefs.py @@ -52,12 +52,15 @@ 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)] - GetParent = ctypes.windll.user32.GetParent - GetParent.argtypes = [HWND] - GetWindowRect = ctypes.windll.user32.GetWindowRect - GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] - CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition - CalculatePopupWindowPosition.argtypes = [ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT)] + try: + CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition + CalculatePopupWindowPosition.argtypes = [ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT)] + GetParent = ctypes.windll.user32.GetParent + GetParent.argtypes = [HWND] + GetWindowRect = ctypes.windll.user32.GetWindowRect + GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] + except: # Not supported under Wine 4.0 + CalculatePopupWindowPosition = None class PreferencesDialog(tk.Toplevel): @@ -305,7 +308,7 @@ class PreferencesDialog(tk.Toplevel): self.grab_set() # Ensure fully on-screen - if platform == 'win32': + if platform == 'win32' and CalculatePopupWindowPosition: position = RECT() GetWindowRect(GetParent(self.winfo_id()), position) if CalculatePopupWindowPosition(POINT(parent.winfo_rootx(), parent.winfo_rooty()), diff --git a/protocol.py b/protocol.py index 21d88819..2c28e2cc 100644 --- a/protocol.py +++ b/protocol.py @@ -8,6 +8,15 @@ import sys from config import appname +if sys.platform == 'win32': + from ctypes import * + from ctypes.wintypes import * + try: + is_wine = windll.ntdll.wine_get_version + except: + is_wine = False + + class GenericProtocolHandler: def __init__(self): @@ -62,10 +71,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): protocolhandler.master.after(ProtocolHandler.POLL, protocolhandler.poll) -elif sys.platform == 'win32' and getattr(sys, 'frozen', False): - - from ctypes import * - from ctypes.wintypes import * +elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine: class WNDCLASS(Structure): _fields_ = [('style', UINT), diff --git a/stats.py b/stats.py index 6b405785..a5bd1ac9 100644 --- a/stats.py +++ b/stats.py @@ -19,13 +19,15 @@ import prefs if platform=='win32': import ctypes from ctypes.wintypes import * - GetParent = ctypes.windll.user32.GetParent - GetParent.argtypes = [HWND] - GetWindowRect = ctypes.windll.user32.GetWindowRect - GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] - CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition - CalculatePopupWindowPosition.argtypes = [ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT)] - + try: + CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition + CalculatePopupWindowPosition.argtypes = [ctypes.POINTER(POINT), ctypes.POINTER(SIZE), UINT, ctypes.POINTER(RECT), ctypes.POINTER(RECT)] + GetParent = ctypes.windll.user32.GetParent + GetParent.argtypes = [HWND] + GetWindowRect = ctypes.windll.user32.GetWindowRect + GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)] + except: # Not supported under Wine 4.0 + CalculatePopupWindowPosition = None def status(data): @@ -270,7 +272,7 @@ class StatsResults(tk.Toplevel): self.grab_set() # Ensure fully on-screen - if platform == 'win32': + if platform == 'win32' and CalculatePopupWindowPosition: position = RECT() GetWindowRect(GetParent(self.winfo_id()), position) if CalculatePopupWindowPosition(POINT(parent.winfo_rootx(), parent.winfo_rooty()),