From ab9b32d63b442d953095c80bfb42f2f1421c08d1 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 18 Mar 2024 23:07:56 -0400 Subject: [PATCH] Stop building and alias winxpgui --- AutoDuck/pywin32.mak | 1 - AutoDuck/winxpgui.d | 3 -- com/win32com/demos/ietoolbar.py | 32 +++++------- com/win32com/server/register.py | 12 ++--- .../shell/demos/servers/folder_view.py | 3 +- mypy.ini | 2 +- pycln.toml | 37 +++++++------- setup.py | 51 +------------------ win32/Demos/win32gui_dialog.py | 21 ++------ win32/Demos/win32gui_menu.py | 10 +--- win32/src/_winxptheme.i | 1 - win32/src/win32gui.i | 27 +--------- win32/src/winxpgui.manifest | 23 --------- win32/src/winxpgui.rc | 2 - win32/winxpgui.py | 17 +++++++ 15 files changed, 64 insertions(+), 178 deletions(-) delete mode 100644 AutoDuck/winxpgui.d delete mode 100644 win32/src/winxpgui.manifest delete mode 100644 win32/src/winxpgui.rc create mode 100644 win32/winxpgui.py diff --git a/AutoDuck/pywin32.mak b/AutoDuck/pywin32.mak index 9ab4500cc..31626a2ad 100644 --- a/AutoDuck/pywin32.mak +++ b/AutoDuck/pywin32.mak @@ -46,7 +46,6 @@ WIN32_SOURCE = $(WIN32_SOURCE_DIR)/*.cpp \ $(GENDIR)/win32process.d $(GENDIR)/wincerapi.d $(GENDIR)/win32gui.d \ $(GENDIR)/win32inet.d $(GENDIR)/_winxptheme.d \ $(GENDIR)/win32job.d \ - winxpgui.d WIN32COM_SOURCE = \ $(WIN32COM_DIR)\src\*.cpp \ diff --git a/AutoDuck/winxpgui.d b/AutoDuck/winxpgui.d deleted file mode 100644 index 78f33f9f1..000000000 --- a/AutoDuck/winxpgui.d +++ /dev/null @@ -1,3 +0,0 @@ -// @doc -// @module winxpgui|A version of built specifically for -// Windows XP. See the module for more details. diff --git a/com/win32com/demos/ietoolbar.py b/com/win32com/demos/ietoolbar.py index b520dcdad..443760c44 100644 --- a/com/win32com/demos/ietoolbar.py +++ b/com/win32com/demos/ietoolbar.py @@ -15,34 +15,26 @@ to catch WM_COMMAND messages. """ +import array +import struct + # imports section import sys import winreg +import commctrl import pythoncom import win32com -from win32com import universal -from win32com.axcontrol import axcontrol -from win32com.client import Dispatch, DispatchWithEvents, constants, gencache, getevents -from win32com.shell import shell -from win32com.shell.shellcon import * - -try: - # try to get styles (winxp) - import winxpgui as win32gui -except: - # import default module (win2k and lower) - import win32gui - -import array -import struct - -import commctrl import win32con +import win32gui import win32ui +from win32com.axcontrol import axcontrol +from win32com.client import Dispatch, gencache +from win32com.shell import shell +from win32com.shell.shellcon import DBIMF_VARIABLEHEIGHT # ensure we know the ms internet controls typelib so we have access to IWebBrowser2 later on -win32com.client.gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1) +gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1) # IDeskBand_methods = ["GetBandInfo"] @@ -252,7 +244,7 @@ def SetSite(self, unknown): # then travel over to a service provider serviceprovider = cmdtarget.QueryInterface(pythoncom.IID_IServiceProvider) # finally ask for the internet explorer application, returned as a dispatch object - self.webbrowser = win32com.client.Dispatch( + self.webbrowser = Dispatch( serviceprovider.QueryService( "{0002DF05-0000-0000-C000-000000000046}", pythoncom.IID_IDispatch ) @@ -326,7 +318,7 @@ def DllRegisterServer(): winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar" ) subKey = winreg.SetValueEx( - hkey, comclass._reg_clsid_, 0, winreg.REG_BINARY, "\0" + hkey, comclass._reg_clsid_, 0, winreg.REG_BINARY, b"\0" ) except OSError: print( diff --git a/com/win32com/server/register.py b/com/win32com/server/register.py index ad3813317..a35d48a3f 100644 --- a/com/win32com/server/register.py +++ b/com/win32com/server/register.py @@ -544,9 +544,9 @@ def UnregisterInfoClasses(*classes, **flags): def ReExecuteElevated(flags): import tempfile + import win32console import win32event # we've already checked we are running XP above import win32process - import winxpgui from win32com.shell import shellcon from win32com.shell.shell import ShellExecuteEx @@ -560,12 +560,10 @@ def ReExecuteElevated(flags): # specifying the parent means the dialog is centered over our window, # which is a good usability clue. # hwnd is unlikely on the command-line, but flags may come from elsewhere - hwnd = flags.get("hwnd", None) - if hwnd is None: - try: - hwnd = winxpgui.GetConsoleWindow() - except winxpgui.error: - hwnd = 0 + try: + hwnd = flags.get("hwnd", win32console.GetConsoleWindow()) + except win32console.error: + hwnd = 0 # Redirect output so we give the user some clue what went wrong. This # also means we need to use COMSPEC. However, the "current directory" # appears to end up ignored - so we execute things via a temp batch file. diff --git a/com/win32comext/shell/demos/servers/folder_view.py b/com/win32comext/shell/demos/servers/folder_view.py index e50efbe23..f7e8436e1 100644 --- a/com/win32comext/shell/demos/servers/folder_view.py +++ b/com/win32comext/shell/demos/servers/folder_view.py @@ -14,14 +14,13 @@ import pythoncom import win32api import win32con +import win32gui import winerror -import winxpgui as win32gui # the needs vista, let alone xp! from win32com.axcontrol import axcontrol # IObjectWithSite from win32com.propsys import propsys from win32com.server.exception import COMException from win32com.server.util import NewEnum as _NewEnum, wrap as _wrap from win32com.shell import shell, shellcon -from win32com.util import IIDToInterfaceName GUID = pythoncom.MakeIID diff --git a/mypy.ini b/mypy.ini index 9055b8492..5b4fb007a 100644 --- a/mypy.ini +++ b/mypy.ini @@ -27,7 +27,7 @@ disable_error_code = attr-defined, method-assign, name-defined exclude = .*((build|adodbapi|Pythonwin/Scintilla|Pythonwin/pywin/idle|[Tt]est|[Dd]emos?)/.*|rasutil.py|setup.py) ; C-modules that will need type-stubs -[mypy-adsi.*,dde,exchange,exchdapi,perfmon,servicemanager,win32api,win32clipboard,win32event,win32evtlog,win32file,win32gui,win32help,win32pdh,win32process,win32ras,win32security,win32service,win32trace,win32ui,win32uiole,win32wnet,wincerapi,winxpgui,_win32sysloader,_winxptheme] +[mypy-adsi.*,dde,exchange,exchdapi,perfmon,servicemanager,win32api,win32console,win32clipboard,win32event,win32evtlog,win32file,win32gui,win32help,win32pdh,win32process,win32ras,win32security,win32service,win32trace,win32ui,win32uiole,win32wnet,wincerapi,_win32sysloader,_winxptheme] ignore_missing_imports = True ; verstamp is installed from win32verstamp.py called in setup.py diff --git a/pycln.toml b/pycln.toml index 49e81c8a1..31a03ec78 100644 --- a/pycln.toml +++ b/pycln.toml @@ -2,23 +2,22 @@ # Many imports with side-effects all = false skip_imports = [ - # Star imported C wrapped modules - "_winxptheme", - "dde", - "ntsecuritycon", - "odbc", - "win32api", - "win32clipboard", - "win32com", - "win32cryptcon", - "win32event", - "win32file", - "win32gui_struct", - "win32gui", - "win32inet", - "win32inetcon", - "win32pipe", - "win32ras", - "win32ui", - "winxpgui", + # Star imported C wrapped modules + "_winxptheme", + "dde", + "ntsecuritycon", + "odbc", + "win32api", + "win32clipboard", + "win32com", + "win32cryptcon", + "win32event", + "win32file", + "win32gui_struct", + "win32gui", + "win32inet", + "win32inetcon", + "win32pipe", + "win32ras", + "win32ui", ] diff --git a/setup.py b/setup.py index 4181b0f4d..6b68def8a 100644 --- a/setup.py +++ b/setup.py @@ -51,10 +51,6 @@ else: from distutils.dep_util import newer_group -# some modules need a static CRT to avoid problems caused by them having a -# manifest. -static_crt_modules = ["winxpgui"] - build_id_patch = build_id if not "." in build_id_patch: build_id_patch = build_id_patch + ".0" @@ -404,11 +400,6 @@ def _why_cant_build_extension(self, ext): if ext.name == "axdebug" and sys.version_info > (3, 10): return "AXDebug no longer builds on 3.11 and up" - # winxpgui cannot be build for win-arm64 due to manifest file conflicts - # skip extension as we probably don't want this extension for win-arm64 platforms - if self.plat_name == "win-arm64" and ext.name == "winxpgui": - return "winxpgui extension cannot be build for win-arm64" - include_dirs = self.compiler.include_dirs + os.environ.get("INCLUDE", "").split( os.pathsep ) @@ -728,12 +719,6 @@ def build_extension(self, ext): # with special defines. So we cannot use a shared # directory for objects, we must use a special one for each extension. old_build_temp = self.build_temp - want_static_crt = ext.name in static_crt_modules - if want_static_crt: - self.compiler.compile_options.remove("/MD") - self.compiler.compile_options.append("/MT") - self.compiler.compile_options_debug.remove("/MDd") - self.compiler.compile_options_debug.append("/MTd") try: build_ext.build_extension(self, ext) @@ -769,11 +754,6 @@ def build_extension(self, ext): self.copy_file(src, dst) finally: self.build_temp = old_build_temp - if want_static_crt: - self.compiler.compile_options.remove("/MT") - self.compiler.compile_options.append("/MD") - self.compiler.compile_options_debug.remove("/MTd") - self.compiler.compile_options_debug.append("/MDd") def get_ext_filename(self, name): # We need to fixup some target filenames. @@ -822,17 +802,6 @@ def swig_sources(self, sources, ext=None): # Patch up the filenames for various special cases... if os.path.basename(base) in swig_interface_parents: swig_targets[source] = base + target_ext - elif ( - self.current_extension.name == "winxpgui" - and os.path.basename(base) == "win32gui" - ): - # More vile hacks. winxpmodule is built from win32gui.i - - # just different #defines are setup for windows.h. - new_target = os.path.join( - os.path.dirname(base), f"winxpgui_swig{target_ext}" - ) - swig_targets[source] = new_target - new_sources.append(new_target) else: new_target = f"{base}_swig{target_ext}" new_sources.append(new_target) @@ -1065,9 +1034,6 @@ def spawn(self, cmd): return if is_link: # remove /MANIFESTFILE:... and add MANIFEST:NO - # (but note that for winxpgui, which specifies a manifest via a - # .rc file, this is ignored by the linker - the manifest specified - # in the .rc file is still added) for i in range(len(cmd)): if cmd[i].startswith(("/MANIFESTFILE:", "/MANIFEST:EMBED")): cmd[i] = "/MANIFEST:NO" @@ -1328,19 +1294,6 @@ def finalize_options(self): libraries="gdi32 user32 comdlg32 comctl32 shell32", define_macros=[("WIN32GUI", None)], ), - # winxpgui is built from win32gui.i, but sets up different #defines before - # including windows.h. It also has an XP style manifest. - WinExt_win32( - "winxpgui", - sources=""" - win32/src/winxpgui.rc win32/src/win32dynamicdialog.cpp - win32/src/win32gui.i - """.split(), - libraries="gdi32 user32 comdlg32 comctl32 shell32", - windows_h_version=0x0500, - define_macros=[("WIN32GUI", None), ("WINXPGUI", None)], - extra_swig_commands=["-DWINXPGUI"], - ), # winxptheme WinExt_win32( "_winxptheme", @@ -2230,7 +2183,7 @@ def convert_optional_data_files(files): "adodbapi", ] -py_modules = expand_modules("win32\\lib") +py_modules = [*expand_modules("win32\\lib"), "win32\\winxpgui"] ext_modules = ( win32_extensions + com_extensions + pythonwin_extensions + other_extensions ) @@ -2421,7 +2374,7 @@ def maybe_fixup_exes(): # Print the list of extension modules we skipped building. excluded_extensions = dist.command_obj["build_ext"].excluded_extensions if excluded_extensions: - skip_whitelist = {"exchdapi", "exchange", "axdebug", "winxpgui"} + skip_whitelist = {"exchdapi", "exchange", "axdebug"} skipped_ex = [] print("*** NOTE: The following extensions were NOT %s:" % what_string) for ext, why in excluded_extensions: diff --git a/win32/Demos/win32gui_dialog.py b/win32/Demos/win32gui_dialog.py index 522cac6de..40ff8bbbe 100644 --- a/win32/Demos/win32gui_dialog.py +++ b/win32/Demos/win32gui_dialog.py @@ -5,21 +5,7 @@ # * Uses a ListView control. # * Dynamically resizes content. # * Uses a second worker thread to fill the list. -# * Demostrates support for windows XP themes. - -# If you are on Windows XP, and specify a '--noxp' argument, you will see: -# * alpha-blend issues with icons -# * The buttons are "old" style, rather than based on the XP theme. -# Hence, using: -# import winxpgui as win32gui -# is recommended. -# Please report any problems. -import sys - -if "--noxp" in sys.argv: - import win32gui -else: - import winxpgui as win32gui +# * Demonstrates support for windows XP themes. import array import os @@ -29,6 +15,7 @@ import commctrl import win32api import win32con +import win32gui import win32gui_struct import winerror @@ -261,8 +248,8 @@ def _SetupList(self): ) # Add an image list - use the builtin shell folder icon - this - # demonstrates the problem with alpha-blending of icons on XP if - # winxpgui is not used in place of win32gui. + # demonstrates that the problem with alpha-blending of icons + # present on XP is not a problem anymore. il = win32gui.ImageList_Create( win32api.GetSystemMetrics(win32con.SM_CXSMICON), win32api.GetSystemMetrics(win32con.SM_CYSMICON), diff --git a/win32/Demos/win32gui_menu.py b/win32/Demos/win32gui_menu.py index 38c4827eb..4b9b71dd0 100644 --- a/win32/Demos/win32gui_menu.py +++ b/win32/Demos/win32gui_menu.py @@ -8,20 +8,14 @@ # * No support for GetMenuItemInfo. # Based on Andy McKay's demo code. -from win32api import * - -# Try and use XP features, so we get alpha-blending etc. -try: - from winxpgui import * -except ImportError: - from win32gui import * -import array import os import struct import sys import win32con +from win32api import * +from win32gui import * from win32gui_struct import * this_dir = os.path.split(sys.argv[0])[0] diff --git a/win32/src/_winxptheme.i b/win32/src/_winxptheme.i index 703d3482e..57fa8e5bc 100644 --- a/win32/src/_winxptheme.i +++ b/win32/src/_winxptheme.i @@ -17,7 +17,6 @@ %{ #define _WIN32_IE 0x0501 // to enable balloon notifications in Shell_NotifyIcon #define _WIN32_WINNT 0x0501 -//#define ISOLATION_AWARE_ENABLED 1 #undef PyHANDLE #include "pywinobjects.h" diff --git a/win32/src/win32gui.i b/win32/src/win32gui.i index 0bb66da96..3e0811532 100644 --- a/win32/src/win32gui.i +++ b/win32/src/win32gui.i @@ -1,23 +1,11 @@ /* File : win32gui.i */ // @doc -%ifdef WINXPGUI -%module winxpgui -%else -%module win32gui // A module which provides an interface to the native win32 - // GUI API.Note that a module also exists, - // which has the same methods as win32gui, but has an XP - // manifest and is setup for side-by-side sharing support for - // certain system DLLs, notably commctl32. -%endif +%module win32gui // A module which provides an interface to the native win32 GUI API. %{ #define _WIN32_IE 0x0501 // to enable balloon notifications in Shell_NotifyIcon #define _WIN32_WINNT 0x0501 -#ifdef WINXPGUI -// This changes the entire world for XP! -#define ISOLATION_AWARE_ENABLED 1 -#endif %} %include "typemaps.i" @@ -275,11 +263,7 @@ PyDict_SetItemString(d, "g_DLGMap", g_DLGMap); PyDict_SetItemString(d, "UNICODE", Py_True); // hack borrowed from win32security since version of SWIG we use doesn't do keyword arguments -#ifdef WINXPGUI -for (PyMethodDef *pmd = winxpguiMethods; pmd->ml_name; pmd++) -#else for (PyMethodDef *pmd = win32guiMethods; pmd->ml_name; pmd++) -#endif if (strcmp(pmd->ml_name, "SetLayeredWindowAttributes")==0 ||strcmp(pmd->ml_name, "GetLayeredWindowAttributes")==0 ||strcmp(pmd->ml_name, "UpdateLayeredWindow")==0 @@ -5675,14 +5659,12 @@ BOOLAPI SetWindowRgn( HRGN INPUT_NULLOK, // @pyparm |hRgn||Handle to region to be set, can be None BOOL Redraw); // @pyparm boolean|Redraw||Indicates if window should be completely redrawn -#ifdef WINXPGUI // @pyswig int, |GetWindowRgnBox|Returns the bounding box for a window's region // @rdesc Returns type of region and rectangle coordinates in device units int_regiontype GetWindowRgnBox( HWND hWnd, // @pyparm |hWnd||Handle to a window that has a window region. (see ) RECT *OUTPUT); -// @comm Only available in winxpgui -#endif + // @pyswig |ValidateRgn|Removes a region from a window's update region BOOLAPI ValidateRgn( HWND hWnd, // @pyparm |hWnd||Handle to the window @@ -7646,11 +7628,6 @@ PyObject *PyEnumPropsEx(PyObject *self, PyObject *args) %} %native(EnumPropsEx) PyEnumPropsEx; -#ifdef WINXPGUI -// strictly available in win2kpro, but this will do for now... -HWND GetConsoleWindow(); -#endif - %{ // @pyswig |RegisterDeviceNotification|Registers the device or type of device for which a window will receive notifications. PyObject *PyRegisterDeviceNotification(PyObject *self, PyObject *args) diff --git a/win32/src/winxpgui.manifest b/win32/src/winxpgui.manifest deleted file mode 100644 index 0e6670d0e..000000000 --- a/win32/src/winxpgui.manifest +++ /dev/null @@ -1,23 +0,0 @@ - - - -Python Win32 Extensions - - - - - - diff --git a/win32/src/winxpgui.rc b/win32/src/winxpgui.rc deleted file mode 100644 index 39ee5d9b6..000000000 --- a/win32/src/winxpgui.rc +++ /dev/null @@ -1,2 +0,0 @@ -#include "windows.h" -ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "winxpgui.manifest" diff --git a/win32/winxpgui.py b/win32/winxpgui.py new file mode 100644 index 000000000..cfde000b3 --- /dev/null +++ b/win32/winxpgui.py @@ -0,0 +1,17 @@ +"""\ +The `winxpgui` module is obsolete and has been completely replaced \ +by `win32gui` and `win32console.GetConsoleWindow`. Use those instead. \ +""" +from __future__ import annotations + +import warnings + +from win32console import GetConsoleWindow as GetConsoleWindow +from win32gui import * + +warnings.warn("""\ +The `winxpgui` module is obsolete and has been completely replaced \ +by `win32gui` and `win32console.GetConsoleWindow`. Use those instead. \ +""", + category=DeprecationWarning, +)