ctypes-commit Mailing List for ctypes (Page 101)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2004-07-22 08:10:51
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29759 Added Files: test_variant.py test_comobject.py Log Message: Moved these files from unittests to unittests/com. --- NEW FILE: test_variant.py --- import unittest, os from ctypes import * def get_refcnt(comptr): # return the COM reference count of a COM interface pointer if not comptr: return 0 comptr.AddRef() return comptr.Release() if os.name == "nt": class VariantTestCase(unittest.TestCase): def __init__(self, *args): # We cannot import these at module level, but want these to be # available in the global namespace global IUnknown, VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib, GUID from ctypes.com import IUnknown, GUID from ctypes.com.automation import VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib unittest.TestCase.__init__(self, *args) def test_com_refcounts(self): # typelib for Internet Explorer tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) self.failUnlessEqual(get_refcnt(tlb), 1) p = POINTER(IUnknown)() tlb.QueryInterface(byref(IUnknown._iid_), byref(p)) self.failUnlessEqual(get_refcnt(tlb), 2) del p self.failUnlessEqual(get_refcnt(tlb), 1) def test_com_pointers(self): ## """Storing a COM interface pointer in a VARIANT increments the refcount, ## changing the variant to contain something else decrements it""" tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) self.failUnlessEqual(get_refcnt(tlb), 1) v = VARIANT(tlb) self.failUnlessEqual(get_refcnt(tlb), 2) p = v.value self.failUnlessEqual(get_refcnt(tlb), 3) del p self.failUnlessEqual(get_refcnt(tlb), 2) v.value = None self.failUnlessEqual(get_refcnt(tlb), 1) def test_null_com_pointers(self): p = POINTER(IUnknown)() self.failUnlessEqual(get_refcnt(p), 0) v = VARIANT(p) self.failUnlessEqual(get_refcnt(p), 0) def test_dispparams(self): # DISPPARAMS is a complex structure, well worth testing. d = DISPPARAMS() d.rgvarg = (VARIANT * 3)() # XXX The following line fails, which is a real bug in ctypes: # SystemError: ...\Objects\listobject.c:105: bad argument to internal function ## d.rgvarg[0].value = 1 def test_pythonobjects(self): objects = [None, 42, 3.14, True, False, "abc", u"abc"] for x in objects: v = VARIANT(x) self.failUnlessEqual(x, v.value) ################################################################ if __name__ == '__main__': unittest.main() --- NEW FILE: test_comobject.py --- import unittest, os, sys from ctypes import * def get_refcnt(comptr): if not comptr: return 0 comptr.AddRef() return comptr.Release() if sys.platform == "win32": class ComTestCase(unittest.TestCase): def __init__(self, *args): unittest.TestCase.__init__(self, *args) global COMObject, IUnknown, GUID, STDMETHOD, HRESULT from ctypes.com import COMObject, IUnknown, GUID, STDMETHOD, HRESULT def setUp(self): class IObjectWithSite(IUnknown): _iid_ = GUID("{FC4801A3-2BA9-11CF-A229-00AA003D7352}") _methods_ = IUnknown._methods_ + [ (STDMETHOD(HRESULT, "SetSite", POINTER(IUnknown))), (STDMETHOD(HRESULT, "GetSite", POINTER(GUID), POINTER(c_void_p)))] class Factory(object): def LockServer(self, *args): pass class MyObject(COMObject): _factory = Factory() _com_interfaces_ = [IObjectWithSite] def IObjectWithSite_SetSite(self, this, pUnkSite): self.m_site = pUnkSite return 0 # S_OK self.impl = MyObject() def tearDown(self): self.impl = None import gc gc.collect() ################ def test_site(self): impl = self.impl p = pointer(impl._com_pointers_[0][1]) self.failUnlessEqual(impl._refcnt, 0) p.AddRef() self.failUnlessEqual(impl._refcnt, 1) p.SetSite(p) self.failUnlessEqual(impl._refcnt, 2) p.SetSite(None) self.failUnlessEqual(impl._refcnt, 1) del p self.failUnlessEqual(impl._refcnt, 0) def test_comobject(self): impl = self.impl self.failUnlessEqual(impl._refcnt, 0) p = pointer(impl._com_pointers_[0][1]) p.AddRef() self.failUnlessEqual(impl._refcnt, 1) self.failUnlessEqual(get_refcnt(p), 1) del p self.failUnlessEqual(impl._refcnt, 0) def test_qi(self): impl = self.impl self.failUnlessEqual(impl._refcnt, 0) p = pointer(impl._com_pointers_[0][1]) p.AddRef() self.failUnlessEqual(get_refcnt(p), 1) p2 = POINTER(IUnknown)() p.QueryInterface(byref(IUnknown._iid_), byref(p2)) self.failUnlessEqual(get_refcnt(p), 2) del p2 self.failUnlessEqual(get_refcnt(p), 1) def test_from_progid(self): g = GUID.from_progid("InternetExplorer.Application") self.failUnlessEqual(g, GUID("{0002DF01-0000-0000-C000-000000000046}")) def test_GUID(self): g1 = GUID("{00000000-0001-0002-0003-000000000000}") g2 = GUID("{00000000-0001-0002-0003-000000000000}") g3 = GUID("{00000000-0001-0002-0003-000000000001}") self.failUnlessEqual(g1, g2) # for now, GUID instances are unhashable. ## d = {} ## d[g1] = None ## self.failUnlessEqual(g1 in d, True) ## self.failUnlessEqual(g2 in d, True) ## self.failUnlessEqual(g3 in d, False) ################################################################ if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2004-07-21 19:55:28
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13968 Modified Files: setup.py Added Files: run_remote_test.py Log Message: Another way to run the tests. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.90 retrieving revision 1.91 diff -C2 -d -r1.90 -r1.91 *** setup.py 16 Jul 2004 19:31:23 -0000 1.90 --- setup.py 21 Jul 2004 19:55:18 -0000 1.91 *************** *** 243,249 **** # tracebacks instance vars. # A sequence of testcase names together with their outcome is returned. ! i, o = os.popen4("%s %s -v" % (sys.executable, path)) ! i.close() cases = [] while 1: line = o.readline() --- 243,249 ---- # tracebacks instance vars. # A sequence of testcase names together with their outcome is returned. ! os.system("%s run_remote_test.py %s" % (sys.executable, path)) cases = [] + o = open("test.output") while 1: line = o.readline() --- NEW FILE: run_remote_test.py --- import os, sys, unittest if __name__ == "__main__": dirname, filename = os.path.split(sys.argv[1]) basename, ext = os.path.splitext(filename) del sys.argv[1] sys.path.append(dirname) runner = unittest.TextTestRunner(open("test.output", "w"), verbosity=2) unittest.main(module=__import__(basename), testRunner=runner) |
From: Thomas H. <th...@us...> - 2004-07-21 06:55:30
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29234 Modified Files: remotetest.py Log Message: *** empty log message *** Index: remotetest.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/remotetest.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** remotetest.py 21 Jul 2004 06:52:50 -0000 1.5 --- remotetest.py 21 Jul 2004 06:55:20 -0000 1.6 *************** *** 118,122 **** if p not in sys.path: sys.path.insert(0, p) ! data = cPickle.dumps(s) open(".result.pck", "w").write(data) if verbose == 2: --- 118,122 ---- if p not in sys.path: sys.path.insert(0, p) ! data = cPickle.dumps(d) open(".result.pck", "w").write(data) if verbose == 2: |
From: Thomas H. <th...@us...> - 2004-07-21 06:53:10
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28924 Modified Files: remotetest.py Log Message: *** empty log message *** Index: remotetest.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/remotetest.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** remotetest.py 21 Jul 2004 06:21:22 -0000 1.4 --- remotetest.py 21 Jul 2004 06:52:50 -0000 1.5 *************** *** 87,91 **** if p not in sys.path: sys.path.insert(0, p) ! d = cPickle.load(open(pickle_name, "r")) result = runner._makeResult(d) --- 87,92 ---- if p not in sys.path: sys.path.insert(0, p) ! data = open(pickle_name, "r").read() ! d = cPickle.loads(data) result = runner._makeResult(d) *************** *** 97,101 **** options[name] = getattr(result, name) ! cPickle.dump(options, open(pickle_name, "w")) ################################################################ --- 98,103 ---- options[name] = getattr(result, name) ! data = cPickle.dumps(options) ! open(pickle_name, "w").write(data) ################################################################ *************** *** 116,120 **** if p not in sys.path: sys.path.insert(0, p) ! cPickle.dump(d, open(".result.pck", "w")) if verbose == 2: os.system("%s remotetest.py -v -p %s %s" % (sys.executable, ".result.pck", a)) --- 118,123 ---- if p not in sys.path: sys.path.insert(0, p) ! data = cPickle.dumps(s) ! open(".result.pck", "w").write(data) if verbose == 2: os.system("%s remotetest.py -v -p %s %s" % (sys.executable, ".result.pck", a)) *************** *** 123,127 **** else: os.system("%s remotetest.py -q -p %s %s" % (sys.executable, ".result.pck", a)) ! d = cPickle.load(open(".result.pck", "r")) result = runner._makeResult(d) os.unlink(".result.pck") --- 126,131 ---- else: os.system("%s remotetest.py -q -p %s %s" % (sys.executable, ".result.pck", a)) ! data = open(".result.pck", "r").read() ! d = cPickle.loads(data) result = runner._makeResult(d) os.unlink(".result.pck") |
From: Thomas H. <th...@us...> - 2004-07-21 06:21:36
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25200 Modified Files: remotetest.py Log Message: *** empty log message *** Index: remotetest.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/remotetest.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** remotetest.py 21 Jul 2004 06:18:22 -0000 1.3 --- remotetest.py 21 Jul 2004 06:21:22 -0000 1.4 *************** *** 33,37 **** except: if self.verbosity == 2: ! self.stream.write("%s ... could not import " % fname) result.addError(TestFile(fname), sys.exc_info()) return result --- 33,37 ---- except: if self.verbosity == 2: ! self.stream.write("(could not import %s) " % fname) result.addError(TestFile(fname), sys.exc_info()) return result |
From: Thomas H. <th...@us...> - 2004-07-21 06:18:32
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24744 Modified Files: remotetest.py Log Message: Catch more error when a file cannot be imported. Index: remotetest.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/remotetest.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** remotetest.py 21 Jul 2004 06:15:35 -0000 1.2 --- remotetest.py 21 Jul 2004 06:18:22 -0000 1.3 *************** *** 31,37 **** try: mod = __import__(modname, globals(), locals(), [""]) ! except ImportError: if self.verbosity == 2: ! self.stream.write("%s ... ImportError " % fname) result.addError(TestFile(fname), sys.exc_info()) return result --- 31,37 ---- try: mod = __import__(modname, globals(), locals(), [""]) ! except: if self.verbosity == 2: ! self.stream.write("%s ... could not import " % fname) result.addError(TestFile(fname), sys.exc_info()) return result |
From: Thomas H. <th...@us...> - 2004-07-21 06:15:44
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24306 Modified Files: remotetest.py Log Message: Unittest classes were old style in Python 2.2, cannot use super. Index: remotetest.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/remotetest.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** remotetest.py 20 Jul 2004 19:04:18 -0000 1.1 --- remotetest.py 21 Jul 2004 06:15:35 -0000 1.2 *************** *** 18,22 **** # - run_file method def _makeResult(self, options=None): ! result = super(RemoteTestRunner, self)._makeResult() if options is not None: result.__dict__.update(options) --- 18,22 ---- # - run_file method def _makeResult(self, options=None): ! result = unittest.TextTestRunner._makeResult(self) if options is not None: result.__dict__.update(options) *************** *** 111,115 **** d = {"errors": [], "failures": [], "testsRun": 0} ! starttime = time.clock() for a in args: p = os.path.dirname(a) --- 111,115 ---- d = {"errors": [], "failures": [], "testsRun": 0} ! starttime = time.time() for a in args: p = os.path.dirname(a) *************** *** 126,130 **** result = runner._makeResult(d) os.unlink(".result.pck") ! runner.report(result, duration = time.clock() - starttime) ################################################################ --- 126,130 ---- result = runner._makeResult(d) os.unlink(".result.pck") ! runner.report(result, duration = time.time() - starttime) ################################################################ |
From: Thomas H. <th...@us...> - 2004-07-20 19:04:48
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4646 Added Files: remotetest.py Log Message: Remove test utility. --- NEW FILE: remotetest.py --- import unittest import os, sys import cPickle class TestFile(object): def __init__(self, path): self.path = path def shortDescription(self): return self.path failureException = AssertionError class RemoteTestRunner(unittest.TextTestRunner): # Differences from unittest.TextTestRunner: # - _makeResult() takes an optional parameter used to initialize the TestResult # - run() accepts a TestResult instance # - run() only runs the tests, does no reporting # - separate report() method # - run_file method def _makeResult(self, options=None): result = super(RemoteTestRunner, self)._makeResult() if options is not None: result.__dict__.update(options) return result def run_file(self, fname, result=None): dirname, filename = os.path.split(fname) modname = os.path.splitext(filename)[0] if dirname not in sys.path: sys.path.insert(0, dirname) try: mod = __import__(modname, globals(), locals(), [""]) except ImportError: if self.verbosity == 2: self.stream.write("%s ... ImportError " % fname) result.addError(TestFile(fname), sys.exc_info()) return result test_classes = [] for name in dir(mod): if name.startswith("_"): continue o = getattr(mod, name) if type(o) is type(unittest.TestCase) and issubclass(o, unittest.TestCase): test_classes.append(o) for item in test_classes: result = self.run(unittest.makeSuite(item), result) return result def run(self, test, result=None): "Run the given test case or test suite." if result is None: result = self._makeResult() test(result) return result def report(self, result, duration=None): "Report the test results." result.printErrors() self.stream.writeln(result.separator2) run = result.testsRun if duration is not None: self.stream.writeln("Ran %d tests in %.3f s" % (run, duration)) else: self.stream.writeln("Ran %d tests" % run) self.stream.writeln() if not result.wasSuccessful(): self.stream.write("FAILED (") failed, errored = map(len, (result.failures, result.errors)) if failed: self.stream.write("failures=%d" % failed) if errored: if failed: self.stream.write(", ") self.stream.write("errors=%d" % errored) self.stream.writeln(")") else: self.stream.writeln("OK") ################################################################ def server(verbose, args, pickle_name): runner = RemoteTestRunner(sys.stderr, 1, verbosity=verbose) for a in args: p = os.path.dirname(a) if p not in sys.path: sys.path.insert(0, p) d = cPickle.load(open(pickle_name, "r")) result = runner._makeResult(d) for a in args: result = runner.run_file(a, result) sys.path.insert(0, os.path.dirname(a)) options = {} for name in "errors failures testsRun".split(): options[name] = getattr(result, name) cPickle.dump(options, open(pickle_name, "w")) ################################################################ def client(verbose, args): import glob, time, tempfile L = [] for a in args: L.extend(glob.glob(a)) args = L runner = RemoteTestRunner(sys.stderr, 1, verbosity=verbose) d = {"errors": [], "failures": [], "testsRun": 0} starttime = time.clock() for a in args: p = os.path.dirname(a) if p not in sys.path: sys.path.insert(0, p) cPickle.dump(d, open(".result.pck", "w")) if verbose == 2: os.system("%s remotetest.py -v -p %s %s" % (sys.executable, ".result.pck", a)) elif verbose == 1: os.system("%s remotetest.py -p %s %s" % (sys.executable, ".result.pck", a)) else: os.system("%s remotetest.py -q -p %s %s" % (sys.executable, ".result.pck", a)) d = cPickle.load(open(".result.pck", "r")) result = runner._makeResult(d) os.unlink(".result.pck") runner.report(result, duration = time.clock() - starttime) ################################################################ def main(): import getopt verbose = 1 pickle_name = None opts, args = getopt.getopt(sys.argv[1:], "qvp:") for o, a in opts: if o == "-q": verbose = 0 elif o == "-v": verbose = 2 elif o == "-p": pickle_name = a if pickle_name: # server mode server(verbose, args, pickle_name) else: # client mode: run tests in remote process client(verbose, args) if __name__ == "__main__": main() |
From: Thomas H. <th...@us...> - 2004-07-20 15:32:35
|
Update of /cvsroot/ctypes/ctypes/win32/com/samples/server/control In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22353 Modified Files: stoplite.py Log Message: Remove the manual AddRef calls. Index: stoplite.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/control/stoplite.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** stoplite.py 21 Apr 2004 18:08:06 -0000 1.4 --- stoplite.py 20 Jul 2004 15:32:22 -0000 1.5 *************** *** 93,97 **** # changes in the view object. if AdvSink: - AdvSink.AddRef() # We have to take ownership of the COM pointer self._view_advisesink = AdvSink else: # got NULL pointer --- 93,96 ---- *************** *** 142,151 **** def IPersistPropertyBag_Load(self, this, pPropBag, pErrorLog): - # We must *always* AddRef() the COM pointers we receive, - # to match the Release() call when they go out of scope! - if pErrorLog: - pErrorLog.AddRef() - if pPropBag: - pPropBag.AddRef() val = self._load_property(u"digits", pPropBag, pErrorLog) self.model._interval = val --- 141,144 ---- *************** *** 159,169 **** def IPersistStreamInit_Load(self, this, pStm): - if pStm: - pStm.AddRef() return S_OK def IPersistStreamInit_Save(self, this, pStm, fClearDirty): - if pStm: - pStm.AddRef() return S_OK --- 152,158 ---- *************** *** 185,189 **** def IOleObject_SetClientSite(self, this, ppClientSite): if ppClientSite: - ppClientSite.AddRef() self._clientsite = ppClientSite else: --- 174,177 ---- *************** *** 215,220 **** def IOleObject_Advise(self, this, pAdvSink, pdwConnection): # IOleObject::Advise - if pAdvSink: - pAdvSink.AddRef() return self._adviseholder.Advise(pAdvSink, pdwConnection) --- 203,206 ---- *************** *** 227,232 **** def IOleObject_DoVerb(self, this, iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect): print "LOG: DoVerb %d" % iVerb - if pActiveSite: - pActiveSite.AddRef() if iVerb == OLEIVERB_PRIMARY and hasattr(self, "_DoVerbPrimary"): return self._DoVerbPrimary(lprcPosRect[0], hwndParent) --- 213,216 ---- |
From: Thomas H. <th...@us...> - 2004-07-20 15:31:59
|
Update of /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22264 Modified Files: toolband.py Log Message: Remove the manual AddRef calls. Index: toolband.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer/toolband.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** toolband.py 16 Jul 2004 16:19:07 -0000 1.2 --- toolband.py 20 Jul 2004 15:31:48 -0000 1.3 *************** *** 192,196 **** def IObjectWithSite_SetSite(self, this, punkSite): if punkSite: - punkSite.AddRef() # I think this is still required, but SHOULD be automatic self.m_Site = punkSite polewindow = POINTER(IOleWindow)() --- 192,195 ---- |
From: Thomas H. <th...@us...> - 2004-07-20 15:23:01
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21000 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/ChangeLog,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ChangeLog 16 Jul 2004 16:05:00 -0000 1.2 --- ChangeLog 20 Jul 2004 15:22:52 -0000 1.3 *************** *** 1,8 **** 2004-07-16 Thomas Heller <th...@py...> ! * __init__.py: More useful debug info from IUnknown.QueryInterface ! and ClassFactory.CreateInstance calls. New interface_name(iid) function, which returns a COM interface name from it's iid. ! \ No newline at end of file --- 1,22 ---- + 2004-07-20 Thomas Heller <th...@py...> + + * ctypes.com: Improve the automatic COM reference counting. + AddRef() is now automatically called when callback functions (COM + methods implemented in Python) receive a COM interface pointer as + parameter. This matches the __del__ method which calls Release(). + 2004-07-16 Thomas Heller <th...@py...> ! * samples\server\IExplorer\toolband.py: New sample implementing an ! Internet Explorer Toolband control. ! ! * ctypes.com.errorinfo: New interfaces. ! ! * ctypes.com: New function CreateGuid() ! ! More useful debug info from IUnknown.QueryInterface and ! ClassFactory.CreateInstance calls. New interface_name(iid) function, which returns a COM interface name from it's iid. ! |
From: Thomas H. <th...@us...> - 2004-07-20 15:18:18
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20296 Modified Files: mallocspy.py Log Message: Add some links. Index: mallocspy.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/mallocspy.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mallocspy.py 16 Jul 2004 15:52:37 -0000 1.3 --- mallocspy.py 20 Jul 2004 15:18:10 -0000 1.4 *************** *** 1,2 **** --- 1,11 ---- + """ + See also: + + http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q139/0/71.asp + + http://www.microsoft.com/msj/1095/activex1095.aspx + + http://msdn.microsoft.com/msdnmag/issues/01/03/leaks/default.aspx + """ from ctypes import * from ctypes.wintypes import BOOL |
From: Thomas H. <th...@us...> - 2004-07-20 15:17:44
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20184 Modified Files: test_comobject.py Log Message: Add a test case which tests the automatic AddRef(). Index: test_comobject.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_comobject.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_comobject.py 4 May 2004 09:16:23 -0000 1.3 --- test_comobject.py 20 Jul 2004 15:17:32 -0000 1.4 *************** *** 12,19 **** def __init__(self, *args): unittest.TestCase.__init__(self, *args) ! global COMObject, IUnknown, GUID ! from ctypes.com import COMObject, IUnknown, GUID def setUp(self): class Factory(object): def LockServer(self, *args): --- 12,25 ---- def __init__(self, *args): unittest.TestCase.__init__(self, *args) ! global COMObject, IUnknown, GUID, STDMETHOD, HRESULT ! from ctypes.com import COMObject, IUnknown, GUID, STDMETHOD, HRESULT def setUp(self): + class IObjectWithSite(IUnknown): + _iid_ = GUID("{FC4801A3-2BA9-11CF-A229-00AA003D7352}") + _methods_ = IUnknown._methods_ + [ + (STDMETHOD(HRESULT, "SetSite", POINTER(IUnknown))), + (STDMETHOD(HRESULT, "GetSite", POINTER(GUID), POINTER(c_void_p)))] + class Factory(object): def LockServer(self, *args): *************** *** 22,26 **** class MyObject(COMObject): _factory = Factory() ! _com_interfaces_ = [IUnknown] self.impl = MyObject() --- 28,36 ---- class MyObject(COMObject): _factory = Factory() ! _com_interfaces_ = [IObjectWithSite] ! ! def IObjectWithSite_SetSite(self, this, pUnkSite): ! self.m_site = pUnkSite ! return 0 # S_OK self.impl = MyObject() *************** *** 28,34 **** --- 38,59 ---- def tearDown(self): self.impl = None + import gc + gc.collect() ################ + def test_site(self): + impl = self.impl + p = pointer(impl._com_pointers_[0][1]) + self.failUnlessEqual(impl._refcnt, 0) + p.AddRef() + self.failUnlessEqual(impl._refcnt, 1) + p.SetSite(p) + self.failUnlessEqual(impl._refcnt, 2) + p.SetSite(None) + self.failUnlessEqual(impl._refcnt, 1) + del p + self.failUnlessEqual(impl._refcnt, 0) + def test_comobject(self): impl = self.impl *************** *** 52,55 **** --- 77,82 ---- p.QueryInterface(byref(IUnknown._iid_), byref(p2)) self.failUnlessEqual(get_refcnt(p), 2) + del p2 + self.failUnlessEqual(get_refcnt(p), 1) def test_from_progid(self): |
From: Thomas H. <th...@us...> - 2004-07-20 15:11:01
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19283 Modified Files: __init__.py Log Message: Automatically AddRef() COM pointers we receive as callback function arguments. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/__init__.py,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** __init__.py 16 Jul 2004 15:42:52 -0000 1.38 --- __init__.py 20 Jul 2004 15:10:52 -0000 1.39 *************** *** 157,162 **** self.__make_vtable() self.__make_methods() ! POINTER(self).__del__ = COMPointer__del__ ! ## POINTER(self).__init__ = COMPointer__init__ def __setattr__(self, name, value): --- 157,165 ---- self.__make_vtable() self.__make_methods() ! P = POINTER(self) ! P.__del__ = COMPointer__del__ ! # the presence of this attribute triggers automatic AddRef() ! # calls in COM method implementations, for aruments we receive. ! P._needs_com_addref_ = None def __setattr__(self, name, value): |
From: Thomas H. <th...@us...> - 2004-07-20 15:07:12
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18410 Modified Files: callbacks.c Log Message: Automatically AddRef() COM pointers we receive as callback function arguments. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** callbacks.c 29 Jun 2004 09:31:29 -0000 1.54 --- callbacks.c 20 Jul 2004 15:07:03 -0000 1.55 *************** *** 56,59 **** --- 56,85 ---- } + #ifdef MS_WIN32 + /* + * We must call AddRef() on non-NULL COM pointers we receive as arguments + * to callback functions - these functions are COM method implementations. + * The Python instances we create have a __del__ method which calls Release(). + * + * The presence of a class attribute named '_needs_com_addref_' triggers this + * behaviour. It would also be possible to call the AddRef() Python method, + * after checking for PyObject_IsTrue(), but this would probably be somewhat + * slower. + */ + static void + TryAddRef(StgDictObject *dict, CDataObject *obj) + { + IUnknown *punk; + + if (NULL == PyDict_GetItemString((PyObject *)dict, "_needs_com_addref_")) + return; + + punk = *(IUnknown **)obj->b_ptr; + if (punk) + punk->lpVtbl->AddRef(punk); + return; + } + #endif + /****************************************************************************** * *************** *** 92,96 **** goto Done; } - for (i = 0; i < nArgs; ++i) { /* Note: new reference! */ --- 118,121 ---- *************** *** 130,133 **** --- 155,161 ---- memcpy(obj->b_ptr, *pArgs, dict->size); PyTuple_SET_ITEM(arglist, i, (PyObject *)obj); + #ifdef MS_WIN32 + TryAddRef(dict, obj); + #endif } else { PyErr_SetString(PyExc_TypeError, |
From: Thomas H. <th...@us...> - 2004-07-20 07:44:16
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16885 Added Files: .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.pyc *.pyo |
From: Thomas H. <th...@us...> - 2004-07-16 19:35:17
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.4 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19518 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Recompiled binaries, just in case. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes_test.pyd,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 Binary files /tmp/cvs1bkmZ2 and /tmp/cvsIDHQ81 differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes.pyd,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 Binary files /tmp/cvsVVOQI6 and /tmp/cvs3RduW5 differ |
From: Thomas H. <th...@us...> - 2004-07-16 19:35:09
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.3 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19411 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Recompiled binaries, just in case. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes_test.pyd,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 Binary files /tmp/cvs6PRNPd and /tmp/cvseTYgW4 differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes.pyd,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 Binary files /tmp/cvs855Mmq and /tmp/cvsVoGNEh differ |
From: Thomas H. <th...@us...> - 2004-07-16 19:31:32
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18806 Added Files: setup.py Log Message: Add setup.py again with +x permission. --- NEW FILE: setup.py --- #!/usr/bin/env python # # $Id: setup.py,v 1.90 2004/07/16 19:31:23 theller Exp $ # # """ctypes is a Python package to create and manipulate C data types in Python, and to call functions in dynamic link libraries/shared dlls. It allows wrapping these libraries in pure Python. """ from __future__ import generators LIBFFI_SOURCES='source/gcc/libffi' ################################################################ import os, sys from distutils.core import setup, Extension, Command import distutils.core from distutils.errors import DistutilsOptionError from distutils.command import build_py, build_ext, clean from distutils.dir_util import mkpath from distutils.util import get_platform kw = {} kw["sources"] = ["source/_ctypes.c", "source/callbacks.c", "source/callproc.c", "source/stgdict.c", "source/cfield.c"] # Support the distutils 'depends' option, if available if hasattr(distutils.core, 'get_distutil_options'): # Python 2.3a1 kw["depends"] = ["source/ctypes.h"] elif (hasattr(distutils.core, 'extension_keywords') and 'depends' in distutils.core.extension_keywords): # Python current CVS kw["depends"] = ["source/ctypes.h"] if os.name == "nt": kw["sources"].extend([ "source/libffi_msvc/types.c", "source/libffi_msvc/ffi.c", "source/libffi_msvc/prep_cif.c", "source/libffi_msvc/win32.c", ]) extensions = [Extension("_ctypes", export_symbols=["DllGetClassObject,PRIVATE", "DllCanUnloadNow,PRIVATE", "CopyComPointer"], libraries=["ole32", "user32", "oleaut32"], include_dirs=["source/libffi_msvc"], **kw), Extension("_ctypes_test", libraries=["oleaut32"], sources=["source/_ctypes_test.c"], include_dirs=["source/libffi_msvc"], ) ] if kw.has_key("depends"): kw["depends"].extend(["source/libffi_msvc/ffi.h", "source/libffi_msvc/fficonfig.h", "source/libffi_msvc/ffitarget.h", "source/libffi_msvc/ffi_common.h"]) else: include_dirs = [] library_dirs = [] extra_link_args = [] if sys.platform == "darwin": kw["sources"].append("source/darwin/dlfcn_simple.c") extra_link_args.extend(['-read_only_relocs', 'warning']) include_dirs.append("source/darwin") extensions = [Extension("_ctypes", libraries=["ffi"], include_dirs=include_dirs, library_dirs=library_dirs, extra_link_args=extra_link_args, **kw), Extension("_ctypes_test", sources=["source/_ctypes_test.c"]) ] ################################################################ # Parts of this section copied from the PyObjC project if sys.platform == 'darwin': # Apple has used build options that don't work with a 'normal' system. # Remove '-arch i386' from the LDFLAGS. import distutils.sysconfig distutils.sysconfig.get_config_vars() x = distutils.sysconfig._config_vars['LDSHARED'] y = x.replace('-arch i386', '') if y != x: print "Fixing Apple strangeness in Python configuration" distutils.sysconfig._config_vars['LDSHARED'] = y ##if sys.platform != 'darwin' and os.path.exists('/usr/include/ffi.h') \ ## or os.path.exists('/usr/local/include/ffi.h'): ## # A system with a pre-existing libffi. ## LIBFFI_SOURCES=None if sys.platform == 'win32': LIBFFI_SOURCES=None platform = get_platform() if platform in ["solaris-2.9-sun4u", "linux-x86_64"]: os.environ["CFLAGS"] = "-fPIC" ################################################################ packages = ["ctypes"] package_dir = {} if sys.platform == "win32": packages.append("ctypes.com") package_dir["ctypes.com"] = "win32/com" packages.append("ctypes.com.samples") package_dir["ctypes.com.samples"] = "win32/com/samples" packages.append("ctypes.com.tools") package_dir["ctypes.com.tools"] = "win32/com/tools" packages.append("ctypes.com.samples.server") package_dir["ctypes.com.samples.server"] = "win32/com/samples/server" packages.append("ctypes.com.samples.server.control") package_dir["ctypes.com.samples.server.control"] = "win32/com/samples/server/control" ################################################################ class test(Command): # Original version of this class posted # by Berthold Hoellmann to dis...@py... description = "test the distribution prior to install" user_options = [ ('test-dirs=', None, "comma-separated list of directories that contain the test definitions"), ('test-prefix=', None, "prefix to the testcase filename"), ('verbosity=', 'V', "verbosity"), ] def initialize_options(self): self.build_base = 'build' # these are decided only after 'build_base' has its final value # (unless overridden by the user or client) self.test_prefix = 'test_' self.verbosity = 1 if sys.platform == "win32": self.test_dirs = r"unittests,unittests\com" else: self.test_dirs = "unittests" # initialize_options() def finalize_options(self): try: self.verbosity = int(self.verbosity) except ValueError: raise DistutilsOptionError, \ "verbosity must be an integer" build = self.get_finalized_command('build') self.build_purelib = build.build_purelib self.build_platlib = build.build_platlib self.test_dirs = self.test_dirs.split(",") # finalize_options() def extend_path(self): # We must add the current directory to $PYTHONPATH for the unittests # running as separate processes pypath = os.environ.get("PYTHONPATH") if pypath: pypath = pypath.split(os.pathsep) + [] else: pypath = [] if os.getcwd() in pypath: return os.environ["PYTHONPATH"] = os.pathsep.join(pypath) def run(self): import glob, unittest, time self.run_command('build') for direct in self.test_dirs: mask = os.path.join(direct, self.test_prefix + "*.py") test_files = glob.glob(mask) print "=== Testing in '%s' ===" % direct self.extend_path() self.testcases = [] self.ok = self.fail = self.errors = 0 self.tracebacks = [] start_time = time.time() for t in test_files: testcases = self.run_test(t) for case in testcases: if self.verbosity > 1: print >> sys.stderr, case elif self.verbosity == 1: if case.endswith("ok"): sys.stderr.write(".") elif case.endswith("FAIL"): sys.stderr.write("F") elif case.endswith("ERROR"): sys.stderr.write("E") else: sys.stderr.write("?") stop_time = time.time() print >> sys.stderr for f in self.tracebacks: print >> sys.stderr, "=" * 42 print >> sys.stderr, f[0] print >> sys.stderr, "-" * 42 print >> sys.stderr, "\n".join(f[1:]) print >> sys.stderr print >> sys.stderr, "-" * 70 print >> sys.stderr, "Ran %d tests in %.3fs" % (len(self.testcases), stop_time - start_time) print >> sys.stderr if self.fail + self.errors == 0: print >> sys.stderr, "OK" else: if self.errors: print >> sys.stderr, "FAILED (failures=%d, errors=%d)" % (self.fail, self.errors) else: print >> sys.stderr, "FAILED (failures=%d)" % self.fail # run() def run_test(self, path): # Run a test file in a separate process, and parse the output. # Collect the results in the ok, fail, error, testcases and # tracebacks instance vars. # A sequence of testcase names together with their outcome is returned. i, o = os.popen4("%s %s -v" % (sys.executable, path)) i.close() cases = [] while 1: line = o.readline() if not line: break line = line.rstrip() if line.startswith('test'): cases.append(line) if line.endswith("ok"): self.ok += 1 elif line.endswith("FAIL"): self.fail += 1 elif line.endswith("ERROR"): self.errors += 1 else: #? self.errors += 1 self.tracebacks.append([line, "Crashed"]) elif line == "=" * 70: # failure or error name = o.readline().rstrip() assert o.readline().rstrip() == "-" * 70 tb = [name] while 1: data = o.readline() if not data.rstrip(): break tb.append(data.rstrip()) self.tracebacks.append(tb) elif line.rstrip() == '-' * 70: pass elif line.startswith("Ran "): pass ## else: ## print line self.testcases.extend(cases) return cases # class test options = {} if (hasattr(distutils.core, 'setup_keywords') and 'classifiers' in distutils.core.setup_keywords): kw['classifiers'] = \ ['Topic :: Software Development', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Intended Audience :: Developers', 'Development Status :: 3 - Alpha', 'Development Status :: 4 - Beta', ] class my_build_py(build_py.build_py): def find_package_modules (self, package, package_dir): """We extend distutils' build_py.find_package_modules() method to include all modules found in the platform specific root package directory into the 'ctypes' root package.""" import glob, sys result = build_py.build_py.find_package_modules(self, package, package_dir) if package == 'ctypes': for pathname in glob.glob(os.path.join(sys.platform, "*.py")): modname = os.path.splitext(os.path.basename(pathname))[0] result.append(('ctypes', modname, pathname)) return result ################################################################ try: walk = os.walk except AttributeError: def walk(top): # Python 2.3's os.walk generator, without the large docstring ;-) # And without the topdown and onerror arguments. from os.path import join, isdir, islink # We may not have read permission for top, in which case we can't # get a list of the files the directory contains. os.path.walk # always suppressed the exception then, rather than blow up for a # minor reason when (say) a thousand readable directories are still # left to visit. That logic is copied here. try: names = os.listdir(top) except OSError, err: return dirs, nondirs = [], [] for name in names: if isdir(join(top, name)): dirs.append(name) else: nondirs.append(name) yield top, dirs, nondirs for name in dirs: path = join(top, name) if not islink(path): for x in walk(path): yield x def find_file_in_subdir(dirname, filename): # if <filename> is in <dirname> or any subdirectory thereof, # return the directory name, else None for d, _, names in walk(dirname): if filename in names: return d return None class my_build_ext(build_ext.build_ext): def run(self): self.build_libffi_static() build_ext.build_ext.run(self) def fix_extension(self, inst_dir): incdir = find_file_in_subdir(os.path.join(inst_dir, "include"), "ffi.h") if not incdir: return 0 libdir = find_file_in_subdir(os.path.join(inst_dir, "lib"), "libffi.a") or \ find_file_in_subdir(os.path.join(inst_dir, "lib64"), "libffi.a") if not libdir: return 0 incdir_2 = find_file_in_subdir(os.path.join(inst_dir, "lib"), "ffitarget.h") if not incdir_2: return 0 for ext in self.extensions: if ext.name == "_ctypes": ext.include_dirs.append(incdir) ext.include_dirs.append(incdir_2) ext.library_dirs.append(libdir) return 1 def build_libffi_static(self): if LIBFFI_SOURCES == None: return src_dir = os.path.abspath(LIBFFI_SOURCES) # Building libffi in a path containing spaces doesn't work: self.build_temp = self.build_temp.replace(" ", "") build_dir = os.path.join(self.build_temp, 'libffi') inst_dir = os.path.abspath(self.build_temp) if not self.force and self.fix_extension(inst_dir): return mkpath(build_dir) config_args = ["--disable-shared", "--enable-static", "--enable-multilib=no", "--prefix='%s'" % inst_dir, ] cmd = "cd %s && '%s/configure' %s && make install" \ % (build_dir, src_dir, " ".join(config_args)) print 'Building static FFI library:' print cmd res = os.system(cmd) if res: print "Failed" sys.exit(res) assert self.fix_extension(inst_dir), "Could not find libffi after building it" # Since we mangle the build_temp dir, we must also do this in the clean command. class my_clean(clean.clean): def run(self): self.build_temp = self.build_temp.replace(" ", "") clean.clean.run(self) if __name__ == '__main__': setup(name="ctypes", ext_modules = extensions, package_dir = package_dir, packages = packages, version="0.6.3", description="create and manipulate C data types in Python", long_description = __doc__, author="Thomas Heller", author_email="th...@py...", license="MIT License", url="http://starship.python.net/crew/theller/ctypes.html", platforms=["windows", "Linux", "MacOS X", "Solaris"], cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, 'clean': my_clean}, **options ) ## Local Variables: ## compile-command: "python setup.py build" ## End: |
From: Thomas H. <th...@us...> - 2004-07-16 19:30:02
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18504 Removed Files: setup.py Log Message: Remove setup.py, will then add it again with +x permission. --- setup.py DELETED --- |
From: Thomas H. <th...@us...> - 2004-07-16 19:25:42
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17439 Modified Files: setup.py Log Message: dummy checkin Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** setup.py 30 Jun 2004 14:01:09 -0000 1.87 --- setup.py 16 Jul 2004 19:25:34 -0000 1.88 *************** *** 12,16 **** from __future__ import generators - # XXX explain LIBFFI_SOURCES LIBFFI_SOURCES='source/gcc/libffi' --- 12,15 ---- |
From: Thomas H. <th...@us...> - 2004-07-16 16:19:16
|
Update of /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13999 Modified Files: toolband.py Log Message: Add credits. Index: toolband.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer/toolband.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** toolband.py 16 Jul 2004 16:16:33 -0000 1.1 --- toolband.py 16 Jul 2004 16:19:07 -0000 1.2 *************** *** 1,3 **** --- 1,7 ---- """ + Based on an idea and sample code from + Author: Eric Koome + Email: ek...@kp... + http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/programmersguide/shell_adv/bands.asp |
From: Thomas H. <th...@us...> - 2004-07-16 16:16:41
|
Update of /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13599 Added Files: toolband.py Log Message: A working, although do-nothing, internet explorer tool band. Based on sample code by Edwin Koome. --- NEW FILE: toolband.py --- """ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/programmersguide/shell_adv/bands.asp http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/components/bandobjs/default.asp """ import _winreg from ctypes import windll, cdll, byref, Structure, POINTER from ctypes import c_void_p, c_int, c_wchar, c_ulong from ctypes.com import COMObject, CLSCTX_INPROC_SERVER, IUnknown, GUID, STDMETHOD, HRESULT from ctypes.com.register import Registrar from ctypes.com.persist import IPersistStream, IPersistStreamInit from ctypes.com.ole import IOleWindow from ctypes.com.hresult import * from ctypes.com.automation import VARIANT from ctypes.wintypes import BOOL, DWORD, RECT, HWND, POINTL COLORREF = DWORD ################################################################ class IObjectWithSite(IUnknown): _iid_ = GUID("{FC4801A3-2BA9-11CF-A229-00AA003D7352}") _methods_ = IUnknown._methods_ + [ (STDMETHOD(HRESULT, "SetSite", POINTER(IUnknown))), (STDMETHOD(HRESULT, "GetSite", POINTER(GUID), POINTER(c_void_p)))] class IDockingWindow(IOleWindow): _iid_ = GUID("{012DD920-7B26-11D0-8CA9-00A0C92DBFE8}") _methods_ = IOleWindow._methods_+ [ (STDMETHOD (HRESULT, "ShowDW", BOOL)), (STDMETHOD (HRESULT, "CloseDW", DWORD)), (STDMETHOD (HRESULT, "ResizeBorderDW", POINTER(RECT), POINTER(IUnknown), BOOL))] ################################################################ DBIM_MINSIZE = 0x0001 DBIM_MAXSIZE = 0x0002 DBIM_INTEGRAL = 0x0004 DBIM_ACTUAL = 0x0008 DBIM_TITLE = 0x0010 DBIM_MODEFLAGS = 0x0020 DBIM_BKCOLOR = 0x0040 DBIMF_NORMAL = 0x0000 DBIMF_VARIABLEHEIGHT = 0x0008 DBIMF_DEBOSSED = 0x0020 DBIMF_BKCOLOR = 0x0040 class DESKBANDINFO(Structure): _fields_ = [("dwMask", DWORD), ("ptMinSize", POINTL), ("ptMaxSize", POINTL), ("ptIntegral", POINTL), ("ptActual", POINTL), ("wszTitle", c_wchar * 256), ("dwModeFlags", DWORD), ("crBkgnd", COLORREF)] OLECMDID_OPEN = 1 OLECMDID_NEW = 2 OLECMDID_SAVE = 3 OLECMDID_SAVEAS = 4 OLECMDID_SAVECOPYAS = 5 OLECMDID_PRINT = 6 OLECMDID_PRINTPREVIEW = 7 OLECMDID_PAGESETUP = 8 OLECMDID_SPELL = 9 OLECMDID_PROPERTIES = 10 OLECMDID_CUT = 11 OLECMDID_COPY = 12 OLECMDID_PASTE = 13 OLECMDID_PASTESPECIAL = 14 OLECMDID_UNDO = 15 OLECMDID_REDO = 16 OLECMDID_SELECTALL = 17 OLECMDID_CLEARSELECTION = 18 OLECMDID_ZOOM = 19 OLECMDID_GETZOOMRANGE = 20 OLECMDID_UPDATECOMMANDS = 21 OLECMDID_REFRESH = 22 OLECMDID_STOP = 23 OLECMDID_HIDETOOLBARS = 24 OLECMDID_SETPROGRESSMAX = 25 OLECMDID_SETPROGRESSPOS = 26 OLECMDID_SETPROGRESSTEXT = 27 OLECMDID_SETTITLE = 28 OLECMDID_SETDOWNLOADSTATE = 29 OLECMDID_STOPDOWNLOAD = 30 OLECMDF_SUPPORTED = 1 OLECMDF_ENABLED = 2 OLECMDF_LATCHED = 4 OLECMDF_NINCHED = 8 class OLECMD(Structure): _fields_ = [("cmdID", c_ulong), # OLECMDID_* ("cmdf", DWORD)] # OLECMDF_* OLECMDTEXTF_NONE = 0 OLECMDTEXTF_NAME = 1 OLECMDTEXTF_STATUS = 2 class OLECMDTEXT(Structure): _fields_ = [("cmdtextf", DWORD), # OLECMDTEXT_* ("cwActual", c_ulong), ("cwBuf", c_ulong), ("rgwz", c_wchar * 1)] # XXX Actual size is the value in the cwBuf field class IOleCommandTarget(IUnknown): _iid_ = GUID("{B722BCCB-4E68-101B-A2BC-00AA00404770}") _methods_ = IUnknown._methods_ + [ STDMETHOD(HRESULT, "QueryStatus", POINTER(GUID), c_ulong, POINTER(OLECMD), POINTER(OLECMDTEXT)), STDMETHOD(HRESULT, "Exec", POINTER(GUID), DWORD, DWORD, POINTER(VARIANT), POINTER(VARIANT)) ] class IDeskBand(IDockingWindow): _iid_= GUID("{EB0FE172-1A3A-11D0-89B3-00A0C90A90AC}") _methods_=IDockingWindow._methods_ + [ (STDMETHOD (HRESULT, "GetBandInfo", DWORD, DWORD, POINTER(DESKBANDINFO)))] DBIF_VIEWMODE_NORMAL = 0x0000 DBIF_VIEWMODE_VERTICAL = 0x0001 DBIF_VIEWMODE_FLOATING = 0x0002 DBIF_VIEWMODE_TRANSPARENT = 0x0004 ################################################################ class ToolBandRegistrar(Registrar): def build_table(self): HKLM = _winreg.HKEY_LOCAL_MACHINE HKCR = _winreg.HKEY_CLASSES_ROOT BHO_KEY = ("Software\\Microsoft\\Internet Explorer\\Toolbar\\") table = Registrar.build_table(self) # rootkey, subkey, valuename, value table.extend([(HKLM, BHO_KEY, self._reg_clsid_, None), (HKCR,"CLSID\\%s\\" % self._reg_clsid_, "", "Python Tool Band"), (HKCR,"CLSID\\%s\\InProcServer32" % self._reg_clsid_, "ThreadingModel", "Apartment") ]) return table # IE seems to crash if we don't implement IOleCommandTarget! class MyBand(COMObject): _reg_clsid_ = "{2BCE5CFB-005C-471A-AE6D-0BAF2E92F5B5}" _reg_progid_ = "Python.Toolband" _reg_clsctx_ = CLSCTX_INPROC_SERVER _com_interfaces_ = [ IPersistStreamInit, IObjectWithSite, IDeskBand, IOleCommandTarget, ## IInputObject ] def _get_registrar(cls): return ToolBandRegistrar(cls) _get_registrar = classmethod(_get_registrar) ################################################################ def IOleCommandTarget_QueryStatus(self, this, pGroup, cCmds, prgCmds, pCmdText): # IOleCommandTarget::QueryStatus print "IOleCommandTarget" if pGroup: print "pGroup", pGroup[0] return S_OK ################################################################ def IPersistStreamInit_InitNew(self, this): return S_OK ################################################################ m_Site = None def IObjectWithSite_SetSite(self, this, punkSite): if punkSite: punkSite.AddRef() # I think this is still required, but SHOULD be automatic self.m_Site = punkSite polewindow = POINTER(IOleWindow)() punkSite.QueryInterface(byref(IOleWindow._iid_), byref(polewindow)) hwndParent = HWND() polewindow.GetWindow(byref(hwndParent)) self.hwndParent = hwndParent.value # Register and create window import win32con self.m_hwnd = windll.user32.CreateWindowExA(0, "button", "button", win32con.WS_CHILD, 0, 0, 0, 0, hwndParent, 0, None, None) else: self.m_Site = None return S_OK ################################################################ m_hwnd = 0 def IOleWindow_GetWindow(self, this, phwnd): if phwnd: phwnd[0] = self.m_hwnd return S_OK else: return E_POINTER ################################################################ def IDockingWindow_CloseDW(self, this, dwReserved): self.IDockingWindow_ShowDW(None, False) if self.m_hwnd: windll.user32.DestroyWindow(self.m_hwnd) self.m_hwnd = 0 return S_OK def IDockingWindow_ShowDW(self, this, bShow): if self.m_hwnd: import win32con if bShow: windll.user32.ShowWindow(self.m_hwnd, win32con.SW_SHOW) else: windll.user32.ShowWindow(self.m_hwnd, win32con.SW_HIDE) return S_OK ################################################################ def IDeskBand_GetBandInfo(self, this, dwBandID, dwViewMode, pdbi): if not pdbi: return E_INVALIDARG dbi = pdbi[0] mask = dbi.dwMask if mask & DBIM_MINSIZE: dbi.ptMinSize.x = 5 dbi.ptMinSize.y = 5 if mask & DBIM_MAXSIZE: dbi.ptMaxSize.x = -1 dbi.ptMaxSize.y = -1 if mask & DBIM_ACTUAL: dbi.ptActual.x = 0 dbi.ptActual.y = 0 if mask & DBIM_INTEGRAL: dbi.ptIntegral.x = 1 dbi.ptIntegral.y = 1 if mask & DBIM_TITLE: dbi.wszTitle = u"Hello World" if mask & DBIM_MODEFLAGS: dbi.dwModeFlags = DBIMF_VARIABLEHEIGHT if mask & DBIM_BKCOLOR: dbi.dwMask &= ~ DBIM_BKCOLOR return S_OK ################################################################ if __name__ == "__main__": from ctypes.com.server import UseCommandLine UseCommandLine(MyBand) |
From: Thomas H. <th...@us...> - 2004-07-16 16:15:42
|
Update of /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13330 Added Files: .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.pyc *.pyo |
From: Thomas H. <th...@us...> - 2004-07-16 16:05:40
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11111 Added Files: errorinfo.py Log Message: Some interfaces, so far only used as a BSTR test case. --- NEW FILE: errorinfo.py --- from ctypes import * from ctypes.wintypes import LPOLESTR from ctypes.com import IUnknown, GUID, STDMETHOD, HRESULT from ctypes.com.automation import BSTR, oleaut32, BSTR from ctypes.com.hresult import S_FALSE, S_OK class ICreateErrorInfo(IUnknown): _iid_ = GUID("{22F03340-547D-101B-8E65-08002B2BD119}") _methods_ = IUnknown._methods_ + [ STDMETHOD(HRESULT, "SetGUID", POINTER(GUID)), STDMETHOD(HRESULT, "SetSource", LPOLESTR), STDMETHOD(HRESULT, "SetDescription", LPOLESTR), STDMETHOD(HRESULT, "SetHelpFile", LPOLESTR), STDMETHOD(HRESULT, "SetHelpContext", LPOLESTR), ] class IErrorInfo(IUnknown): _iid_ = GUID("{1CF2B120-547D-101B-8E65-08002B2BD119}") _methods_ = IUnknown._methods_ + [ STDMETHOD(HRESULT, "GetGUID", POINTER(GUID)), STDMETHOD(HRESULT, "GetSource", POINTER(BSTR)), STDMETHOD(HRESULT, "GetDescription", POINTER(BSTR)), STDMETHOD(HRESULT, "GetHelpFile", POINTER(BSTR)), STDMETHOD(HRESULT, "GetHelpContext", POINTER(BSTR)), ] def CreateErrorInfo(): cei = POINTER(ICreateErrorInfo)() oleaut32.CreateErrorInfo(byref(cei)) return cei def GetErrorInfo(): errinfo = POINTER(IErrorInfo)() if S_OK == oleaut32.GetErrorInfo(0, byref(errinfo)): return errinfo return None def SetErrorInfo(errinfo): return oleaut32.SetErrorInfo(0, errinfo) ################################################################ if __name__ == "__main__": def doit(): for i in range(10): cei = CreateErrorInfo() cei.SetSource(u"Spam, spam, and spam") SetErrorInfo(cei) ei = GetErrorInfo() src = BSTR() ei.GetSource(byref(src)) oleaut32.SysAllocString(u"aber halle") from mallocspy import MallocSpy mallocspy = MallocSpy() mallocspy.register() doit() import ctypes.com windll.ole32.CoUninitialize() print "Clean" mallocspy.revoke() print "Done" ## ctypes.com.__cleaner = None |