mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Improve _GUID & typedef definition + add a sample using gdef.meta to search for a name/value in generated defs
This commit is contained in:
@@ -1878,8 +1878,7 @@ typedef struct _GUID {
|
||||
USHORT Data2;
|
||||
USHORT Data3;
|
||||
BYTE Data4[ 8 ];
|
||||
} GUID, IID, *REFIID, *REFCLSID;
|
||||
|
||||
} GUID, IID, *REFIID, *REFCLSID, *LPGUID, *REFGUID;
|
||||
|
||||
|
||||
struct _TMP_signscale {
|
||||
|
||||
@@ -51,8 +51,3 @@ class _GUID(INITIAL_GUID):
|
||||
if not isinstance(other, (_GUID, INITIAL_GUID)):
|
||||
return NotImplemented
|
||||
return (self.Data1, self.Data2, self.Data3, self.Data4[:]) == (other.Data1, other.Data2, other.Data3, other.Data4[:])
|
||||
|
||||
LPGUID = POINTER(_GUID)
|
||||
REFGUID = POINTER(_GUID)
|
||||
REFCLSID = POINTER(_GUID)
|
||||
REFIID = POINTER(_GUID)
|
||||
@@ -632,10 +632,10 @@ class InitialCOMGenerator(CtypesGenerator):
|
||||
|
||||
def analyse(self, data):
|
||||
self.real_type = {}
|
||||
self.add_exports("IID")
|
||||
self.add_exports("GUID")
|
||||
self.add_exports("LPGUID") # setup in InitialCOMGenerator.HEADER
|
||||
self.add_exports("REFGUID") # setup in InitialCOMGenerator.HEADER
|
||||
# self.add_exports("IID")
|
||||
# self.add_exports("GUID")
|
||||
# self.add_exports("LPGUID") # setup in InitialCOMGenerator.HEADER
|
||||
# self.add_exports("REFGUID") # setup in InitialCOMGenerator.HEADER
|
||||
self.add_exports("COMInterface")
|
||||
self.add_exports("COMImplementation")
|
||||
for cominterface in data:
|
||||
@@ -737,7 +737,7 @@ class MetafileGenerator(object):
|
||||
def generate_walker(namelist, target_module):
|
||||
def my_walker():
|
||||
for name in namelist:
|
||||
yield getattr(target_module, name)
|
||||
yield name, getattr(target_module, name)
|
||||
return my_walker
|
||||
""")
|
||||
def __init__(self, filename):
|
||||
|
||||
@@ -4926,14 +4926,22 @@ _DEBUG_EXCEPTION_FILTER_PARAMETERS
|
||||
|
||||
_GUID
|
||||
'''''
|
||||
.. class:: IID
|
||||
|
||||
Alias for :class:`_GUID`
|
||||
|
||||
.. class:: REFCLSID
|
||||
|
||||
Pointer to :class:`_GUID`
|
||||
|
||||
.. class:: REFGUID
|
||||
|
||||
Pointer to :class:`_GUID`
|
||||
|
||||
.. class:: LPGUID
|
||||
|
||||
Pointer to :class:`_GUID`
|
||||
|
||||
.. class:: IID
|
||||
|
||||
Alias for :class:`_GUID`
|
||||
|
||||
.. class:: GUID
|
||||
|
||||
Alias for :class:`_GUID`
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
import windows
|
||||
import windows.generated_def as gdef
|
||||
import windows.generated_def.meta as meta
|
||||
|
||||
def match(s1, s2):
|
||||
# return s1 in s2
|
||||
return s1.lower() in s2.lower()
|
||||
|
||||
def search_name_in_function(target):
|
||||
for funcname in meta.functions:
|
||||
if match(target, funcname):
|
||||
print(funcname)
|
||||
|
||||
def search_name_in_enum(target):
|
||||
for name, enum in meta.enums_walker():
|
||||
if match(target, name):
|
||||
print(name, enum)
|
||||
|
||||
def search_name_in_struct(target):
|
||||
for name, struct in meta.structs_walker():
|
||||
if match(target, name):
|
||||
print(name, struct)
|
||||
if hasattr(struct, "_fields_"):
|
||||
# import pdb;pdb.set_trace()
|
||||
for fname, ftype in struct._fields_:
|
||||
if match(target, fname):
|
||||
print("Field <{0}> in <{1}>: {2}".format(fname, name, struct))
|
||||
|
||||
def search_name_in_windef(target):
|
||||
for name, windef in meta.windef_walker():
|
||||
if match(target, name):
|
||||
print(windef)
|
||||
|
||||
def search_name_in_interface(target):
|
||||
for name, interface in meta.interfaces_walker():
|
||||
if not issubclass(interface, windows.generated_def.interfaces.COMInterface):
|
||||
continue
|
||||
if match(target, name):
|
||||
print(name, interface)
|
||||
for mname, mvalue in interface._functions_.items():
|
||||
if match(target, mname):
|
||||
print("Method <{0}> of <{1}>: {2}".format(mname, name, mvalue))
|
||||
|
||||
def search_name(target):
|
||||
print("== Functions ==")
|
||||
search_name_in_function(target)
|
||||
print("== Enums ==")
|
||||
search_name_in_enum(target)
|
||||
print("== Structs ==")
|
||||
search_name_in_struct(target)
|
||||
print("== Windef ==")
|
||||
search_name_in_windef(target)
|
||||
print("== Interfaces ==")
|
||||
search_name_in_interface(target)
|
||||
|
||||
def search_value(target):
|
||||
for name, windef in meta.windef_walker():
|
||||
if target == windef:
|
||||
print(windef)
|
||||
|
||||
parser = argparse.ArgumentParser(prog=__file__)
|
||||
parser.add_argument('target', help='The name or value to research in PythonForWindows generated definition')
|
||||
res = parser.parse_args()
|
||||
target = res.target
|
||||
try:
|
||||
itarget = int(target, 0)
|
||||
except ValueError:
|
||||
print("Searching name <{0}>".format(target))
|
||||
search_name(target)
|
||||
else:
|
||||
print("== Searching value <{0:#x}> ==".format(itarget))
|
||||
print ""
|
||||
search_value(itarget)
|
||||
File diff suppressed because one or more lines are too long
@@ -2508,8 +2508,10 @@ class _GUID(Structure):
|
||||
("Data3", USHORT),
|
||||
("Data4", BYTE * 8),
|
||||
]
|
||||
IID = _GUID
|
||||
REFCLSID = POINTER(_GUID)
|
||||
REFGUID = POINTER(_GUID)
|
||||
LPGUID = POINTER(_GUID)
|
||||
IID = _GUID
|
||||
GUID = _GUID
|
||||
REFIID = POINTER(_GUID)
|
||||
|
||||
@@ -2567,12 +2569,10 @@ class _GUID(INITIAL_GUID):
|
||||
return NotImplemented
|
||||
return (self.Data1, self.Data2, self.Data3, self.Data4[:]) == (other.Data1, other.Data2, other.Data3, other.Data4[:])
|
||||
|
||||
LPGUID = POINTER(_GUID)
|
||||
REFCLSID = POINTER(_GUID)
|
||||
REFGUID = POINTER(_GUID)
|
||||
REFCLSID = POINTER(_GUID)
|
||||
REFIID = POINTER(_GUID)
|
||||
LPGUID = POINTER(_GUID)
|
||||
IID = _GUID
|
||||
REFCLSID = POINTER(_GUID)
|
||||
GUID = _GUID
|
||||
REFIID = POINTER(_GUID)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user