From rbell01824 at earthlink.net Sun Jul 1 17:45:45 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Sun, 1 Jul 2007 10:45:45 -0500 Subject: [python-win32] IE DOM ptr as input to DLL function - Doingthisright? In-Reply-To: <00d401c7bad1$a1eaa870$0200a8c0@enfoldsystems.local> References: <00d401c7bad1$a1eaa870$0200a8c0@enfoldsystems.local> Message-ID: <017701c7bbf6$e59b7d30$6701a8c0@rjbmain> Jef, I'm not sure if this is helpful but you might try taking a look at the Pamie code for how it gets deals with the DOM. Additionally the following code snip may be helpful (self is win32com.Client.Dispatch returned IE object) Regards, Richard ----- code ----- def Dom(self, errorFlag = True, message = None ): """ Sets Yamie's dom attribute (topmost element of the page's DOM tree). yie.Dom([errorFlag,][errorMessage])->object #HTML element in the DOM tree The DOM is rebuilt after each navigation. Previous values are no longer good. Parameters: errorFlag (boolean) If True, COM error messages are written to stderr. Otherwise, COM error messages are surpressed. message (string) A message to output on COM errors. Returns: dom (object) The topmost element in the page's DOM tree. dom is None on COM error. Set status and comError. Usage: >>> dom = yie.Dom() >>> print dom #doctest: +ELLIPSIS >>> print dom.CLSID {3050F560-98B5-11CF-BB82-00AA00BDCE0B} >>> len(dir(dom)) 65 >>> len(dom._prop_map_get_.keys()) 130 >>> dir(dom) == ['CLSID', 'FireEvent', '_ApplyTypes_', '__cmp__', '__doc__', ... '__getattr__', '__init__', '__module__', '__repr__', '__setattr__', '_get_good_object_', ... '_get_good_single_object_', '_oleobj_', '_prop_map_get_', '_prop_map_put_', ... 'addBehavior', 'addFilter', 'appendChild', 'applyElement', 'attachEvent', 'blur', ... 'clearAttributes', 'click', 'cloneNode', 'coclass_clsid', 'componentFromPoint', ... 'contains', 'createControlRange', 'detachEvent', 'doScroll', 'dragDrop', 'focus', ... 'getAdjacentText', 'getAttribute', 'getAttributeNode', 'getBoundingClientRect', ... 'getClientRects', 'getElementsByTagName', 'getExpression', 'hasChildNodes', ... 'insertAdjacentElement', 'insertAdjacentHTML', 'insertAdjacentText', 'insertBefore', ... 'mergeAttributes', 'normalize', 'releaseCapture', 'removeAttribute', ... 'removeAttributeNode', 'removeBehavior', 'removeChild', 'removeExpression', ... 'removeFilter', 'removeNode', 'replaceAdjacentText', 'replaceChild', 'replaceNode', ... 'scrollIntoView', 'setActive', 'setAttribute', 'setAttributeNode', 'setCapture', ... 'setExpression', 'swapNode', 'toString'] True >>> dom._prop_map_get_.keys()== ['all', 'contentEditable', 'parentElement', ... 'onrowsinserted', 'disabled', 'filters', 'onrowexit', 'children', 'style', ... 'ondataavailable', 'nodeName', 'ondatasetchanged', 'clientLeft', 'accessKey', ... 'offsetLeft', 'ondatasetcomplete', 'currentStyle', 'hideFocus', 'onclick', 'onkeypress', ... 'onbeforeupdate', 'onpropertychange', 'onresizestart', 'onmouseover', 'recordNumber', ... 'onscroll', 'onrowenter', 'clientHeight', 'onmouseenter', 'canHaveChildren', 'onkeyup', ... 'readyStateValue', 'onreadystatechange', 'dir', 'tagUrn', 'onfocusout', 'innerHTML', ... 'className', 'ondeactivate', 'onmoveend', 'ondragleave', 'glyphMode', 'onresize', ... 'version', 'onresizeend', 'offsetTop', 'onfocus', 'ondrag', 'previousSibling', ... 'onfocusin', 'nodeType', 'onbeforeeditfocus', 'onkeydown', 'outerText', 'onbeforecopy', ... 'language', 'title', 'firstChild', 'oncut', 'onbeforedeactivate', 'attributes', ... 'onmove', 'offsetParent', 'behaviorUrns', 'clientWidth', 'outerHTML', 'tagName', ... 'offsetHeight', 'onerrorupdate', 'onbeforepaste', 'childNodes', 'tabIndex', ... 'scrollWidth', 'onpage', 'isDisabled', 'onhelp', 'oncontrolselect', 'onmouseup', ... 'onmousemove', 'isMultiLine', 'onblur', 'onmouseout', 'oncellchange', 'sourceIndex', ... 'scrollLeft', 'parentTextEdit', 'onmousewheel', 'lastChild', 'scrollHeight', ... 'oncontextmenu', 'onrowsdelete', 'readyState', 'inflateBlock', 'onlayoutcomplete', ... 'innerText', 'onmovestart', 'offsetWidth', 'uniqueID', 'onafterupdate', 'ondragenter', ... 'nextSibling', 'onmousedown', 'clientTop', 'parentNode', 'oncopy', 'onfilterchange', ... 'id', 'ondrop', 'isTextEdit', 'onbeforecut', 'ownerDocument', 'onactivate', ... 'runtimeStyle', 'document', 'isContentEditable', 'ondragstart', 'onmouseleave', ... 'uniqueNumber', 'scrollTop', 'onpaste', 'ondragover', 'lang', 'ondragend', ... 'canHaveHTML', 'scopeName', 'nodeValue', 'onlosecapture', 'onbeforeactivate', ... 'ondblclick', 'onselectstart'] True """ try: node = self.Document.all.tags("HTML") self.dom = node.item(0) return self.dom except pythoncom.com_error, (hr, hrtxt, addinfo, arg): self.dom = None if not message: message = 'Dom error' self._ComError( errorFlag, message, hr, hrtxt, addinfo, arg) return None |-----Original Message----- |From: python-win32-bounces at python.org [mailto:python-win32- |bounces at python.org] On Behalf Of Mark Hammond |Sent: Friday, June 29, 2007 11:47 PM |To: 'Jef Allbright'; python-win32 at python.org |Subject: Re: [python-win32] IE DOM ptr as input to DLL function - |Doingthisright? | |> I'm a newbie to Win32 COM and am unsure whether my current problem |> lies in what I'm doing or possibly in some quirk of the DLL I'm trying |> to use from Python. |> |> I have a snippet of C++ that I want to implement in Python: |> |> IDispatch* pVoid; |> m_pBrowserApp->get_Document(&pVoid); |> m_pAnalyzer->Analyze(pVoid, _variant_t(5L)); |> pVoid->Release(); |> |> At first, I tried using win32com.Client.Dispatch to create a COM |> object for both my DLL and for the IE browser, and that worked well up |> to the point where I tried to use the ie.Document object as input to |> Analyze where it expects the pVoid. Got "argument is not a COM |> object" | |In general, COM itself doesn't understand a "void *". In the example |above, |that first param would probably be best defined as IUnknown rather than |void. Further, in general, win32com only supports IDispatch based |interfaces, but the C++ example above is using vtables. If you can get |your |analyzer interface working via IDispatch, it will work correctly from |Python, as well as VBScript, JS, etc... | |I'm afraid I can't help with the comtypes issues... | |Cheers, | |Mark | |_______________________________________________ |Python-win32 mailing list |Python-win32 at python.org |http://mail.python.org/mailman/listinfo/python-win32 From rwupole at msn.com Sun Jul 1 20:33:01 2007 From: rwupole at msn.com (Roger Upole) Date: Sun, 1 Jul 2007 14:33:01 -0400 Subject: [python-win32] Re: PythonWin won't start the second time Message-ID: <000b01c7bc0e$448920b0$0100a8c0@rupole> "Zeev B" wrote: > This is the comparison of the two files (starting at offset 0): > > ----------------------------------------------------- > L0 B3 F2 0D 0A 94 BF 29 42 63 00 00 00 00 00 00 00 ??.."?)Bc....... > R0 B3 F2 0D 0A A4 CD 29 42 63 00 00 00 00 00 00 00 ??..??)Bc....... > > L - the working version > R - the crashing version > > The bytes that differ are the 5th and 6th. Any idea? > > Roger, Thanks for your patients. > > Ze'ev I'm just about out of ideas here. After looking at the code in import.c, it looks like those 2 bytes are part of the timestamp that python uses to check if the module has been modified since it was last compiled to pyc. Does it crash if you import intpyapp from the python console ? If you run python in verbose mode, it should tell you where it got the module from and why it's recompiling it. python.exe -vv >>> from pywin.framework import intpyapp Roger From rwupole at msn.com Sun Jul 1 22:14:49 2007 From: rwupole at msn.com (Roger Upole) Date: Sun, 1 Jul 2007 16:14:49 -0400 Subject: [python-win32] Anyone else have windows context menus fail to Message-ID: <000701c7bc1c$7c7a8960$0100a8c0@rupole> "R. Alan Monroe" wrote: >I noticed the "Edit" context menu option in Windows Explorer was > opening an older version of pythonwin. I re-ran the pywin32 210 > installer to see if it would patch it up, but no dice. > > I can hand-correct these of course, but shouldn't it be working out of > the box? Flaw in the installer? > > >> Windows Registry Editor Version 5.00 >> >> [HKEY_CLASSES_ROOT\Python.File] >> @="Python File" >> >> [HKEY_CLASSES_ROOT\Python.File\AutoRegister] >> @="C:\\WINNT\\System32\\PythonCOM23.dll" <---------- WRONG? >> >> [HKEY_CLASSES_ROOT\Python.File\DefaultIcon] >> @="C:\\Python25\\DLLs\\py.ico" >> >> [HKEY_CLASSES_ROOT\Python.File\shell] >> >> [HKEY_CLASSES_ROOT\Python.File\shell\Edit] >> >> [HKEY_CLASSES_ROOT\Python.File\shell\Edit\command] >> @="C:\\Python23\\pythonwin.exe /edit \"%1\"" <---------- WRONG? >> >> [HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE] >> >> [HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command] >> @="\"C:\\Python25\\pythonw.exe\" \"C:\\Python25\\Lib\\idlelib\\idle.pyw\" -n -e \"%1\"" >> >> [HKEY_CLASSES_ROOT\Python.File\shell\open] >> >> [HKEY_CLASSES_ROOT\Python.File\shell\open\command] >> @="\"C:\\Python25\\python.exe\" \"%1\" %*" > > Alan The registry entries for Pythonwin have been added to the postinstall script. Roger From jef at jefallbright.net Mon Jul 2 19:15:41 2007 From: jef at jefallbright.net (Jef Allbright) Date: Mon, 2 Jul 2007 10:15:41 -0700 Subject: [python-win32] IE DOM ptr as input to DLL function - Doingthisright? In-Reply-To: <017701c7bbf6$e59b7d30$6701a8c0@rjbmain> References: <00d401c7bad1$a1eaa870$0200a8c0@enfoldsystems.local> <017701c7bbf6$e59b7d30$6701a8c0@rjbmain> Message-ID: On 7/1/07, Richard Bell wrote: ... On 6/29/07, Mark Hammond wrote: ... Thanks Richard and Mark for providing a broader sense of the territory. At this point I suspect Ctypes might do what I need, but that too is mostly unexplored territory for me. In the meantime I've installed a Microsoft C++ platform (yuck!) so I can experiment there in parallel. - Jef From zeevb.public at gmail.com Mon Jul 2 21:05:40 2007 From: zeevb.public at gmail.com (Zeev B) Date: Mon, 2 Jul 2007 22:05:40 +0300 Subject: [python-win32] PythonWin won't start the second time In-Reply-To: <000b01c7bc0e$448920b0$0100a8c0@rupole> References: <000b01c7bc0e$448920b0$0100a8c0@rupole> Message-ID: <4ea013420707021205v7cb8c980i3197b82de1c896cf@mail.gmail.com> No, It doesn't crash if I import it from the python console. I ran python.exe -v (after replacing the file with the original pyc that does work - the one that was generated in the installation) and indeed it recompiles because of a bad timestamp. Following are the relevant lines from the verbose output: # c:\Python25\lib\site-packages\Pythonwin\pywin\framework\intpyapp.pyc has bad mtime import pywin.framework.intpyapp # from c:\Python25\lib\site-packages\Pythonwin\pywin\framework\intpyapp.py # wrote c:\Python25\lib\site-packages\Pythonwin\pywin\framework\intpyapp.pyc Of course once recompiled it crashed Pythonwin (but not the console when importing) This is the DrWatson report: Microsoft (R) DrWtsn32 Copyright (C) 1985-2001 Microsoft Corp. All rights reserved. Application exception occurred: App: C:\Python25\Lib\site-packages\pythonwin\Pythonwin.exe (pid=3924) When: 02/07/2007 @ 21:59:12.190 Exception number: c0000005 (access violation) *----> System Information <----* Computer Name: HOMEPC User Name: Zeev Terminal Session Id: 0 Number of Processors: 2 Processor Type: x86 Family 15 Model 4 Stepping 10 Windows Version: 5.1 Current Build: 2600 Service Pack: 2 Current Type: Multiprocessor Free Registered Organization: Home Registered Owner: SZ-SB *----> Task List <----* 0 System Process 4 System 628 smss.exe 676 csrss.exe 700 winlogon.exe 744 services.exe 756 lsass.exe 924 svchost.exe 992 svchost.exe 1088 MsMpEng.exe 1128 svchost.exe 1236 svchost.exe 1348 svchost.exe 1412 ccSetMgr.exe 1952 ccEvtMgr.exe 2040 ccProxy.exe 124 SNDSrvc.exe 220 SPBBCSvc.exe 388 symlcsvc.exe 368 spoolsv.exe 2328 ALUSchedulerSvc.exe 2760 MDM.EXE 2796 navapsvc.exe 2976 SR_Service.exe 3072 SR_WatchDog.exe 3096 svchost.exe 3192 ULCDRSvr.exe 3260 CALMAIN.exe 608 alg.exe 1532 NSCSRVCE.EXE 1968 Explorer.EXE 1880 SR_GUI.Exe 3480 TSVNCache.exe 3288 igfxtray.exe 2968 hkcmd.exe 4056 igfxpers.exe 2216 RTHDCPL.EXE 1472 MSASCui.exe 3360 PicasaMediaDetector.exe 2336 PDVDServ.exe 200 hpztsb04.exe 3744 ccApp.exe 1440 jusched.exe 1056 PowerBar.exe 3024 ctfmon.exe 3028 msmsgs.exe 1068 GoogleToolbarNotifier.exe 4008 firefox.exe 1648 TOTALCMD.EXE 3996 Skype.exe 1096 skypePM.exe 648 cmd.exe 2352 notepad.exe 1508 cmd.exe 3008 notepad.exe 3924 Pythonwin.exe 1084 drwtsn32.exe *----> Module List <----* (0000000000400000 - 0000000000406000: C:\Python25\Lib\site-packages\pythonwin\Pythonwin.exe (000000001e000000 - 000000001e206000: C:\WINDOWS\system32\python25.dll (000000001e280000 - 000000001e322000: C:\Python25\Lib\site-packages\pythonwin\win32ui.pyd (000000001e530000 - 000000001e53c000: C:\Python25\Lib\site-packages\pythonwin\dde.pyd (000000001e770000 - 000000001e789000: C:\WINDOWS\system32\pywintypes25.dll (000000001e890000 - 000000001e8a5000: C:\Python25\lib\site-packages\win32\win32api.pyd (000000005ad70000 - 000000005ada8000: C:\WINDOWS\system32\UxTheme.dll (000000005cb70000 - 000000005cb96000: C:\WINDOWS\system32\ShimEng.dll (000000005d090000 - 000000005d12a000: C:\WINDOWS\system32\comctl32.dll (00000000629c0000 - 00000000629c9000: C:\WINDOWS\system32\LPK.DLL (00000000651b0000 - 00000000651d2000: C:\PROGRA~1\COMMON~1\SYMANT~1\ANTISPAM\ASOEHOOK.DLL (000000006af90000 - 000000006afee000: C:\Program Files\Common Files\Symantec Shared\ccL40.dll (000000006f880000 - 000000006fa4a000: C:\WINDOWS\AppPatch\AcGenral.DLL (0000000073000000 - 0000000073026000: C:\WINDOWS\system32\WINSPOOL.DRV (0000000074720000 - 000000007476b000: C:\WINDOWS\system32\MSCTF.dll (0000000074d90000 - 0000000074dfb000: C:\WINDOWS\system32\USP10.dll (00000000769c0000 - 0000000076a73000: C:\WINDOWS\system32\USERENV.dll (0000000076b40000 - 0000000076b6d000: C:\WINDOWS\system32\WINMM.dll (0000000077120000 - 00000000771ac000: C:\WINDOWS\system32\OLEAUT32.dll (00000000773d0000 - 00000000774d3000: C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll (00000000774e0000 - 000000007761d000: C:\WINDOWS\system32\ole32.dll (0000000077b40000 - 0000000077b62000: C:\WINDOWS\system32\Apphelp.dll (0000000077be0000 - 0000000077bf5000: C:\WINDOWS\system32\MSACM32.dll (0000000077c00000 - 0000000077c08000: C:\WINDOWS\system32\VERSION.dll (0000000077c10000 - 0000000077c68000: C:\WINDOWS\system32\msvcrt.dll (0000000077dd0000 - 0000000077e6b000: C:\WINDOWS\system32\ADVAPI32.dll (0000000077e70000 - 0000000077f01000: C:\WINDOWS\system32\RPCRT4.dll (0000000077f10000 - 0000000077f57000: C:\WINDOWS\system32\GDI32.dll (0000000077f60000 - 0000000077fd6000: C:\WINDOWS\system32\SHLWAPI.dll (0000000077fe0000 - 0000000077ff1000: C:\WINDOWS\system32\secur32.dll (000000007c140000 - 000000007c246000: C:\WINDOWS\system32\MFC71.DLL (000000007c360000 - 000000007c3b6000: C:\WINDOWS\system32\MSVCR71.dll (000000007c3c0000 - 000000007c43c000: C:\WINDOWS\system32\MSVCP71.dll (000000007c800000 - 000000007c8f5000: C:\WINDOWS\system32\kernel32.dll (000000007c900000 - 000000007c9b0000: C:\WINDOWS\system32\ntdll.dll (000000007c9c0000 - 000000007d1d5000: C:\WINDOWS\system32\SHELL32.dll (000000007e410000 - 000000007e4a0000: C:\WINDOWS\system32\USER32.dll *----> State Dump for Thread Id 0xc2c <----* eax=00000000 ebx=00000009 ecx=000002bc edx=1e1d9ab8 esi=00d45d20 edi=00000009 eip=1e0658a5 esp=0013f3c8 ebp=0013f52c iopl=0 nv up ei pl zr na po nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246 *** WARNING: Unable to verify checksum for C:\WINDOWS\system32\python25.dll *** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINDOWS\system32\python25.dll - function: python25!PyErr_Occurred 1e065891 750a jnz python25!PyErr_SetString+0x2d (1e06589d) 1e065893 8b5604 mov edx,[esi+0x4] 1e065896 56 push esi 1e065897 ff5218 call dword ptr [edx+0x18] 1e06589a 83c404 add esp,0x4 1e06589d 5e pop esi 1e06589e c3 ret 1e06589f cc int 3 python25!PyErr_Occurred: 1e0658a0 a150261f1e mov eax,[python25!PyThreadState_Current (1e1f2650)] FAULT ->1e0658a5 8b4028 mov eax,[eax+0x28] ds:0023:00000028=???????? 1e0658a8 c3 ret 1e0658a9 cc int 3 1e0658aa cc int 3 1e0658ab cc int 3 1e0658ac cc int 3 1e0658ad cc int 3 1e0658ae cc int 3 1e0658af cc int 3 python25!PyErr_GivenExceptionMatches: 1e0658b0 55 push ebp *----> Stack Back Trace <----* *** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINDOWS\system32\MFC71.DLL - WARNING: Stack unwind information not available. Following frames may be wrong. ChildEBP RetAddr Args to Child 0013f52c 7c1c8e4a 00cf0000 00002b78 00bfc1e0 python25!PyErr_Occurred+0x5 0013f55c 7c1c9b6f 00c17e18 00cf0000 00000000 MFC71!Ordinal4019+0x62 ffffffff 00000000 00000000 00000000 00000000 MFC71!Ordinal4021+0x18 *----> Raw Stack Dump <----* 000000000013f3c8 04 2e 07 1e c8 69 1e 1e - 70 2e 07 1e 30 00 00 00 .....i..p...0... 000000000013f3d8 29 00 00 00 00 00 00 00 - 8d 19 0d 1e c8 69 1e 1e )............i.. 000000000013f3e8 09 00 00 00 09 00 00 00 - 00 00 00 00 be 00 09 1e ................ 000000000013f3f8 09 00 00 00 29 00 00 00 - 40 f4 13 00 00 00 00 00 ....)... at ....... 000000000013f408 f6 fb 08 1e 40 f4 13 00 - 3c f4 13 00 29 00 00 00 .... at ...<...)... 000000000013f418 09 00 00 00 00 00 00 00 - a4 f4 13 00 00 00 00 00 ................ 000000000013f428 00 00 00 00 c8 01 09 1e - 40 f4 13 00 3c f4 13 00 ........ at ...<... 000000000013f438 00 00 00 00 58 f4 13 00 - f5 45 2e 1e 01 02 09 1e ....X....E...... 000000000013f448 58 f4 13 00 d4 f4 13 00 - 8e 8b 2b 1e f4 45 2e 1e X.........+..E.. 000000000013f458 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 000000000013f468 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 000000000013f478 00 00 cf 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 000000000013f488 a9 fb 2b 1e d4 f4 13 00 - d4 f4 13 00 e0 c1 bf 00 ..+............. 000000000013f498 ea 79 2b 1e d4 f4 13 00 - 57 05 90 00 40 be bc 00 .y+.....W... at ... 000000000013f4a8 00 00 00 00 a4 b9 be 00 - 68 7e c1 00 00 00 00 00 ........h~...... 000000000013f4b8 50 f5 13 00 18 d4 2c 1e - 00 00 00 00 0a 76 1c 7c P.....,......v.| 000000000013f4c8 d4 f4 13 00 78 2b 00 00 - e0 c1 bf 00 00 00 00 00 ....x+.......... 000000000013f4d8 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ 000000000013f4e8 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 cf 00 ................ 000000000013f4f8 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 ................ ---- This is the error report prepared by windows: Ze'ev On 7/1/07, Roger Upole wrote: > "Zeev B" wrote: > > This is the comparison of the two files (starting at offset 0): > > > > ----------------------------------------------------- > > L0 B3 F2 0D 0A 94 BF 29 42 63 00 00 00 00 00 00 00 ??.."?)Bc....... > > R0 B3 F2 0D 0A A4 CD 29 42 63 00 00 00 00 00 00 00 ??..??)Bc....... > > > > L - the working version > > R - the crashing version > > > > The bytes that differ are the 5th and 6th. Any idea? > > > > Roger, Thanks for your patients. > > > > Ze'ev > > I'm just about out of ideas here. > After looking at the code in import.c, it looks like those 2 bytes > are part of the timestamp that python uses to check if the module > has been modified since it was last compiled to pyc. > > Does it crash if you import intpyapp from the python console ? > If you run python in verbose mode, it should tell you where it got > the module from and why it's recompiling it. > > python.exe -vv > >>> from pywin.framework import intpyapp > > Roger > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From nytrokiss at gmail.com Tue Jul 3 20:48:45 2007 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 3 Jul 2007 11:48:45 -0700 Subject: [python-win32] Threading Issue Message-ID: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> Dear List. When spawning a thread using the threading module syntax new_thread = threading.Thread(target=function_returning_a_list) How can i get the list that this function is supposed to return. Thanks James -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/09ecf20e/attachment.html From nytrokiss at gmail.com Tue Jul 3 21:08:47 2007 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 3 Jul 2007 12:08:47 -0700 Subject: [python-win32] Threading Issue In-Reply-To: <468A9E33.1010001@noaa.gov> References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> Message-ID: <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> So i need to make the list a global variable On 7/3/07, Jim Vickroy wrote: > > James Matthews wrote: > > Dear List. > > When spawning a thread using the threading module syntax new_thread = > threading.Thread(target=function_returning_a_list) How can i get the list > that this function is supposed to return. > > Thanks > James > > > -- > http://www.goldwatches.com/watches.asp?Brand=14 > http://www.jewelerslounge.com > > ------------------------------ > > _______________________________________________ > Python-win32 mailing listPython-win32 at python.orghttp://mail.python.org/mailman/listinfo/python-win32 > > Hello James, > > There is no direct way to do what you want. Here is an example of how to > indirectly do it: > > >>> import threading > >>> def foo(result): > ... [result.append(i) for i in range(4)] > ... > >>> result = list() > >>> thread = threading.Thread(target=foo, args=(result,)) > >>> thread.start() > >>> result > [0, 1, 2, 3] > >>> > -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/f8497565/attachment.html From Jim.Vickroy at noaa.gov Tue Jul 3 21:12:01 2007 From: Jim.Vickroy at noaa.gov (Jim Vickroy) Date: Tue, 03 Jul 2007 13:12:01 -0600 Subject: [python-win32] Threading Issue In-Reply-To: <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> Message-ID: <468A9F81.2060507@noaa.gov> James Matthews wrote: > So i need to make the list a global variable It could be but that is not necessary. The list is simply a variable known to the program unit that creates the threading.Thread(...) instance. > > On 7/3/07, *Jim Vickroy* > wrote: > > James Matthews wrote: >> Dear List. >> >> When spawning a thread using the threading module syntax >> new_thread = threading.Thread(target=function_returning_a_list) >> How can i get the list that this function is supposed to return. >> >> Thanks >> James >> >> >> -- >> http://www.goldwatches.com/watches.asp?Brand=14 >> http://www.jewelerslounge.com >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Python-win32 mailing list >> Python-win32 at python.org >> http://mail.python.org/mailman/listinfo/python-win32 >> > Hello James, > > There is no direct way to do what you want. Here is an example of > how to indirectly do it: > > >>> import threading > >>> def foo(result): > ... [result.append(i) for i in range(4)] > ... > >>> result = list() > >>> thread = threading.Thread(target=foo, args=(result,)) > >>> thread.start() > >>> result > [0, 1, 2, 3] > >>> > > > > > -- > http://www.goldwatches.com/watches.asp?Brand=14 > http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/eb2ef61e/attachment.htm From Jim.Vickroy at noaa.gov Tue Jul 3 21:06:27 2007 From: Jim.Vickroy at noaa.gov (Jim Vickroy) Date: Tue, 03 Jul 2007 13:06:27 -0600 Subject: [python-win32] Threading Issue In-Reply-To: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> Message-ID: <468A9E33.1010001@noaa.gov> James Matthews wrote: > Dear List. > > When spawning a thread using the threading module syntax new_thread = > threading.Thread(target=function_returning_a_list) How can i get the > list that this function is supposed to return. > > Thanks > James > > > -- > http://www.goldwatches.com/watches.asp?Brand=14 > http://www.jewelerslounge.com > ------------------------------------------------------------------------ > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > Hello James, There is no direct way to do what you want. Here is an example of how to indirectly do it: >>> import threading >>> def foo(result): ... [result.append(i) for i in range(4)] ... >>> result = list() >>> thread = threading.Thread(target=foo, args=(result,)) >>> thread.start() >>> result [0, 1, 2, 3] >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/a9d22801/attachment.htm From timr at probo.com Tue Jul 3 23:00:44 2007 From: timr at probo.com (Tim Roberts) Date: Tue, 03 Jul 2007 14:00:44 -0700 Subject: [python-win32] Threading Issue In-Reply-To: <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> Message-ID: <468AB8FC.6040408@probo.com> James Matthews wrote: > So i need to make the list a global variable No, that's not what he did at all. The names just happened to be the same, that's all. Consider it this way: import threading def foo( threadresult ): threadresult.extend( range(4) ) result = list() thread = threading.Thread(target=foo, args=(result,)) thread.start() result -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nytrokiss at gmail.com Tue Jul 3 23:21:34 2007 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 3 Jul 2007 14:21:34 -0700 Subject: [python-win32] Threading Issue In-Reply-To: <468AB8FC.6040408@probo.com> References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> <468AB8FC.6040408@probo.com> Message-ID: <8a6b8e350707031421p5822a0bax84505001bf3cf923@mail.gmail.com> Ok i have resolved the issue thank you! James On 7/3/07, Tim Roberts wrote: > > James Matthews wrote: > > So i need to make the list a global variable > > No, that's not what he did at all. The names just happened to be the > same, that's all. Consider it this way: > > import threading > def foo( threadresult ): > threadresult.extend( range(4) ) > > result = list() > thread = threading.Thread(target=foo, args=(result,)) > thread.start() > result > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/d5df7136/attachment.html From emlynj at gmail.com Tue Jul 3 23:22:36 2007 From: emlynj at gmail.com (Emlyn Jones) Date: Tue, 3 Jul 2007 22:22:36 +0100 Subject: [python-win32] Threading Issue In-Reply-To: References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> <468AB8FC.6040408@probo.com> Message-ID: On 7/3/07, Emlyn Jones wrote: > On 7/3/07, Tim Roberts wrote: > James Matthews wrote: > > > So i need to make the list a global variable > > > > No, that's not what he did at all. The names just happened to be the > > same, that's all. Consider it this way: > > > > import threading > > def foo( threadresult ): > > threadresult.extend( range(4) ) > > > > result = list() > > thread = threading.Thread(target=foo, args=(result,)) > > thread.start() > > result > > How about using an object derived from Thread and making 'result' a member of it? http://docs.python.org/lib/thread-objects.html You'd probably also want a variable to tell you if the function has finished. -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments From nytrokiss at gmail.com Tue Jul 3 23:42:30 2007 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 3 Jul 2007 14:42:30 -0700 Subject: [python-win32] Threading Issue In-Reply-To: References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> <468AB8FC.6040408@probo.com> Message-ID: <8a6b8e350707031442h6a5561c5oeafe03a9ded2e2d9@mail.gmail.com> Thanks Emlyn Just one more issue i have here. When i pass a string as an argument to the thread it seems to call the method returning the string as a tuple and i get an error that the method gets 48 arguments and it can only accept 2? If this doesn't make sense here is the code. for links in urls: links_thread = threading.Thread(target=self.next_page_finder,args=links) # Links is a string threaded_objects.append(links_thread) I get this error: Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python25\lib\threading.py", line 460, in __bootstrap self.run() File "C:\Python25\lib\threading.py", line 440, in run self.__target(*self.__args, **self.__kwargs) TypeError: next_page_finder() takes exactly 2 arguments (48 given) Thanks James On 7/3/07, Emlyn Jones wrote: > > On 7/3/07, Emlyn Jones wrote: > > On 7/3/07, Tim Roberts wrote: > > James Matthews wrote: > > > > So i need to make the list a global variable > > > > > > No, that's not what he did at all. The names just happened to be the > > > same, that's all. Consider it this way: > > > > > > import threading > > > def foo( threadresult ): > > > threadresult.extend( range(4) ) > > > > > > result = list() > > > thread = threading.Thread(target=foo, args=(result,)) > > > thread.start() > > > result > > > > > How about using an object derived from Thread and making 'result' a > member of it? > > http://docs.python.org/lib/thread-objects.html > > You'd probably also want a variable to tell you if the function has > finished. > > -- > () ascii ribbon campaign - against html e-mail > /\ www.asciiribbon.org - against proprietary attachments > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/6bdcad5b/attachment.htm From Jim.Vickroy at noaa.gov Tue Jul 3 23:49:58 2007 From: Jim.Vickroy at noaa.gov (Jim Vickroy) Date: Tue, 03 Jul 2007 15:49:58 -0600 Subject: [python-win32] Threading Issue In-Reply-To: <8a6b8e350707031442h6a5561c5oeafe03a9ded2e2d9@mail.gmail.com> References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> <468AB8FC.6040408@probo.com> <8a6b8e350707031442h6a5561c5oeafe03a9ded2e2d9@mail.gmail.com> Message-ID: <468AC486.7040308@noaa.gov> James Matthews wrote: > Thanks Emlyn > > Just one more issue i have here. When i pass a string as an argument > to the thread it seems to call the method returning the string as a > tuple and i get an error that the method gets 48 arguments and it can > only accept 2? > > If this doesn't make sense here is the code. > > for links in urls: > links_thread = > threading.Thread(target=self.next_page_finder,args=links) # Links is a > string that argument (i.e., links) is expected to be a python tuple so what you need is: links_thread = threading.Thread(target=self.next_page_finder,args=(links,)) > threaded_objects.append(links_thread) > I get this error: > Exception in thread Thread-1: > Traceback (most recent call last): > File "C:\Python25\lib\threading.py", line 460, in __bootstrap > self.run() > File "C:\Python25\lib\threading.py", line 440, in run > self.__target(*self.__args, **self.__kwargs) > TypeError: next_page_finder() takes exactly 2 arguments (48 given) > > Thanks > > James > > > On 7/3/07, * Emlyn Jones* > > wrote: > > On 7/3/07, Emlyn Jones > wrote: > > On 7/3/07, Tim Roberts > > wrote: > > James Matthews wrote: > > > > So i need to make the list a global variable > > > > > > No, that's not what he did at all. The names just happened to > be the > > > same, that's all. Consider it this way: > > > > > > import threading > > > def foo( threadresult ): > > > threadresult.extend( range(4) ) > > > > > > result = list() > > > thread = threading.Thread (target=foo, args=(result,)) > > > thread.start() > > > result > > > > > How about using an object derived from Thread and making 'result' a > member of it? > > http://docs.python.org/lib/thread-objects.html > > You'd probably also want a variable to tell you if the function > has finished. > > -- > () ascii ribbon campaign - against html e-mail > /\ www.asciiribbon.org - against > proprietary attachments > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > > > -- > http://www.goldwatches.com/watches.asp?Brand=14 > http://www.jewelerslounge.com > ------------------------------------------------------------------------ > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/ea7f29e6/attachment.html From nytrokiss at gmail.com Wed Jul 4 00:01:47 2007 From: nytrokiss at gmail.com (James Matthews) Date: Tue, 3 Jul 2007 15:01:47 -0700 Subject: [python-win32] Threading Issue In-Reply-To: <468AC486.7040308@noaa.gov> References: <8a6b8e350707031148u5d2ba949m97558cf599343b3c@mail.gmail.com> <468A9E33.1010001@noaa.gov> <8a6b8e350707031208o728e43ddkc7377a3c2dd12107@mail.gmail.com> <468AB8FC.6040408@probo.com> <8a6b8e350707031442h6a5561c5oeafe03a9ded2e2d9@mail.gmail.com> <468AC486.7040308@noaa.gov> Message-ID: <8a6b8e350707031501l21163becoc7bfbbe95a188c4c@mail.gmail.com> Thanks On 7/3/07, Jim Vickroy wrote: > > James Matthews wrote: > > Thanks Emlyn > > Just one more issue i have here. When i pass a string as an argument to > the thread it seems to call the method returning the string as a tuple and i > get an error that the method gets 48 arguments and it can only accept 2? > > If this doesn't make sense here is the code. > > for links in urls: > links_thread = threading.Thread(target=self.next_page_finder,args=links) > # Links is a string > > that argument (i.e., links) is expected to be a python tuple so what you > need is: > links_thread = threading.Thread(target=self.next_page_finder > ,args=(links,)) > > threaded_objects.append(links_thread) > I get this error: > Exception in thread Thread-1: > Traceback (most recent call last): > File "C:\Python25\lib\threading.py", line 460, in __bootstrap > self.run() > File "C:\Python25\lib\threading.py", line 440, in run > self.__target(*self.__args, **self.__kwargs) > TypeError: next_page_finder() takes exactly 2 arguments (48 given) > > Thanks > > James > > > On 7/3/07, Emlyn Jones wrote: > > > > On 7/3/07, Emlyn Jones wrote: > > > On 7/3/07, Tim Roberts wrote: > > > James Matthews wrote: > > > > > So i need to make the list a global variable > > > > > > > > No, that's not what he did at all. The names just happened to be > > the > > > > same, that's all. Consider it this way: > > > > > > > > import threading > > > > def foo( threadresult ): > > > > threadresult.extend( range(4) ) > > > > > > > > result = list() > > > > thread = threading.Thread (target=foo, args=(result,)) > > > > thread.start() > > > > result > > > > > > > > How about using an object derived from Thread and making 'result' a > > member of it? > > > > http://docs.python.org/lib/thread-objects.html > > > > You'd probably also want a variable to tell you if the function has > > finished. > > > > -- > > () ascii ribbon campaign - against html e-mail > > /\ www.asciiribbon.org - against proprietary attachments > > _______________________________________________ > > Python-win32 mailing list > > Python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > > -- > http://www.goldwatches.com/watches.asp?Brand=14 > http://www.jewelerslounge.com > > ------------------------------ > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.orghttp://mail.python.org/mailman/listinfo/python-win32 > > > -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070703/1e761443/attachment.htm From jason.ferrara at jacquette.com Wed Jul 4 16:30:26 2007 From: jason.ferrara at jacquette.com (Jason Ferrara) Date: Wed, 4 Jul 2007 10:30:26 -0400 Subject: [python-win32] issues with win32com constants and static/dynamic dispatch Message-ID: I'm trying to use a COM library from python. If I use dynamic dispatch, the com objects all behave correctly, but the constants defined in the COM library don't show up. If I use static dispatch, the constants show up, but COM objects returned by calls into the COM library seem broken. As example, starting with dynamic dispatch Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging \sensor_data") >>> c=cams[0] >>> print c >>> print c.productName Micron Imaging DEMO2 So far everything is fine, but now... >>> print win32com.client.constants.MI_BAYER_8 Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\win32com\client \__init__.py", line 168, in __getattr__ raise AttributeError, a AttributeError: MI_BAYER_8 This is no good. So now I try static dispatch Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> mi=win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib") >>> print win32com.client.constants.MI_BAYER_8 1 Things are looking better, but now... >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging \sensor_data") >>> c=cams[0] >>> print c >>> print c.productName Traceback (most recent call last): File "", line 1, in AttributeError: 'PyIUnknown' object has no attribute 'productName' So whats going on here? What am I doing wrong? Thanks - J -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070704/c57e0eb9/attachment.html From simon.dahlbacka at gmail.com Wed Jul 4 17:20:29 2007 From: simon.dahlbacka at gmail.com (Simon Dahlbacka) Date: Wed, 4 Jul 2007 18:20:29 +0300 Subject: [python-win32] issues with win32com constants and static/dynamic dispatch In-Reply-To: References: Message-ID: <57124720707040820o4e57246fhe9041f2ff6f198b8@mail.gmail.com> my best guess is that you should be using .ProductName (capital p) as static dispatch is case sensitive.. /S On 7/4/07, Jason Ferrara wrote: > > I'm trying to use a COM library from python. > > If I use dynamic dispatch, the com objects all behave correctly, but the > constants defined in the COM library don't show up. > > If I use static dispatch, the constants show up, but COM objects returned > by calls into the COM library seem broken. > > As example, starting with dynamic dispatch > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import win32com.client > >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") > >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") > >>> c=cams[0] > >>> print c > > >>> print c.productName > Micron Imaging DEMO2 > > So far everything is fine, but now... > > >>> print win32com.client.constants.MI_BAYER_8 > Traceback (most recent call last): > File "", line 1, in > File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line > 168, in > __getattr__ > raise AttributeError, a > AttributeError: MI_BAYER_8 > > This is no good. So now I try static dispatch > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import win32com.client > >>> mi=win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib") > >>> print win32com.client.constants.MI_BAYER_8 > 1 > > Things are looking better, but now... > > >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") > >>> c=cams[0] > >>> print c > > >>> print c.productName > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'PyIUnknown' object has no attribute 'productName' > > > So whats going on here? What am I doing wrong? > > Thanks > > - J > > > > > > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070704/9479c974/attachment.html From jason.ferrara at jacquette.com Wed Jul 4 17:38:48 2007 From: jason.ferrara at jacquette.com (Jason Ferrara) Date: Wed, 4 Jul 2007 11:38:48 -0400 Subject: [python-win32] issues with win32com constants and static/dynamic dispatch In-Reply-To: <57124720707040820o4e57246fhe9041f2ff6f198b8@mail.gmail.com> References: <57124720707040820o4e57246fhe9041f2ff6f198b8@mail.gmail.com> Message-ID: <49409DFF-C2F5-49F7-976C-5EE2FC4F9CC5@jacquette.com> On Jul 4, 2007, at 11:20 AM, Simon Dahlbacka wrote: > my best guess is that you should be using .ProductName (capital p) > as static dispatch is case sensitive.. > > /S Thats not it. productName is the correct case. And also.. >>> print c >>> dir(c) ['QueryInterface', '__class__', '__cmp__', '__delattr__', '__doc__', '__getattri bute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__re pr__', '__setattr__', '__str__'] That doesn't look right at all. Shouldn't I see the COM methods and attributes? For objects that do work I get stuff that looks much more sensible. >>> print mi >>> dir(mi) ['CLSID', 'CloseCameras', 'OpenCameras', '_ApplyTypes_', '__cmp__', '__doc__', ' __getattr__', '__init__', '__module__', '__repr__', '__setattr__', '_get_good_ob ject_', '_get_good_single_object_', '_oleobj_', '_prop_map_get_', '_prop_map_put _', 'coclass_clsid'] > > > On 7/4/07, Jason Ferrara < jason.ferrara at jacquette.com> wrote: > I'm trying to use a COM library from python. > > If I use dynamic dispatch, the com objects all behave correctly, > but the constants defined in the COM library don't show up. > > If I use static dispatch, the constants show up, but COM objects > returned by calls into the COM library seem broken. > > As example, starting with dynamic dispatch > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> import win32com.client > >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") > >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging > \sensor_data") > >>> c=cams[0] > >>> print c > > >>> print c.productName > Micron Imaging DEMO2 > > So far everything is fine, but now... > > >>> print win32com.client.constants.MI_BAYER_8 > Traceback (most recent call last): > File "", line 1, in > File "C:\Python25\Lib\site-packages\win32com\client > \__init__.py", line 168, in > __getattr__ > raise AttributeError, a > AttributeError: MI_BAYER_8 > > This is no good. So now I try static dispatch > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> import win32com.client > >>> mi= win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib") > >>> print win32com.client.constants.MI_BAYER_8 > 1 > > Things are looking better, but now... > > >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging > \sensor_data") > >>> c=cams[0] > >>> print c > > >>> print c.productName > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'PyIUnknown' object has no attribute 'productName' > > > So whats going on here? What am I doing wrong? > > Thanks > > - J > > > > > > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070704/1a940d17/attachment.htm From rbell01824 at earthlink.net Wed Jul 4 18:04:12 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Wed, 4 Jul 2007 11:04:12 -0500 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: <49409DFF-C2F5-49F7-976C-5EE2FC4F9CC5@jacquette.com> References: <57124720707040820o4e57246fhe9041f2ff6f198b8@mail.gmail.com> <49409DFF-C2F5-49F7-976C-5EE2FC4F9CC5@jacquette.com> Message-ID: <009001c7be54$f7353c60$6701a8c0@rjbmain> In my continued work on a COM automation interface for IE I've encountered a strange/impossible Python behavior. Here's what appears to be the offending code: ----- code ----- nodes = self.DomGetNListFilterValue(node, tags, properties, value, intoFrames, errorFlag, message) print 'DomGetANodeFilterValue', nodes #DomGetANodeFilterValue [] print 'DomGetANodeFilterValue', len(nodes) #DomGetANodeFilterValue 1 print 'DomGetANodeFilterValue[%s]'%nodes[0] #DomGetANodeFilterValue[] if len(nodes) == 1: print 'DomGetANodeFilterValue[%s]'%(nodes[0]) #DomGetANodeFilterValue[] #but under debugger, #nodes[0] # return nodes[0] ----- end code ----- The call to DomGetNListFilterValue returns a list with 1 object per the print statements (the comments contain the print statements output). But an attempt to reference the object returns nothing per the following print statement. Curiously, setting a break point and referencing nodes[0] DOES return the correct value!?! I've never seen this kind of behavior. Does anyone have any clues? Thanks for any help. Regards, Richard From emlynj at gmail.com Wed Jul 4 18:21:52 2007 From: emlynj at gmail.com (Emlyn Jones) Date: Wed, 4 Jul 2007 17:21:52 +0100 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: <009001c7be54$f7353c60$6701a8c0@rjbmain> References: <57124720707040820o4e57246fhe9041f2ff6f198b8@mail.gmail.com> <49409DFF-C2F5-49F7-976C-5EE2FC4F9CC5@jacquette.com> <009001c7be54$f7353c60$6701a8c0@rjbmain> Message-ID: On 7/4/07, Richard Bell wrote: > > In my continued work on a COM automation interface for IE I've encountered a > strange/impossible Python behavior. Here's what appears to be the offending > code: > > ----- code ----- > nodes = self.DomGetNListFilterValue(node, tags, properties, value, > intoFrames, errorFlag, message) > print 'DomGetANodeFilterValue', nodes > #DomGetANodeFilterValue [ Library.DispHTMLInputElement instance at 0x34839088>] > print 'DomGetANodeFilterValue', len(nodes) > #DomGetANodeFilterValue 1 > print 'DomGetANodeFilterValue[%s]'%nodes[0] > #DomGetANodeFilterValue[] > if len(nodes) == 1: > print 'DomGetANodeFilterValue[%s]'%(nodes[0]) > #DomGetANodeFilterValue[] > #but under debugger, > #nodes[0] > # Library.DispHTMLInputElement instance at 0x34839088> > return nodes[0] > ----- end code ----- > > The call to DomGetNListFilterValue returns a list with 1 object per the > print statements (the comments contain the print statements output). But an > attempt to reference the object returns nothing per the following print > statement. Curiously, setting a break point and referencing nodes[0] DOES > return the correct value!?! I've never seen this kind of behavior. Does > anyone have any clues? > Hello, Not had much to do with COM but I would check out what Library.DispHTMLInputElement' s implementation of __str__ does. What happens if you try nodes[0].__repr__() (or nodes[0].__unicode__()?) I can't think off the top of my head what the builtin to retrieve a list item is from a list object but that might be worth checking too. Cheers, Emlyn. -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments From rbell01824 at earthlink.net Wed Jul 4 19:00:14 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Wed, 4 Jul 2007 12:00:14 -0500 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: References: <57124720707040820o4e57246fhe9041f2ff6f198b8@mail.gmail.com><49409DFF-C2F5-49F7-976C-5EE2FC4F9CC5@jacquette.com><009001c7be54$f7353c60$6701a8c0@rjbmain> Message-ID: <009401c7be5c$cadae400$6701a8c0@rjbmain> Thanks Emlyn, that's got me a bit further. I tried your suggestions and also tried to see if the object was the one expected. Here's the output: node0 = nodes[0] print 'DomGetANodeFilterValue type', type(node0) # DomGetANodeFilterValue type print 'DomGetANodeFilterValue tagName[%s]'%node0.tagName #DomGetANodeFilterValue tagName[INPUT] print 'DomGetANodeFilterValue outerHTML[%s]'%node0.outerHTML #DomGetANodeFilterValue outerHTML[] #It appears that node0 is the desired node, notwithstanding the print issue print 'DomGetANodeFilterValue nodes[0].__repr__() %s'%nodes[0].__repr__() # DomGetANodeFilterValue nodes[0].__repr__() print 'DomGetANodeFilterValue nodes[0].__unicode__() %s'%nodes[0].__unicode__() # DomGetANodeFilterValue nodes[0].__unicode__() The first couple of prints tell me that the object node0 is the one expected and seems to be useable in that I can reference the objects properties and get the expected values. Interestingly __repr__ returns the right kind of object reference. I'll look into your list item suggestion as that seems more likely to be the essential part of the issue. Thanks again. Richard |-----Original Message----- |From: python-win32-bounces at python.org [mailto:python-win32- |bounces at python.org] On Behalf Of Emlyn Jones |Sent: Wednesday, July 04, 2007 11:22 AM |To: python-win32 at python.org |Subject: Re: [python-win32] Strange/impossible Python COM interface |behavior | |On 7/4/07, Richard Bell wrote: |> |> In my continued work on a COM automation interface for IE I've |encountered a |> strange/impossible Python behavior. Here's what appears to be the |offending |> code: |> |> ----- code ----- |> nodes = self.DomGetNListFilterValue(node, tags, properties, |value, |> intoFrames, errorFlag, |message) |> print 'DomGetANodeFilterValue', nodes |> #DomGetANodeFilterValue [ Library.DispHTMLInputElement instance at 0x34839088>] |> print 'DomGetANodeFilterValue', len(nodes) |> #DomGetANodeFilterValue 1 |> print 'DomGetANodeFilterValue[%s]'%nodes[0] |> #DomGetANodeFilterValue[] |> if len(nodes) == 1: |> print 'DomGetANodeFilterValue[%s]'%(nodes[0]) |> #DomGetANodeFilterValue[] |> #but under debugger, |> #nodes[0] |> # Library.DispHTMLInputElement instance at 0x34839088> |> return nodes[0] |> ----- end code ----- |> |> The call to DomGetNListFilterValue returns a list with 1 object per the |> print statements (the comments contain the print statements output). But |an |> attempt to reference the object returns nothing per the following print |> statement. Curiously, setting a break point and referencing nodes[0] |DOES |> return the correct value!?! I've never seen this kind of behavior. Does |> anyone have any clues? |> |Hello, |Not had much to do with COM but I would check out what | Library.DispHTMLInputElement' |s implementation of __str__ does. What happens if you try |nodes[0].__repr__() (or nodes[0].__unicode__()?) |I can't think off the top of my head what the builtin to retrieve a |list item is from a list object but that might be worth checking too. | |Cheers, |Emlyn. |-- |() ascii ribbon campaign - against html e-mail |/\ www.asciiribbon.org - against proprietary attachments |_______________________________________________ |Python-win32 mailing list |Python-win32 at python.org |http://mail.python.org/mailman/listinfo/python-win32 From rbell01824 at earthlink.net Thu Jul 5 00:08:13 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Wed, 4 Jul 2007 17:08:13 -0500 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: <009401c7be5c$cadae400$6701a8c0@rjbmain> References: <57124720707040820o4e57246fhe9041f2ff6f198b8@mail.gmail.com><49409DFF-C2F5-49F7-976C-5EE2FC4F9CC5@jacquette.com><009001c7be54$f7353c60$6701a8c0@rjbmain> <009401c7be5c$cadae400$6701a8c0@rjbmain> Message-ID: <009501c7be87$d29d3910$6701a8c0@rjbmain> A bit more testing revealed that there are two issues, one a bug in my code and the other a potential issue with the python COM code. First, I'd written a routine to flash an IE DOM node and moved it into a class. Unfortunately, I coded it like this in the class: def DomFlash(node, flashes=5, errorFlag = True, message = None ): when it should be like this: def DomFlash(self, node, flashes=5, errorFlag = True, message = None ): I invoked it thus: yie.DomFlash(qNode) and the node did not flash. Coding the correct def, of course, cures this behavior. But, while trying to find this bug, I inserted some debug code that raised the print issue. It is now exhibited in the following code: qNode = yie.DomGetANodeFilterValue(yie.dom, 'INPUT', 'id;name;value', 'q' ) print '\n***** qnode class <<<%s>>>'%qNode.__class__ print '\n***** qNode=<<<%s>>>'%qNode print '\n***** DomGetANodeFilterValue qNode.__str__()<<<%s>>>'%qNode.__str__() print '\n***** DomGetANodeFilterValue q Node.__repr__()<<<%s>>>'%qNode.__repr__() print '\n***** `qnode`<<<%s>>>'%`qNode` which produces the following output: ***** qnode class <<>> ***** qNode=<<<>>> ***** DomGetANodeFilterValue qNode.__str__()<<<>>> ***** DomGetANodeFilterValue qNode.__repr__()<<<>>> ***** `qNode`<<<>>> The class is correct (as was expected given the earlier test). Print still does not produce the expected output. __str__ does not produce the expected output. Since it is defined and print uses __str__ if it exists, it is unsurprising that print fails. __repr__ produces the expected output `qNode` produces the expected output as expected since `` uses __repr__ http://docs.python.org/ref/customization.html provides some interesting background. Some checking of the COM interface code (I use early binding) finds the following code supporting DispHTMLInputElement: # Default property for this class is 'value' def __call__(self): return self._ApplyTypes_(*(-2147413011, 2, (8, 0), (), "value", None)) # str(ob) and int(ob) will use __call__ def __unicode__(self, *args): try: return unicode(self.__call__(*args)) except pythoncom.com_error: return repr(self) def __str__(self, *args): return str(self.__unicode__(*args)) def __int__(self, *args): return int(self.__call__(*args)) Here __str__ depends on __unicode__ that depends on __call__ that depends on _ApplyTypes_. This appears to be inherited from DispatchBaseClass via from win32com.client import DispatchBaseClass I'm unable to find DispatchBaseClass and so can not chase the issue further (never mind that I'm a bit over my head in the Win32Com code). Interestingly, __repr__ is NOT in the GenPY output code, so I assume it is also in DispatchBaseClass. I'm guessing that _ApplyTypes_ is misbehaving but am not sure. In any event, thanks for your assistance. While not resolved the problem is not critical since it only involves print and there is a work around via ``. Hopefully, Mark will pick up this thread and be able to shed a bit of light. Regards, Richard |-----Original Message----- |From: python-win32-bounces at python.org [mailto:python-win32- |bounces at python.org] On Behalf Of Richard Bell |Sent: Wednesday, July 04, 2007 12:00 PM |To: 'Emlyn Jones'; python-win32 at python.org |Subject: Re: [python-win32] Strange/impossible Python COM interface |behavior | | |Thanks Emlyn, that's got me a bit further. I tried your suggestions and |also tried to see if the object was the one expected. Here's the output: | | node0 = nodes[0] | print 'DomGetANodeFilterValue type', type(node0) | # DomGetANodeFilterValue type | print 'DomGetANodeFilterValue tagName[%s]'%node0.tagName | #DomGetANodeFilterValue tagName[INPUT] | print 'DomGetANodeFilterValue outerHTML[%s]'%node0.outerHTML | #DomGetANodeFilterValue outerHTML[] | #It appears that node0 is the desired node, notwithstanding the |print issue | print 'DomGetANodeFilterValue nodes[0].__repr__() |%s'%nodes[0].__repr__() | # DomGetANodeFilterValue nodes[0].__repr__() | | print 'DomGetANodeFilterValue nodes[0].__unicode__() |%s'%nodes[0].__unicode__() | # DomGetANodeFilterValue nodes[0].__unicode__() | |The first couple of prints tell me that the object node0 is the one |expected |and seems to be useable in that I can reference the objects properties and |get the expected values. Interestingly __repr__ returns the right kind of |object reference. | |I'll look into your list item suggestion as that seems more likely to be |the |essential part of the issue. | |Thanks again. | |Richard | ||-----Original Message----- ||From: python-win32-bounces at python.org [mailto:python-win32- ||bounces at python.org] On Behalf Of Emlyn Jones ||Sent: Wednesday, July 04, 2007 11:22 AM ||To: python-win32 at python.org ||Subject: Re: [python-win32] Strange/impossible Python COM interface ||behavior || ||On 7/4/07, Richard Bell wrote: ||> ||> In my continued work on a COM automation interface for IE I've ||encountered a ||> strange/impossible Python behavior. Here's what appears to be the ||offending ||> code: ||> ||> ----- code ----- ||> nodes = self.DomGetNListFilterValue(node, tags, properties, ||value, ||> intoFrames, errorFlag, ||message) ||> print 'DomGetANodeFilterValue', nodes ||> #DomGetANodeFilterValue [ Library.DispHTMLInputElement instance at 0x34839088>] ||> print 'DomGetANodeFilterValue', len(nodes) ||> #DomGetANodeFilterValue 1 ||> print 'DomGetANodeFilterValue[%s]'%nodes[0] ||> #DomGetANodeFilterValue[] ||> if len(nodes) == 1: ||> print 'DomGetANodeFilterValue[%s]'%(nodes[0]) ||> #DomGetANodeFilterValue[] ||> #but under debugger, ||> #nodes[0] ||> # Library.DispHTMLInputElement instance at 0x34839088> ||> return nodes[0] ||> ----- end code ----- ||> ||> The call to DomGetNListFilterValue returns a list with 1 object per the ||> print statements (the comments contain the print statements output). |But ||an ||> attempt to reference the object returns nothing per the following print ||> statement. Curiously, setting a break point and referencing nodes[0] ||DOES ||> return the correct value!?! I've never seen this kind of behavior. |Does ||> anyone have any clues? ||> ||Hello, ||Not had much to do with COM but I would check out what || Library.DispHTMLInputElement' ||s implementation of __str__ does. What happens if you try ||nodes[0].__repr__() (or nodes[0].__unicode__()?) ||I can't think off the top of my head what the builtin to retrieve a ||list item is from a list object but that might be worth checking too. || ||Cheers, ||Emlyn. ||-- ||() ascii ribbon campaign - against html e-mail ||/\ www.asciiribbon.org - against proprietary attachments ||_______________________________________________ ||Python-win32 mailing list ||Python-win32 at python.org ||http://mail.python.org/mailman/listinfo/python-win32 | |_______________________________________________ |Python-win32 mailing list |Python-win32 at python.org |http://mail.python.org/mailman/listinfo/python-win32 From jason.ferrara at jacquette.com Thu Jul 5 00:30:13 2007 From: jason.ferrara at jacquette.com (Jason Ferrara) Date: Wed, 4 Jul 2007 18:30:13 -0400 Subject: [python-win32] win32com array handling bug? Message-ID: <3C9DE899-15D7-4757-8CDE-8C5C4376A460@jacquette.com> I'm making a COM call that should return a two dimensional array, but instead I get back a buffer that appears to only contain a single row from the array. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") >>> c=cams[0] >>> c.startTransport() >>> c.updateFrameSize(c.sensor.width, c.sensor.height, 8,0) >>> f=c.grabFrame() At this point f should be a 2048 by 1536 array of bytes, but instead... >>> len(f) 2048 >>> type(f) I know the COM library is returning the right data because if I do a similar trick with IronPython... IronPython 1.1 (1.1) on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved. >>> import clr >>> clr.AddReferenceToFile("MIDLIBCOMLib.dll") >>> import MIDLIBCOMLib >>> mi=MIDLIBCOMLib.MIDLibClass() >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") >>> c=cams[0] >>> c.startTransport() >>> c.updateFrameSize(c.sensor.width, c.sensor.height, 8,0) >>> f=c.grabFrame() >>> len(f) 3145728 >>> type(f) >>> Its been squashed down to a 1 dimensional array, but at least all the data is there. From mhammond at skippinet.com.au Thu Jul 5 01:03:42 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 5 Jul 2007 09:03:42 +1000 Subject: [python-win32] issues with win32com constants and static/dynamicdispatch In-Reply-To: Message-ID: <04b801c7be8f$91fb6140$0200a8c0@enfoldsystems.local> That is strange - the problem is that the resulting COM object is returning an IUnknown rather than an IDispatch. A work around should be to say: c = cams[0] c = win32com.client.Dispatch(c) or possibly: c = win32com.client.Dispatch(c.QueryInterface(pythoncom.IID_IDispatch)) I think we could also argue this is a bug in win32com - it should try and QI any IUnknown objects - but changing this might break existing code... Mark -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of Jason Ferrara Sent: Thursday, 5 July 2007 12:30 AM To: python-win32 at python.org Subject: [python-win32] issues with win32com constants and static/dynamicdispatch I'm trying to use a COM library from python. If I use dynamic dispatch, the com objects all behave correctly, but the constants defined in the COM library don't show up. If I use static dispatch, the constants show up, but COM objects returned by calls into the COM library seem broken. As example, starting with dynamic dispatch Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") >>> c=cams[0] >>> print c >>> print c.productName Micron Imaging DEMO2 So far everything is fine, but now... >>> print win32com.client.constants.MI_BAYER_8 Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 168, in __getattr__ raise AttributeError, a AttributeError: MI_BAYER_8 This is no good. So now I try static dispatch Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> mi=win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib") >>> print win32com.client.constants.MI_BAYER_8 1 Things are looking better, but now... >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") >>> c=cams[0] >>> print c >>> print c.productName Traceback (most recent call last): File "", line 1, in AttributeError: 'PyIUnknown' object has no attribute 'productName' So whats going on here? What am I doing wrong? Thanks - J -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070705/f784f4b2/attachment-0001.htm From mhammond at skippinet.com.au Thu Jul 5 01:09:31 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 5 Jul 2007 09:09:31 +1000 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: <009501c7be87$d29d3910$6701a8c0@rjbmain> Message-ID: <04c201c7be90$6186a2d0$0200a8c0@enfoldsystems.local> > from win32com.client import DispatchBaseClass > > I'm unable to find DispatchBaseClass and so can not chase the > issue further Its in win32com.client.__init__.py > (never mind that I'm a bit over my head in the Win32Com code). > Interestingly, __repr__ is NOT in the GenPY output code, so I > assume it is > also in DispatchBaseClass. I'm guessing that _ApplyTypes_ is > misbehaving > but am not sure. > > In any event, thanks for your assistance. While not resolved > the problem is > not critical since it only involves print and there is a work > around via ``. > Hopefully, Mark will pick up this thread and be able to shed > a bit of light. I'm afraid I don't understand the problem you are currently trying to demonstrate. Doing str(com_obj) will attempt to use the com object's "default" method or property and use that, while 'repr' does not. This is mainly done for things like ADO 'field' objects, where the default method fetches the value for the field, for example. Mark From mhammond at skippinet.com.au Thu Jul 5 01:12:33 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 5 Jul 2007 09:12:33 +1000 Subject: [python-win32] win32com array handling bug? In-Reply-To: <3C9DE899-15D7-4757-8CDE-8C5C4376A460@jacquette.com> Message-ID: <04c501c7be90$ce54f1f0$0200a8c0@enfoldsystems.local> > I'm making a COM call that should return a two dimensional > array, but > instead I get back a buffer that appears to only contain a > single row > from the array. > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import win32com.client > >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") > >>> cams=mi.OpenCameras("C:\Program Files\Micron > Imaging\sensor_data") > >>> c=cams[0] > >>> c.startTransport() > >>> c.updateFrameSize(c.sensor.width, c.sensor.height, 8,0) > >>> f=c.grabFrame() > > At this point f should be a 2048 by 1536 array of bytes, but > instead... > > >>> len(f) > 2048 > >>> type(f) > Arrays of type VT_UI1 are returned as buffers. You should find the length of f is 1536, and you can treat it as a string (ie, just index into it to fetch the values, len() to get the length, slice it, etc). This is primarily done as an optimization, so we don't need to waste time and space building lists of lists of integers when the data is more naturally a 'string of bytes' anyway. Mark From jason.ferrara at jacquette.com Thu Jul 5 01:21:33 2007 From: jason.ferrara at jacquette.com (Jason Ferrara) Date: Wed, 4 Jul 2007 19:21:33 -0400 Subject: [python-win32] win32com array handling bug? In-Reply-To: <04c501c7be90$ce54f1f0$0200a8c0@enfoldsystems.local> References: <04c501c7be90$ce54f1f0$0200a8c0@enfoldsystems.local> Message-ID: On Jul 4, 2007, at 7:12 PM, Mark Hammond wrote: >>>>> >> >> At this point f should be a 2048 by 1536 array of bytes, but >> instead... >> >>>>> len(f) >> 2048 >>>>> type(f) >> > > Arrays of type VT_UI1 are returned as buffers. You should find the > length > of f is 1536, and you can treat it as a string (ie, just index into > it to > fetch the values, len() to get the length, slice it, etc). This is > primarily done as an optimization, so we don't need to waste time > and space > building lists of lists of integers when the data is more naturally a > 'string of bytes' anyway. > > Mark > I don't quite follow. I understand (well, I think I understand) how a buffer works. The problem is that the length is wrong. As shown above, the length of f is 2048. If the array was being returned correctly as a buffer, then the length should be 3145728 (2048 * 1536). From mhammond at skippinet.com.au Thu Jul 5 01:35:42 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 5 Jul 2007 09:35:42 +1000 Subject: [python-win32] win32com array handling bug? In-Reply-To: Message-ID: <04c801c7be94$0a184b30$0200a8c0@enfoldsystems.local> > On Jul 4, 2007, at 7:12 PM, Mark Hammond wrote: > >>>>> > >> > >> At this point f should be a 2048 by 1536 array of bytes, but > >> instead... > >> > >>>>> len(f) > >> 2048 > >>>>> type(f) > >> > > > > Arrays of type VT_UI1 are returned as buffers. You should > find the > > length > > of f is 1536, and you can treat it as a string (ie, just > index into > > it to > > fetch the values, len() to get the length, slice it, etc). This is > > primarily done as an optimization, so we don't need to waste time > > and space > > building lists of lists of integers when the data is more > naturally a > > 'string of bytes' anyway. > > > > Mark > > > > I don't quite follow. > > I understand (well, I think I understand) how a buffer works. The > problem is that the length is wrong. > > As shown above, the length of f is 2048. If the array was being > returned correctly > as a buffer, then the length should be 3145728 (2048 * 1536). Hrm - I misunderstood. a 2048x1536 array of bytes *should* be returned as a list with 2048 entries, each being a buffer of size 1536. I guess I'll need to try and reproduce this in the test suite... Mark From bgailer at alum.rpi.edu Thu Jul 5 01:42:29 2007 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Wed, 04 Jul 2007 16:42:29 -0700 Subject: [python-win32] Threading Issue Message-ID: <468C3065.4030104@alum.rpi.edu> Following is untested but based on other work I've done: import threading class Foo: def __init__(self): self.list = [] def run(self): # manipulate the list from within the thread foo = Foo() threading.Thread(target = foo.run) ... foo.list # access the list as modified by the thread -- Bob Gailer 510-978-4454 Oakland, CA 919-636-4239 Chapel Hill, NC From fuzzyman at voidspace.org.uk Thu Jul 5 01:54:43 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 05 Jul 2007 00:54:43 +0100 Subject: [python-win32] Python Magazine - pywin32 Message-ID: <468C3343.2080806@voidspace.org.uk> Hello all, There is a new Python magazine just launching: http://www.pythonmagazine.com They are looking for articles that will appeal to Windows users, so if anyone fancies getting paid to write an article on pywin32 I'm sure they will be interested. Michael Foord http://www.voidspace.org.uk/ironpython/index.shtml From jason.ferrara at jacquette.com Thu Jul 5 02:03:40 2007 From: jason.ferrara at jacquette.com (Jason Ferrara) Date: Wed, 4 Jul 2007 20:03:40 -0400 Subject: [python-win32] issues with win32com constants and static/dynamicdispatch In-Reply-To: <04b801c7be8f$91fb6140$0200a8c0@enfoldsystems.local> References: <04b801c7be8f$91fb6140$0200a8c0@enfoldsystems.local> Message-ID: <554F2B67-F2AC-48DF-AB83-74E41E24507D@jacquette.com> c = win32com.client.Dispatch(c.QueryInterface(pythoncom.IID_IDispatch)) works. Thanks! FYI, c=win32com.client.Dispatch(c) does not. >>> c=win32com.client.Dispatch(c) Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 96, in Dispatch return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx) File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 44, in __WrapDispatch return dynamic.Dispatch(dispatch, userName, WrapperClass, typeinfo, UnicodeToString=UnicodeToString,clsctx=clsctx) File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 111, in Dispatch typeinfo = IDispatch.GetTypeInfo() AttributeError: 'PyIUnknown' object has no attribute 'GetTypeInfo' On Jul 4, 2007, at 7:03 PM, Mark Hammond wrote: > That is strange - the problem is that the resulting COM object is > returning an IUnknown rather than an IDispatch. A work around > should be to say: > > c = cams[0] > c = win32com.client.Dispatch(c) > > or possibly: > > c = win32com.client.Dispatch(c.QueryInterface > (pythoncom.IID_IDispatch)) > > I think we could also argue this is a bug in win32com - it should > try and QI any IUnknown objects - but changing this might break > existing code... > > Mark > -----Original Message----- > From: python-win32-bounces at python.org [mailto:python-win32- > bounces at python.org]On Behalf Of Jason Ferrara > Sent: Thursday, 5 July 2007 12:30 AM > To: python-win32 at python.org > Subject: [python-win32] issues with win32com constants and static/ > dynamicdispatch > > I'm trying to use a COM library from python. > > If I use dynamic dispatch, the com objects all behave correctly, > but the constants defined in the COM library don't show up. > > If I use static dispatch, the constants show up, but COM objects > returned by calls into the COM library seem broken. > > As example, starting with dynamic dispatch > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> import win32com.client > >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") > >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging > \sensor_data") > >>> c=cams[0] > >>> print c > > >>> print c.productName > Micron Imaging DEMO2 > > So far everything is fine, but now... > > >>> print win32com.client.constants.MI_BAYER_8 > Traceback (most recent call last): > File "", line 1, in > File "C:\Python25\Lib\site-packages\win32com\client > \__init__.py", line 168, in > __getattr__ > raise AttributeError, a > AttributeError: MI_BAYER_8 > > This is no good. So now I try static dispatch > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> import win32com.client > >>> mi=win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib") > >>> print win32com.client.constants.MI_BAYER_8 > 1 > > Things are looking better, but now... > > >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging > \sensor_data") > >>> c=cams[0] > >>> print c > > >>> print c.productName > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'PyIUnknown' object has no attribute 'productName' > > > So whats going on here? What am I doing wrong? > > Thanks > > - J > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070704/498a3d2b/attachment-0001.html From meledictas at gmail.com Thu Jul 5 11:15:14 2007 From: meledictas at gmail.com (Chatchai Neanudorn) Date: Thu, 5 Jul 2007 16:15:14 +0700 Subject: [python-win32] Loading performance counter problem Message-ID: <6f10a16a0707050215ub69368eufa3c83d4a15d8518@mail.gmail.com> Hi all, I 'm trying to load my application perfmance counter into window perfmon. I use example found in Python Programming on Win32 book. I can install service sucessfully. I can see my service in services list. My broblem is, I got error below --- Command --- C:\PyPerf>python PipeService2.py --perfmonini=perf_install.ini install --- Error --- The service was installed OK, but the performance monitor data could not be loaded. (2001, 'LoadPerfCounterTextStrings', 'The specified driver is invalid.') --- Environtment --- -Window server 2003 -Python 2.4.4 -pywin32-210.win32-py2.4.exe --- Service script PipeService2.py --- # PipeService2.py # # A sample demonstrating a service which uses a # named-pipe to accept client connections, # and writes data to the event log. import win32serviceutil import win32service import win32event import win32pipe import win32file import pywintypes import winerror import perfmon import os class PipeService(win32serviceutil.ServiceFramework): _svc_name_ = "PythonPipeService" _svc_display_name_ = "A sample Python service using named pipes" def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # Create an event which we will use to wait on. # The "service stop" request will set this event. self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) # We need to use overlapped IO for this, so we dont block when # waiting for a client to connect. This is the only effective way # to handle either a client connection, or a service stop request. self.overlapped = pywintypes.OVERLAPPED() # And create an event to be used in the OVERLAPPED object. self.overlapped.hEvent = win32event.CreateEvent(None,0,0,None) # Finally initialize our Performance Monitor counters self.InitPerfMon() def InitPerfMon(self): # Magic numbers (2 and 4) must match header and ini file used # at install - could lookup ini, but then Id need it a runtime # A counter for number of connections per second. self.counterConnections=perfmon.CounterDefinition(2) # We arent expecting many, so we set the scale high (ie, x10) # Note the scale is 10^DefaultScale = ie, to get 10, we use 1! self.counterConnections.DefaultScale = 1 # Now a counter for the number of bytes received per second. self.counterBytes=perfmon.CounterDefinition(4) # A scale of 1 is fine for this counter. self.counterBytes.DefaultScale = 0 # Now register our counters with the performance monitor perfObjectType = perfmon.ObjectType( (self.counterConnections, self.counterBytes) ) self.perfManager = perfmon.PerfMonManager( self._svc_name_, (perfObjectType,), "perfmondata") def TermPerfMon(self): self.perfManager.Close() self.perfManager = None def SvcStop(self): # Before we do anything, tell the SCM we are starting the stop process. self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # And set my event. win32event.SetEvent(self.hWaitStop) def SvcDoRun(self): # Log a "started" message to the event log. import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, '')) # We create our named pipe. pipeName = "\\\\.\\pipe\\PyPipeService" openMode = win32pipe.PIPE_ACCESS_DUPLEX | win32file.FILE_FLAG_OVERLAPPED pipeMode = win32pipe.PIPE_TYPE_MESSAGE # When running as a service, we must use special security for the pipe sa = pywintypes.SECURITY_ATTRIBUTES() # Say we do have a DACL, and it is empty # (ie, allow full access!) sa.SetSecurityDescriptorDacl ( 1, None, 0 ) pipeHandle = win32pipe.CreateNamedPipe(pipeName, openMode, pipeMode, win32pipe.PIPE_UNLIMITED_INSTANCES, 0, 0, 6000, # default buffers, and 6 second timeout. sa) # Loop accepting and processing connections while 1: try: hr = win32pipe.ConnectNamedPipe(pipeHandle, self.overlapped) except error, details: print "Error connecting pipe!", details pipeHandle.Close() break if hr==winerror.ERROR_PIPE_CONNECTED: # Client is fast, and already connected - signal event win32event.SetEvent(self.overlapped.hEvent) # Wait for either a connection, or a service stop request. timeout = win32event.INFINITE waitHandles = self.hWaitStop, self.overlapped.hEvent rc = win32event.WaitForMultipleObjects(waitHandles, 0, timeout) if rc==win32event.WAIT_OBJECT_0: # Stop event break else: # Pipe event - read the data, and write it back. # But first, increment our Performance Monitor data self.counterConnections.Increment() # (We only handle a max of 255 characters for this sample) try: hr, data = win32file.ReadFile(pipeHandle, 256) win32file.WriteFile(pipeHandle, "You sent me:" + data) # And disconnect from the client. win32pipe.DisconnectNamedPipe(pipeHandle) # Update our performance monitor "bytes read" counter self.counterBytes.Increment(len(data)) # Log a message to the event log indicating what we did. message = "Processed %d bytes for client connection" % \ len(data) servicemanager.LogInfoMsg(message) except win32file.error: # Client disconnected without sending data # or before reading the response. # Thats OK - just get the next connection continue # cleanup our PerfMon counters. self.TermPerfMon() # Now log a "service stopped" message servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_, '')) if __name__=='__main__': win32serviceutil.HandleCommandLine(PipeService) --- ini file --- ; PipeService2_install.ini ; File used at installation time to install ; Performance Monitor Counters for our sample service. ; [info] ; drivername MUST be the same as the service name drivername=PythonPipeService symbolfile=PipeService2_install.h [languages] 009=English [text] SERVICE_009_NAME=Python Demo Service SERVICE_009_HELP=Shows performance statistics for the sample Python service CONNECTIONS_009_NAME=Number of connections per second. CONNECTIONS_009_HELP=Indicates the load on the service. BYTES_009_NAME=Bytes read/sec BYTES_009_HELP=Number of bytes read per second by the service. --- header file --- // PipeService2_install.h // File used at installation time to install // Performance Monitor Counters for our sample service. // // All these list the counters in order. // Important that you add these in this order in // the Python code. #define SERVICE 0 #define CONNECTIONS 2 // Number of connections #define BYTES 4 // Number of bytes received. Regards Chatchai -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070705/5edce84d/attachment.html From rbell01824 at earthlink.net Thu Jul 5 21:38:44 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Thu, 5 Jul 2007 14:38:44 -0500 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: <04c201c7be90$6186a2d0$0200a8c0@enfoldsystems.local> References: <009501c7be87$d29d3910$6701a8c0@rjbmain> <04c201c7be90$6186a2d0$0200a8c0@enfoldsystems.local> Message-ID: <00b801c7bf3c$1b294160$6701a8c0@rjbmain> Mark, During development of the IE automation class I've frequently gotten a DOM node by using one of the IE COM interfaces such as nodeList = ie.getElementsByTagName or one of the interfaces available via a DOM node such as nodeList = node.getElementsByTagName. To facilitate python treatment of such list, I convert the HTML collection object into a Python list with code that like this: tagNodes = node.getElementsByTagName(tag) # foundNodes is a COM ElementList, iterate and append to myNodes for tNode in tagNodes: nodes.append(tNode) Then when I want one of the individual DOM nodes I just index into the Python list like this: aNode = nodes[0] During development, I've often found it useful to put in some debug statements to print the object aNode like this: print aNode Up until yesterday I'd always found that when I did so I'd get some output more or less like this: During debugging of my def mistake (after correction of the mistake) I had the following debug print statements in my code: ----- code ----- print '\n***** Try the INPUT node q at www.google.com' qNode = yie.DomGetANodeFilterValue(yie.dom, 'INPUT', 'id;name;value', 'q' ) print '-- type qNode <<<%s>>>'%type(qNode) print '-- qNode class <<<%s>>>'%qNode.__class__ print '-- DomGetANodeFilterValue qNode.__str__()<<<%s>>>'%qNode.__str__() print '-- qNode=<<<%s>>>'%qNode print '-- DomGetANodeFilterValue qNode.__repr__()<<<%s>>>'%qNode.__repr__() print '-- `qnode`<<<%s>>>'%`qNode` print '\n***** Try the same node when returned as a list' qNode2 = yie.DomGetNListFilterValue(yie.dom, 'INPUT', 'id;name;value', 'q') print '-- type qNode2 <<<%s>>>'%type(qNode2) print '-- len(qNode2) <<<%s>>>'%len(qNode2) print '-- qNode2 <<<%s>>>'%qNode2 print '-- qNode2[0] <<<%s>>>'%qNode2[0] print '-- qNode2[0] class <<<%s>>>'%qNode2[0].__class__ print '\n***** Try yie.dom, an HTML node' print '-- typw yie.dom <<<%s>>>'%type(yie.dom) print '-- yie.dom class <<<%s>>>'%yie.dom.__class__ print '-- yie.dom <<<%s>>>'%yie.dom print '\n***** Try the body node' bNode = yie.DomGetNList(yie.dom, 'BODY') print '-- bNode class <<<%s>>>'%bNode.__class__ print '-- bNode <<<%s>>>'%bNode print '\n***** Try DIV id=gbar' dNode = yie.DomGetANodeFilterProperties(yie.dom, 'DIV', 'id=gbar') print '-- dNode class <<<%s>>>'%dNode.__class__ print '-- dNode <<<%s>>>'%dNode ----- end code ----- This code produces the following output: ----- output ----- ***** Try the INPUT node q at www.google.com -- type qNode <<<>>> -- qNode class <<>> -- DomGetANodeFilterValue qNode.__str__()<<<>>> -- qNode=<<<>>> -- DomGetANodeFilterValue qNode.__repr__()<<<>>> -- `qnode`<<<>>> ***** Try the same node when returned as a list -- type qNode2 <<<>>> -- len(qNode2) <<<1>>> -- qNode2 <<<[]>>> -- qNode2[0] <<<>>> -- qNode2[0] class <<>> ***** Try yie.dom, an HTML node -- typw yie.dom <<<>>> -- yie.dom class <<>> -- yie.dom <<<>>> ***** Try the body node -- bNode class <<<>>> -- bNode <<<[]>>> ***** Try DIV id=gbar -- dNode class <<>> -- dNode <<<>>> ----- end output --- Several things caught my attention about this. First, the attempt to print qNode (an object of class win32com.gen_py.3050F1C5-98B5-11CF-BB82-00AA00BDCE0Bx0x4x0.DispHTMLInputElem ent) produces a zero length string. However print of nodes for other HTML tags such as HTML, BODY, or DIV produces strings that describe the object. Second, when the INPUT node named 'q' is returned as an item in a list (see qNode2) printing the list prints the item. I'm not sure what's different about printing an item in a list vs printing the item, but clearly something different is involved even though the underlying object is of the same type. So it is possible to print some DOM nodes and get a non-zero length string, but not all DOM nodes, and (at least insofar as I've looked) it is possible to print all DOM nodes when an item is in a list. This seems to me rather uneven (and unhandy) behavior, but I'm not really sure it's a bug. I did poke a bit more at the Win32Com code but got to _ApplyTypes_ where my understanding vanished. Please forgive the length of this message but I wanted to try to be clear. Regards, Richard |-----Original Message----- |From: Mark Hammond [mailto:mhammond at skippinet.com.au] |Sent: Wednesday, July 04, 2007 6:10 PM |To: 'Richard Bell'; python-win32 at python.org |Subject: RE: [python-win32] Strange/impossible Python COM interface |behavior | |> from win32com.client import DispatchBaseClass |> |> I'm unable to find DispatchBaseClass and so can not chase the |> issue further | |Its in win32com.client.__init__.py | |> (never mind that I'm a bit over my head in the Win32Com code). |> Interestingly, __repr__ is NOT in the GenPY output code, so I |> assume it is |> also in DispatchBaseClass. I'm guessing that _ApplyTypes_ is |> misbehaving |> but am not sure. |> |> In any event, thanks for your assistance. While not resolved |> the problem is |> not critical since it only involves print and there is a work |> around via ``. |> Hopefully, Mark will pick up this thread and be able to shed |> a bit of light. | |I'm afraid I don't understand the problem you are currently trying to |demonstrate. Doing str(com_obj) will attempt to use the com object's |"default" method or property and use that, while 'repr' does not. This is |mainly done for things like ADO 'field' objects, where the default method |fetches the value for the field, for example. | |Mark From mhammond at skippinet.com.au Fri Jul 6 00:40:39 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 6 Jul 2007 08:40:39 +1000 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: <00b801c7bf3c$1b294160$6701a8c0@rjbmain> Message-ID: <00a301c7bf55$83a59220$090a0a0a@enfoldsystems.local> > Several things caught my attention about this. > > First, the attempt to print qNode (an object of class > win32com.gen_py.3050F1C5-98B5-11CF-BB82-00AA00BDCE0Bx0x4x0.Dis > pHTMLInputElem > ent) produces a zero length string. However print of nodes > for other HTML > tags such as HTML, BODY, or DIV produces strings that > describe the object. Yes - as I mentioned before, str(ob) calls a COM method on 'ob' - so what 'print ob' yields is up to the object, not up to win32com. > Second, when the INPUT node named 'q' is returned as an item > in a list (see > qNode2) printing the list prints the item. I'm not sure > what's different > about printing an item in a list vs printing the item, but > clearly something > different is involved even though the underlying object is of > the same type. This is just Python. When you 'print ob', you are doing, basically, print str(ob). But when ob is a list, the list object itself uses repr() on the list elements. So if 'ob' is in a list, you get different results than if it is not. This is Python, not win32com. Mark From rbell01824 at earthlink.net Fri Jul 6 01:23:12 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Thu, 5 Jul 2007 19:23:12 -0400 Subject: [python-win32] Strange/impossible Python COM interface behavior In-Reply-To: <00a301c7bf55$83a59220$090a0a0a@enfoldsystems.local> References: <00b801c7bf3c$1b294160$6701a8c0@rjbmain> <00a301c7bf55$83a59220$090a0a0a@enfoldsystems.local> Message-ID: <007401c7bf5b$74f39c80$6801a8c0@homeoffice.benchmarkinternational.com> Thanks Mark, that clears up the behavior. I'd been suspicious that it was an underlying COM method but couldn't really tell from my limited understanding of Win32Com. I'd not understood the differences in printing an object and printing a list of objects, so you've improved my Python education yet again. Thanks. Regards, Richard |-----Original Message----- |From: Mark Hammond [mailto:mhammond at skippinet.com.au] |Sent: Thursday, July 05, 2007 6:41 PM |To: 'Richard Bell'; python-win32 at python.org |Subject: RE: [python-win32] Strange/impossible Python COM interface |behavior | |> Several things caught my attention about this. |> |> First, the attempt to print qNode (an object of class |> win32com.gen_py.3050F1C5-98B5-11CF-BB82-00AA00BDCE0Bx0x4x0.Dis |> pHTMLInputElem |> ent) produces a zero length string. However print of nodes |> for other HTML |> tags such as HTML, BODY, or DIV produces strings that |> describe the object. | |Yes - as I mentioned before, str(ob) calls a COM method on 'ob' - so what |'print ob' yields is up to the object, not up to win32com. | |> Second, when the INPUT node named 'q' is returned as an item |> in a list (see |> qNode2) printing the list prints the item. I'm not sure |> what's different |> about printing an item in a list vs printing the item, but |> clearly something |> different is involved even though the underlying object is of |> the same type. | |This is just Python. When you 'print ob', you are doing, basically, print |str(ob). But when ob is a list, the list object itself uses repr() on the |list elements. So if 'ob' is in a list, you get different results than if |it is not. This is Python, not win32com. | |Mark From grickert at coldstorage.com Fri Jul 6 23:22:10 2007 From: grickert at coldstorage.com (Gerrat Rickert) Date: Fri, 6 Jul 2007 17:22:10 -0400 Subject: [python-win32] Trying to build debug version of win32 extensions Message-ID: I'm trying to build a debug version of the win32 extensions (basically to help track down a memory leak in a COM automation program I've written). To that end, I purchased a Visual C++ .Net Deluxe Learning Edition Book (which is probably the cheapest way to get the Visual C++ compiler required). Following the instructions in the source distribution, I was able to build a debug version of python from source (unfortunately, I know very little about C/C++). I checked out the python win32 source files, and am trying to build a debug version of this as well, but I'm not having much success. Though matter where I place the main directory with the win32 source files, it still fails to compile - I get an error: LINK: fatal error LINK1104: cannot open file 'python24_d.lib' [I'm trying to build using: "python setup.py -q build -debug"] This file exists in the directory I compiled the debug version of the main python distribution, but I'm not sure what I need to do so that the setup program can find it. Any help/direction would be appreciated. Thanks, Gerrat -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070706/1269156f/attachment.htm From timr at probo.com Fri Jul 6 23:52:06 2007 From: timr at probo.com (Tim Roberts) Date: Fri, 06 Jul 2007 14:52:06 -0700 Subject: [python-win32] Trying to build debug version of win32 extensions In-Reply-To: References: Message-ID: <468EB986.2030604@probo.com> Gerrat Rickert wrote: > > I?m trying to build a debug version of the win32 extensions (basically > to help track down a memory leak in a COM automation program I?ve > written). To that end, I purchased a Visual C++ .Net Deluxe Learning > Edition Book (which is probably the cheapest way to get the Visual C++ > compiler required). > That includes Visual C++ 2003. I thought Python was switching over to VC++ 2005. Mark will know for sure. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From teekaysoh at gmail.com Mon Jul 9 02:29:57 2007 From: teekaysoh at gmail.com (TK Soh) Date: Mon, 9 Jul 2007 08:29:57 +0800 Subject: [python-win32] polling with os.popen3 In-Reply-To: <4685ACCE.3040007@probo.com> References: <58b84f8e0706281325t1ab817ddk2b7e2c7eed91c0c1@mail.gmail.com> <46842BC9.7030908@probo.com> <58b84f8e0706291452i155dd5bcub71b529de2a12f3d@mail.gmail.com> <4685ACCE.3040007@probo.com> Message-ID: <58b84f8e0707081729q471e092ct43c5707f663b9e2@mail.gmail.com> On 6/30/07, Tim Roberts wrote: > TK Soh wrote: > > On 6/29/07, Tim Roberts wrote: > >> TK Soh wrote: > >> > I'm trying to use os.popen3 to replace subprocess.Popen for python 2.3 > >> > compatibility. According to the document, os.Popen3 class is not > >> > supported on Win32, so I can't poll() the pipe. I wonder how I can > >> > check if the process open by os.popen3 is still running. Thanks in > >> > advance for any advice or pointers. > >> > >> Surely, the MOST efficient way to do this has to be to download the > >> Python 2.3 version of subprocess from > >> http://effbot.org/downloads/#subprocess. > > > > Thanks for the advice, but this isn't exactly something I have in mind > > though. I was thinking more of a solution 'native' to python 2.3. > > Why? What's the point? If subprocess is known to solve your problem, > then why would you waste even half an hour of your time trying to > re-engineer it? It's not like this is some hack job by a high schooler > -- that download is the same subprocess module that was accepted into > Python 2.4, by the same author. Admin access is required for Installation. This is tightly controlled at my work place. From mhammond at skippinet.com.au Mon Jul 9 03:25:42 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 9 Jul 2007 11:25:42 +1000 Subject: [python-win32] Trying to build debug version of win32 extensions In-Reply-To: Message-ID: <034101c7c1c8$12116ba0$090a0a0a@enfoldsystems.local> You also need to build Python itself in debug mode - that creates python_d.* AFAIK, there has been no decision about the official Python 2.6 compiler and VS2003 is still the "official" one for 2.5... Cheers, Mark -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of Gerrat Rickert Sent: Saturday, 7 July 2007 7:22 AM To: python-win32 at python.org Subject: [python-win32] Trying to build debug version of win32 extensions I'm trying to build a debug version of the win32 extensions (basically to help track down a memory leak in a COM automation program I've written). To that end, I purchased a Visual C++ .Net Deluxe Learning Edition Book (which is probably the cheapest way to get the Visual C++ compiler required). Following the instructions in the source distribution, I was able to build a debug version of python from source (unfortunately, I know very little about C/C++). I checked out the python win32 source files, and am trying to build a debug version of this as well, but I'm not having much success. Though matter where I place the main directory with the win32 source files, it still fails to compile - I get an error: LINK: fatal error LINK1104: cannot open file 'python24_d.lib' [I'm trying to build using: "python setup.py -q build -debug"] This file exists in the directory I compiled the debug version of the main python distribution, but I'm not sure what I need to do so that the setup program can find it. Any help/direction would be appreciated. Thanks, Gerrat -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 5332 bytes Desc: not available Url : http://mail.python.org/pipermail/python-win32/attachments/20070709/56c915db/attachment.bin From grickert at coldstorage.com Mon Jul 9 16:37:44 2007 From: grickert at coldstorage.com (Gerrat Rickert) Date: Mon, 9 Jul 2007 10:37:44 -0400 Subject: [python-win32] Trying to build debug version of win32 extensions In-Reply-To: <034101c7c1c8$12116ba0$090a0a0a@enfoldsystems.local> Message-ID: Thanks for your reply, Mark. I probably wasn't very clear, but I did build a debug version of python. I'll provide more detailed information, as I'm sure the solution to my quandry is very likely a no-brainer for most of the people on this list. I checked out a copy of the python 2.4.4 source distribution into a directory (c:\temp\Python-2.4.4). Following the instructions in the PCBuild subdirectory, I did a build with the 'debug' solution configuration for pythoncore, python, and the subprojects that built out-of-the-box. The build was successful (no errors or warnings). This created files like 'python24_d.lib' in my c:\temp\Python-2.4.4\Pcbuild\ directory. Next I checked out source files for pywin32-210, and unpacked them into 'c:\temp\pywin32' (thereby creating directories similar to 'c:\temp\pywin32\com', etc.). I'm not exactly sure where these source files should live in order to do the debug build, but I thought as a first guess, I'd put them where other "subprojects" would go. The notes for building Python itself said that "if your Pcbuild is .......\dist\src\Pcbuild\, unpack into new subdirectories of dist\". In my case, the '\dist' would correspond to 'c:\temp'. This project may not be the same thing as other subprojects, but it seemed like a good guess to me. I then tried building the pywin32 extensions with: "python setup.py -q build -debug", and it failed with the error I mentioned. I also tried putting the pywin32 directory under c:\temp\Python-2.4.4, as well as under c:\temp\Python-2.4.4\Pcbuild - neither of these worked either. Do I actually need to install the debug version of python that I built? (I'd prefer not to overwrite my regular python build, but will happily do that if that's what is required). Do I need to set some environment variables? I believe I likely just need to tell the build program for pywin32 where the debug version of python is, but I'm not sure how to do that. Sorry for the long explanation for a very elementary question, but what am I doing wrong? Regards, Gerrat -----Original Message----- From: Mark Hammond [mailto:mhammond at skippinet.com.au] Sent: Sunday, July 08, 2007 9:26 PM To: Gerrat Rickert; python-win32 at python.org Subject: Re: [python-win32] Trying to build debug version of win32 extensions You also need to build Python itself in debug mode - that creates python_d.* AFAIK, there has been no decision about the official Python 2.6 compiler and VS2003 is still the "official" one for 2.5... Cheers, Mark -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of Gerrat Rickert Sent: Saturday, 7 July 2007 7:22 AM To: python-win32 at python.org Subject: [python-win32] Trying to build debug version of win32 extensions I'm trying to build a debug version of the win32 extensions (basically to help track down a memory leak in a COM automation program I've written). To that end, I purchased a Visual C++ .Net Deluxe Learning Edition Book (which is probably the cheapest way to get the Visual C++ compiler required). Following the instructions in the source distribution, I was able to build a debug version of python from source (unfortunately, I know very little about C/C++). I checked out the python win32 source files, and am trying to build a debug version of this as well, but I'm not having much success. Though matter where I place the main directory with the win32 source files, it still fails to compile - I get an error: LINK: fatal error LINK1104: cannot open file 'python24_d.lib' [I'm trying to build using: "python setup.py -q build -debug"] This file exists in the directory I compiled the debug version of the main python distribution, but I'm not sure what I need to do so that the setup program can find it. Any help/direction would be appreciated. Thanks, Gerrat From sidnei at enfoldsystems.com Mon Jul 9 16:51:29 2007 From: sidnei at enfoldsystems.com (Sidnei da Silva) Date: Mon, 9 Jul 2007 11:51:29 -0300 Subject: [python-win32] Trying to build debug version of win32 extensions In-Reply-To: References: <034101c7c1c8$12116ba0$090a0a0a@enfoldsystems.local> Message-ID: I believe you just have to run setup.py with 'python_d.exe' that is in PCBuild\python_d.exe instead of 'python.exe', though I might be wrong. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214 From grickert at coldstorage.com Mon Jul 9 17:19:37 2007 From: grickert at coldstorage.com (Gerrat Rickert) Date: Mon, 9 Jul 2007 11:19:37 -0400 Subject: [python-win32] Trying to build debug version of win32 extensions In-Reply-To: Message-ID: LOL! duh...here I was believing this had something to do with the mysterious build process for c/c++ projects that I know nothing about, and it turns out it was just a stupid matter of me running my regular version of python to execute the setup.py script (instead of the debug version I built). Thanks so much - that was it. Regards, Gerrat -----Original Message----- From: sidnei.da.silva at gmail.com [mailto:sidnei.da.silva at gmail.com] On Behalf Of Sidnei da Silva Sent: Monday, July 09, 2007 10:51 AM To: Gerrat Rickert Cc: python-win32 at python.org Subject: Re: [python-win32] Trying to build debug version of win32 extensions I believe you just have to run setup.py with 'python_d.exe' that is in PCBuild\python_d.exe instead of 'python.exe', though I might be wrong. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214 From nytrokiss at gmail.com Mon Jul 9 20:47:00 2007 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 9 Jul 2007 11:47:00 -0700 Subject: [python-win32] urllib and Outlook 2007 Message-ID: <8a6b8e350707091147r119e55cta2cfe78d56efef01@mail.gmail.com> Dear List I have two questions. 1. Is there any way to change the user-agent when using urllib.urlopenwithout having to subclass it? 2. I cannot seem to find anything on reading outlook email using COM everything i find is out dated can anyone give me some pointers or a place to find some information. Thanks James -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070709/e4665d4b/attachment.htm From larry.bates at websafe.com Mon Jul 9 21:42:06 2007 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 09 Jul 2007 14:42:06 -0500 Subject: [python-win32] urllib and Outlook 2007 In-Reply-To: <8a6b8e350707091147r119e55cta2cfe78d56efef01@mail.gmail.com> References: <8a6b8e350707091147r119e55cta2cfe78d56efef01@mail.gmail.com> Message-ID: James Matthews wrote: > Dear List > > I have two questions. > > > 1. Is there any way to change the user-agent when using urllib.urlopen > without having to subclass it? > > 2. I cannot seem to find anything on reading outlook email using COM > everything i find is out dated can anyone give me some pointers or a > place to find some information. > > Thanks > James > > -- > http://www.goldwatches.com/watches.asp?Brand=14 > http://www.jewelerslounge.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 I can help with #2: Did you even try Google? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266625 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/173216 http://www.boddie.org.uk/python/COM.html http://cephas.net/blog/2004/09/17/sending-your-outlook-calendar-using-python/ Also I would look at SpamBayes add-in source code. http://spambayes.sourceforge.net/applications.html -Larry From nytrokiss at gmail.com Mon Jul 9 23:50:58 2007 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 9 Jul 2007 14:50:58 -0700 Subject: [python-win32] urllib and Outlook 2007 In-Reply-To: References: <8a6b8e350707091147r119e55cta2cfe78d56efef01@mail.gmail.com> Message-ID: <8a6b8e350707091450u954441fl9aa9d8049c54a434@mail.gmail.com> Thank you Larry however those websites don't help me when i want to be able to retrieve email content. On 7/9/07, Larry Bates wrote: > > James Matthews wrote: > > Dear List > > > > I have two questions. > > > > > > 1. Is there any way to change the user-agent when using urllib.urlopen > > without having to subclass it? > > > > 2. I cannot seem to find anything on reading outlook email using COM > > everything i find is out dated can anyone give me some pointers or a > > place to find some information. > > > > Thanks > > James > > > > -- > > http://www.goldwatches.com/watches.asp?Brand=14 > > http://www.jewelerslounge.com > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Python-win32 mailing list > > Python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > I can help with #2: > > Did you even try Google? > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266625 > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/173216 > http://www.boddie.org.uk/python/COM.html > > http://cephas.net/blog/2004/09/17/sending-your-outlook-calendar-using-python/ > > Also I would look at SpamBayes add-in source code. > http://spambayes.sourceforge.net/applications.html > > -Larry > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070709/619b118d/attachment.htm From nytrokiss at gmail.com Tue Jul 10 00:20:00 2007 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 9 Jul 2007 15:20:00 -0700 Subject: [python-win32] Dispatch Error Message-ID: <8a6b8e350707091520m7ff34cf9x5d2acef7e4890b17@mail.gmail.com> I see people using this code however it doesn't seem to work for me! Any help Thanks James Code: from win32com.client import constants, Dispatch outlook = Dispatch("Outlook.Application") Error com_error: (-2146959355, 'Server execution failed', None, None) Traceback (innermost last): File "c:\Users\blank\Desktop\Code\Outlook Extention\untitled-1.py", line 1, in from win32com.client import constants, Dispatch File "c:\Users\blank\Desktop\Code\Outlook Extention\untitled-1.py", line 2, in outlook = Dispatch("Outlook.Application") File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070709/f8a22f5e/attachment.html From meledictas at gmail.com Tue Jul 10 19:00:11 2007 From: meledictas at gmail.com (Chatchai Neanudorn) Date: Wed, 11 Jul 2007 00:00:11 +0700 Subject: [python-win32] Start Performance counter logs failed. Message-ID: <6f10a16a0707101000w2f362755i357aafbb17937db5@mail.gmail.com> Hi, I have created custom performance counter using python win32 extension. I can see my performance object and my counter. Everything work fiine. Problem is, when I create a counter log to log my counter. I cannot start it. An event view report that open procedure of perfmondata.dll failed. Anybody help will be my pleased. Regards Chatchai -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070711/843dd452/attachment.htm From sidnei at enfoldsystems.com Tue Jul 10 19:20:37 2007 From: sidnei at enfoldsystems.com (Sidnei da Silva) Date: Tue, 10 Jul 2007 14:20:37 -0300 Subject: [python-win32] Start Performance counter logs failed. In-Reply-To: <6f10a16a0707101000w2f362755i357aafbb17937db5@mail.gmail.com> References: <6f10a16a0707101000w2f362755i357aafbb17937db5@mail.gmail.com> Message-ID: On 7/10/07, Chatchai Neanudorn wrote: > Hi, > > I have created custom performance counter using python win32 > extension. I can see my performance object and my counter. Everything work > fiine. > > Problem is, when I create a counter log to log my counter. I cannot start > it. An event view report that open procedure of perfmondata.dll failed. > > Anybody help will be my pleased. FWIW, I've experienced the same issue, so it's not an isolated case. I've reported this to Mark Hammond a few months ago, but he had not time to look at it so far. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214 From larry.bates at websafe.com Tue Jul 10 23:40:12 2007 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 10 Jul 2007 16:40:12 -0500 Subject: [python-win32] urllib and Outlook 2007 In-Reply-To: <8a6b8e350707091450u954441fl9aa9d8049c54a434@mail.gmail.com> References: <8a6b8e350707091147r119e55cta2cfe78d56efef01@mail.gmail.com> <8a6b8e350707091450u954441fl9aa9d8049c54a434@mail.gmail.com> Message-ID: James Matthews wrote: > Thank you Larry however those websites don't help me when i want to be > able to retrieve email content. > > On 7/9/07, *Larry Bates* < larry.bates at websafe.com > > wrote: > > James Matthews wrote: > > Dear List > > > > I have two questions. > > > > > > 1. Is there any way to change the user-agent when using urllib.urlopen > > without having to subclass it? > > > > 2. I cannot seem to find anything on reading outlook email using COM > > everything i find is out dated can anyone give me some pointers or a > > place to find some information. > > > > Thanks > > James > > > > -- > > http://www.goldwatches.com/watches.asp?Brand=14 > > http://www.jewelerslounge.com > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Python-win32 mailing list > > Python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > I can help with #2: > > Did you even try Google? > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266625 > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/173216 > > http://www.boddie.org.uk/python/COM.html > http://cephas.net/blog/2004/09/17/sending-your-outlook-calendar-using-python/ > > > Also I would look at SpamBayes add-in source code. > http://spambayes.sourceforge.net/applications.html > > -Larry > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > > > -- > http://www.goldwatches.com/watches.asp?Brand=14 > http://www.jewelerslounge.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 The source code for spambayes should certainly help. I know that application reads all the text of incoming email messages to determine if they are SPAM. -Larry From barrybb at gmail.com Thu Jul 12 20:02:06 2007 From: barrybb at gmail.com (Barry B) Date: Thu, 12 Jul 2007 10:02:06 -0800 Subject: [python-win32] problem with win32com and one-based indexed collections Message-ID: <5877a4cb0707121102y7868c943i607033c43f5feb69@mail.gmail.com> I have run across what I believe may be a shortcoming with win32com when trying to call functions that expect one-based indexed arrays as input. The function I'm trying to invoke which demonstrates the problem is defined in my documentation as follows: HRESULT SyncRead( [in] SHORT Source, [in] LONG NumItems, [in] SAFEARRAY(LONG) * ServerHandles, [out] SAFEARRAY(VARIANT) * Values, [out] SAFEARRAY(LONG) * Errors, [out,optional] VARIANT * Qualities, [out,optional] VARIANT * TimeStamps); In Python, this looks like: server_handles = [16384,16385] num_items = 2 values, errors, qualities, timestamps = groups.SyncRead(2, num_items, server_handles) The num_items parameter is supposed to tell the function the total number sever_handles being passed in. Anyway, the above code always throws a com exception and fails. I am assuming this issue is due to the SyncRead function using one-based indexing for its array collection. However, if I append an extra "dummy" argument to the beginning of the server_handles list, it will always work. server_handles = [0, 16384,16385] num_items = 2 values, errors, qualities, timestamps = groups.SyncRead(2, num_items, server_handles) The above example is a very poor solution since it appears to produce a slow memory leak in my application. Every 10 to 12 times the SyncRead call is invoked using the exact same server_handles, memory consumption increases by 4kb. This memory leak problem does not happen when called from VB. As an amusing test, I tried setting the variables passed to the function as follows: server_handles = [0, 16384, 16385, 0, 0, 0, 0, 0, 0, 0, 0, 0] num_items = 2 This makes an even bigger memory leak, leading me to believe any extra elements passed in the list beyond the num_items passed will always be allocated but never freed. Does Mark or anyone else know how to correctly pass a collection to a COM call using one-based indexing that won't cause a mem leak? I couldn't find any mention of this issue in the Python Win32 book other than an Excel example which didn't seem to apply. -BB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070712/e9395105/attachment.htm From jason.ferrara at jacquette.com Fri Jul 13 17:51:26 2007 From: jason.ferrara at jacquette.com (Jason Ferrara) Date: Fri, 13 Jul 2007 11:51:26 -0400 Subject: [python-win32] win32com array handling bug? In-Reply-To: <04c801c7be94$0a184b30$0200a8c0@enfoldsystems.local> References: <04c801c7be94$0a184b30$0200a8c0@enfoldsystems.local> Message-ID: If I make the following change to oleargs.cpp --- oleargs.cpp.orig 2007-07-13 11:21:30.711416000 -0400 +++ oleargs.cpp 2007-07-13 11:22:46.764499200 -0400 @@ -834,6 +834,16 @@ if (FAILED(hres)) return PyCom_BuildPyException(hres); long cElems = ub-lb+1; + for(UINT d = dimNo+ 1; d<=nDims; d++) + { + hres = SafeArrayGetLBound(psa, d, &lb); + if (FAILED(hres)) + return PyCom_BuildPyException(hres); + hres = SafeArrayGetUBound(psa, d, &ub); + if (FAILED(hres)) + return PyCom_BuildPyException(hres); + cElems *= (ub - lb + 1); + } long dataSize = cElems * sizeof(unsigned char); PyObject *ret = PyBuffer_New(dataSize); if (ret!=NULL) { then I get the full array back, but of course it comes back as an array of 1 dimension. The original dimension information is lost. Which leads to the question of what is the correct object to return in this case. I don't think that a tuple of buffers, as you describe below, is really the right thing. For that to work either you have to reverse the dimension order of the array, or the buffers have to contain data that originally wasn't contiguous (the buffers hold columns instead of rows). Neither seems particularly useful. Would it make sense to return an object thats a buffer that holds the full array data, but also has some additional attribute that contains the original array dimensions? For my particular case that would be the idea, since I want to feed the data into PIL.Image.frombuffer, which takes a buffer plus a size tuple. But I'm not sure what the best choice would be for general use. Also, what is the procedure for building a windows installer for pywin32? I can't seem to find any documentation on that. I'd like to create an installer that contains the above patch that I can use until fix makes it into an offical pywin32 release. Thanks -J On Jul 4, 2007, at 7:35 PM, Mark Hammond wrote: >> On Jul 4, 2007, at 7:12 PM, Mark Hammond wrote: >>> >>> Arrays of type VT_UI1 are returned as buffers. You should >> find the >>> length >>> of f is 1536, and you can treat it as a string (ie, just >> index into >>> it to >>> fetch the values, len() to get the length, slice it, etc). This is >>> primarily done as an optimization, so we don't need to waste time >>> and space >>> building lists of lists of integers when the data is more >> naturally a >>> 'string of bytes' anyway. >>> >>> Mark >>> >> >> I don't quite follow. >> >> I understand (well, I think I understand) how a buffer works. The >> problem is that the length is wrong. >> >> As shown above, the length of f is 2048. If the array was being >> returned correctly >> as a buffer, then the length should be 3145728 (2048 * 1536). > > Hrm - I misunderstood. a 2048x1536 array of bytes *should* be > returned as a > list with 2048 entries, each being a buffer of size 1536. I guess > I'll need > to try and reproduce this in the test suite... > > Mark > From grickert at coldstorage.com Fri Jul 13 21:44:07 2007 From: grickert at coldstorage.com (Gerrat Rickert) Date: Fri, 13 Jul 2007 15:44:07 -0400 Subject: [python-win32] problem with win32com and one-based indexed collections In-Reply-To: <5877a4cb0707121102y7868c943i607033c43f5feb69@mail.gmail.com> Message-ID: Barry, I cannot believe someone else (other than me) finally had this exact same issue (pretty much in the same context too)! I always assumed it was something else I had done that was responsible for the memory leak (I had a multi-threaded program with this issue). I'm in the process of changing my program to be event-driven (OnDataChange instead of SyncRead). This doesn't really solve the problem, but will hopefully avoid it. Gerrat. ________________________________ I have run across what I believe may be a shortcoming with win32com when trying to call functions that expect one-based indexed arrays as input. The function I'm trying to invoke which demonstrates the problem is defined in my documentation as follows: HRESULT SyncRead( [in] SHORT Source, [in] LONG NumItems, [in] SAFEARRAY(LONG) * ServerHandles, [out] SAFEARRAY(VARIANT) * Values, [out] SAFEARRAY(LONG) * Errors, [out,optional] VARIANT * Qualities, [out,optional] VARIANT * TimeStamps); In Python, this looks like: server_handles = [16384,16385] num_items = 2 values, errors, qualities, timestamps = groups.SyncRead(2, num_items, server_handles) The num_items parameter is supposed to tell the function the total number sever_handles being passed in. Anyway, the above code always throws a com exception and fails. I am assuming this issue is due to the SyncRead function using one-based indexing for its array collection. However, if I append an extra "dummy" argument to the beginning of the server_handles list, it will always work. server_handles = [0, 16384,16385] num_items = 2 values, errors, qualities, timestamps = groups.SyncRead(2, num_items, server_handles) The above example is a very poor solution since it appears to produce a slow memory leak in my application. Every 10 to 12 times the SyncRead call is invoked using the exact same server_handles, memory consumption increases by 4kb. This memory leak problem does not happen when called from VB. As an amusing test, I tried setting the variables passed to the function as follows: server_handles = [0, 16384, 16385, 0, 0, 0, 0, 0, 0, 0, 0, 0] num_items = 2 This makes an even bigger memory leak, leading me to believe any extra elements passed in the list beyond the num_items passed will always be allocated but never freed. Does Mark or anyone else know how to correctly pass a collection to a COM call using one-based indexing that won't cause a mem leak? I couldn't find any mention of this issue in the Python Win32 book other than an Excel example which didn't seem to apply. -BB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070713/c7d85053/attachment.html From gayatri_iyer at yahoo.com Mon Jul 16 02:50:20 2007 From: gayatri_iyer at yahoo.com (gayatri iyer) Date: Sun, 15 Jul 2007 17:50:20 -0700 (PDT) Subject: [python-win32] win32com.client for linux Message-ID: <498122.41755.qm@web33115.mail.mud.yahoo.com> I'm working towards fetching wmi information from a remote windows server target. The client is a linux appliance. Can i get the win32com.client for linux ? Kindly help. Thanks. --------------------------------- Sucker-punch spam with award-winning protection. Try the free Yahoo! Mail Beta. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070715/f02ffcc5/attachment.html From timr at probo.com Mon Jul 16 22:39:14 2007 From: timr at probo.com (Tim Roberts) Date: Mon, 16 Jul 2007 13:39:14 -0700 Subject: [python-win32] win32com.client for linux In-Reply-To: <498122.41755.qm@web33115.mail.mud.yahoo.com> References: <498122.41755.qm@web33115.mail.mud.yahoo.com> Message-ID: <469BD772.2040508@probo.com> gayatri iyer wrote: > I'm working towards fetching wmi information from a remote windows > server target. The client is a linux appliance. Can i get the > win32com.client for linux ? Not directly. However, WMI is a protocol-based service, kind of like a web server. There are packages available that let you query a WMI server using relatively standard HTTP requests. That might work for you. Start here: http://forums.cacti.net/about11752.html -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From excalibur.xcalibur at gmail.com Mon Jul 16 23:59:36 2007 From: excalibur.xcalibur at gmail.com (Excalibur Xcalibur) Date: Mon, 16 Jul 2007 17:59:36 -0400 Subject: [python-win32] missing module ['win32com.gen_py'] Message-ID: Hi Everyone, I compiled a script on win32 using py2exe and it's the first time I get the following error: ----------------------------------------------------------------------------------------------------------------------------------------------------------- The following modules appear to be missing: ['win32com.gen_py'] ----------------------------------------------------------------------------------------------------------------------------------------------------------- I'm pretty sure I installed all the required libraries and win32 extensions. This particular error happened when I tried to compile some Tk GUI using the easygui.py library. ( http://www.ferg.org/easygui/) If I execute *python program.py* directly, everything works fine. Any clues? -- Excalibur -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070716/bf002394/attachment.htm From mhammond at skippinet.com.au Tue Jul 17 00:42:26 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 17 Jul 2007 08:42:26 +1000 Subject: [python-win32] missing module ['win32com.gen_py'] In-Reply-To: Message-ID: <095601c7c7fa$961330e0$090a0a0a@enfoldsystems.local> You can probably ignore that message from py2exe, unless the program fails when executed. If it does, please include the complete tracebacks you see. Mark -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of Excalibur Xcalibur Sent: Tuesday, 17 July 2007 8:00 AM To: python-win32 at python.org Subject: [python-win32] missing module ['win32com.gen_py'] Hi Everyone, I compiled a script on win32 using py2exe and it's the first time I get the following error: -------------------------------------------------------------------------- ---------------------------------------------------------------------------- ----- The following modules appear to be missing: ['win32com.gen_py'] -------------------------------------------------------------------------- ---------------------------------------------------------------------------- ----- I'm pretty sure I installed all the required libraries and win32 extensions. This particular error happened when I tried to compile some Tk GUI using the easygui.py library. ( http://www.ferg.org/easygui/) If I execute *python program.py* directly, everything works fine. Any clues? -- Excalibur -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070717/446eeaa5/attachment.html From excalibur.xcalibur at gmail.com Tue Jul 17 02:51:58 2007 From: excalibur.xcalibur at gmail.com (Excalibur Xcalibur) Date: Mon, 16 Jul 2007 17:51:58 -0700 Subject: [python-win32] missing module ['win32com.gen_py'] In-Reply-To: <095601c7c7fa$961330e0$090a0a0a@enfoldsystems.local> References: <095601c7c7fa$961330e0$090a0a0a@enfoldsystems.local> Message-ID: Dear Mark, Thanks for the reply. For some weird reasons at times it compiles with the error message and on on other occasions it doesn't. Now it didn't and the EXE file was simply neat! -- Excalibur On 7/16/07, Mark Hammond wrote: > > You can probably ignore that message from py2exe, unless the program > fails when executed. If it does, please include the complete tracebacks you > see. > > Mark > > -----Original Message----- > *From:* python-win32-bounces at python.org [mailto: > python-win32-bounces at python.org]*On Behalf Of *Excalibur Xcalibur > *Sent:* Tuesday, 17 July 2007 8:00 AM > *To:* python-win32 at python.org > *Subject:* [python-win32] missing module ['win32com.gen_py'] > > Hi Everyone, > I compiled a script on win32 using py2exe and it's the > first time I get the following error: > > ----------------------------------------------------------------------------------------------------------------------------------------------------------- > > > The following modules appear to be missing: > > ['win32com.gen_py'] > > ----------------------------------------------------------------------------------------------------------------------------------------------------------- > > > I'm pretty sure I installed all the required libraries and win32 > extensions. This particular error happened when I tried to compile some Tk > GUI using the easygui.py library. ( http://www.ferg.org/easygui/) > > If I execute *python program.py* directly, everything works fine. Any > clues? > > -- > Excalibur > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070716/6eda217a/attachment.html From jeff.taylor at wj.com Thu Jul 19 21:36:05 2007 From: jeff.taylor at wj.com (Jeff Taylor) Date: Thu, 19 Jul 2007 14:36:05 -0500 Subject: [python-win32] High Baud Rate Serial Port Question Message-ID: <469FBD25.1020008@wj.com> I know this has probably been brought up many years ago, but I'm rather new to Python. Is there a way to open a serial port with a baudrate greater than 115.2kbps? I'm currently using pyserial and it can handle over 115.2, but when it calls win32file, win32file gives back a bad parameter error for higher baudrates (like 230400 or 460800 bps). Any help would be appreciated. Thanks. Jeff From marten.hedman at btk.fi Fri Jul 20 07:24:34 2007 From: marten.hedman at btk.fi (=?ISO-8859-1?Q?M=E5rten_Hedman?=) Date: Fri, 20 Jul 2007 08:24:34 +0300 Subject: [python-win32] Backing up and clearing event logs Message-ID: <46A04712.5030305@btk.fi> Hello, I am trying to write a script for backing up and clearing event logs on our Windows 2003 servers, using Python 2.5 and Tim Golden's WMI module. While testing with the Application log on a local Windows XP machine I seem to get stuck on the parameters to WMI. The following code: import wmi c = wmi.WMI(privileges=["Backup"]) logfiles = c.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Application'") for lf in logfiles: lf.BackupEventLog("c:\\temp\\Applog.evt") gives the following error message: Traceback (most recent call last): File "", line 2, in File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ raise pythoncom.com_error, details com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx', 'Invalid parameter ', None, 0, -2147217400), None) If I use the full wmi moniker, ie c = wmi.WMI(moniker="winmgmts:{impersonationLevel=impersonate,(Backup)}\\\\ketjap\\root\\cimv2") I get the same error. Have I missed somthing regarding impersonation and privileges? Thank's in advance Marten Hedman -- ------------------------------------------------------------------------ M?rten Hedman phone: +358-(0)2-333 8037 Systems Manager fax: +358-(0)2-333 8000 Turku Centre for Biotechnology Marten.Hedman at btk.fi Turku, Finland http://www.btk.fi/~marten From mail at timgolden.me.uk Fri Jul 20 10:54:47 2007 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 20 Jul 2007 09:54:47 +0100 Subject: [python-win32] Backing up and clearing event logs In-Reply-To: <46A04712.5030305@btk.fi> References: <46A04712.5030305@btk.fi> Message-ID: <46A07857.5080602@timgolden.me.uk> M?rten Hedman wrote: > Hello, > > I am trying to write a script for backing up and clearing event logs on > our Windows 2003 servers, using Python 2.5 and Tim Golden's WMI module. > While testing with the Application log on a local Windows XP machine I > seem to get stuck on the parameters to WMI. > > The following code: > > import wmi > c = wmi.WMI(privileges=["Backup"]) > logfiles = c.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE > LogFileName='Application'") > > for lf in logfiles: > lf.BackupEventLog("c:\\temp\\Applog.evt") > > gives the following error message: > > Traceback (most recent call last): > File "", line 2, in > File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line > 491, in __getattr__ > raise pythoncom.com_error, details > com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx', > 'Invalid parameter ', None, 0, -2147217400), None) I doubt if the moniker's got anything to do with it. You're just falling foul of the fact that I haven't released the fix which allows positional args in a WMI method call: you have to use named args. So... >>> import wmi >>> c = wmi.WMI () >>> log = c.Win32_NTEventLogFile >>> print log.BackupEventlog (ReturnValue) | Needs: SeSecurityPrivilege, SeBackupPrivilege> >>> ... try: lf.BackupEventLog (ArchiveFileName="c:\\temp\\blah.blah") TJG From nytrokiss at gmail.com Fri Jul 20 23:40:46 2007 From: nytrokiss at gmail.com (James Matthews) Date: Fri, 20 Jul 2007 14:40:46 -0700 Subject: [python-win32] Python Flagged as a Virus by AVG Message-ID: <8a6b8e350707201440s66ee9286k2009e2b92f5393ff@mail.gmail.com> I was reading a Microsoft news group and came across this post Got this during a scan of my computer: infected: object C:\hp\bin\python-2.2.3.exe:\comparisons.html result: trojan horse PHP/MPack.B status: infected embedded object inefected: object C:\hp\bin\python-2.2.3.exe What can/should I do about this? Thanks for your help. then there is another post I got the same thing with my free AVG, but it was not moved to virus valut. Have no idea what to do. Any help is appreciated!!! Mine says Comparisons.HTML PHP/MPACKB Python-2.2.1.exe then finnaly I just read on the AVG forum, many folks have gotten this threat today, it is a false positive. To clear it, update your virus definitions and then run another scan. The new update is suppose to fix it. I did an update, then another scan, and it finally came back clean. Seems it isn't going in people's virus vaults. Hope this helps........:-) -- http://www.goldwatches.com/watches.asp?Brand=14 http://www.jewelerslounge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070720/2bdaf733/attachment.htm From rbell01824 at earthlink.net Sat Jul 21 00:02:27 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Fri, 20 Jul 2007 17:02:27 -0500 Subject: [python-win32] Inserting method into COM object dictionary Message-ID: <000001c7cb19$aac6ba80$6701a8c0@rjbmain> The following code creates an IE browser, navigates to Google, and then clicks on the 'News' link. ----- code ----- ie = win32com.client.DispatchEx('InternetExplorer.Application') ie.Visible = 1 ie.Navigate('www.google.com') time.sleep(10) # show a '.' access fairly deep into the page's DOM (to the 'News' link) print 'navigate' anchor = ie.Document.all.tags('BODY').item(0).all.tags('DIV').item(0).all.tags('NOBR' ).item(0).all.tags('DIV').item(3).all.tags('A').item(0) print 'click' anchor.click() ----- end code ----- Interestingly, the rather long statement 'anchor =' works (yes I know there are easier ways to get to the desired tag). I assume (my Python is not so good that I KNOW) that it works since the expression is evaluated left to right and each method returns an object that, in turn, has the appropriate methods for subsequent evaluation. Question 1:Is this the case? While the DOM's navigation methods, see http://msdn2.microsoft.com/en-us/library/ms533050.aspx are powerful, there are a number of instances where I'd like to enhance them. I'm considering the possibility of 'inserting' a method into the object's class dictionary that does so. A bit of experimentation shows that this is possible for any given DOM object. However, there are a bunch of these. The ones I've looked at derive from win32com.client.DispatchBaseClass. Question 2: Do ALL the IE COM objects derive from this class? How can I know for sure without exhaustive examination? A bit more experimentation yielded the following test code: ----- code ----- # test 'injecting' functions into DispatchBaseClass import win32com.client import time class yamieX(object): def __init__(self, wait = 5): self.wait = wait self.ie = win32com.client.DispatchEx('InternetExplorer.Application') self.ie.Visible = 1 self.ie.Navigate('www.google.com') time.sleep(wait) # inject DOM extensions win32com.client.DispatchBaseClass.__dict__['tag']=tag win32com.client.DispatchBaseClass.__dict__['clickWait']=clickWait def GoBack(self): self.ie.GoBack() time.sleep(self.wait) def Wait(self): time.sleep(self.wait) def _body(self): return self.ie.Document.all.tags('BODY').item(0) body = property(_body, None, None, None) def tag(object, str, index=0): return object.all.tags(str).item(index) def clickWait(object, yamieX): object.click() yamieX.Wait() #################### # try the magic out #################### yie = yamieX() print "show a '.' access fairly deep into the page's DOM (to the 'News' link)" print 'navigate and click' anchor = yie.ie.Document.all.tags('BODY').item(0).all.tags('DIV').item(0).all.tags('N OBR').item(0).all.tags('DIV').item(3).all.tags('A').item(0) anchor.click() yie.Wait() print 'show we got to http://news.google.com/nwshp?tab=wn LocationURL=', \ yie.ie.LocationURL == u'http://news.google.com/nwshp?tab=wn' print print 'go back' yie.GoBack() print print "do it again using tag extension" anchor = yie.body.tag('DIV').tag('NOBR').tag('DIV',3).tag('A').clickWait(yie) #anchor.click() yie.Wait() print 'show we got to http://news.google.com/nwshp?tab=wn LocationURL=', \ yie.ie.LocationURL == u'http://news.google.com/nwshp?tab=wn' print 'success' ----- end code ----- All this appears to work in that it creates the expected output. But I'm a bit concerned in that I'm poking Python and win32com rather hard. Question 3: Any advice or observations on how 'safe' this might be? Thanks for any feedback. Regards, Richard From larry.bates at websafe.com Sat Jul 21 23:26:06 2007 From: larry.bates at websafe.com (Larry Bates) Date: Sat, 21 Jul 2007 16:26:06 -0500 Subject: [python-win32] High Baud Rate Serial Port Question In-Reply-To: <469FBD25.1020008@wj.com> References: <469FBD25.1020008@wj.com> Message-ID: Jeff Taylor wrote: > I know this has probably been brought up many years ago, but I'm rather > new to Python. > > Is there a way to open a serial port with a baudrate greater than > 115.2kbps? I'm currently using pyserial and it can handle over 115.2, > but when it calls win32file, win32file gives back a bad parameter error > for higher baudrates (like 230400 or 460800 bps). > > Any help would be appreciated. > > Thanks. > > Jeff Normally baud rates higher than that take "special" hardware. Normal UARTs don't typically run that high. You also have a problem with interference on serial cables at those frequencies so people move to RS-422 or some other interface. -Larry From phnx783 at adelphia.net Mon Jul 23 07:18:11 2007 From: phnx783 at adelphia.net (sue) Date: Sun, 22 Jul 2007 22:18:11 -0700 Subject: [python-win32] how to drive rational rose with pywincom? Message-ID: <46A43A13.2050107@adelphia.net> I've run makepy against rationalrose.tlb. The python file itself looks fine and matches data from Rose's TLB import. However, nothing seems to work. Rose-Perl, Rose-Ruby, and even IBM's own Java2rei module didn't help. 1. gencache.EnsureModule() never finds a file in the cache, and generates a new one in my user account, in spite of having local admin. 2. Dispatch() is always late-binding. (The python file appears to support early binding.) 3. I can read a few top-level properties (Model, FileName,CommandLine), but all methods (even readonly ones) are either not found or return COM objects with no properties or methods. 4. I've also tried starting Rose as an Application Server "rose.exe /Application" and attaching to the running process. No joy. I'm running Rose 2003 and ActivePython 2.5.0.0 on WinXP. I have no problems driving Office, IE, Outlook, or ClearCase. Any suggestions would be appreciated. Sue. From marten.hedman at btk.fi Mon Jul 23 12:12:32 2007 From: marten.hedman at btk.fi (=?ISO-8859-1?Q?M=E5rten_Hedman?=) Date: Mon, 23 Jul 2007 13:12:32 +0300 Subject: [python-win32] Backing up and clearing event logs In-Reply-To: <46A07857.5080602@timgolden.me.uk> References: <46A04712.5030305@btk.fi> <46A07857.5080602@timgolden.me.uk> Message-ID: <46A47F10.2060106@btk.fi> Tim Golden wrote: > M?rten Hedman wrote: >> Hello, >> >> I am trying to write a script for backing up and clearing event logs on >> our Windows 2003 servers, using Python 2.5 and Tim Golden's WMI module. >> While testing with the Application log on a local Windows XP machine I >> seem to get stuck on the parameters to WMI. >> >> The following code: >> >> import wmi >> c = wmi.WMI(privileges=["Backup"]) >> logfiles = c.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE >> LogFileName='Application'") >> >> for lf in logfiles: >> lf.BackupEventLog("c:\\temp\\Applog.evt") >> >> gives the following error message: >> >> Traceback (most recent call last): >> File "", line 2, in >> File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line >> 491, in __getattr__ >> raise pythoncom.com_error, details >> com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx', >> 'Invalid parameter ', None, 0, -2147217400), None) > > I doubt if the moniker's got anything to do with it. > You're just falling foul of the fact that I haven't > released the fix which allows positional args in > a WMI method call: you have to use named args. So... > > > >>> import wmi > >>> c = wmi.WMI () > >>> log = c.Win32_NTEventLogFile > >>> print log.BackupEventlog > (ReturnValue) | Needs: SeSecurityPrivilege, SeBackupPrivilege> > >>> > > > > ... try: > > lf.BackupEventLog (ArchiveFileName="c:\\temp\\blah.blah") Thank you for your quick answer. Unfortunately I get the same error message. BTW, is WMI case sensitive regarding method names? If I run your example with 'print log.BackupEventLog', I get the error: >>> c=wmi.WMI() >>> log=c.Win32_NTEventLogFile >>> print log.BackupEventLog Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site-packages\wmi.py", line 474, in __getattr__ handle_com_error (error_info) File "C:\Python25\lib\site-packages\wmi.py", line 188, in handle_com_error raise x_wmi, "\n".join (exception_string) x_wmi: -0x7ffdfff7 - Exception occurred. Error in: SWbemObjectEx -0x7ffbefd1 - Invalid method Parameter(s) >>> Both 'lf.BackupEventLog (ArchiveFileName="c:\\temp\\blah.blah")' and 'lf.BackupEventlog (...)' returns the same error though M?rten Hedman From mail at timgolden.me.uk Mon Jul 23 12:40:28 2007 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 Jul 2007 11:40:28 +0100 Subject: [python-win32] Backing up and clearing event logs In-Reply-To: <46A47F10.2060106@btk.fi> References: <46A04712.5030305@btk.fi> <46A07857.5080602@timgolden.me.uk> <46A47F10.2060106@btk.fi> Message-ID: <46A4859C.60405@timgolden.me.uk> M?rten Hedman wrote: > Thank you for your quick answer. Unfortunately I get the same error > message. > > BTW, is WMI case sensitive regarding method names? If I run your example > with 'print log.BackupEventLog', I get the error: > > > >>> c=wmi.WMI() > >>> log=c.Win32_NTEventLogFile > >>> print log.BackupEventLog > Traceback (most recent call last): > File "", line 1, in > File "C:\Python25\lib\site-packages\wmi.py", line 474, in __getattr__ > handle_com_error (error_info) > File "C:\Python25\lib\site-packages\wmi.py", line 188, in > handle_com_error > raise x_wmi, "\n".join (exception_string) > x_wmi: -0x7ffdfff7 - Exception occurred. > Error in: SWbemObjectEx > -0x7ffbefd1 - Invalid method Parameter(s) > >>> > > > Both 'lf.BackupEventLog (ArchiveFileName="c:\\temp\\blah.blah")' and > 'lf.BackupEventlog (...)' returns the same error though OK. The bottom line seems to be: 1) I was (partly) wrong 2) Microsoft generates crap error messages The following code works for me: import wmi c = wmi.WMI (privileges=["security", "backup"]) for log in c.Win32_NTEventLogFile (LogfileName="Application"): print log.FileName result, = log.BackupEventlog (ArchiveFileName=r"c:\temp\%s.log" % log.FileName) if result <> 0: raise RuntimeError, "%s could note be written: error %d" % (log.FileName, result) Note several things: a) You have to take security & backup privs. This was actually documented on the method description (print log.BackupEventlog) but I missed it first time round. b) You have -- in this version of the module -- to pass the ArchiveFileName keyword parameter. c) The method is named (at least on my XP SP2 box) "BackupEventlog" (note the capitalisation). I don't know if the underlying WMI is case-sensitive, but the module uses a dictionary to cache method names, which obviously *is* case-sensitive. Any unknown property is passed through direct to the underlying provider. What that does with it is unknown (to me :) Hope all that helps. Tim PS As a footnote, I have this very frustrating experience where *some* people -- and it looks to me as though you're one of them -- get the property passthrough stuff for free (ie it would happen even without my module) where I never do. I've never managed to track this down. TJG From rwupole at msn.com Mon Jul 23 20:44:01 2007 From: rwupole at msn.com (Roger Upole) Date: Mon, 23 Jul 2007 14:44:01 -0400 Subject: [python-win32] Re: Backing up and clearing event logs Message-ID: <000a01c7cd59$72828bd0$0100a8c0@rupole> Tim Golden wrote: > PS As a footnote, I have this very frustrating experience where > *some* people -- and it looks to me as though you're one of > them -- get the property passthrough stuff for free (ie it would > happen even without my module) where I never do. I've never > managed to track this down. TJG The difference is most likely due to whether or not the makepy generated module has been created for WMI objects. If it has, only the standard methods from the typelib are directly available (_Properties, _Methods, etc). Roger From mail at timgolden.me.uk Mon Jul 23 20:59:59 2007 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 Jul 2007 19:59:59 +0100 Subject: [python-win32] Backing up and clearing event logs In-Reply-To: <000a01c7cd59$72828bd0$0100a8c0@rupole> References: <000a01c7cd59$72828bd0$0100a8c0@rupole> Message-ID: <46A4FAAF.6040601@timgolden.me.uk> Roger Upole wrote: > Tim Golden wrote: >> PS As a footnote, I have this very frustrating experience where >> *some* people -- and it looks to me as though you're one of >> them -- get the property passthrough stuff for free (ie it would >> happen even without my module) where I never do. I've never >> managed to track this down. TJG > > The difference is most likely due to whether or not the makepy > generated module has been created for WMI objects. > If it has, only the standard methods from the typelib are > directly available (_Properties, _Methods, etc). > > Roger Thanks, Roger. That was my thought, too, but I tried it backwards, forwards, with, without and still couldn't get it to happen for me. (It was a while ago and I probably wasn't very methodical but...) At some point I'll sit down calmly and give it another go, but there's no real incentive for me. It's just curious. TJG From thebrianmartin at gmail.com Tue Jul 24 04:14:13 2007 From: thebrianmartin at gmail.com (Brian Martin) Date: Mon, 23 Jul 2007 22:14:13 -0400 Subject: [python-win32] how to get select behavior for non-socket objects Message-ID: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> Hello, I understand that the select module will only work with sockets under windows. Is there a built-in python module for win32 that provides some kind of multiplexing ability for something like a serial port (via pyserial). thanks, brian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070723/64376313/attachment.html From marten.hedman at btk.fi Tue Jul 24 10:01:59 2007 From: marten.hedman at btk.fi (=?ISO-8859-1?Q?M=E5rten_Hedman?=) Date: Tue, 24 Jul 2007 11:01:59 +0300 Subject: [python-win32] Backing up and clearing event logs In-Reply-To: <46A4859C.60405@timgolden.me.uk> References: <46A04712.5030305@btk.fi> <46A07857.5080602@timgolden.me.uk> <46A47F10.2060106@btk.fi> <46A4859C.60405@timgolden.me.uk> Message-ID: <46A5B1F7.6060101@btk.fi> Tim Golden wrote: > M?rten Hedman wrote: >> Thank you for your quick answer. Unfortunately I get the same error >> message. >> >> BTW, is WMI case sensitive regarding method names? If I run your example >> with 'print log.BackupEventLog', I get the error: >> >> >> >>> c=wmi.WMI() >> >>> log=c.Win32_NTEventLogFile >> >>> print log.BackupEventLog >> Traceback (most recent call last): >> File "", line 1, in >> File "C:\Python25\lib\site-packages\wmi.py", line 474, in __getattr__ >> handle_com_error (error_info) >> File "C:\Python25\lib\site-packages\wmi.py", line 188, in >> handle_com_error >> raise x_wmi, "\n".join (exception_string) >> x_wmi: -0x7ffdfff7 - Exception occurred. >> Error in: SWbemObjectEx >> -0x7ffbefd1 - Invalid method Parameter(s) >> >>> >> >> >> Both 'lf.BackupEventLog (ArchiveFileName="c:\\temp\\blah.blah")' and >> 'lf.BackupEventlog (...)' returns the same error though > > OK. The bottom line seems to be: > > 1) I was (partly) wrong > 2) Microsoft generates crap error messages Yes, i have noticed that. > > The following code works for me: > > > import wmi > c = wmi.WMI (privileges=["security", "backup"]) > for log in c.Win32_NTEventLogFile (LogfileName="Application"): > print log.FileName > result, = log.BackupEventlog (ArchiveFileName=r"c:\temp\%s.log" % log.FileName) > if result <> 0: > raise RuntimeError, "%s could note be written: error %d" % (log.FileName, result) > > Thank you very much! This code also works for me. > > Note several things: > > a) You have to take security & backup privs. This was actually > documented on the method description (print log.BackupEventlog) > but I missed it first time round. > > b) You have -- in this version of the module -- to pass the > ArchiveFileName keyword parameter. > Yes, I have understood that from earlier email and other documentation. > c) The method is named (at least on my XP SP2 box) "BackupEventlog" > (note the capitalisation). I don't know if the underlying WMI is > case-sensitive, but the module uses a dictionary to cache method > names, which obviously *is* case-sensitive. Any unknown property > is passed through direct to the underlying provider. What that does > with it is unknown (to me :) Most of the documentation I have seen names the method "BackupEventLog". The MSDN documentation at http://msdn2.microsoft.com/en-US/library/aa384808.aspx uses both versions, so there seems to be some confusion around. > > Hope all that helps. > > Tim > It did indeed. Thank you again for your help. M?rten -- ------------------------------------------------------------------------ M?rten Hedman phone: +358-(0)2-333 8037 Systems Manager fax: +358-(0)2-333 8000 Turku Centre for Biotechnology Marten.Hedman at btk.fi Turku, Finland http://www.btk.fi/~marten From marten.hedman at btk.fi Tue Jul 24 10:18:59 2007 From: marten.hedman at btk.fi (=?ISO-8859-1?Q?M=E5rten_Hedman?=) Date: Tue, 24 Jul 2007 11:18:59 +0300 Subject: [python-win32] Backing up and clearing event logs In-Reply-To: <46A4FAAF.6040601@timgolden.me.uk> References: <000a01c7cd59$72828bd0$0100a8c0@rupole> <46A4FAAF.6040601@timgolden.me.uk> Message-ID: <46A5B5F3.2090908@btk.fi> Tim Golden wrote: > Roger Upole wrote: >> Tim Golden wrote: >>> PS As a footnote, I have this very frustrating experience where >>> *some* people -- and it looks to me as though you're one of >>> them -- get the property passthrough stuff for free (ie it would >>> happen even without my module) where I never do. I've never >>> managed to track this down. TJG >> The difference is most likely due to whether or not the makepy >> generated module has been created for WMI objects. >> If it has, only the standard methods from the typelib are >> directly available (_Properties, _Methods, etc). >> >> Roger > > Thanks, Roger. That was my thought, too, but I tried > it backwards, forwards, with, without and still > couldn't get it to happen for me. (It was a while > ago and I probably wasn't very methodical but...) > > At some point I'll sit down calmly and give it > another go, but there's no real incentive for > me. It's just curious. > > TJG Just a comment: My current, temporary, Python environment is very basic, only Python 2.5.1, pywin32 v. 210 and wmi.py v. 1.3 on a WinXP SP2 laptop. I have not run makepy on any type libraries. Should I do this, and in that case on which library? Most of my work related python programming has to do with administrating a Windows 2003 domain. M?rten From mail at timgolden.me.uk Tue Jul 24 11:06:46 2007 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 Jul 2007 10:06:46 +0100 Subject: [python-win32] Backing up and clearing event logs In-Reply-To: <46A5B5F3.2090908@btk.fi> References: <000a01c7cd59$72828bd0$0100a8c0@rupole> <46A4FAAF.6040601@timgolden.me.uk> <46A5B5F3.2090908@btk.fi> Message-ID: <46A5C126.8090002@timgolden.me.uk> M?rten Hedman wrote: > Just a comment: My current, temporary, Python environment is very basic, > only Python 2.5.1, pywin32 v. 210 and wmi.py v. 1.3 on a WinXP SP2 > laptop. I have not run makepy on any type libraries. Should I do this, > and in that case on which library? Most of my work related python > programming has to do with administrating a Windows 2003 domain. In general, the reason for running makepy is to give win32com.client access to things like named constants and function parameters and so on. (Means you can call the standard Python help () on the class, too). If you know enough about the objects you're using you don't need to do this. In addition, you can always call win32com.client.gencache.EnsureDispatch on individual objects to generate their proxy modules. I initially did this within the wmi module but then people were having problems using it as a module within a py2exe or some other embedded system. So I switched to using dynamic despatch and using a little function of Thomas Heller's which pulled the constants directly from the dynamic proxy. In short, you probably don't need to, but it likewise probably won't do any harm. One thing to be aware of is that, while COM itself seems to be case-*in*sensitive, the proxy modules which makepy generates are Python code, and so are case-sensitive. Any existing code which used different case from the generated module will fall over. YM, as they say, MV TJG From timr at probo.com Tue Jul 24 18:52:16 2007 From: timr at probo.com (Tim Roberts) Date: Tue, 24 Jul 2007 09:52:16 -0700 Subject: [python-win32] how to get select behavior for non-socket objects In-Reply-To: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> References: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> Message-ID: <46A62E40.3010900@probo.com> Brian Martin wrote: > Hello, I understand that the select module will only work with sockets > under windows. Is there a built-in python module for win32 that > provides some kind of multiplexing ability for something like a serial > port (via pyserial). There's just no good way to implement such a thing in the Windows API. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Wed Jul 25 01:02:28 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 25 Jul 2007 09:02:28 +1000 Subject: [python-win32] how to get select behavior for non-socket objects In-Reply-To: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> Message-ID: <0efa01c7ce46$b6b0ef70$090a0a0a@enfoldsystems.local> If you have a Windows handle (such as a handle to the serial port, a handle to a file, or a socket), you can generally use win32event.WaitForMultipleObjects() Mark -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of Brian Martin Sent: Tuesday, 24 July 2007 12:14 PM To: python-win32 at python.org Subject: [python-win32] how to get select behavior for non-socket objects Hello, I understand that the select module will only work with sockets under windows. Is there a built-in python module for win32 that provides some kind of multiplexing ability for something like a serial port (via pyserial). thanks, brian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070725/5b8cf29b/attachment.htm From waldemar.osuch at gmail.com Wed Jul 25 03:08:36 2007 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Tue, 24 Jul 2007 19:08:36 -0600 Subject: [python-win32] how to get select behavior for non-socket objects In-Reply-To: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> References: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> Message-ID: <6fae95540707241808w2ceebc1aj53b3e8a97bf6b460@mail.gmail.com> On 7/23/07, Brian Martin wrote: > Hello, I understand that the select module will only work with sockets under > windows. Is there a built-in python module for win32 that provides some kind > of multiplexing > ability for something like a serial port (via pyserial). > > thanks, > brian > I do not know if it fits your purpose or how good it is but Twisted folks have an implementation. http://twistedmatrix.com/trac/browser/trunk/twisted/internet/_win32serialport.py Waldemar From rasjidw at gmail.com Wed Jul 25 13:48:59 2007 From: rasjidw at gmail.com (Rasjid Wilcox) Date: Wed, 25 Jul 2007 21:48:59 +1000 Subject: [python-win32] Registering a Server COM to make it visible in thereference list In-Reply-To: <000f01c78acd$cc0c37b0$090a0a0a@enfoldsystems.local> References: <462F74CB.3060103@cenix-bioscience.com> <000f01c78acd$cc0c37b0$090a0a0a@enfoldsystems.local> Message-ID: On 4/30/07, Mark Hammond wrote: > That list is of the type-libraries registered in the system, and by default, > Python has no such typelib. It is possible to manually create a typelib > that describes your object though - google for other posts by me on this > topic. For many years, there has been interest in upgrading win32com to > auto-create a typelib - let me know if you are interested in helping with > that... I've tried googling for said posts by Mark, but I'm not having a lot of luck finding said posts. As for helping with the auto-create idea, what kind of experience is needed, and do we have any idea of how much work is involved? Cheers, Rasjid. From carl at personnelware.com Thu Jul 26 21:19:22 2007 From: carl at personnelware.com (Carl Karsten) Date: Thu, 26 Jul 2007 14:19:22 -0500 Subject: [python-win32] SendMessageTimeout() ? Message-ID: <46A8F3BA.5080509@personnelware.com> I am pretty sure I need to call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue); And can't figure out how. Here is the background of what/why: I am trying to "add a dir to the windows search path." Apparently this is a two step process: 1) add dir to reg key, 2) make win notice the new value. Here is my #1. from _winreg import * ... h = OpenKeyEx( hive, key, 0, KEY_SET_VALUE ) NewPath = curPath + ';' + DirToAdd SetValueEx(h, 'path', 0, REG_EXPAND_SZ, NewPath ) CloseKey(h) I am basing my step 2 on: "... modifications to the environment variables do not result in immediate change .... To effect these changes ... broadcast a WM_SETTINGCHANGE message..." http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q104011 Carl K From rbell01824 at earthlink.net Thu Jul 26 23:53:04 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Thu, 26 Jul 2007 16:53:04 -0500 Subject: [python-win32] win32ui and flashing box Message-ID: <009d01c7cfcf$59630530$6701a8c0@rjbmain> I'm a complete neophyte when it comes to window's GUI and need a bit of help. I'm working on an application that automated IE and want to draw a flashing box around screen elements. I can find the coordinates OK but am a bit unclear on how to actually draw a box in such a fashion that when the flashing stops the screen is as it was before it started. A bit of investigation suggests that something like this ought to work: import win32gui, win32ui def box(hdc, x, y, w, h): hdc.MoveTo(x, y) hdc.LineTo(x+w, y) hdc.LineTo(x+w, y+h) hdc.LineTo(x, h+h) hdc.LineTo(x, y) hdc = win32ui.CreateDCFromHandle(win32gui.GetDesktopWindow()) box(hdc, 200, 200, 200, 200) But when I run the code I get a win32ui: LineTo failed exception. Is there a simple way of doing this? From mhammond at skippinet.com.au Fri Jul 27 00:45:21 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 27 Jul 2007 08:45:21 +1000 Subject: [python-win32] win32com array handling bug? In-Reply-To: Message-ID: <10c301c7cfd6$a6365cc0$090a0a0a@enfoldsystems.local> sorry for the delay: > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org]On Behalf Of Jason Ferrara > Sent: Saturday, 14 July 2007 1:51 AM > To: Mark Hammond > Cc: python-win32 at python.org > Subject: Re: [python-win32] win32com array handling bug? ... > I don't think that a tuple of buffers, as you describe below, is > really the right thing. For that to work either you have to reverse > the dimension order of the array, or the buffers have to > contain data > that originally wasn't contiguous (the buffers hold columns instead > of rows). Neither seems particularly useful. I'm a little confused by that. If I create an array with dims [8,5], I end up with 8 rows and 5 columns. I don't see why I could return 8 tuples of strings, each with length 5. Each tuple would hold what was initially contiguous memory. Joining these strings together would give an exact representation of the original buffer. 3d arrays might be tricker - my brain has been exploding with just 2d recently :) But: > Would it make sense to return an object thats a buffer that > holds the > full array data, but also has some additional attribute that > contains > the original array dimensions? For my particular case that would be > the idea, since I want to feed the data into PIL.Image.frombuffer, > which takes a buffer plus a size tuple. But I'm not sure what the > best choice would be for general use. I can buy that argument. We are already special-casing UI1, so returning a "flat" result would seem to make sense. If the 2d array is large, and python only needs the data to pass it on somewhere else, there would be significant performance benefits. If the initial dimensions were available, it would still be quite simple for someone to slice the data back up so they could treat it as an array. However, I'm a little reluctant to do apply your patch until we do have an object that can also return the dimensions - otherwise we end up with it being 1/2 fixed and another few years before it is really "fixed" for all users. I've put your patch and the start of some test code at https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1709340&group_i d=78018 (thanks to Kevin for starting that) and I'd welcome contributions that allow us to return a new "buffer-like" object that can also records the dimensions of the array. Cheers, Mark From timr at probo.com Fri Jul 27 01:06:42 2007 From: timr at probo.com (Tim Roberts) Date: Thu, 26 Jul 2007 16:06:42 -0700 Subject: [python-win32] win32ui and flashing box In-Reply-To: <009d01c7cfcf$59630530$6701a8c0@rjbmain> References: <009d01c7cfcf$59630530$6701a8c0@rjbmain> Message-ID: <46A92902.1010001@probo.com> Richard Bell wrote: > I'm working on an application that automated IE and want to draw a flashing > box around screen elements. I can find the coordinates OK but am a bit > unclear on how to actually draw a box in such a fashion that when the > flashing stops the screen is as it was before it started. A bit of > investigation suggests that something like this ought to work: > > import win32gui, win32ui > def box(hdc, x, y, w, h): > hdc.MoveTo(x, y) > hdc.LineTo(x+w, y) > hdc.LineTo(x+w, y+h) > hdc.LineTo(x, h+h) > hdc.LineTo(x, y) > > hdc = win32ui.CreateDCFromHandle(win32gui.GetDesktopWindow()) > CreateDCFromHandle creates a Python wrapper from a Windows HDC handle. You're passing it a window handle, not a DC handle. Try this instead: hdc = win32ui.CreateDCFromHandle( win32gui.GetDC( 0 ) ) You can use win32gui.GetDesktopWindow() instead of the 0 if you want. They should do the exact same thing. > But when I run the code I get a win32ui: LineTo failed exception. Is there > a simple way of doing this? > This is NOT going to draw it in an erasable way. If you want to draw a flashing box that can be removed, you need to change the ROP2 to, for example, R2_NOT. That will invert the colors every time you draw it. Draw it once, you see it; draw it again, it disappears. Also note that dc.Rectangle is quicker than four LineTo calls. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Fri Jul 27 02:27:08 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 27 Jul 2007 10:27:08 +1000 Subject: [python-win32] SendMessageTimeout() ? In-Reply-To: <46A8F3BA.5080509@personnelware.com> Message-ID: <10c601c7cfe4$de9665c0$090a0a0a@enfoldsystems.local> > I am pretty sure I need to call > > SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, > (LPARAM) "Environment", SMTO_ABORTIFHUNG, > 5000, &dwReturnValue); > > And can't figure out how. import win32gui, win32con rc, dwReturnValue = win32gui.SendMessageTimeout(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, "Environment", win32con.SMTO_ABORTIFHUNG, 5000) Cheers, Mark From rbell01824 at earthlink.net Fri Jul 27 05:03:49 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Thu, 26 Jul 2007 22:03:49 -0500 Subject: [python-win32] win32ui and flashing box In-Reply-To: <46A92902.1010001@probo.com> References: <009d01c7cfcf$59630530$6701a8c0@rjbmain> <46A92902.1010001@probo.com> Message-ID: <009e01c7cffa$c213a730$6701a8c0@rjbmain> Tim, Thanks for the help. Here's what I've got import win32gui import win32ui import time gui_dc = win32gui.GetDC(0) # int handle of DC for screen pycdc = win32ui.CreateDCFromHandle(gui_dc) # PyCDC object pycdc.SetROP2(7) # R2_XOR (i think) for i in range(0,5): pycdc.Rectangle((1400, 200, 1500, 300)) # make a solid rectangle (but how to make hollow) time.sleep(.250) # hang out pycdc.Rectangle((1400, 200, 1500, 300)) # put the screen back time.sleep(.250) # hang out win32gui.ReleaseDC(gui_dc,0) # is this all I have to release? print 'done' It seems to basically work but am I releasing/deleting things appropriately (I read something online about being sure to do so)? Regards, Richard |-----Original Message----- |From: python-win32-bounces at python.org [mailto:python-win32- |bounces at python.org] On Behalf Of Tim Roberts |Sent: Thursday, July 26, 2007 6:07 PM |To: Python-Win32 List |Subject: Re: [python-win32] win32ui and flashing box | |Richard Bell wrote: |> I'm working on an application that automated IE and want to draw a |flashing |> box around screen elements. I can find the coordinates OK but am a bit |> unclear on how to actually draw a box in such a fashion that when the |> flashing stops the screen is as it was before it started. A bit of |> investigation suggests that something like this ought to work: |> |> import win32gui, win32ui |> def box(hdc, x, y, w, h): |> hdc.MoveTo(x, y) |> hdc.LineTo(x+w, y) |> hdc.LineTo(x+w, y+h) |> hdc.LineTo(x, h+h) |> hdc.LineTo(x, y) |> |> hdc = win32ui.CreateDCFromHandle(win32gui.GetDesktopWindow()) |> | |CreateDCFromHandle creates a Python wrapper from a Windows HDC handle. |You're passing it a window handle, not a DC handle. Try this instead: | | hdc = win32ui.CreateDCFromHandle( win32gui.GetDC( 0 ) ) | |You can use win32gui.GetDesktopWindow() instead of the 0 if you want. |They should do the exact same thing. | |> But when I run the code I get a win32ui: LineTo failed exception. Is |there |> a simple way of doing this? |> | |This is NOT going to draw it in an erasable way. If you want to draw a |flashing box that can be removed, you need to change the ROP2 to, for |example, R2_NOT. That will invert the colors every time you draw it. |Draw it once, you see it; draw it again, it disappears. | |Also note that dc.Rectangle is quicker than four LineTo calls. | |-- |Tim Roberts, timr at probo.com |Providenza & Boekelheide, Inc. | |_______________________________________________ |Python-win32 mailing list |Python-win32 at python.org |http://mail.python.org/mailman/listinfo/python-win32 From carl at personnelware.com Fri Jul 27 18:07:18 2007 From: carl at personnelware.com (Carl Karsten) Date: Fri, 27 Jul 2007 11:07:18 -0500 Subject: [python-win32] SendMessageTimeout() ? In-Reply-To: <10c601c7cfe4$de9665c0$090a0a0a@enfoldsystems.local> References: <10c601c7cfe4$de9665c0$090a0a0a@enfoldsystems.local> Message-ID: <46AA1836.4060509@personnelware.com> Mark Hammond wrote: >> I am pretty sure I need to call >> >> SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, >> (LPARAM) "Environment", SMTO_ABORTIFHUNG, >> 5000, &dwReturnValue); >> >> And can't figure out how. > > import win32gui, win32con > rc, dwReturnValue = win32gui.SendMessageTimeout(win32con.HWND_BROADCAST, > win32con.WM_SETTINGCHANGE, 0, "Environment", win32con.SMTO_ABORTIFHUNG, > 5000) Awesome. OT question, Should this effect the PATH in the shell that called addtopath.py? os.environ['PATH'] = os.environ['PATH'] + ';' + DirToAdd currently I have an inst.bat with lines like this: addtopath.py svn-win32-1.4.4\bin path %path%;"%ProgramFiles%\svn-win32-1.4.4\bin" Be nice to consolidate. and just in case I haven't hijacked my own thread enough: does pywin32-210.win32-py2.5.exe have any command line switches so I don't have to hit 'next next...'? Carl K From timr at probo.com Fri Jul 27 18:50:49 2007 From: timr at probo.com (Tim Roberts) Date: Fri, 27 Jul 2007 09:50:49 -0700 Subject: [python-win32] SendMessageTimeout() ? In-Reply-To: <46AA1836.4060509@personnelware.com> References: <10c601c7cfe4$de9665c0$090a0a0a@enfoldsystems.local> <46AA1836.4060509@personnelware.com> Message-ID: <46AA2269.4050400@probo.com> Carl Karsten wrote: > OT question, > Should this effect the PATH in the shell that called addtopath.py? > > os.environ['PATH'] = os.environ['PATH'] + ';' + DirToAdd > > currently I have an inst.bat with lines like this: > > addtopath.py svn-win32-1.4.4\bin > path %path%;"%ProgramFiles%\svn-win32-1.4.4\bin" > > Be nice to consolidate. > Nope. Many people find it counterintuitive, but it turns out to be very difficult to change the environment of the program that calls you. Remember that the shell's environment is part of the shell's address space, and you don't have any control over that. Your process inherits a COPY of that environment, and if you change your environment the changes will propagate to your children, but when your process exits, your changes disappear. One trick I have seen that eliminates the duplication is to have "addtopath.py" generate a batch file, so you do something like this: addtopath.py svn-win32-1.4.4\bin call makechanges.bat erase makechanges.bat Then addtopath.py can write the appropriate PATH statement to makechanges.bat. For robustness, you could add this to the top: echo pause Someone forgot to create the batch file. >makechanges.bat > and just in case I haven't hijacked my own thread enough: > does > pywin32-210.win32-py2.5.exe > have any command line switches so I don't have to hit 'next next...'? > I believe it is a standard MSI installer, and if so you should be able to use the normal switches. /q and /qn suppress the UI altogether. /qb- should display a basic UI but with no modal dialog boxes. You may need to experiment. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rbell01824 at earthlink.net Fri Jul 27 19:10:29 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Fri, 27 Jul 2007 12:10:29 -0500 Subject: [python-win32] Have IHTMLWindow2 object need corresponding IHTMLWindow3 object Message-ID: <002901c7d071$091c7410$6701a8c0@rjbmain> In an application that automates IE I'm trying to get an HTML nodes screen coordinates so I can 'flash' the node. Thanks to this list, I'm able to flash. I can also get the offsets for the node within the 'BODY' tag. Now all I need is the HWND or screen coordinates of the window holding the BODY tag. Each tag has a parentDocument property that returns a DispHTMLDocument object. The DispHTMLDocument object has a parentWindow property that returns a IHTMLWindow2 object. Unfortunately, the IHTMLWindow2 object does not offer a HWND or a screen coordinates. However the IHTMLWindow3 class DOES offer what appears to be screen coordinates, screenLeft(Retrieves the x-coordinate of the upper left-hand corner of the browser's client area, relative to the upper left-hand corner of the screen.) and screenRight. Question: How do I get from a IHTMLWindow2 to a IHTMLWindow3. A bit of looking at the interface code in 3050F1C5-98B5-11CF-BB82-00AA00BDCE0Bx0x4x0.py reveals this snip: class HTMLWindow2(CoClassBaseClass): # A CoClass CLSID = IID('{D48A6EC6-6A4A-11CF-94A7-444553540000}') coclass_sources = [ HTMLWindowEvents2, HTMLWindowEvents, ] default_source = HTMLWindowEvents coclass_interfaces = [ IHTMLWindow5, IHTMLWindow4, DispHTMLWindow2, IHTMLWindow3, IHTMLWindow2, ] default_interface = DispHTMLWindow2 This suggests that there may be a way to get from one class to the other. Question: But how? From thebrianmartin at gmail.com Fri Jul 27 20:09:59 2007 From: thebrianmartin at gmail.com (Brian Martin) Date: Fri, 27 Jul 2007 14:09:59 -0400 Subject: [python-win32] how to get select behavior for non-socket objects In-Reply-To: <0efa01c7ce46$b6b0ef70$090a0a0a@enfoldsystems.local> References: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> <0efa01c7ce46$b6b0ef70$090a0a0a@enfoldsystems.local> Message-ID: <7a1d02e10707271109r25424908x5990b21d03f877d8@mail.gmail.com> Question.. Is 'Python Programming on Win32' the only resource we have so far or are their other more recent books out? I'm looking at this win32event.WaitForMultipleObjects call and I'm kind of baffled at where to start. I've got all these native python handles to serial ports and sockets which I use in a select call in Unix-land. To go to the win32event approach I am at a loss. How do I get from these python handles to a PyHandle fit for the win32 api? Anyone know of any other resources or examples I could look at? On 7/24/07, Mark Hammond wrote: > > If you have a Windows handle (such as a handle to the serial port, a > handle to a file, or a socket), you can generally use > win32event.WaitForMultipleObjects() > > Mark > > -----Original Message----- > *From:* python-win32-bounces at python.org [mailto: > python-win32-bounces at python.org]*On Behalf Of *Brian Martin > *Sent:* Tuesday, 24 July 2007 12:14 PM > *To:* python-win32 at python.org > *Subject:* [python-win32] how to get select behavior for non-socket > objects > > Hello, I understand that the select module will only work with sockets > under windows. Is there a built-in python module for win32 that provides > some kind of multiplexing > ability for something like a serial port (via pyserial). > > thanks, > brian > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070727/bc68f8ba/attachment.html From thebrianmartin at gmail.com Fri Jul 27 21:32:16 2007 From: thebrianmartin at gmail.com (Brian Martin) Date: Fri, 27 Jul 2007 15:32:16 -0400 Subject: [python-win32] how to get select behavior for non-socket objects In-Reply-To: <7a1d02e10707271109r25424908x5990b21d03f877d8@mail.gmail.com> References: <7a1d02e10707231914y108f612gde44f415ac587b3c@mail.gmail.com> <0efa01c7ce46$b6b0ef70$090a0a0a@enfoldsystems.local> <7a1d02e10707271109r25424908x5990b21d03f877d8@mail.gmail.com> Message-ID: <7a1d02e10707271232w3e778374k94f514cc89126930@mail.gmail.com> Nevermind, I actually decided to read the above book a little more closely and I think I understand things a little more.... :) On 7/27/07, Brian Martin wrote: > > Question.. Is 'Python Programming on Win32' the only resource we have so > far or are their other more recent books out? > I'm looking at this win32event.WaitForMultipleObjects call and I'm kind of > baffled at where to start. I've got all these native python handles to > serial ports and sockets which I use in a select call in Unix-land. To go to > the win32event approach I am at a loss. How do I get from these python > handles to a PyHandle fit for the win32 api? Anyone know of any other > resources or examples I could look at? > > > > > On 7/24/07, Mark Hammond wrote: > > > > If you have a Windows handle (such as a handle to the serial port, a > > handle to a file, or a socket), you can generally use > > win32event.WaitForMultipleObjects() > > > > Mark > > > > -----Original Message----- > > *From:* python-win32-bounces at python.org [mailto: > > python-win32-bounces at python.org]*On Behalf Of *Brian Martin > > *Sent:* Tuesday, 24 July 2007 12:14 PM > > *To:* python-win32 at python.org > > *Subject:* [python-win32] how to get select behavior for non-socket > > objects > > > > Hello, I understand that the select module will only work with sockets > > under windows. Is there a built-in python module for win32 that provides > > some kind of multiplexing > > ability for something like a serial port (via pyserial). > > > > thanks, > > brian > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070727/1f5b87fb/attachment.html From rbell01824 at earthlink.net Sat Jul 28 00:41:47 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Fri, 27 Jul 2007 17:41:47 -0500 Subject: [python-win32] Have IHTMLWindow2 object need correspondingIHTMLWindow3 object and flash box In-Reply-To: <002901c7d071$091c7410$6701a8c0@rjbmain> References: <002901c7d071$091c7410$6701a8c0@rjbmain> Message-ID: <003601c7d09f$51b6a410$6701a8c0@rjbmain> By way of thanks to Tim (who helped with the flash code) and Mark (who posted the CastTo clue last year) here's a working example that: - opens a browser - navigates to google - finds the query tag - flashes it - finds the button tag - flashes it Thanks for your help. If anyone wants to use it, know that I've not tested the code extensively. The usual disclaimers about fitness definitely apply. BTW, there's an interesting bit of fuss in getting the tag's screen coordinates. It turned out to be a bit trickier than I'd expected. Regards, Richard --- code --- import win32com.client import win32gui import win32ui import pprint import time def flashTag(tag): top, left, bottom, right = cord(tag) flash(top, left, bottom, right) def cord(tag): # get the offset # see http://www.webreference.com/dhtml/diner/realpos1/ # see http://msdn2.microsoft.com/en-us/library/ms530302.aspx nL = tag.offsetLeft nT = tag.offsetTop eP = tag.offsetParent while eP: if eP.__class__.__name__ == 'IHTMLElement': eP = eP.document.all.item(eP.sourceIndex) if(eP.tagName <> 'TABLE'): # modified from ref since want on screen not BODY relative nL += eP.clientLeft nT += eP.clientTop nL += eP.offsetLeft nT += eP.offsetTop eP = eP.offsetParent # get the doc doc = tag.ownerDocument # the doc pwin = doc.parentWindow # its parent HTML style window pwin2 = win32com.client.CastTo(pwin, 'IHTMLWindow3') # the cast to get to screen... top = pwin2.screenTop + nT # screen cords for HTML style window left = pwin2.screenLeft + nL return (top, left, top+tag.offsetHeight, left+tag.offsetWidth) def flash(top, left, bottom, right): gui_dc = win32gui.GetDC(0) # int handle screen DC pycdc = win32ui.CreateDCFromHandle(gui_dc) # PyCDC object pycdc.SetROP2(7) # R2_XOR brush = win32ui.CreateBrush(0, 0, 0) # create a brush (solid, no color) pycdc.SelectObject(brush) # put it in the dc pen = win32ui.CreatePen(0, 3, 0x00ff00) # colorref is 0x00bbggrr pycdc.SelectObject(pen) # put it in the dc cord = (left, top, right, bottom) for i in range(0,5): pycdc.Rectangle(cord) # make a solid rectangle time.sleep(.250) # hang out pycdc.Rectangle(cord) # put the screen back time.sleep(.250) # hang out win32gui.ReleaseDC(gui_dc,0) # all I have to release? def DomEleToNode(element): xx = element.document.all.item(element.sourceIndex) return xx time.time() ie = win32com.client.DispatchEx('InternetExplorer.Application') ie.Visible = 1 ie.Navigate('www.google.com') time.sleep(3) queryHTML = ie.Document.all.tags('INPUT').namedItem('q') flashTag(queryHTML) btnTag = ie.Document.all.tags('INPUT').namedItem('btnG') flashTag(btnTag) --- end code --- From timr at probo.com Sat Jul 28 01:11:16 2007 From: timr at probo.com (Tim Roberts) Date: Fri, 27 Jul 2007 16:11:16 -0700 Subject: [python-win32] Have IHTMLWindow2 object need correspondingIHTMLWindow3 object and flash box In-Reply-To: <003601c7d09f$51b6a410$6701a8c0@rjbmain> References: <002901c7d071$091c7410$6701a8c0@rjbmain> <003601c7d09f$51b6a410$6701a8c0@rjbmain> Message-ID: <46AA7B94.6060909@probo.com> Richard Bell wrote: > def flash(top, left, bottom, right): > gui_dc = win32gui.GetDC(0) # int handle screen DC > pycdc = win32ui.CreateDCFromHandle(gui_dc) # PyCDC object > pycdc.SetROP2(7) # R2_XOR > brush = win32ui.CreateBrush(0, 0, 0) # create a brush (solid, > no color) > pycdc.SelectObject(brush) # put it in the dc > pen = win32ui.CreatePen(0, 3, 0x00ff00) # colorref is 0x00bbggrr > pycdc.SelectObject(pen) # put it in the dc > There's a minor performance issue issue here. You are creating a solid black brush. That means when you do the Rectangle call, the graphics driver actually has to go draw the inside with black. Now, since you specified R2_XOR, that will have no effect on the pixels (since x ^ 0 is 0), but the graphics chip will still draw it. If you use the hollow brush, as I suggested, then the driver won't even be ASKED to fill the interior. brush = win32ui.GetStockObject( 5 ) # HOLLOW_BRUSH -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Jul 28 01:36:50 2007 From: timr at probo.com (Tim Roberts) Date: Fri, 27 Jul 2007 16:36:50 -0700 Subject: [python-win32] Have IHTMLWindow2 object need correspondingIHTMLWindow3 object and flash box In-Reply-To: <46AA7B94.6060909@probo.com> References: <002901c7d071$091c7410$6701a8c0@rjbmain> <003601c7d09f$51b6a410$6701a8c0@rjbmain> <46AA7B94.6060909@probo.com> Message-ID: <46AA8192.8020409@probo.com> Tim Roberts wrote: > ... > If you use the hollow brush, as I suggested, then the driver won't even > be ASKED to fill the interior. > > brush = win32ui.GetStockObject( 5 ) # HOLLOW_BRUSH > D'oh, did I really say win32ui? That's wrong. brush = win32gui.GetStockObject( 5 ) # HOLLOW_BRUSH -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Sat Jul 28 03:23:54 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 28 Jul 2007 11:23:54 +1000 Subject: [python-win32] SendMessageTimeout() ? In-Reply-To: <46AA2269.4050400@probo.com> Message-ID: <117e01c7d0b5$f6d17a90$090a0a0a@enfoldsystems.local> Tim writes: > > and just in case I haven't hijacked my own thread enough: > > does > > pywin32-210.win32-py2.5.exe > > have any command line switches so I don't have to hit 'next > next...'? > > > > I believe it is a standard MSI installer, and if so you should be able > to use the normal switches. /q and /qn suppress the UI altogether. > /qb- should display a basic UI but with no modal dialog > boxes. You may > need to experiment. Actually, the .exe installers are not MSI at all, and sadly they do not support cmdline options. I'm playing with creating MSI packages, at least for the x64 build but the 32bit versions probably will not see .msi for a little while (I see no real advantage, and some costs, in making each build available as *both* .exe and .msi) Cheers, Mark From mhammond at skippinet.com.au Sat Jul 28 03:47:40 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 28 Jul 2007 11:47:40 +1000 Subject: [python-win32] attributes fro pywin32 exceptions Message-ID: <118201c7d0b9$48dcde30$090a0a0a@enfoldsystems.local> Hi all, I need to upgrade the pywin32 exceptions (pywintypes.api_error and pywintypes.com_error) to be real exception objects. Part of this will be giving the exceptions named attributes. pywin32-211 will have many significant changes, so that seems like the right time to make *all* such significant changes in the pipeline. Firstly, I'm leaning towards just leaving these exceptions unrelated to each other - ie, I will probably *not* introduce a "base exception" that both these exceptions derive from. This means that it will not be possible to catch both exceptions by specifying a single exception value. In my opinion, the 2 errors really aren't related closely to each other - eg, the "error number" portions of the exceptions are drawn from different sets. This is how it works today, so nothing will be lost, but I'm wondering if anyone sees a good reason that these 2 exceptions *should* have an exposed base class? Finally, I'd like some advice and opinions on the name of these attributes - specifically, the 'error number' attributes. I'm leaning towards having api_error use an attribute named 'errno'. The only downside to this is that the 'errno' values for this exception would *not* be identical to the 'errno' attribute on (say) IOError - for example, a "permission denied" error would have a api_error errno of 5 (ERROR_ACCESS_DENIED) while an IOError may have 13 (errno.EACCES). Does anyone see a real problem in using errno for this attribute even though the values are not traditional 'errno' values? The names for com_error aren't obvious to me. I'm reluctant to use 'errno' with com_error - its not a simple "error number", but a HRESULT - a subtle but real difference, without any overlap in the values. I'm leaning towards using 'hresult' here. So, I'm leaning towards: catch win32api.error, exc: n, m, f = exc being equivilent to: catch win32api.error, exc: n = exc.errno m = exc.message f = exc.functionname and: catch pythoncom.error, exc: hr, msg, exc, arg = exc being the same as: catch pythoncom.error, exc: hr = exc.hresult msg = exc.message exc = exc.excepinfo # EXCEPINFO is the name of the COM structure arg = exc.arg_error where 'exc', if not None, will have attributes 'wcode', 'source', 'description', 'helpfile', 'helpcontext' and 'scode', which are based on the names in the EXCEPINFO structure. Note that that names will be optional - you will still be able to 'unpack' exceptions just like now - the new attributes are a convenience. All comments welcome! Thanks, Mark From mc at mclaveau.com Sun Jul 29 10:31:43 2007 From: mc at mclaveau.com (Michel Claveau) Date: Sun, 29 Jul 2007 10:31:43 +0200 Subject: [python-win32] attributes fro pywin32 exceptions References: <118201c7d0b9$48dcde30$090a0a0a@enfoldsystems.local> Message-ID: <001e01c7d1ba$e6cd3980$0601a8c0@PORTABLES> Hello! > All comments welcome! CCC = Clear & Cool for a Caboodle OK, good work ; you can, now, go to holidays... if it's in France, I have some rocks (in drink), for you ;-o) @-salutations Michel Claveau From rasjidw at gmail.com Mon Jul 30 03:32:11 2007 From: rasjidw at gmail.com (Rasjid Wilcox) Date: Mon, 30 Jul 2007 11:32:11 +1000 Subject: [python-win32] Registering a Server COM to make it visible in thereference list In-Reply-To: References: <462F74CB.3060103@cenix-bioscience.com> <000f01c78acd$cc0c37b0$090a0a0a@enfoldsystems.local> Message-ID: > On 4/30/07, Mark Hammond wrote: > > That list is of the type-libraries registered in the system, and by default, > > Python has no such typelib. It is possible to manually create a typelib > > that describes your object though - google for other posts by me on this > > topic. For many years, there has been interest in upgrading win32com to > > auto-create a typelib - let me know if you are interested in helping with > > that... I am interested in helping with the auto creation of the typelib file. On 7/25/07, Rasjid Wilcox wrote: > As for helping with the auto-create idea, what kind of experience is > needed, and do we have any idea of how much work is involved? Based on my reading so far, it seems that what is required is the auto-generation of the appropriate IDL file, which can then be compiled into a TLB file using the standard Microsoft MIDL compiler. It would appear to me that the creation of the IDL file could be done entirely in Python, without a deep knowledge of C being required. Have I missed something? Is it more complex than this? My employer would be interested in getting this working as long as the amount of work involved is measured in weeks and not months, as would provide a clean way to migrate vb6 apps to Python in an incremental manner. Cheers, Rasjid. From mhammond at skippinet.com.au Mon Jul 30 04:52:53 2007 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 30 Jul 2007 12:52:53 +1000 Subject: [python-win32] Registering a Server COM to make it visible in thereference list In-Reply-To: Message-ID: <006d01c7d254$b9ecd3e0$1c0a0a0a@enfoldsystems.local> > I am interested in helping with the auto creation of the typelib file. Excellent! Sadly, google can't seem to find my earlier posts on this topic. Many years ago I posted sample code that could create a typelib from pure-python. > > On 7/25/07, Rasjid Wilcox wrote: > > As for helping with the auto-create idea, what kind of experience is > > needed, and do we have any idea of how much work is involved? > > Based on my reading so far, it seems that what is required is the > auto-generation of the appropriate IDL file, which can then be > compiled into a TLB file using the standard Microsoft MIDL compiler. > It would appear to me that the creation of the IDL file could be done > entirely in Python, without a deep knowledge of C being required. > Have I missed something? Is it more complex than this? There should be no need to create an IDL file - enough interfaces are exposed so that we can create the typelib directly. The problem I see is how to infer the intent of the Python programmer, who probably does *not* want to author the interfaces externally. In other words, the typelib should be able to be created only from information inside the .py file. class MyCOMObject: ... def Foo(self, bar): return "foo" Somehow we need to allow this to be annotated so that the programmer can say "bar must be a string, and the result must be a string". Last I thought about this, Python 'decorators' were just a gleam in someone's eye, so they may offer a solution. Ideally, we would look at tools like pyrex which may already have grown ways to annotate types of things it deals with. Another (easier) issue is to decide on the semantics for creation of the typelib - eg, do we force the programmer to nominate the typelib GUID, and any version annotations necessary? How hard do we try to stop them shooting themselves in the foot by, for example, changing method signatures without chaning the version or GUID? etc. > My employer would be interested in getting this working as long as the > amount of work involved is measured in weeks and not months, as would > provide a clean way to migrate vb6 apps to Python in an incremental > manner. That sounds great! As implied above, I don't think the major problems will be related to the actual creation of the typelib, but instead in determining what to populate it with. If the "obviously correct" answer was apparent today (along with code that could extract this info), I'd expect it could be done in a matter of days. Cheers, Mark From rbell01824 at earthlink.net Tue Jul 31 01:36:13 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Mon, 30 Jul 2007 18:36:13 -0500 Subject: [python-win32] Have IHTMLWindow2 object need correspondingIHTMLWindow3 object and flash box In-Reply-To: <46AA8192.8020409@probo.com> References: <002901c7d071$091c7410$6701a8c0@rjbmain> <003601c7d09f$51b6a410$6701a8c0@rjbmain><46AA7B94.6060909@probo.com> <46AA8192.8020409@probo.com> Message-ID: <008301c7d302$6bad8e00$6701a8c0@rjbmain> Thanks again Tim, I'll make the change. BTW, anyone looking at this code, should be warned that it only works properly in a fairly limited set of simple cases. A bit more testing showed that there are (at least) issues with: Tags that are off the browser's client area Tags in frames Tags in scrollable regions that are off the scrollable region And doubtless a very large number of others. When I'm able to sort through the mess (and it is a most unholy mess) I'll post the code. Regards, Richard |-----Original Message----- |From: python-win32-bounces at python.org [mailto:python-win32- |bounces at python.org] On Behalf Of Tim Roberts |Sent: Friday, July 27, 2007 6:37 PM |To: Python-Win32 List |Subject: Re: [python-win32] Have IHTMLWindow2 object need |correspondingIHTMLWindow3 object and flash box | |Tim Roberts wrote: |> ... |> If you use the hollow brush, as I suggested, then the driver won't even |> be ASKED to fill the interior. |> |> brush = win32ui.GetStockObject( 5 ) # HOLLOW_BRUSH |> | |D'oh, did I really say win32ui? That's wrong. | | brush = win32gui.GetStockObject( 5 ) # HOLLOW_BRUSH | |-- |Tim Roberts, timr at probo.com |Providenza & Boekelheide, Inc. | |_______________________________________________ |Python-win32 mailing list |Python-win32 at python.org |http://mail.python.org/mailman/listinfo/python-win32 From rbell01824 at earthlink.net Tue Jul 31 14:50:41 2007 From: rbell01824 at earthlink.net (Richard Bell) Date: Tue, 31 Jul 2007 07:50:41 -0500 Subject: [python-win32] Have IHTMLWindow2 objectneed correspondingIHTMLWindow3 object and flash box In-Reply-To: <008301c7d302$6bad8e00$6701a8c0@rjbmain> References: <002901c7d071$091c7410$6701a8c0@rjbmain> <003601c7d09f$51b6a410$6701a8c0@rjbmain><46AA7B94.6060909@probo.com><46AA8192.8020409@probo.com> <008301c7d302$6bad8e00$6701a8c0@rjbmain> Message-ID: <003901c7d371$68003e00$6701a8c0@rjbmain> Tim, Did you really mean: brush = win32ui.CreateBrush(1, 0, 0) # create a brush (hollow, no color) since the win32gui brush will not select into the device context? Which brings me to the real question: What's the difference between win32ui and win32gui anyway and what's the best online reference for them? Regards, Richard BTW, here's the code as it now stands. --- code --- def flash( left, top, width, height ): """ put a flashing box at cordinates """ gui_dc = win32gui.GetDC(0) # int handle of DC for screen pycdc = win32ui.CreateDCFromHandle(gui_dc) # PyCDC object pycdc.SetROP2(7) # R2_XOR brush = win32ui.CreateBrush(1, 0, 0) # create a brush (hollow, no color) pycdc.SelectObject(brush) # put it in the dc pen = win32ui.CreatePen(0, 3, 0x00ff00) # create a pen (solid, 3 pels wide, color) # colorref is 0x00bbggrr pycdc.SelectObject(pen) # put it in the dc adj = 0 # or 4 cord = (left, top, left+width+adj, top + height+adj) # +1 for the way windows draws rect # +3 for pen width for i in range(0,5): # 5 flashes pycdc.Rectangle(cord) # make a solid rectangle time.sleep(.250) # hang out pycdc.Rectangle(cord) # put the screen back time.sleep(.250) # hang out win32gui.ReleaseDC(gui_dc,0) # is this all I have to release? --- end code --- | |Thanks again Tim, I'll make the change. | ||Tim Roberts wrote: ||> ... ||> If you use the hollow brush, as I suggested, then the driver won't even ||> be ASKED to fill the interior. ||> ||> brush = win32ui.GetStockObject( 5 ) # HOLLOW_BRUSH ||> || ||D'oh, did I really say win32ui? That's wrong. || || brush = win32gui.GetStockObject( 5 ) # HOLLOW_BRUSH || ||-- ||Tim Roberts, timr at probo.com ||Providenza & Boekelheide, Inc. From timr at probo.com Tue Jul 31 19:22:03 2007 From: timr at probo.com (Tim Roberts) Date: Tue, 31 Jul 2007 10:22:03 -0700 Subject: [python-win32] Have IHTMLWindow2 objectneed correspondingIHTMLWindow3 object and flash box In-Reply-To: <003901c7d371$68003e00$6701a8c0@rjbmain> References: <002901c7d071$091c7410$6701a8c0@rjbmain> <003601c7d09f$51b6a410$6701a8c0@rjbmain><46AA7B94.6060909@probo.com><46AA8192.8020409@probo.com> <008301c7d302$6bad8e00$6701a8c0@rjbmain> <003901c7d371$68003e00$6701a8c0@rjbmain> Message-ID: <46AF6FBB.5090405@probo.com> Richard Bell wrote: > Tim, > > Did you really mean: > > brush = win32ui.CreateBrush(1, 0, 0) # create a brush (hollow, no color) > > since the win32gui brush will not select into the device context? > Perhaps the win32gui brush needs to be wrapped or unwrapped in some way. I'll have to check that out. I don't know whether it is a raw handle or a Python-wrapped handle object. In any case, it should produce the same results as what you have, except that you need to remember to delete the one you created. > Which brings me to the real question: > > What's the difference between win32ui and win32gui anyway and what's the > best online reference for them? > As I understand it, win32gui exposes the raw GDI APIs and deals with raw GDI handles as plain integers. win32ui is an attempt to wrap the raw GDI interfaces with Pythonic wrapper objects. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Brad.Johnson at ballardtech.com Tue Jul 31 18:25:28 2007 From: Brad.Johnson at ballardtech.com (Brad Johnson) Date: Tue, 31 Jul 2007 16:25:28 +0000 (UTC) Subject: [python-win32] Utilizing a raw IDispatch Pointer from Python Message-ID: I have a C++ application that creates a collection of COM objects. I am embedding a Python interpreter that will have access to Automation objects written in C++. I would like to give the Python interpreter access to the IDispatch interface on these objects. Stated another way, how can I have Python consume a IDispatch pointer from C++ and wrap it with one of those nice Python classes (IPyDispatch?) automatically? Thanks in advance. From len200612 at revolutioncontrols.com Wed Jul 25 16:55:53 2007 From: len200612 at revolutioncontrols.com (Len Remmerswaal) Date: Wed, 25 Jul 2007 16:55:53 +0200 Subject: [python-win32] win32com does not recognise an Interface for events Message-ID: <46A76479.6020102@revolutioncontrols.com> Hi, I am trying to apply the Siemens S7ProSim Automation object using Python. However, after running makepy my test script fails. I have done some digging into DispatchWithEvents, makepy and MSDN. It turns out that the event interface seems not to be included in the result file from makepy, while the vtable for the same is. This causes calls to DispatchWithEvents to fail. I ran the MS ITypelib viewer over the dll, and also makepy. Here are the results. For reference, from the OLE Viewer (some details left out): -------------------------------------------- // typelib filename: s7wspsmx.dll [ uuid(83CC0D80-FEDA-11D1-BE76-0060B06816CF), version(1.0), helpstring("Siemens S7ProSim COM Object") ] library S7PROSIMLib { // Forward declare all types defined in this typelib interface IS7ProSimEvents; interface IS7ProSim; [ odl, uuid(83CC0D82-FEDA-11D1-BE76-0060B06816CF), helpstring("Event interface for S7ProSim COM Object"), oleautomation ] interface IS7ProSimEvents : IUnknown { [helpstring("Fired when single scan is done.")] HRESULT _stdcall ScanFinished(VARIANT ScanInfo); [helpstring("Fired when unable to connect to Control Engine.")] HRESULT _stdcall ConnectionError( BSTR ControlEngine, long Error); [helpstring("Fired when a new PLC switch state is detected.")] HRESULT _stdcall PLCSimStateChanged(BSTR NewState); [helpstring("Fired when a Pause/Continue state change is detected.")] HRESULT _stdcall PauseStateChanged(BSTR NewState); [helpstring("Fired when a ScanMode change is detected.")] HRESULT _stdcall ScanModeChanged(BSTR NewState); }; [ uuid(83CC0D83-FEDA-11D1-BE76-0060B06816CF), helpstring("S7ProSim Class") ] coclass S7ProSim { [default] interface IS7ProSim; [default, source] interface IS7ProSimEvents; }; [ odl, uuid(83CC0D81-FEDA-11D1-BE76-0060B06816CF), helpstring("IS7ProSim Interface for S7ProSim COM Object"), dual, oleautomation ] interface IS7ProSim : IDispatch { (.... dispatchable functions ....) }; (.... constant declarations ....) }; For reference, from '83CC0D80-FEDA-11D1-BE76-0060B06816CFx0x1x0.py' (some details left out): ------------------------------------------------------------------------------ # -*- coding: mbcs -*- # Created by makepy.py version 0.4.95 # By python version 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] # From type library 's7wspsmx.dll' # On Wed Jul 18 17:55:20 2007 """Siemens S7ProSim COM Object""" makepy_version = '0.4.95' python_version = 0x20400f0 (....) CLSID = IID('{83CC0D80-FEDA-11D1-BE76-0060B06816CF}') MajorVersion = 1 MinorVersion = 0 LibraryFlags = 8 LCID = 0x0 class constants: (....) from win32com.client import DispatchBaseClass class IS7ProSim(DispatchBaseClass): """IS7ProSim Interface for S7ProSim COM Object""" CLSID = IID('{83CC0D81-FEDA-11D1-BE76-0060B06816CF}') coclass_clsid = IID('{83CC0D83-FEDA-11D1-BE76-0060B06816CF}') (.... dispatchable functions ....) from win32com.client import CoClassBaseClass # This CoClass is known by the name 'S7wspsmx.S7ProSim.1' class S7ProSim(CoClassBaseClass): # A CoClass # S7ProSim Class CLSID = IID('{83CC0D83-FEDA-11D1-BE76-0060B06816CF}') coclass_sources = [ ] coclass_interfaces = [ IS7ProSim, ] default_interface = IS7ProSim IS7ProSim_vtables_dispatch_ = 1 IS7ProSim_vtables_ = [ (.... dispatchable funtions table entries ....) ] IS7ProSimEvents_vtables_dispatch_ = 0 IS7ProSimEvents_vtables_ = [ (( 'ScanFinished' , 'ScanInfo' , ), 1, (1, (), [ (12, 0, None, None) , ], 1 , 1 , 4 , 0 , 12 , (3, 0, None, None) , 0 , )), (( 'ConnectionError' , 'ControlEngine' , 'Error' , ), 2, (2, (), [ (8, 0, None, None) , (3, 0, None, None) , ], 1 , 1 , 4 , 0 , 16 , (3, 0, None, None) , 0 , )), (( 'PLCSimStateChanged' , 'NewState' , ), 3, (3, (), [ (8, 0, None, None) , ], 1 , 1 , 4 , 0 , 20 , (3, 0, None, None) , 0 , )), (( 'PauseStateChanged' , 'NewState' , ), 4, (4, (), [ (8, 0, None, None) , ], 1 , 1 , 4 , 0 , 24 , (3, 0, None, None) , 0 , )), (( 'ScanModeChanged' , 'NewState' , ), 5, (5, (), [ (8, 0, None, None) , ], 1 , 1 , 4 , 0 , 28 , (3, 0, None, None) , 0 , )), ] RecordMap = { } CLSIDToClassMap = { '{83CC0D81-FEDA-11D1-BE76-0060B06816CF}' : IS7ProSim, '{83CC0D83-FEDA-11D1-BE76-0060B06816CF}' : S7ProSim, } CLSIDToPackageMap = {} win32com.client.CLSIDToClass.RegisterCLSIDsFromDict( CLSIDToClassMap ) VTablesToPackageMap = {} VTablesToClassMap = { '{83CC0D81-FEDA-11D1-BE76-0060B06816CF}' : 'IS7ProSim', '{83CC0D82-FEDA-11D1-BE76-0060B06816CF}' : 'IS7ProSimEvents', } NamesToIIDMap = { 'IS7ProSimEvents' : '{83CC0D82-FEDA-11D1-BE76-0060B06816CF}', 'IS7ProSim' : '{83CC0D81-FEDA-11D1-BE76-0060B06816CF}', } win32com.client.constants.__dicts__.append(constants.__dict__) ----------end of listings --------------------------------------------------------------- Note the differences between these listings in the definition of CoClass IS7ProSim, repeated here for convenience: Ole Viewer: [ uuid(83CC0D83-FEDA-11D1-BE76-0060B06816CF), helpstring("S7ProSim Class") ] coclass S7ProSim { [default] interface IS7ProSim; [default, source] interface IS7ProSimEvents; }; makepy class S7ProSim(CoClassBaseClass): # A CoClass # S7ProSim Class CLSID = IID('{83CC0D83-FEDA-11D1-BE76-0060B06816CF}') coclass_sources = [ ] coclass_interfaces = [ IS7ProSim, ] default_interface = IS7ProSim OLE Viewer finds a second interface IS7ProSimEvents that is made the default source makepy does not recognise IS7ProSimEvents as an interface at all. Running my (test) script yields this: ---------------------- import win32com.client as w32c sS7PROSIM = 'S7wspsmx.S7ProSim.1' class testCalls: (.... class definition with event functions ....) obj = w32c.DispatchWithEvents(sS7PROSIM, testCalls) Result: File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 263, in DispatchWithEvents raise ValueError, "This COM object does not support events." ValueError: This COM object does not support events. In file "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 261-263: events_class = getevents(clsid) if events_class is None: raise ValueError, "This COM object does not support events." get_events(clsid) seems to return None. The clsid given to getevents is "IID('{83CC0D81-FEDA-11D1-BE76-0060B06816CF}')" This is the clsid for the IS7ProSim, derived from IDispatch. In file "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 323-376: def getevents(clsid): (....) # find clsid given progid or clsid clsid=str(pywintypes.IID(clsid)) # return default outgoing interface for that class klass = gencache.GetClassForCLSID(clsid) try: return klass.default_source except AttributeError: # See if we have a coclass for the interfaces. try: return gencache.GetClassForCLSID(klass.coclass_clsid).default_source except AttributeError: return None gencache.GetClassForCLSID(clsid) returns the class with docstring """IS7ProSim Interface for S7ProSim COM Object""" This is correct. This class has no sources, as can be seen in the OLE Viewer output, and the AttributError is thrown. OK. klass.coclass_clsid is '{83CC0D83-FEDA-11D1-BE76-0060B06816CF}'. OK. gencache.GetClassForCLSID(klass.coclass_clsid) returns a class with the following properties: base class : CoClassBaseClass coclass_interface : [] coclass_sources : [] clsid : {83CC0D83-FEDA-11D1-BE76-0060B06816CF} There is no attribute default_source, so the AttributeError is thrown again. This is correct with respect to the makepy output, but not with repsect to the actual OLE object. IMHO the makepy output should have included IS7PrSomEvents as an interface and declared it as default_source within CoClass S7SimPro. Right? So how come it does not? Tracking the makepy actions: ---------------------------- A convenient break point location is makepy.py line 263: gen.generate(....) Walking on till genpy.py line 737 self.CollectOleItemInfosFromType() returned a (correct) list of all OleItem information headers: infotype doc[0] doc[1] TKIND_INTERFACE, 'IS7ProSimEvents', 'Event interface for S7ProSim COM Object' TKIND_COCLASS, 'S7ProSim', 'S7ProSim Class' TKIND_DISPATCH, 'IS7ProSim', 'IS7ProSim Interface for S7ProSim COM Object' a number of (infotype 0 and 6) entries for the constant enumerations This list is run through to colelct and build all oleItems, enumItems, recordItems and vtableItems pass 0: TKIND_INTERFACE, 'IS7ProSimEvents', 'Event interface for S7ProSim COM Object' oleItem, vtableItem = self._Build_Interface(type_info_tuple) returns (None, ) returns (None, ). This will lead to the exclusion of this interface later on. So how does this happen? In self._Build_Interface: oleItem = vtableItem = None if infotype == pythoncom.TKIND_DISPATCH or \ (infotype == pythoncom.TKIND_INTERFACE and attr[11] & pythoncom.TYPEFLAG_FDISPATCHABLE): oleItem = DispatchItem(info, attr, doc) Well, infotype == TKIND_INTERFACE, and attr[11] (wTypeFlags) == 256 (TYPEFLAG_FOLEAUTOMATION). This seems to be a good reason to ignore the interface: oleItem remains None, BTW: a simple DisPatch call (i.o. DispatchWithEvents) works fine, except for ignoring the events of course. Did I stumble on a bug here or am I completely missing a point? Please help out. Thanks, Len Remmerswaal From meledictas at gmail.com Tue Jul 31 11:16:11 2007 From: meledictas at gmail.com (Chatchai Neanudorn) Date: Tue, 31 Jul 2007 16:16:11 +0700 Subject: [python-win32] One than services with perfmon. Message-ID: <6f10a16a0707310216u1623de8dn9c0f7d0b1c1377be@mail.gmail.com> Hi, I have two python services running in a machine. Each service need to has a perfmon. But when I start both service, only a lastest started service has counter in perfmon???. An additional *serious* thing is, When we have two services with two owner, only one service can start, the rest can't with access dined error. Chatchai -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070731/4b0cf513/attachment.htm From Yogirlie at aol.com Tue Jul 10 20:01:18 2007 From: Yogirlie at aol.com (Yogirlie at aol.com) Date: Tue, 10 Jul 2007 18:01:18 -0000 Subject: [python-win32] Re: how to load 2 python COM DLLs in single app? Message-ID: Hi - is there a way that I can easily fix a problem: pythondll load library will not load when i start up my computer. thanks ************************************** See what's free at http://www.aol.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20070710/8eb547df/attachment.html From bobklahn at comcast.net Wed Jul 18 12:33:25 2007 From: bobklahn at comcast.net (Bob Klahn) Date: Wed, 18 Jul 2007 10:33:25 -0000 Subject: [python-win32] dde server creation error : [Errno 22] invalid argument Message-ID: <20070718103325.46E931E400F@bag.python.org> I've written a Python program that uses DDE. The program runs quite nicely on my XP SP2 PC. I'm using Python 2.5.1. But when a friend of mine tries to run it, he gets the subject error on the server.Create line: server = dde.CreateServer() server.Create("CC_DDE") My friend also has XP SP2, and is using Python 2.5 ; I've asked him to upgrade to Python 2.5.1. What are possible causes of this problem? BTW, what's the purpose of the Create() argument? My friend gets the invalid-argument no matter what literal he puts there; I can use the same arguments he's tried without a problem. Googling this, I also found that Create() can take a second argument, an integer, but I don't know what that does. If these arguments are documented somewhere on the Web, please clue me in. Bob From thekit at gmail.com Mon Jul 23 09:59:02 2007 From: thekit at gmail.com (Thibault Ketterer) Date: Mon, 23 Jul 2007 07:59:02 -0000 Subject: [python-win32] Getting file security access info on network Message-ID: it works for me with this code import win32security,pywintypes try: filo = win32security.GetFileSecurity(path, win32security.OWNER_SECURITY_INFORMATION) sid = filo.GetSecurityDescriptorOwner() account, domain, typecode = win32security.LookupAccountSid(None, sid) except pywintypes.error,details: account = domain = "" errcode = details[0] print "error acces:", path print domain + u'\\' + account -- Thibault ketterer