示例#1
0
文件: test_wmi.py 项目: 5Nap/Geometry
import unittest as ut
from ctypes import POINTER
from comtypes.client import CoGetObject
from comtypes.test import requires

requires("time")


# WMI has dual interfaces.
# Some methods/properties have "[out] POINTER(VARIANT)" parameters.
# This test checks that these parameters are returned as strings:
# that's what VARIANT.__ctypes_from_outparam__ does.
class Test(ut.TestCase):
    def test_wmi(self):
        wmi = CoGetObject("winmgmts:")
        disks = wmi.InstancesOf("Win32_LogicalDisk")

        # There are different typelibs installed for WMI on win2k and winXP.
        # WbemScripting refers to their guid:
        #   Win2k:
        #     import comtypes.gen._565783C6_CB41_11D1_8B02_00600806D9B6_0_1_1 as mod
        #   WinXP:
        #     import comtypes.gen._565783C6_CB41_11D1_8B02_00600806D9B6_0_1_2 as mod
        # So, the one that's referenced onm WbemScripting will be used, whether the actual
        # typelib is available or not.  XXX
        from comtypes.gen import WbemScripting
        WbemScripting.wbemPrivilegeCreateToken

        for item in disks:
            # obj[index] is forwarded to obj.Item(index)
            # .Value is a property with "[out] POINTER(VARIANT)" parameter.
示例#2
0
import glob
import os
import unittest
import warnings
import comtypes.typeinfo
import comtypes.client
import comtypes.client._generate
from comtypes.test import requires

requires("typelibs")

# filter warnings about interfaces without a base interface; they will
# be skipped in the code generation.
warnings.filterwarnings("ignore",
                        "Ignoring interface .* which has no base interface",
                        UserWarning)

# don't print messages when typelib wrappers are generated
comtypes.client._generate.__verbose__ = False

sysdir = os.path.join(os.environ["SystemRoot"], "system32")

progdir = os.environ["ProgramFiles"]
common_progdir = os.environ["CommonProgramFiles"]

# This test takes quite some time.  It tries to build wrappers for ALL
# .dll, .tlb, and .ocx files in the system directory which contain typelibs.

class Test(unittest.TestCase):
    def setUp(self):
        "Do not write the generated files into the comtypes.gen directory"
示例#3
0
import unittest

from ctypes import PyDLL, py_object, c_void_p, byref, POINTER

from ctypes.wintypes import BOOL

from comtypes import IUnknown

from comtypes.client import CreateObject

from comtypes.automation import IDispatch

from comtypes.test import requires

requires("pythoncom")

import pythoncom

import win32com.client

# We use the PyCom_PyObjectFromIUnknown function in pythoncom25.dll to

# convert a comtypes COM pointer into a pythoncom COM pointer.

# Fortunately this function is exported by the dll...

#

# This is the C prototype; we must pass 'True' as third argument:

#
示例#4
0
import sys
import unittest
import doctest

from comtypes.test import requires

# This test is unreliable...
requires("events")


class EventsTest(unittest.TestCase):
    def test(self):
        import comtypes.test.test_showevents
        doctest.testmod(comtypes.test.test_showevents,
                        optionflags=doctest.ELLIPSIS)

    # These methods are never called, they only contain doctests.
    if sys.version_info >= (3, 0):

        def IE_ShowEvents(self):
            '''
            >>> from comtypes.client import CreateObject, ShowEvents, PumpEvents
            >>>
            >>> o = CreateObject("InternetExplorer.Application")
            >>> con = ShowEvents(o)
            # event found: DWebBrowserEvents2_StatusTextChange
            # event found: DWebBrowserEvents2_ProgressChange
            # event found: DWebBrowserEvents2_CommandStateChange
            # event found: DWebBrowserEvents2_DownloadBegin
            # event found: DWebBrowserEvents2_DownloadComplete
            # event found: DWebBrowserEvents2_TitleChange
示例#5
0
import unittest as ut
from ctypes import POINTER
from comtypes.client import CoGetObject
from comtypes.test import requires

requires("time")

# WMI has dual interfaces.
# Some methods/properties have "[out] POINTER(VARIANT)" parameters.
# This test checks that these parameters are returned as strings:
# that's what VARIANT.__ctypes_from_outparam__ does.
class Test(ut.TestCase):
    def test_wmi(self):
        wmi = CoGetObject("winmgmts:")
        disks = wmi.InstancesOf("Win32_LogicalDisk")

        # There are different typelibs installed for WMI on win2k and winXP.
        # WbemScripting refers to their guid:
        #   Win2k:
        #     import comtypes.gen._565783C6_CB41_11D1_8B02_00600806D9B6_0_1_1 as mod
        #   WinXP:
        #     import comtypes.gen._565783C6_CB41_11D1_8B02_00600806D9B6_0_1_2 as mod
        # So, the one that's referenced onm WbemScripting will be used, whether the actual
        # typelib is available or not.  XXX
        from comtypes.gen import WbemScripting
        WbemScripting.wbemPrivilegeCreateToken

        for item in disks:
            # obj[index] is forwarded to obj.Item(index)
            # .Value is a property with "[out] POINTER(VARIANT)" parameter.
            a = item.Properties_["Caption"].Value
示例#6
0
import sys
import unittest
import doctest

from comtypes.test import requires

# This test is unreliable...
requires("events")

class EventsTest(unittest.TestCase):

    def test(self):
        import comtypes.test.test_showevents
        doctest.testmod(comtypes.test.test_showevents, optionflags=doctest.ELLIPSIS)

    # These methods are never called, they only contain doctests.
    if sys.version_info >= (3, 0):
        def IE_ShowEvents(self):
            '''
            >>> from comtypes.client import CreateObject, ShowEvents, PumpEvents
            >>>
            >>> o = CreateObject("InternetExplorer.Application")
            >>> con = ShowEvents(o)
            # event found: DWebBrowserEvents2_StatusTextChange
            # event found: DWebBrowserEvents2_ProgressChange
            # event found: DWebBrowserEvents2_CommandStateChange
            # event found: DWebBrowserEvents2_DownloadBegin
            # event found: DWebBrowserEvents2_DownloadComplete
            # event found: DWebBrowserEvents2_TitleChange
            # event found: DWebBrowserEvents2_PropertyChange
            # event found: DWebBrowserEvents2_BeforeNavigate2
import unittest

from ctypes import PyDLL, py_object, c_void_p, byref, POINTER
from ctypes.wintypes import BOOL

from comtypes import IUnknown
from comtypes.client import CreateObject
from comtypes.automation import IDispatch
from comtypes.test import requires

requires("pythoncom")
import pythoncom
import win32com.client

# We use the PyCom_PyObjectFromIUnknown function in pythoncom25.dll to
# convert a comtypes COM pointer into a pythoncom COM pointer.
# Fortunately this function is exported by the dll...
#
# This is the C prototype; we must pass 'True' as third argument:
#
# PyObject *PyCom_PyObjectFromIUnknown(IUnknown *punk, REFIID riid, BOOL bAddRef)

_PyCom_PyObjectFromIUnknown = PyDLL(pythoncom.__file__).PyCom_PyObjectFromIUnknown
_PyCom_PyObjectFromIUnknown.restype = py_object
_PyCom_PyObjectFromIUnknown.argtypes = (POINTER(IUnknown), c_void_p, BOOL)

def comtypes2pywin(ptr, interface=None):
    """Convert a comtypes pointer 'ptr' into a pythoncom
    PyI<interface> object.

    'interface' specifies the interface we want; it must be a comtypes
示例#8
0
import glob
import os
import unittest
import warnings
import comtypes.typeinfo
import comtypes.client
import comtypes.client._generate
from comtypes.test import requires

requires("typelibs")

# filter warnings about interfaces without a base interface; they will
# be skipped in the code generation.
warnings.filterwarnings("ignore",
                        "Ignoring interface .* which has no base interface",
                        UserWarning)

# don't print messages when typelib wrappers are generated
comtypes.client._generate.__verbose__ = False

sysdir = os.path.join(os.environ["SystemRoot"], "system32")

progdir = os.environ["ProgramFiles"]
common_progdir = os.environ["CommonProgramFiles"]

# This test takes quite some time.  It tries to build wrappers for ALL
# .dll, .tlb, and .ocx files in the system directory which contain typelibs.

class Test(unittest.TestCase):
    def setUp(self):
        "Do not write the generated files into the comtypes.gen directory"