From skippy.hammond at gmail.com Sun Apr 1 04:09:17 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sun, 01 Apr 2012 12:09:17 +1000 Subject: [python-win32] wait for new clipboard data? In-Reply-To: <4F771E44.8020701@gmail.com> References: <4F771E44.8020701@gmail.com> Message-ID: <4F77B8CD.4060104@gmail.com> I think there is a clipboard watcher concept, but pywin32 doesn't expose it. One option might be to simply poll win32clipboard.GetClipboardSequenceNumber() - but the docs list some caveats which might mean it doesn't work in all cases (specifically in delayed rendering) Cheers, Mark On 1/04/2012 2:09 AM, reckoner wrote: > I'm doing some automation using Python and I'm looking for something > similar to Autohotkey's Clipwait function. > > see here: http://www.autohotkey.com/docs/commands/ClipWait.htm > > This basically waits for new clipboard data after a previous copy > operation (like ctrl+c). > > Thanks! > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From eric.maggard at hp.com Sun Apr 1 18:04:34 2012 From: eric.maggard at hp.com (Maggard, Eric) Date: Sun, 1 Apr 2012 16:04:34 +0000 Subject: [python-win32] [pywin32 extensions] Traceback error on running startup script Message-ID: Hi, I am working on a Win7 machine (64-bit), but would like to embed pywin into a 32-bit MFC app. I downloaded the 217 build for python 3.2 and then downloaded the python-3.2.2.msi install package. I installed python and then installed the pywin32 extensions. I also downloaded the source files pywin32-217.zip and successfully built the pythonwin application. I made sure I downloaded the 32 bit versions to match my application I am embedding into. I followed the embedding guild: http://tgolden.sc.sabren.com/pywin32-docs/html/pythonwin/doc/EmbeddingWin32ui.html and then also looked at your pythonwin application files. When I start mu application, I am getting a traceback error when the function Win32uiHostGlue::DynamicApplicationInit is executing the following line: rc = (*pfnWin32uiInit)(this, (TCHAR *)cmd, (TCHAR *)additionalPaths); The error that it is showing is: tuple: ('invalid syntax', ('', 1, 1, '??????????????????????\x0f\n')) I have tried to pass a CString, string, CString.GetString(), and string.c_str() and the traceback error changes slightly, but I always get the error. I am thinking python is not parsing the command string correctly. I copied the pythonwin directly under the build directory I did to my application directory. I traced the steps leading up to that line and it seems python is getting initialized correctly. I can start the pythonwin application that is included under the build directory... so, I know it should be working. Here is the initialization I am using: CString startup = "import pywin.framework.startup"; // Check for theGlue Initialization if (!theGlue.DynamicApplicationInit(startup)) { AfxMessageBox("Could not attach to the Python win32ui extensions."); // return FALSE; } else AfxMessageBox("Python initialized"); If I can't get this working, then I am thinking about removing the 3.2 version and trying the 3.1 or the 2.7 versions. Thanks for your help, Eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Mon Apr 2 02:06:23 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 02 Apr 2012 10:06:23 +1000 Subject: [python-win32] [pywin32 extensions] Traceback error on running startup script In-Reply-To: References: Message-ID: <4F78ED7F.2040808@gmail.com> Are you building your code as a unicode application? In Python 3.3, the "TCHAR" will actually be unicode. If you do roll back to python 2.x, it will be a regular "char *". Mark On 2/04/2012 2:04 AM, Maggard, Eric wrote: > Hi, > > I am working on a Win7 machine (64-bit), but would like to embed pywin > into a 32-bit MFC app. I downloaded the 217 build for python 3.2 and > then downloaded the python-3.2.2.msi install package. I installed > python and then installed the pywin32 extensions. I also downloaded the > source files pywin32-217.zip and successfully built the pythonwin > application. I made sure I downloaded the 32 bit versions to match my > application I am embedding into. > > I followed the embedding guild: > http://tgolden.sc.sabren.com/pywin32-docs/html/pythonwin/doc/EmbeddingWin32ui.html > and then also looked at your pythonwin application files. > > When I start mu application, I am getting a traceback error when the > function Win32uiHostGlue::DynamicApplicationInit is executing the > following line: > > rc = (*pfnWin32uiInit)(this, (TCHAR *)cmd, (TCHAR *)additionalPaths); > > The error that it is showing is: > > tuple: ('invalid syntax', ('', 1, 1, > '??????????????????????\x0f\n')) > > I have tried to pass a CString, string, CString.GetString(), and > string.c_str() and the traceback error changes slightly, but I always > get the error. I am thinking python is not parsing the command string > correctly. > > I copied the pythonwin directly under the build directory I did to my > application directory. I traced the steps leading up to that line and > it seems python is getting initialized correctly. I can start the > pythonwin application that is included under the build directory? so, I > know it should be working. > > Here is the initialization I am using: > > CString startup = "import pywin.framework.startup"; > > // Check for theGlue Initialization > > if (!theGlue.DynamicApplicationInit(startup)) { > > AfxMessageBox("Could not attach to the Python win32ui > extensions."); > > // return FALSE; > > } > > else > > AfxMessageBox("Python initialized"); > > If I can?t get this working, then I am thinking about removing the 3.2 > version and trying the 3.1 or the 2.7 versions. > > Thanks for your help, > > Eric > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From eric.maggard at hp.com Mon Apr 2 16:47:22 2012 From: eric.maggard at hp.com (Maggard, Eric) Date: Mon, 2 Apr 2012 14:47:22 +0000 Subject: [python-win32] [pywin32 extensions] Traceback error on running startup script In-Reply-To: <4F78ED7F.2040808@gmail.com> References: <4F78ED7F.2040808@gmail.com> Message-ID: Hi Mark, Thanks for the message. Nope, I am not using Unicode, so I guess that is where the problem is. I did get 2.7 running and initializing, but I am having a problem getting the interactive window to show, open a script, or create new script. I tried to run the startup.py and intpyapp.py scripts, but neither did anything that I could see. Then I setup this script to try to start an interactive session: import sys import win32ui # First step - redirect python output to the debugging device, until we # can create a window to capture it. # Note that this is only useful while debugging, and simply sends any # Python output (ie, exceptions while developing the startup code) is # printed to the MSVC debugger. Note that since this code was written, # the win32trace module has appeared, giving another alternative to # debugging this code. class DebugOutput: softspace=1 def write(self,message): win32ui.OutputDebug(message) sys.stderr=sys.stdout=DebugOutput() # One of your first priorities should be to set sys.stdout to somewhere useful, # depending on what useful means to your application. This code simply creates # the Pythonwin Interactive Window, which handles this automatically. # Now here is the code that does the real work. import win32con from pywin.framework import intpyapp, app, interact class SpecApp(intpyapp.InteractivePythonApp): def InitInstance(self): # Call the base class (if you want) intpyapp.InteractivePythonApp.InitInstance(self) # Do domething useful, specific to your app. # Here, we minimise the interactive window. # (after painting the main frame) win32ui.PumpWaitingMessages() interact.edit.currentView.GetParent().ShowWindow(win32con.SW_MINIMIZE) app = SpecApp() It didn't start an interactive session in my application. I looked in the intpyapp.py script and I tried to setup menu items to do call the ID_FILE_IMPORT, ID_FILE_RUN, and ID_VIEW_INTERACTIVE. But even running the intpyapp.py script, the menu items in my app or greyed out. Do I need to setup handlers under my app to process these? I didn't think I would need to, since I thought the pywin would process the calls first. How can I check that pywin is actually getting initialized and running? Thanks, Eric -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: Sunday, April 01, 2012 6:06 PM To: Maggard, Eric Cc: python-win32 at python.org Subject: Re: [python-win32] [pywin32 extensions] Traceback error on running startup script Are you building your code as a unicode application? In Python 3.3, the "TCHAR" will actually be unicode. If you do roll back to python 2.x, it will be a regular "char *". Mark On 2/04/2012 2:04 AM, Maggard, Eric wrote: > Hi, > > I am working on a Win7 machine (64-bit), but would like to embed pywin > into a 32-bit MFC app. I downloaded the 217 build for python 3.2 and > then downloaded the python-3.2.2.msi install package. I installed > python and then installed the pywin32 extensions. I also downloaded the > source files pywin32-217.zip and successfully built the pythonwin > application. I made sure I downloaded the 32 bit versions to match my > application I am embedding into. > > I followed the embedding guild: > http://tgolden.sc.sabren.com/pywin32-docs/html/pythonwin/doc/EmbeddingWin32ui.html > and then also looked at your pythonwin application files. > > When I start mu application, I am getting a traceback error when the > function Win32uiHostGlue::DynamicApplicationInit is executing the > following line: > > rc = (*pfnWin32uiInit)(this, (TCHAR *)cmd, (TCHAR *)additionalPaths); > > The error that it is showing is: > > tuple: ('invalid syntax', ('', 1, 1, > '??????????????????????\x0f\n')) > > I have tried to pass a CString, string, CString.GetString(), and > string.c_str() and the traceback error changes slightly, but I always > get the error. I am thinking python is not parsing the command string > correctly. > > I copied the pythonwin directly under the build directory I did to my > application directory. I traced the steps leading up to that line and > it seems python is getting initialized correctly. I can start the > pythonwin application that is included under the build directory... so, I > know it should be working. > > Here is the initialization I am using: > > CString startup = "import pywin.framework.startup"; > > // Check for theGlue Initialization > > if (!theGlue.DynamicApplicationInit(startup)) { > > AfxMessageBox("Could not attach to the Python win32ui > extensions."); > > // return FALSE; > > } > > else > > AfxMessageBox("Python initialized"); > > If I can't get this working, then I am thinking about removing the 3.2 > version and trying the 3.1 or the 2.7 versions. > > Thanks for your help, > > Eric > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From davidm at pulsonix.com Mon Apr 2 17:09:28 2012 From: davidm at pulsonix.com (David Manns) Date: Mon, 2 Apr 2012 16:09:28 +0100 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception Message-ID: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> We have a scripting engine interface in our application. This works fine for loading/calling VBscript and Javascript scripting engines, but PythonScript fails. Specifically, it fails at : m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM) where m_pAxsScript is the IActiveScript interface acquired through CoCreateInstance. The hresult returned is: 80004005 which to my mind implies some kind of 'access denied' error. We are using Python 2.7.2 and Pywin32 2.7 on a Windows 7 32-bit system. We have this problem here on a test machine that was set up to match that in use at one of our customers who is now stuck being unable to run any of his Python scripts. Any clues or suggestions would be gratefully received. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Apr 2 18:51:26 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 2 Apr 2012 09:51:26 -0700 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> Message-ID: <4F79D90E.8000503@probo.com> David Manns wrote: > > We have a scripting engine interface in our application. This works > fine for loading/calling VBscript and Javascript scripting engines, > but PythonScript fails. Specifically, it fails at : > > m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM) > > where m_pAxsScript is the IActiveScript interface acquired through > CoCreateInstance. The hresult returned is: > > 80004005 > > which to my mind implies some kind of 'access denied' error. > Have you enabled Python as an Active Scripting engine? It's not enabled by default, because there are security issues that couldn't be completely eliminated without disabling parts of the interpreter. See win32comext\axscript\client\pyscript.py. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skippy.hammond at gmail.com Tue Apr 3 07:04:48 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 03 Apr 2012 15:04:48 +1000 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <4F79D90E.8000503@probo.com> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> <4F79D90E.8000503@probo.com> Message-ID: <4F7A84F0.1060701@gmail.com> On 3/04/2012 2:51 AM, Tim Roberts wrote: > David Manns wrote: >> >> We have a scripting engine interface in our application. This works >> fine for loading/calling VBscript and Javascript scripting engines, >> but PythonScript fails. Specifically, it fails at : >> >> m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM) >> >> where m_pAxsScript is the IActiveScript interface acquired through >> CoCreateInstance. The hresult returned is: >> >> 80004005 >> >> which to my mind implies some kind of 'access denied' error. >> > > Have you enabled Python as an Active Scripting engine? It's not enabled > by default, because there are security issues that couldn't be > completely eliminated without disabling parts of the interpreter. See > win32comext\axscript\client\pyscript.py. Actually, it should be enabled by default - it is just that we don't support any of the "safety options" of the active script interfaces. Thus, the end result is that the engine is available in contexts like Windows Scripting Host or ASP, but not in IE. Mark From skippy.hammond at gmail.com Tue Apr 3 07:11:28 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 03 Apr 2012 15:11:28 +1000 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> Message-ID: <4F7A8680.7030409@gmail.com> On 3/04/2012 1:09 AM, David Manns wrote: > We have a scripting engine interface in our application. This works fine > for loading/calling VBscript and Javascript scripting engines, but > PythonScript fails. Specifically, it fails at : > > m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM) > > where m_pAxsScript is the IActiveScript interface acquired through > CoCreateInstance. The hresult returned is: > > 80004005 > > which to my mind implies some kind of 'access denied' error. We are > using Python 2.7.2 and Pywin32 2.7 on a Windows 7 32-bit system. We have > this problem here on a test machine that was set up to match that in use > at one of our customers who is now stuck being unable to run any of his > Python scripts. > > Any clues or suggestions would be gratefully received. > > David I'd suggest you: * Execute "python win32comext\axscript\client\pyscript.py -debug" - this will re-register the engine for debugging. * Execute "python -m win32traceutil" - this will start a process which is capturing messages from the COM object now it is in debug mode. * Attempt to create and use the engine - this should cause output to be generated. Given the error is E_FAIL and the pyscript engine doesn't specifically throw that, I suspect you will see a traceback. Another alternative is to use the IErrorInfo interfaces (I think that is what they are called) to try and grab more information at runtime. Mark From davidm at pulsonix.com Wed Apr 4 10:02:11 2012 From: davidm at pulsonix.com (David Manns) Date: Wed, 4 Apr 2012 09:02:11 +0100 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <4F7A8680.7030409@gmail.com> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> <4F7A8680.7030409@gmail.com> Message-ID: <0b6b01cd1239$3d4154e0$b7c3fea0$@pulsonix.com> Mark, Tried doing that, but nothing comes out on the debug trace at all. Do I have to uncomment or add any trace commands in any of the .py files, or should I expect to see things appear on the console already? Best regards, David -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: 03 April 2012 06:11 To: David Manns Cc: python-win32 at python.org Subject: Re: [python-win32] IActiveScript::AddNamedItem fails with exception On 3/04/2012 1:09 AM, David Manns wrote: > We have a scripting engine interface in our application. This works > fine for loading/calling VBscript and Javascript scripting engines, > but PythonScript fails. Specifically, it fails at : > > m_pAxsScript->AddNamedItem("application", SCRIPTITEM_NAMEDITEM) > > where m_pAxsScript is the IActiveScript interface acquired through > CoCreateInstance. The hresult returned is: > > 80004005 > > which to my mind implies some kind of 'access denied' error. We are > using Python 2.7.2 and Pywin32 2.7 on a Windows 7 32-bit system. We > have this problem here on a test machine that was set up to match that > in use at one of our customers who is now stuck being unable to run > any of his Python scripts. > > Any clues or suggestions would be gratefully received. > > David I'd suggest you: * Execute "python win32comext\axscript\client\pyscript.py -debug" - this will re-register the engine for debugging. * Execute "python -m win32traceutil" - this will start a process which is capturing messages from the COM object now it is in debug mode. * Attempt to create and use the engine - this should cause output to be generated. Given the error is E_FAIL and the pyscript engine doesn't specifically throw that, I suspect you will see a traceback. Another alternative is to use the IErrorInfo interfaces (I think that is what they are called) to try and grab more information at runtime. Mark From mhammond at skippinet.com.au Wed Apr 4 10:52:50 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 04 Apr 2012 18:52:50 +1000 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <0b6b01cd1239$3d4154e0$b7c3fea0$@pulsonix.com> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> <4F7A8680.7030409@gmail.com> <0b6b01cd1239$3d4154e0$b7c3fea0$@pulsonix.com> Message-ID: <4F7C0BE2.1040204@skippinet.com.au> On 4/04/2012 6:02 PM, David Manns wrote: > Mark, > > Tried doing that, but nothing comes out on the debug trace at all. Do I have > to uncomment or add any trace commands in any of the .py files, or should I > expect to see things appear on the console already? Ack - sorry about that: > * Execute "python win32comext\axscript\client\pyscript.py -debug" - this > will re-register the engine for debugging. Should say "--debug" and the message it prints should say "for debugging". Mark From davidm at pulsonix.com Wed Apr 4 12:20:13 2012 From: davidm at pulsonix.com (David Manns) Date: Wed, 4 Apr 2012 11:20:13 +0100 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <4F7C0BE2.1040204@skippinet.com.au> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> <4F7A8680.7030409@gmail.com> <0b6b01cd1239$3d4154e0$b7c3fea0$@pulsonix.com> <4F7C0BE2.1040204@skippinet.com.au> Message-ID: <0bf301cd124c$85fae800$91f0b800$@pulsonix.com> Mark, Thanks, that's better! Now I get this trace output: Collecting Python Trace Output... Object with win32trace dispatcher created (object=None) in ._InvokeEx_-SetScriptSite(,) [1,0,None] Debugging interfaces not available - debugging is disabled.. in ._InvokeEx_-InitNew() [1,0,None] in ._InvokeEx_-AddNamedItem(u'application', 14) [1,0,None] **************** ASSERTION FAILED ******************* The typeKind of the object is unexpected in ._InvokeEx_-Close() [1,0,None] Hopefully that means more to you than it does to me! Best regards, David -----Original Message----- From: Mark Hammond [mailto:mhammond at skippinet.com.au] Sent: 04 April 2012 09:53 To: David Manns Cc: python-win32 at python.org Subject: Re: [python-win32] IActiveScript::AddNamedItem fails with exception On 4/04/2012 6:02 PM, David Manns wrote: > Mark, > > Tried doing that, but nothing comes out on the debug trace at all. Do > I have to uncomment or add any trace commands in any of the .py files, > or should I expect to see things appear on the console already? Ack - sorry about that: > * Execute "python win32comext\axscript\client\pyscript.py -debug" - > this will re-register the engine for debugging. Should say "--debug" and the message it prints should say "for debugging". Mark From mhammond at skippinet.com.au Thu Apr 5 01:16:47 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 05 Apr 2012 09:16:47 +1000 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <0bf301cd124c$85fae800$91f0b800$@pulsonix.com> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> <4F7A8680.7030409@gmail.com> <0b6b01cd1239$3d4154e0$b7c3fea0$@pulsonix.com> <4F7C0BE2.1040204@skippinet.com.au> <0bf301cd124c$85fae800$91f0b800$@pulsonix.com> Message-ID: <4F7CD65F.9080007@skippinet.com.au> On 4/04/2012 8:20 PM, David Manns wrote: > Mark, > > Thanks, that's better! > > Now I get this trace output: > > Collecting Python Trace Output... > Object with win32trace dispatcher created (object=None) > in 0x058BF300>._InvokeEx_-SetScriptSite( obj at 0x043F > F22C>,) [1,0,None] > Debugging interfaces not available - debugging is disabled.. > in 0x058BF300>._InvokeEx_-InitNew() [1,0,None] > in 0x058BF300>._InvokeEx_-AddNamedItem(u'application', 14) [1,0,None] > **************** ASSERTION FAILED ******************* > The typeKind of the object is unexpected > in 0x058BF300>._InvokeEx_-Close() [1,0,None] > > > Hopefully that means more to you than it does to me! FWIW, the implementation is all in python in the win32comext\axscript\client directory. Grepping for this message shows it as appearing in framework.py in the function GetSourceTypeInfo(). This function is attempting to locate the possible events for an item, but it is only expecting the typeinfo to be one of TKIND_COCLASS or TKIND_INTERFACE - sadly it doesn't report what was actually found, but you might be able to determine that as it is your typeinfo being examined. Assuming your objects don't actually have events, the simplest fix would be to just change: if typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]: RaiseAssert(winerror.E_UNEXPECTED, "The typeKind of the object is unexpected") to if typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]: return None [Sadly there is also a bug in that RaiseAssert function - it has the args wrong when creating the exception - it should read 'raise Exception(desc, scode)', hence the E_UNEXPECTED is coming out as E_FAIL - but that's not really a big deal...] Let me know if that works for you and I'll make that change for the next release. Cheers, Mark From bgailer at gmail.com Thu Apr 5 16:00:39 2012 From: bgailer at gmail.com (bob gailer) Date: Thu, 05 Apr 2012 10:00:39 -0400 Subject: [python-win32] Problem with PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. Message-ID: <4F7DA587.5020706@gmail.com> I open a .py file, work away and all is OK. I drag the vertical divider to show the object treeview. I type some text then a period and get: >>> Firing event 'KeyDot' failed. Traceback (most recent call last): File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\bindings.py", line 142, in fire rc = binding.handler(*args) File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line 307, in KeyDotEvent self._AutoComplete() File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line 465, in _AutoComplete minline, maxline, curclass = self._GetClassInfoFromBrowser() File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line 520, in _GetClassInfoFromBrowser if not browser.list: return (minline,maxline,None) # Not initialized File "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line 62, in __getattr__ ... many many more of this line File "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line 62, in __getattr__ return getattr(self, attr) File "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line 60, in __getattr__ return getattr(self.listControl, attr) RuntimeError: maximum recursion depth exceeded There is an extra period after the one I typed. Can this be fixed? -- Bob Gailer 919-636-4239 Chapel Hill NC -------------- next part -------------- An HTML attachment was scrubbed... URL: From bgailer at gmail.com Fri Apr 6 17:34:16 2012 From: bgailer at gmail.com (bob gailer) Date: Fri, 06 Apr 2012 11:34:16 -0400 Subject: [python-win32] Problem with PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. Message-ID: <4F7F0CF8.7010704@gmail.com> I open a .py file, work away and all is OK. I drag the vertical divider to show the object treeview. I type some text then a period and get: >>> Firing event 'KeyDot' failed. Traceback (most recent call last): File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\bindings.py", line 142, in fire rc = binding.handler(*args) File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line 307, in KeyDotEvent self._AutoComplete() File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line 465, in _AutoComplete minline, maxline, curclass = self._GetClassInfoFromBrowser() File "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line 520, in _GetClassInfoFromBrowser if not browser.list: return (minline,maxline,None) # Not initialized File "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line 62, in __getattr__ ... many many more of this line File "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line 62, in __getattr__ return getattr(self, attr) File "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line 60, in __getattr__ return getattr(self.listControl, attr) RuntimeError: maximum recursion depth exceeded There is an extra period after the one I typed. Can this be fixed? -- Bob Gailer 919-636-4239 Chapel Hill NC -------------- next part -------------- An HTML attachment was scrubbed... URL: From rupole at hotmail.com Fri Apr 6 20:36:00 2012 From: rupole at hotmail.com (Roger Upole) Date: Fri, 6 Apr 2012 14:36:00 -0400 Subject: [python-win32] Problem with PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. References: <4F7DA587.5020706@gmail.com> Message-ID: Looks like this is due to some of the changes to support Python 3. As I recall, it was difficult to get the inheritance from pywin.mfc.object.Object to work properly for both Python 2 and 3. The autocomplete code is doing some introspection, so the attribute lookup gets even more complicated. I'll try to take a closer look at it this weekend. Roger From bgailer at gmail.com Fri Apr 6 21:32:20 2012 From: bgailer at gmail.com (bob gailer) Date: Fri, 06 Apr 2012 15:32:20 -0400 Subject: [python-win32] Minor irritant Message-ID: <4F7F44C4.1010507@gmail.com> Every time I open a file for editing the tab key starts out at 4 spaces even though I have set Tab size and Indent Size to 2 in Options. I must use alt+u to change it. -- Bob Gailer 919-636-4239 Chapel Hill NC -------------- next part -------------- An HTML attachment was scrubbed... URL: From bgailer at gmail.com Fri Apr 6 21:45:13 2012 From: bgailer at gmail.com (bob gailer) Date: Fri, 06 Apr 2012 15:45:13 -0400 Subject: [python-win32] Another minor irritant. Message-ID: <4F7F47C9.7030303@gmail.com> In the watch window ctrl-x,c,v do not work (for cut copy and paste). I must use the context menu. -- Bob Gailer 919-636-4239 Chapel Hill NC -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Apr 6 22:27:12 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 6 Apr 2012 13:27:12 -0700 Subject: [python-win32] Minor irritant In-Reply-To: <4F7F44C4.1010507@gmail.com> References: <4F7F44C4.1010507@gmail.com> Message-ID: <4F7F51A0.2050200@probo.com> bob gailer wrote: > Every time I open a file for editing the tab key starts out at 4 > spaces even though I have set Tab size and Indent Size to 2 in > Options. I must use alt+u to change it. What application are you talking about? It would be entertaining to start a holy war about tabs and indents here. Suffice it to say that I disagree with your choices.. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From js.20120405 at gmail.com Sat Apr 7 05:19:19 2012 From: js.20120405 at gmail.com (John S) Date: Fri, 6 Apr 2012 23:19:19 -0400 Subject: [python-win32] Casting to IRTDUpdateEvent object Message-ID: I'm trying to implement excelRTDserver.py ( http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/movpy-2.0.0-py2.4.4/movpy/lib/win32com/demos/excelRTDServer.py). I'm running Excel 2010 (32bit) so I change the EXCEL_TLB_MINOR value to 7. The add-in is visible in the Excel add-ins list and if I enter =RTD("Python.RTD.TimeServer","","seconds","5") into a cell, I get the current time. But it never updates. If I change the "5" to another number, I get an update but after the initial change it never updates. I've isolated the problem to an exception raised when the callback object returned by Excel is attempted to be cast into a IRTDUpdateEvent object. This was discussed on this list previously ( http://mail.python.org/pipermail/python-win32/2011-March/011324.html) but no solution. I tried the suggested solution of using CastTo, but when EnsureDispatch is called within gencache.py it raises the exception at the first line within the try statement (ti = disp._oleobj_.GetTypeInfo()). So my question is how do I get the callback object to work? Any help would be greatly appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at slort.org Sat Apr 7 16:22:06 2012 From: chris at slort.org (Christopher Nilsson) Date: Sun, 8 Apr 2012 00:22:06 +1000 Subject: [python-win32] Casting to IRTDUpdateEvent object In-Reply-To: References: Message-ID: Hello, I sent a reply privately, but for the list's benefit, I'll send a copy here too. With luck, everything I say is wrong and somebody will have a solution. :) I fear that things with IRTDUpdateEvent have changed with recent versions of excel (since Excel 2007? I guess that's not so 'recent' anymore...). While hunting around for news of interface changes, I came across this thread in a java forum: http://www.nevaobject.com/phpbb3/viewtopic.php?t=516 The part that worries me is this comment: "Apparently in Excel 12 (Excel 2007) the RTD callback object that implements dual IRTDUpdateEvent interface throws exception (generic COM exception 0x80020009) when is called via IDispatch. If you use v-table binding the call to UpdateNotify succeeds. I don't really know whether it is a bug in Excel 12 or a feature." So far I haven't been able to confirm this against the MSDN information... But if this is true, it does explain the problem being seen. Many older examples on the web, and pywin32+makepy treat this interface as IDispatch, and wrap it accordingly. I don't think we can fix this with pywin32 as it is right now. My understanding is that it relies on IDispatch support. May need to look at comtypes (http://starship.python.net/crew/theller/comtypes/) to wrap the (new?) IRTDUpdateEvent objects, or maybe a C extension. :( It's a pity, since everything else appears to still work. Just the callback object Excel supplies no longer seems to support all the interfaces it advertises (I'm betting makepy wouldn't even try to build the IDispatch wrapper if QueryInterface said it wasn't supported). I don't currently have a copy of Office, with my daily job being in linux land these days, so even though I'd like to, I doubt I'll be much help fixing this. Regards, Chris. On 7 April 2012 13:19, John S wrote: > I'm trying to implement excelRTDserver.py ( > http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/movpy-2.0.0-py2.4.4/movpy/lib/win32com/demos/excelRTDServer.py). > I'm running Excel 2010 (32bit) so I change the EXCEL_TLB_MINOR value to 7. > The add-in is visible in the Excel add-ins list and if I enter > =RTD("Python.RTD.TimeServer","","seconds","5") into a cell, I get the > current time. But it never updates. If I change the "5" to another number, > I get an update but after the initial change it never updates. > > I've isolated the problem to an exception raised when the callback object > returned by Excel is attempted to be cast into a IRTDUpdateEvent object. > This was discussed on this list previously ( > http://mail.python.org/pipermail/python-win32/2011-March/011324.html) but > no solution. I tried the suggested solution of using CastTo, but when > EnsureDispatch is called within gencache.py it raises the exception at the > first line within the try statement (ti = disp._oleobj_.GetTypeInfo()). > > So my question is how do I get the callback object to work? Any help would > be greatly appreciated. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From takeshi.ikeya at gmail.com Sun Apr 8 06:32:43 2012 From: takeshi.ikeya at gmail.com (takeshi ikeya) Date: Sun, 8 Apr 2012 13:32:43 +0900 Subject: [python-win32] SMIEngine(COM) Message-ID: Anyone help me ? I really appreciate win32extension. I'm trying to use some 3'rd parties COM. First I tested win32extension installation. >>> import win32com.client >>> sh = win32com.client.Dispatch('Shell.Application') >>> sh.SetTime() Goes OK. My windows Registry is HKEY_CLASS_ROOT ... Shell.Application Shell.Autoplay ... SMIEngine.SMIHost ... I want to use this (Animatics's servo) SMIEngine.SMIScan SMIEngine is explained herer http://www.animatics.com/products/software/animatics/code-dev-software/smiengine.html Next step. I tried 'Shell.Autoplay'. Simply because it's on the next apeerance. >>> sa = win32com.client.Dispatch('Shell.Autoplay') Traceback (most recent call last): File "", line 1, in sa = win32com.client.Dispatch('Shell.Autoplay') File "D:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147467262, '\x83C\x83\x93\x83^\x81[\x83t\x83F\x83C\x83X\x82\xaa\x83T\x83|\x81[\x83g\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9\x82\xf1', None, None) >>> Dispatch() returns error And 'SMIEngine.SMIHost' (this is what I'm trying) >>> smi = win32com.client.Dispatch('SMIEngine.SMIHost') Traceback (most recent call last): File "", line 1, in smi = win32com.client.Dispatch('SMIEngine.SMIHost') File "D:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147467262, '\x83C\x83\x93\x83^\x81[\x83t\x83F\x83C\x83X\x82\xaa\x83T\x83|\x81[\x83g\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9\x82\xf1', None, None) >>> returns same error. What is the error of Dispatch()? I really expecting your advice. Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From rupole at hotmail.com Sun Apr 8 09:11:14 2012 From: rupole at hotmail.com (Roger Upole) Date: Sun, 8 Apr 2012 03:11:14 -0400 Subject: [python-win32] Problem with PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. References: <4F7F0CF8.7010704@gmail.com> Message-ID: "bob gailer" wrote in message news:4F7F0CF8.7010704 at gmail.com... >I open a .py file, work away and all is OK. > I drag the vertical divider to show the object treeview. > I type some text then a period and get: > > >>> Firing event 'KeyDot' failed. > Traceback (most recent call last): > File > "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\bindings.py", > line 142, in fire > rc = binding.handler(*args) > File > "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line > 307, in KeyDotEvent > self._AutoComplete() > File > "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line > 465, in _AutoComplete > minline, maxline, curclass = self._GetClassInfoFromBrowser() > File > "D:\Python27\Lib\site-packages\pythonwin\pywin\scintilla\view.py", line > 520, in _GetClassInfoFromBrowser > if not browser.list: return (minline,maxline,None) # Not initialized > File > "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line > 62, in __getattr__ > ... many many more of this line > File > "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line > 62, in __getattr__ > return getattr(self, attr) > File > "D:\Python27\Lib\site-packages\pythonwin\pywin\tools\hierlist.py", line > 60, in __getattr__ > return getattr(self.listControl, attr) > RuntimeError: maximum recursion depth exceeded > > There is an extra period after the one I typed. > > Can this be fixed? > Just checked in a fix for this. Roger From rupole at hotmail.com Sun Apr 8 19:24:37 2012 From: rupole at hotmail.com (Roger Upole) Date: Sun, 8 Apr 2012 13:24:37 -0400 Subject: [python-win32] Another minor irritant. References: <4F7F47C9.7030303@gmail.com> Message-ID: "bob gailer" wrote in message news:4F7F47C9.7030303 at gmail.com... > In the watch window ctrl-x,c,v do not work (for cut copy and paste). I > must use the context menu. The API doesn't supply any way to change how the Edit control is created. Looks like we're just going to have to live with this one. Roger From dived38295 at mypacks.net Mon Apr 9 18:19:36 2012 From: dived38295 at mypacks.net (dived38295 at mypacks.net) Date: Mon, 9 Apr 2012 12:19:36 -0400 (GMT-04:00) Subject: [python-win32] Why does a python COM server return different data to VBA and Python clients? Message-ID: <18784847.1333988377499.JavaMail.root@wamui-hunyo.atl.sa.earthlink.net> An HTML attachment was scrubbed... URL: From timr at probo.com Mon Apr 9 18:50:57 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 9 Apr 2012 09:50:57 -0700 Subject: [python-win32] SMIEngine(COM) In-Reply-To: References: Message-ID: <4F831371.7030400@probo.com> takeshi ikeya wrote: > Anyone help me ? > I really appreciate win32extension. > I'm trying to use some 3'rd parties COM. > > First I tested win32extension installation. > > >>> import win32com.client > >>> sh = win32com.client.Dispatch('Shell.Application') > >>> sh.SetTime() > > Goes OK. > ... > Next step. I tried 'Shell.Autoplay'. > Simply because it's on the next apeerance. > > >>> sa = win32com.client.Dispatch('Shell.Autoplay') > ... > Traceback (most recent call last): ... > File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", > line 85, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > com_error: (-2147467262 , > '\x83C\x83\x93\x83^\x81[\x83t\x83F\x83C\x83X\x82\xaa\x83T\x83|\x81[\x83g\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9\x82\xf1', > None, None) > >>> > > Dispatch() returns error -2147467262 is 0x80004002, which is E_NOINTERFACE. There are two different ways of talking to a COM server: "early binding" and "late binding". "Early binding" is what you use from C++. It means the COM client knows the full layout of the COM object, including all of the methods it supports, and in what order they appear in the function table. All COM objects support "early binding". "Late binding" is what you use from, for example, Visual Basic. With "late binding", the object supports an interface called IDispatch. I can use the IDispatch interface to ask the object about the methods it supports and the parameter types for each method. An object with IDispatch can be used by more clients, but it is somewhat painful to add. So, many objects only support "early binding". win32com.client.Dispatch uses late binding. Shell.Application supports IDispatch, but Shell.Autoplay does not, and apparently neither does SMIEngine.SMIHost. You get the E_NOINTERFACE error because the object does not support IDispatch. You can use early binding from Python by creating a proxy wrapper. You can do this by using the "makepy" command in the Python distribution, or by using win32com.client.gencache.EnsureDispatch instead of win32com.client.Dispatch. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From jeffwelch at earthlink.net Mon Apr 9 19:40:05 2012 From: jeffwelch at earthlink.net (jeffwelch at earthlink.net) Date: Mon, 9 Apr 2012 13:40:05 -0400 (EDT) Subject: [python-win32] Why does a python COM server return different data to VBA and Python clients? Message-ID: <33354431.1333993205774.JavaMail.root@elwamui-cypress.atl.sa.earthlink.net> My apologies to the list about my earlier question that was in html. My webmail is supposed to default to plain text but clearly did not. I am trying to write a Python server that will be used by a C++ client. It has taken me quite a while longer than I expected. I have been through the archives and that helped me get to where I am. Many thanks to all those who support these packages. I am using Python 2.5.1 as it is required by some vendor equipment that I must use. One of the reasons it took me a while to get this going was that I was trying to test it in Python. Once I switched to testing it in VBA then I made much faster progress. For demonstration purposes I used the Pippo test in the 'win32com\test' directory. I modified the testpippo.py by adding some code at the start of the testLeaks method. I added the 4 lines: in1 = 15 inout1 = 99 hr= self.object.Method3( in1, inout1) print hr, "retval = %d inout1 = %d"%(hr[0], hr[1]) The printed line was "(0, -31) retval = 0 inout1 = -31". I get "retval = -41 inout1= -31" if I execute the VBA code: Sub TestPippo() Dim obj As Pippo Dim in1 As Long Dim inout1 As Long Set obj = CreateObject("Python.Test.Pippo") in1 = 1 inout1 = 2 retval = obj.Method3(in1, inout1) MsgBox ("retval = " & retval & " inout1 = " & inout1) End Sub Is there a way to call the same Python Server Method, Method3, so that both Python and VBA receive the same return data? Regards, j From davidm at pulsonix.com Tue Apr 10 10:20:32 2012 From: davidm at pulsonix.com (David Manns) Date: Tue, 10 Apr 2012 09:20:32 +0100 Subject: [python-win32] IActiveScript::AddNamedItem fails with exception In-Reply-To: <4F7CD65F.9080007@skippinet.com.au> References: <081b01cd10e2$9985aba0$cc9102e0$@pulsonix.com> <4F7A8680.7030409@gmail.com> <0b6b01cd1239$3d4154e0$b7c3fea0$@pulsonix.com> <4F7C0BE2.1040204@skippinet.com.au> <0bf301cd124c$85fae800$91f0b800$@pulsonix.com> <4F7CD65F.9080007@skippinet.com.au> Message-ID: <06b301cd16f2$cd99d540$68cd7fc0$@pulsonix.com> Mark, I had to make that suggested change in two places in framework.py, plus a change at around line 408 where FindBuildSubItemEvents tries to call GetFuncDesc on the defaultType returned from GetDefaultSourceTypeInfo: defaultType = self.GetDefaultSourceTypeInfo(typeinfo) #***** WESTDEV EDIT **************************** if defaultType != None: #********************************************** index = 0 while 1: ... This finally allows our tiny test script (just creates a text file in c:\temp) to run successfully, so I will now pass a copy of the amended framework.py to our customer to see if this allows him to make some progress with his own 'real' scripts. Best regards, David -----Original Message----- From: Mark Hammond [mailto:mhammond at skippinet.com.au] Sent: 05 April 2012 00:17 To: David Manns Cc: python-win32 at python.org Subject: Re: [python-win32] IActiveScript::AddNamedItem fails with exception On 4/04/2012 8:20 PM, David Manns wrote: > Mark, > > Thanks, that's better! > > Now I get this trace output: > > Collecting Python Trace Output... > Object with win32trace dispatcher created (object=None) > in 0x058BF300>._InvokeEx_-SetScriptSite( 0x058BF300>0x05806F58 with > obj at 0x043F > F22C>,) [1,0,None] > Debugging interfaces not available - debugging is disabled.. > in 0x058BF300>._InvokeEx_-InitNew() [1,0,None] > in 0x058BF300>._InvokeEx_-AddNamedItem(u'application', 14) [1,0,None] > **************** ASSERTION FAILED ******************* The typeKind of > the object is unexpected in > 0x058BF300>._InvokeEx_-Close() [1,0,None] > > > Hopefully that means more to you than it does to me! FWIW, the implementation is all in python in the win32comext\axscript\client directory. Grepping for this message shows it as appearing in framework.py in the function GetSourceTypeInfo(). This function is attempting to locate the possible events for an item, but it is only expecting the typeinfo to be one of TKIND_COCLASS or TKIND_INTERFACE - sadly it doesn't report what was actually found, but you might be able to determine that as it is your typeinfo being examined. Assuming your objects don't actually have events, the simplest fix would be to just change: if typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]: RaiseAssert(winerror.E_UNEXPECTED, "The typeKind of the object is unexpected") to if typeKind not in [pythoncom.TKIND_COCLASS, pythoncom.TKIND_INTERFACE]: return None [Sadly there is also a bug in that RaiseAssert function - it has the args wrong when creating the exception - it should read 'raise Exception(desc, scode)', hence the E_UNEXPECTED is coming out as E_FAIL - but that's not really a big deal...] Let me know if that works for you and I'll make that change for the next release. Cheers, Mark From takeshi.ikeya at gmail.com Wed Apr 11 13:20:22 2012 From: takeshi.ikeya at gmail.com (takeshi ikeya) Date: Wed, 11 Apr 2012 20:20:22 +0900 Subject: [python-win32] SMIEngine(COM) In-Reply-To: <4F831371.7030400@probo.com> References: <4F831371.7030400@probo.com> Message-ID: Thank you Tom. I tried 'EnsureDispatch()' following your advice. This is it. >>> import win32com.client >>> sh = win32com.client.gencache.EnsureDispatch('Shell.Autoplay') Traceback (most recent call last): File "", line 1, in sh = wcc.gencache.EnsureDispatch('Shell.Autoplay') File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 529, in EnsureDispatch disp = win32com.client.Dispatch(prog_id) File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147467262, 'Inteface is not supported', None, None) Same error occured on 'Shell.Autoplay'. And so on my 'SMIEngine.SMIhost'. Then I went tolaunch 'makepy.py' I was asked to 'Select library' But what is this 'library' mean ? Nothin like 'Shell.autoplay' or 'SMIEngine'. Sorry I'm not familiar with COM. Regards ikeya 2012/4/10 Tim Roberts > takeshi ikeya wrote: > > Anyone help me ? > > I really appreciate win32extension. > > I'm trying to use some 3'rd parties COM. > > > > First I tested win32extension installation. > > > > >>> import win32com.client > > >>> sh = win32com.client.Dispatch('Shell.Application') > > >>> sh.SetTime() > > > > Goes OK. > > ... > > Next step. I tried 'Shell.Autoplay'. > > Simply because it's on the next apeerance. > > > > >>> sa = win32com.client.Dispatch('Shell.Autoplay') > > ... > > Traceback (most recent call last): ... > > File "D:\Python27\lib\site-packages\win32com\client\dynamic.py", > > line 85, in _GetGoodDispatch > > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > > pythoncom.IID_IDispatch) > > com_error: (-2147467262 , > > > '\x83C\x83\x93\x83^\x81[\x83t\x83F\x83C\x83X\x82\xaa\x83T\x83|\x81[\x83g\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9\x82\xf1', > > None, None) > > >>> > > > > Dispatch() returns error > > -2147467262 is 0x80004002, which is E_NOINTERFACE. > > There are two different ways of talking to a COM server: "early binding" > and "late binding". > > "Early binding" is what you use from C++. It means the COM client knows > the full layout of the COM object, including all of the methods it > supports, and in what order they appear in the function table. All COM > objects support "early binding". > > "Late binding" is what you use from, for example, Visual Basic. With > "late binding", the object supports an interface called IDispatch. I > can use the IDispatch interface to ask the object about the methods it > supports and the parameter types for each method. An object with > IDispatch can be used by more clients, but it is somewhat painful to > add. So, many objects only support "early binding". > > win32com.client.Dispatch uses late binding. Shell.Application supports > IDispatch, but Shell.Autoplay does not, and apparently neither does > SMIEngine.SMIHost. You get the E_NOINTERFACE error because the object > does not support IDispatch. > > You can use early binding from Python by creating a proxy wrapper. You > can do this by using the "makepy" command in the Python distribution, or > by using win32com.client.gencache.EnsureDispatch instead of > win32com.client.Dispatch. > > -- > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Apr 11 19:12:42 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 11 Apr 2012 10:12:42 -0700 Subject: [python-win32] SMIEngine(COM) In-Reply-To: References: <4F831371.7030400@probo.com> Message-ID: <4F85BB8A.9090509@probo.com> takeshi ikeya wrote: > Thank you Tom. > I tried 'EnsureDispatch()' following your advice. > ... > pywintypes.com_error: (-2147467262, 'Inteface is not supported', None, > None) > > Same error occured on 'Shell.Autoplay'. And so on my 'SMIEngine.SMIhost'. Not every COM object was intended to be used by the "general public". There is no public definition that corresponds to the class ID for Shell.Autoplay. > Then I went tolaunch 'makepy.py' > I was asked to 'Select library' > But what is this 'library' mean ? > Nothin like 'Shell.autoplay' or 'SMIEngine'. > > Sorry I'm not familiar with COM. Well, that's a problem, if you plan to use COM objects. It is worthwhile to do a little reading about COM basics. In order to use a COM object, somehow your application has to learn what functions that object provides, and what parameters each function expects. You can't just make that up. That can be done in three basic ways. (1) If the object was designed only to be used from C++, you might have a C++ header file that describes the object. (2) If the object was designed for "late binding", it will support the IDispatch interface. (3) If the object was designed for "early binding", there will be a "type library" that includes all of the definitions. A type library contains a collection of COM class definitions and interface definitions in a partly compiled form. That's what makepy.py wants. When you installed the SMI product, it registered its objects. If it also registered its type library, you can use that to build the Python interface. Note that the name of a type library often includes the manufacturer, so look for "Animatics SMIEngine". Animatics says on their web site that the SMIEngine interface works with Python. Have you considered contacting them for support? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From takeshi.ikeya at gmail.com Thu Apr 12 00:37:18 2012 From: takeshi.ikeya at gmail.com (takeshi ikeya) Date: Thu, 12 Apr 2012 07:37:18 +0900 Subject: [python-win32] SMIEngine(COM) In-Reply-To: <4F85BB8A.9090509@probo.com> References: <4F831371.7030400@probo.com> <4F85BB8A.9090509@probo.com> Message-ID: Thank you Tim. Yes. I'm not familiar with COM, but Animatics'manual about SMIengine explains every objects and their interfaces. So I think, if I can get an instance of them, I can try and go ahead.. I also contacted with Animatics engineer through their agent. And their answer is "I know little about Python. Most of the information I have seen indicates using ctypes. http://www.codeproject.com/Articles/299580/C-Cplusplus-Python-interop http://python.net/crew/theller/ctypes/tutorial.html " And they asked "Why not use C++ ?" They adviced using 'ctypes', but I think 'ctypes' is for ordinary DLL. The 'ctypes' can't handle COM, and can't create an instance. Or, their advice is right ? I should use 'ctypes' ? I'd like to go all in Python. Regards ikeya 2012/4/12 Tim Roberts > takeshi ikeya wrote: > > Thank you Tom. > > I tried 'EnsureDispatch()' following your advice. > > ... > > pywintypes.com_error: (-2147467262, 'Inteface is not supported', None, > > None) > > > > Same error occured on 'Shell.Autoplay'. And so on my 'SMIEngine.SMIhost'. > > Not every COM object was intended to be used by the "general public". > There is no public definition that corresponds to the class ID for > Shell.Autoplay. > > > > Then I went tolaunch 'makepy.py' > > I was asked to 'Select library' > > But what is this 'library' mean ? > > Nothin like 'Shell.autoplay' or 'SMIEngine'. > > > > Sorry I'm not familiar with COM. > > Well, that's a problem, if you plan to use COM objects. It is > worthwhile to do a little reading about COM basics. > > In order to use a COM object, somehow your application has to learn what > functions that object provides, and what parameters each function > expects. You can't just make that up. That can be done in three basic > ways. (1) If the object was designed only to be used from C++, you > might have a C++ header file that describes the object. (2) If the > object was designed for "late binding", it will support the IDispatch > interface. (3) If the object was designed for "early binding", there > will be a "type library" that includes all of the definitions. > > A type library contains a collection of COM class definitions and > interface definitions in a partly compiled form. That's what makepy.py > wants. When you installed the SMI product, it registered its objects. > If it also registered its type library, you can use that to build the > Python interface. Note that the name of a type library often includes > the manufacturer, so look for "Animatics SMIEngine". > > Animatics says on their web site that the SMIEngine interface works with > Python. Have you considered contacting them for support? > > -- > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Apr 12 19:44:44 2012 From: timr at probo.com (Tim Roberts) Date: Thu, 12 Apr 2012 10:44:44 -0700 Subject: [python-win32] SMIEngine(COM) In-Reply-To: References: <4F831371.7030400@probo.com> <4F85BB8A.9090509@probo.com> Message-ID: <4F87148C.6080909@probo.com> takeshi ikeya wrote: > > I'm not familiar with COM, but Animatics'manual about SMIengine > explains every objects and their interfaces. > So I think, if I can get an instance of them, I can try and go ahead.. > I also contacted with Animatics engineer through their agent. > ... > And they asked > > "Why not use C++ ?" That's a very poor excuse for an answer on their part, since their web site SPECIFICALLY says this: SMIEngine is based on the Windows Component Object Model (COM) and works with: * Microsoft C++ * Borland C++ * Microsoft Visual Basic (VB) * VBA (Visual Basic for Applications) * MS.Net environment * Borland Delphi * Pascal * Python * LabView (when installed as an Active-X component) > > They adviced using 'ctypes', but I think 'ctypes' is for ordinary DLL. > The 'ctypes' can't handle COM, and can't create an instance. > > Or, their advice is right ? > I should use 'ctypes' ? You are correct, they are wrong. ctypes is for normal DLLs. There is a "comtypes" module that provides a ctypes-like interface for COM objects, but that should not be necessary. Their web site advertises Python support. They ought to be able to tell you how to do it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From emmanuel.chomarat at gmail.com Thu Apr 12 20:20:02 2012 From: emmanuel.chomarat at gmail.com (Emmanuel Chomarat) Date: Thu, 12 Apr 2012 20:20:02 +0200 Subject: [python-win32] Help compiling Python and some modules with Visual Studio 11 Message-ID: Hi, I need some help to compile python source code under Visual Studio 11. I need to have my own delivery process as I also need to compile few extra modules that are not always available under windows ( lxml for inst is not up to date). Any help or references will be very much appreciated . I am struggling to compile dependencies(sqlite, zlib) and the core python modules. If any one has some experience sorting out these issues that would be fantastic. Thx Emmanuel From etienne.labaume at free.fr Thu Apr 12 23:37:35 2012 From: etienne.labaume at free.fr (etienne.labaume at free.fr) Date: Thu, 12 Apr 2012 23:37:35 +0200 (CEST) Subject: [python-win32] Help compiling Python and some modules with Visual Studio 11 In-Reply-To: Message-ID: <690515521.103800368.1334266655029.JavaMail.root@zimbra8-e1.priv.proxad.net> Hi, As far as I know, the most recent version of MS compiler you can use to build Python is Visual Studio 2008. http://bugs.python.org/issue13210 -- ?tienne ----- Mail original ----- De: "Emmanuel Chomarat" ?: python-win32 at python.org Envoy?: Jeudi 12 Avril 2012 20:20:02 Objet: [python-win32] Help compiling Python and some modules with Visual Studio 11 Hi, I need some help to compile python source code under Visual Studio 11. I need to have my own delivery process as I also need to compile few extra modules that are not always available under windows ( lxml for inst is not up to date). Any help or references will be very much appreciated . I am struggling to compile dependencies(sqlite, zlib) and the core python modules. If any one has some experience sorting out these issues that would be fantastic. Thx Emmanuel _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Fri Apr 13 04:07:54 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 13 Apr 2012 12:07:54 +1000 Subject: [python-win32] Why does a python COM server return different data to VBA and Python clients? In-Reply-To: <33354431.1333993205774.JavaMail.root@elwamui-cypress.atl.sa.earthlink.net> References: <33354431.1333993205774.JavaMail.root@elwamui-cypress.atl.sa.earthlink.net> Message-ID: <4F878A7A.702@gmail.com> On 10/04/2012 3:40 AM, jeffwelch at earthlink.net wrote: > My apologies to the list about my earlier question that was in html. My webmail is supposed to default to plain text but clearly did not. > > I am trying to write a Python server that will be used by a C++ client. It has taken me quite a while longer than I expected. I have been through the archives and that helped me get to where I am. Many thanks to all those who support these packages. > > I am using Python 2.5.1 as it is required by some vendor equipment that I must use. > > One of the reasons it took me a while to get this going was that I was trying to test it in Python. Once I switched to testing it in VBA then I made much faster progress. > > For demonstration purposes I used the Pippo test in the 'win32com\test' directory. I modified the testpippo.py by adding some code at the start of the testLeaks method. I added the 4 lines: > > in1 = 15 > inout1 = 99 > hr= self.object.Method3( in1, inout1) > print hr, "retval = %d inout1 = %d"%(hr[0], hr[1]) > > > The printed line was "(0, -31) retval = 0 inout1 = -31". > what is Method3 here? The pippo tests don't have such a method. But note that in Python, you generally don't see the "hresult" - so it would be more accurate to have it read something like: results = self.object.Method3( in1, inout1) as Python doesn't have a concept of "byref" args, the "results" object is a tuple with the return value of the function, if any, plus any "byref" args created. In the example above, I'm guessing the function has returned 0 and one byref arg was presented, with the new value being -31. In the VB example below, VB does have byrefs, so the out args end up in the same argument they were passed in. I can't explain why VB for -41 for the result when Python got zero though, but I also can't find the "method3" to help explain it. Mark > > I get "retval = -41 inout1= -31" if I execute the VBA code: > > Sub TestPippo() > Dim obj As Pippo > Dim in1 As Long > Dim inout1 As Long > > Set obj = CreateObject("Python.Test.Pippo") > in1 = 1 > inout1 = 2 > retval = obj.Method3(in1, inout1) > MsgBox ("retval = " & retval & " inout1 = " & inout1) > > End Sub > > > Is there a way to call the same Python Server Method, Method3, so that both Python and VBA receive the same return data? > > Regards, > j > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From breamoreboy at yahoo.co.uk Fri Apr 13 05:58:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 13 Apr 2012 04:58:24 +0100 Subject: [python-win32] Can pylauncher run pip or easy_install for different versions of Python? Message-ID: Hi all, I've tried reading PEP397 and this https://bitbucket.org/vinay.sajip/pylauncher/src/tip/Doc/launcher.rst but couldn't get my head around it, so the question is as the subject. As an aside, are people aware that there is already a pylauncher see http://pylauncher.garage.maemo.org/ ? -- Cheers. Mark Lawrence. From rsyring at gmail.com Fri Apr 13 06:12:20 2012 From: rsyring at gmail.com (Randy Syring) Date: Fri, 13 Apr 2012 00:12:20 -0400 Subject: [python-win32] Can pylauncher run pip or easy_install for different versions of Python? In-Reply-To: References: Message-ID: <4F87A7A4.1080406@gmail.com> Looks like it could, but you would have to give it the version you wanted and then pass in the path to the pip or easy_install script. But, maybe its not needed. On my system, the .exe files are installed with and without the version numbers. So, I have: Directory of c:\Python26\Scripts 02/11/2011 04:07 PM . 02/11/2011 04:07 PM .. 10/20/2009 06:08 AM 286 easy_install-2.6-script.py 11/22/2010 03:04 PM 355 easy_install-2.6-script.pyc 11/22/2010 03:04 PM 355 easy_install-2.6-script.pyo 10/20/2009 06:08 AM 7,168 easy_install-2.6.exe 10/20/2009 06:08 AM 515 easy_install-2.6.exe.manifest 10/20/2009 06:08 AM 278 easy_install-script.py 11/22/2010 03:04 PM 347 easy_install-script.pyc 11/22/2010 03:04 PM 347 easy_install-script.pyo 10/20/2009 06:08 AM 7,168 easy_install.exe 10/20/2009 06:08 AM 511 easy_install.exe.manifest 12/06/2010 03:54 PM 265 pip-2.6-script.py 12/06/2010 03:54 PM 7,168 pip-2.6.exe 12/06/2010 03:54 PM 522 pip-2.6.exe.manifest 12/06/2010 03:54 PM 257 pip-script.py 12/06/2010 03:54 PM 7,168 pip.exe 12/06/2010 03:54 PM 518 pip.exe.manifest And similar for my 2.7 install. So, the following commands should work for installing for specific versions of python if the Scripts directories are all on your PATH: easy_install-2.6 easy_install-2.7 pip-2.6 pip-2.7 If that isn't sufficient, maybe you can tell us more about what you are trying to do. The pylauncher docs seemed pretty thorough, is there something specific you don't understand? --------------------------------------------- Randy Syring Development& Executive Director Level 12 Technologies Direct: 502-276-0459 Office: 502-212-9913 Principled People, Technology that Works On 04/12/2012 11:58 PM, Mark Lawrence wrote: > Hi all, > > I've tried reading PEP397 and this > https://bitbucket.org/vinay.sajip/pylauncher/src/tip/Doc/launcher.rst > but couldn't get my head around it, so the question is as the subject. > > As an aside, are people aware that there is already a pylauncher see > http://pylauncher.garage.maemo.org/ ? > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian at python.org Fri Apr 13 06:18:05 2012 From: brian at python.org (Brian Curtin) Date: Thu, 12 Apr 2012 23:18:05 -0500 Subject: [python-win32] Can pylauncher run pip or easy_install for different versions of Python? In-Reply-To: References: Message-ID: On Thu, Apr 12, 2012 at 22:58, Mark Lawrence wrote: > Hi all, > > I've tried reading PEP397 and this > https://bitbucket.org/vinay.sajip/pylauncher/src/tip/Doc/launcher.rst but > couldn't get my head around it, so the question is as the subject. > > As an aside, are people aware that there is already a pylauncher see > http://pylauncher.garage.maemo.org/ ? I don't think the name matters all that much. It'll be included directly in the CPython installers, and the launcher itself is called py.exe anyway, so "pylauncher" is just some folder name under Vinay's account. From breamoreboy at yahoo.co.uk Fri Apr 13 06:35:02 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 13 Apr 2012 05:35:02 +0100 Subject: [python-win32] Can pylauncher run pip or easy_install for different versions of Python? In-Reply-To: <4F87A7A4.1080406@gmail.com> References: <4F87A7A4.1080406@gmail.com> Message-ID: On 13/04/2012 05:12, Randy Syring wrote: > Looks like it could, but you would have to give it the version you > wanted and then pass in the path to the pip or easy_install script. > > But, maybe its not needed. On my system, the .exe files are installed > with and without the version numbers. So, I have: > > Directory of c:\Python26\Scripts > > 02/11/2011 04:07 PM . > 02/11/2011 04:07 PM .. > > 10/20/2009 06:08 AM 286 easy_install-2.6-script.py > 11/22/2010 03:04 PM 355 easy_install-2.6-script.pyc > 11/22/2010 03:04 PM 355 easy_install-2.6-script.pyo > 10/20/2009 06:08 AM 7,168 easy_install-2.6.exe > 10/20/2009 06:08 AM 515 easy_install-2.6.exe.manifest > 10/20/2009 06:08 AM 278 easy_install-script.py > 11/22/2010 03:04 PM 347 easy_install-script.pyc > 11/22/2010 03:04 PM 347 easy_install-script.pyo > 10/20/2009 06:08 AM 7,168 easy_install.exe > 10/20/2009 06:08 AM 511 easy_install.exe.manifest > > 12/06/2010 03:54 PM 265 pip-2.6-script.py > 12/06/2010 03:54 PM 7,168 pip-2.6.exe > 12/06/2010 03:54 PM 522 pip-2.6.exe.manifest > 12/06/2010 03:54 PM 257 pip-script.py > 12/06/2010 03:54 PM 7,168 pip.exe > 12/06/2010 03:54 PM 518 pip.exe.manifest > > And similar for my 2.7 install. So, the following commands should work > for installing for specific versions of python if the Scripts > directories are all on your PATH: > > easy_install-2.6 > easy_install-2.7 > pip-2.6 > pip-2.7 > > If that isn't sufficient, maybe you can tell us more about what you are > trying to do. The pylauncher docs seemed pretty thorough, is there > something specific you don't understand? > > --------------------------------------------- > Randy Syring > Development& Executive Director > Level 12 Technologies > Direct: 502-276-0459 > Office: 502-212-9913 > > Principled People, Technology that Works > > > On 04/12/2012 11:58 PM, Mark Lawrence wrote: >> Hi all, >> >> I've tried reading PEP397 and this >> https://bitbucket.org/vinay.sajip/pylauncher/src/tip/Doc/launcher.rst >> but couldn't get my head around it, so the question is as the subject. >> >> As an aside, are people aware that there is already a pylauncher see >> http://pylauncher.garage.maemo.org/ ? >> > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 Thanks for the fast response, it had never occurred to me that there were version numbers available for these programs, so that's my question answered. -- Cheers. Mark Lawrence. From support at pulsonix.com Fri Apr 13 13:14:47 2012 From: support at pulsonix.com (Pulsonix Tech Support) Date: Fri, 13 Apr 2012 12:14:47 +0100 Subject: [python-win32] Need advice on iterator implementation in scripting host Message-ID: <0ee201cd1966$a346d7e0$e9d487a0$@pulsonix.com> We have an ActiveX scripting host implementation in our application (written in C++), so that users can run scripts to access our data from inside the application. Current problem is that iterating from Python script doesn't work right. You can iterate through a collection, but attempts to do this a second time cause application crashes or unexpected behaviour. Seems to work okay from VBscript though. This may be because we are not raising StopIteration exception when iterator.Next() has no items left. But I can't find any information about how to do this from a C++ scripting host implementation. Best regards, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From karra.etc at gmail.com Fri Apr 13 15:17:16 2012 From: karra.etc at gmail.com (Sriram ET.) Date: Fri, 13 Apr 2012 18:47:16 +0530 Subject: [python-win32] PyIMAPIFolder.DeleteFolder ?? Message-ID: I am trying to programatically delete a Contacts folder (that I programatically created using PyIMAPI.CreateFolder), when I get the following exception: AttributeError: 'PyIMAPIFolder' object has no attribute 'DeleteFolder' I can see there is an EmptyFolder() implemented, and documented at: http://timgolden.me.uk/pywin32-docs/PyIMAPIFolder__EmptyFolder_meth.html) ... so why not DeleteFolder? Should I be looking in some other place? Regards, -Sriram -------------- next part -------------- An HTML attachment was scrubbed... URL: From hossain.iqbal at gmail.com Fri Apr 13 17:22:24 2012 From: hossain.iqbal at gmail.com (Riz Hossain) Date: Fri, 13 Apr 2012 11:22:24 -0400 Subject: [python-win32] WMI to find private memory usage Message-ID: Hello, I am looking for a way to capture the private memory usage by a process (the one that shows on task manager). I searched online a lot but I am only seeing information on working memory size. It would be also a great if I could get the peak value of private memory usage. Thanks, Riz for process in c: if process.Caption.lower() == 'rimdevicemanager.exe': keys = process.properties.keys() keys.sort() print '\n'.join(['%s: %s' % (key, getattr(process, key)) for key in keys]) -- This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Apr 13 17:26:18 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 13 Apr 2012 16:26:18 +0100 Subject: [python-win32] WMI to find private memory usage In-Reply-To: References: Message-ID: <4F88459A.1050607@timgolden.me.uk> On 13/04/2012 16:22, Riz Hossain wrote: > Hello, > > I am looking for a way to capture the private memory usage by a process > (the one that shows on task manager). I searched online a lot but I am > only seeing information on working memory size. It would be also a > great if I could get the peak value of private memory usage. While I've never done what you're describing, the first place I'd look is psutil: http://code.google.com/p/psutil/ TJG From karra.etc at gmail.com Fri Apr 13 17:39:06 2012 From: karra.etc at gmail.com (Sriram ET.) Date: Fri, 13 Apr 2012 21:09:06 +0530 Subject: [python-win32] PyIMAPIFolder.DeleteFolder ?? In-Reply-To: References: Message-ID: I am trying to programatically delete a Contacts folder (that I programatically created using PyIMAPI.CreateFolder), when I get the following exception: AttributeError: 'PyIMAPIFolder' object has no attribute 'DeleteFolder' I can see there is an EmptyFolder() implemented, and documented at: http://timgolden.me.uk/pywin32-docs/PyIMAPIFolder__EmptyFolder_meth.html) ... so why not DeleteFolder? Should I be looking in some other place? Regards, -Sriram -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Apr 13 18:47:37 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 13 Apr 2012 09:47:37 -0700 Subject: [python-win32] SMIEngine(COM) In-Reply-To: References: <4F831371.7030400@probo.com> <4F85BB8A.9090509@probo.com> <4F87148C.6080909@probo.com> Message-ID: <4F8858A9.1060506@probo.com> takeshi ikeya wrote: > > I showed your mail to the agent of Animatics. > He promised that he'll find a good software engineer in Animatics. > and make him find some answer. That seems like exactly the right thing to do. > But I am afraid.... Well, the only fear is that it will take too long. If they can show you one example, you can take it from there. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From hossain.iqbal at gmail.com Fri Apr 13 18:51:45 2012 From: hossain.iqbal at gmail.com (Riz Hossain) Date: Fri, 13 Apr 2012 12:51:45 -0400 Subject: [python-win32] WMI to find private memory usage In-Reply-To: <4F88459A.1050607@timgolden.me.uk> References: <4F88459A.1050607@timgolden.me.uk> Message-ID: Thanks for the reply Tim. I have tried the below code: import psutil p = psutil.Process(3540) print p.get_memory_info() it outputs: meminfo(rss=157237248, vms=139837440) which is the memory for working set and commit. This is still not returning me the private value (which is what you see on your task manager). Thanks, Riz On Fri, Apr 13, 2012 at 11:26 AM, Tim Golden wrote: > On 13/04/2012 16:22, Riz Hossain wrote: > > Hello, > > > > I am looking for a way to capture the private memory usage by a process > > (the one that shows on task manager). I searched online a lot but I am > > only seeing information on working memory size. It would be also a > > great if I could get the peak value of private memory usage. > > While I've never done what you're describing, the first place > I'd look is psutil: > > http://code.google.com/p/psutil/ > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Riz Hossain Engineering Physics (B.Eng) Software Test Specialist Research In Motion 295 Phillip Street Waterloo, ON N2L 3L3 This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From karra.etc at gmail.com Sat Apr 14 07:19:29 2012 From: karra.etc at gmail.com (Sriram ET.) Date: Sat, 14 Apr 2012 10:49:29 +0530 Subject: [python-win32] Error trying to do a EmptyFolder() (MAPI) Message-ID: I have a folder in the Root Folder of a message store that I am trying to clear using EmptyFolder(). The code is as follows: folder = store.OpenEntry(eid, None, MOD_FLAG) hr = folder.EmptyFolder(0, None, 0) I get the error: ' Error: unsupported operand type(s) for &: 'NoneType' and 'int' Changing the code to folder = store.OpenEntry(eid, None, MOD_FLAG) hr = folder.EmptyFolder(0, 0, 0) I get the following exception: "Error: The Python instance can not be converted to a COM object" This is a command line tool, and I do not need the progress of the operation. Can someone tell me what is the correct way to invoke EmptyFolder()? Thanks, Sriram -------------- next part -------------- An HTML attachment was scrubbed... URL: From dived38295 at mypacks.net Mon Apr 16 19:01:03 2012 From: dived38295 at mypacks.net (dived38295 at mypacks.net) Date: Mon, 16 Apr 2012 13:01:03 -0400 (GMT-04:00) Subject: [python-win32] Why does a python COM server return different data to VBA and Python clients? Message-ID: <21663067.1334595664281.JavaMail.root@elwamui-cypress.atl.sa.earthlink.net> Thanks for the reply. I forgot that I had copied Method2 and Method3 from a thread I saw from 2006, 2006-October/005094. That thread just seemed to die without resolution. I was going to include the differences but I determined why it failed. According to the Microsoft support website "By default, VBA passes arguments by reference." I would have expected VBA to make an "[in]" parameter use ByVal but that didn't happen, so I did some digging. I found that my example was returning more data than expected. If I removed the extra return value it works and the "[in]" parameter from VBA is not overwritten. If I forward declare the method in VBA then it detects the extra data and reports an error. I find the VBA behavior a bit confusing. For anyone interested you can see this behavior using the Pippo test with the following changes: I added the following line to the "pippo.idl" interface IPippo: [id(4), helpstring("method Method3")] HRESULT Method3([in] long in1, [in, out] long *inout1, [out, retval] long *val); [id(99), helpstring("method Method4")] HRESULT Method4([in] long in1, [in, out] long *inout1, [out, retval] long *val); I added the following lines to the pippo_server.py class CPippo. Note that Method 4 is returning an extra value. def Method3(self, in1, inout1): return( 1010,1011 ) def Method4(self, in1, inout1): return( 1010,1011,1012 ) Execute the following VBA code (Excel, or Word have VBA in macros): Private Declare Function Pippo_Method3 Lib "TESTSERVERLib.Pippo" (ByVal in1 As Long, inout1 As Long) As Long Sub TestPippo() Dim obj As Object Dim in1 As Long Dim inout1 As Long Set obj = CreateObject("Python.Test.Pippo") in1 = -1 inout1 = -2 retval3 = obj.Method3(in1, inout1) outputMessage = outputMessage & " Forward declared - Method 3 retval3 = " & retval3 & " inout1 = " & inout1 & " in1 = " & in1 & vbCrLf in1 = -1 inout1 = -2 retval4 = obj.Method4(in1, inout1) outputMessage = outputMessage & "Not Forward declared - Method 4 retval4 = " & retval4 & " inout1 = " & inout1 & " in1 = " & in1 & vbCrLf MsgBox outputMessage End Sub If you call Method4 from a Python client then it only sees a tuple with 2 elements as expected by the idl. It did seem odd that the VBA saw more data so I guess the Python server method return data is not checked against the registered tlb and just passes the data directly through to the COM client. J From skippy.hammond at gmail.com Tue Apr 17 03:14:43 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 17 Apr 2012 11:14:43 +1000 Subject: [python-win32] Need advice on iterator implementation in scripting host In-Reply-To: <0ee201cd1966$a346d7e0$e9d487a0$@pulsonix.com> References: <0ee201cd1966$a346d7e0$e9d487a0$@pulsonix.com> Message-ID: <4F8CC403.5010808@gmail.com> On 13/04/2012 9:14 PM, Pulsonix Tech Support wrote: > We have an ActiveX scripting host implementation in our application > (written in C++), so that users can run scripts to access our data from > inside the application. > > Current problem is that iterating from Python script doesn?t work right. > You can iterate through a collection, but attempts to do this a second > time cause application crashes or unexpected behaviour. Seems to work > okay from VBscript though. > > This may be because we are not raising StopIteration exception when > iterator.Next() has no items left. But I can?t find any information > about how to do this from a C++ scripting host implementation. win32com has some iterator support built in, but was done way before Python itself had proper iterators so probably isn't ideal. The most basic support is enabled when the object has a "Count" property and an Item() method. Some support for IEnumVARIANT also exists, but it requires you to wrap the object in win32com.client.util.Iterator - which I should possibly revisit as we might be able to make that seamless. How are you attempting to expose iteration? Mark From skippy.hammond at gmail.com Tue Apr 17 03:19:24 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 17 Apr 2012 11:19:24 +1000 Subject: [python-win32] PyIMAPIFolder.DeleteFolder ?? In-Reply-To: References: Message-ID: <4F8CC51C.9030309@gmail.com> On 14/04/2012 1:39 AM, Sriram ET. wrote: > > I am trying to programatically delete a Contacts folder (that I > programatically created using PyIMAPI.CreateFolder), when I get the > following exception: > > AttributeError: 'PyIMAPIFolder' object has no attribute 'DeleteFolder' > > I can see there is an EmptyFolder() implemented, and documented at: > http://timgolden.me.uk/pywin32-docs/PyIMAPIFolder__EmptyFolder_meth.html) ... > so why not DeleteFolder? Should I be looking in some other place? I'm afraid that simply isn't exposed by pywin32 as yet. Mark From skippy.hammond at gmail.com Tue Apr 17 03:25:08 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 17 Apr 2012 11:25:08 +1000 Subject: [python-win32] Error trying to do a EmptyFolder() (MAPI) In-Reply-To: References: Message-ID: <4F8CC674.7030603@gmail.com> On 14/04/2012 3:19 PM, Sriram ET. wrote: > I have a folder in the Root Folder of a message store that I am trying > to clear using EmptyFolder(). The code is as follows: > > folder = store.OpenEntry(eid, None, MOD_FLAG) > hr = folder.EmptyFolder(0, None, 0) > > I get the error: ' Error: unsupported operand type(s) for &: 'NoneType' > and 'int' I'm afraid I can't explain that at all - None should be fine there and nothing in the MAPI support should be trying to do the & - are you sure the traceback points there. > > Changing the code to > > folder = store.OpenEntry(eid, None, MOD_FLAG) > hr = folder.EmptyFolder(0, 0, 0) > > I get the following exception: "Error: The Python instance can not be > converted to a COM object" That's not a great message but is expected. Mark > > This is a command line tool, and I do not need the progress of the > operation. Can someone tell me what is the correct way to invoke > EmptyFolder()? > > Thanks, > Sriram > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From karra.etc at gmail.com Tue Apr 17 07:37:31 2012 From: karra.etc at gmail.com (Sriram ET.) Date: Tue, 17 Apr 2012 11:07:31 +0530 Subject: [python-win32] PyIMAPIFolder.DeleteFolder ?? In-Reply-To: <4F8CC51C.9030309@gmail.com> References: <4F8CC51C.9030309@gmail.com> Message-ID: On Tue, Apr 17, 2012 at 6:49 AM, Mark Hammond wrote: > On 14/04/2012 1:39 AM, Sriram ET. wrote: > >> >> I am trying to programatically delete a Contacts folder (that I >> programatically created using PyIMAPI.CreateFolder), when I get the >> following exception: >> >> AttributeError: 'PyIMAPIFolder' object has no attribute 'DeleteFolder' >> >> I can see there is an EmptyFolder() implemented, and documented at: >> http://timgolden.me.uk/**pywin32-docs/PyIMAPIFolder__** >> EmptyFolder_meth.html) >> ... >> so why not DeleteFolder? Should I be looking in some other place? >> > > I'm afraid that simply isn't exposed by pywin32 as yet. Hi Mark, is there anything I can do (like raise a feature request) or something that will put it somewhere in your roadmap? -Sriram -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhammond at skippinet.com.au Tue Apr 17 07:42:35 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 17 Apr 2012 15:42:35 +1000 Subject: [python-win32] PyIMAPIFolder.DeleteFolder ?? In-Reply-To: References: <4F8CC51C.9030309@gmail.com> Message-ID: <4F8D02CB.201@skippinet.com.au> On 17/04/2012 3:37 PM, Sriram ET. wrote: > On Tue, Apr 17, 2012 at 6:49 AM, Mark Hammond > wrote: > > On 14/04/2012 1:39 AM, Sriram ET. wrote: > > > I am trying to programatically delete a Contacts folder (that I > programatically created using PyIMAPI.CreateFolder), when I get the > following exception: > > AttributeError: 'PyIMAPIFolder' object has no attribute > 'DeleteFolder' > > I can see there is an EmptyFolder() implemented, and documented at: > http://timgolden.me.uk/__pywin32-docs/PyIMAPIFolder____EmptyFolder_meth.html > ) > ... > so why not DeleteFolder? Should I be looking in some other place? > > > I'm afraid that simply isn't exposed by pywin32 as yet. > > > Hi Mark, is there anything I can do (like raise a feature request) or > something that will put it somewhere in your roadmap? A feature request at sourceforce.net/projects/pywin32 would do that. Cheers, Mark From support at pulsonix.com Tue Apr 17 09:57:53 2012 From: support at pulsonix.com (Pulsonix Tech Support) Date: Tue, 17 Apr 2012 08:57:53 +0100 Subject: [python-win32] Need advice on iterator implementation in scripting host In-Reply-To: <4F8CC403.5010808@gmail.com> References: <0ee201cd1966$a346d7e0$e9d487a0$@pulsonix.com> <4F8CC403.5010808@gmail.com> Message-ID: <000f01cd1c6f$cb4e0d10$61ea2730$@pulsonix.com> Mark, Our axscript host implementation is based around the old "ActiveScriptHost" class by Ernest Laurentin. Our base collection class is a template class implements _NewEnum, Count and other functions as per this dispatch map: DISP_PROPERTY_EX_ID(C##BaseName, "_NewEnum", DISPID_NEWENUM, _NewEnum, SetNotSupported, VT_UNKNOWN) DISP_PROPERTY_EX_ID(C##BaseName, "Count", DISP_ID_COUNT, GetCount, SetNotSupported, VT_I2) DISP_FUNCTION(C##BaseName, "Add", Add, VT_DISPATCH, VTS_VARIANT VTS_VARIANT) DISP_FUNCTION(C##BaseName, "Item", GetItem, VT_DISPATCH, VTS_VARIANT) DISP_FUNCTION(C##BaseName, "Remove", Remove, VT_EMPTY, VTS_VARIANT) DISP_DEFVALUE(C##BaseName, "Item") I'm not sure where this came from now, probably from one of the MS MFC samples, possibly XRTFrame. The implementation of Next does "return ResultFromScode(S_FALSE)" on reaching the end of the list of available items. The debug tracing inside our app shows that all the expected objects are being created and destroyed, so it may be something wrong in our internal 'wiring' that relates the scriptable objects to our internal data model objects that is not properly tidying up. We have yet to prove that it really is the absence of a StopIteration exception that is causing the app crash, so we are continuing to unpick the code. Best regards, David. -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: 17 April 2012 02:15 To: support at pulsonix.com Cc: python-win32 at python.org Subject: Re: [python-win32] Need advice on iterator implementation in scripting host On 13/04/2012 9:14 PM, Pulsonix Tech Support wrote: > We have an ActiveX scripting host implementation in our application > (written in C++), so that users can run scripts to access our data > from inside the application. > > Current problem is that iterating from Python script doesn't work right. > You can iterate through a collection, but attempts to do this a second > time cause application crashes or unexpected behaviour. Seems to work > okay from VBscript though. > > This may be because we are not raising StopIteration exception when > iterator.Next() has no items left. But I can't find any information > about how to do this from a C++ scripting host implementation. win32com has some iterator support built in, but was done way before Python itself had proper iterators so probably isn't ideal. The most basic support is enabled when the object has a "Count" property and an Item() method. Some support for IEnumVARIANT also exists, but it requires you to wrap the object in win32com.client.util.Iterator - which I should possibly revisit as we might be able to make that seamless. How are you attempting to expose iteration? Mark From karra.etc at gmail.com Thu Apr 19 13:46:41 2012 From: karra.etc at gmail.com (Sriram ET.) Date: Thu, 19 Apr 2012 17:16:41 +0530 Subject: [python-win32] Error trying to do a EmptyFolder() (MAPI) In-Reply-To: <4F8CC674.7030603@gmail.com> References: <4F8CC674.7030603@gmail.com> Message-ID: On Tue, Apr 17, 2012 at 6:55 AM, Mark Hammond wrote: > On 14/04/2012 3:19 PM, Sriram ET. wrote: > >> I have a folder in the Root Folder of a message store that I am trying >> to clear using EmptyFolder(). The code is as follows: >> >> folder = store.OpenEntry(eid, None, MOD_FLAG) >> hr = folder.EmptyFolder(0, None, 0) >> >> I get the error: ' Error: unsupported operand type(s) for &: 'NoneType' >> and 'int' >> > > I'm afraid I can't explain that at all - None should be fine there and > nothing in the MAPI support should be trying to do the & - are you sure the > traceback points there. I am sorry, my bad. I tried to process a non-existent error code causing some problems. There was no issue with the routine itself. Regards, Sriram -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffwelch at earthlink.net Thu Apr 19 15:32:05 2012 From: jeffwelch at earthlink.net (jeffwelch at earthlink.net) Date: Thu, 19 Apr 2012 09:32:05 -0400 (EDT) Subject: [python-win32] comtypes.server.register is case sensitive to filenames, see registry PythonClass. Message-ID: <7132492.1334842325744.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net> I was having intermittent problems creating a Python COM object that I am using as a test/learning exercise. What I finally noticed was that when I was command line registering the object I was not consistent in typing the name of the python file. Executing the DOS command line: python TestMsgBox.py -regserver Yields the following registry entry: HKEY_CLASSES_ROOT\CLSID\{a4c0208f-8888-11e1-ac67-b8ac6f92cf9d}\InprocServer32 PythonClass = "TestMsgBox.TestMsgBox" Executing the DOS command line: python TestMsgBox.py -regserver Yields the following registry entry: HKEY_CLASSES_ROOT\CLSID\{a4c0208f-8888-11e1-ac67-b8ac6f92cf9d}\InprocServer32 PythonClass = "testmsgbox.TestMsgBox" I created the smallest sample I could to reproduce it. import comtypes class TestMsgBox( comtypes.IUnknown ): _case_insensitive_ = True _reg_threading_ = "Both" _reg_progid_ = "TestMsgBoxLib.TestMsgBox" _reg_desc_ = "MessageBox sample for testing" _reg_clsctx_ = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER _reg_clsid_ = "{a4c0208f-8888-11e1-ac67-b8ac6f92cf9d}" if __name__ == "__main__": from comtypes.server.register import UseCommandLine UseCommandLine(TestMsgBox) I don't know if this was intended behavior but I had not seen it documented. From python at venix.com Thu Apr 19 22:32:08 2012 From: python at venix.com (Lloyd Kvam) Date: Thu, 19 Apr 2012 16:32:08 -0400 Subject: [python-win32] vb errors from Python COM object now include the traceback lines Message-ID: <1334867528.3782.126.camel@venix-laptop.venix.com> I am upgrading an old windows application from Python 2.4 to Python 2.6. The application is written in portable Python. A GUI interface was created by using Visual Basic (VB 6) and a Python module that wraps the application as a COM object. With python 2.4 (and pywin32-210) exceptions resulted in a VB ERR object where the description was the text from the Python exception. With python 2.6 (and pywin-217) the description includes the traceback making the error messages hopelessly confusing to the user. I could not find any documentation describing the change or offering any configuration clues. Comparing the win32com source trees has not helped. I could not find a change in the Python code relating to the traceback appearing in the descriptions. I am hoping one of you can point me in the right direction. My alternative appears to be (painfully) writing some VB code to discard the traceback lines from Err.Description. -- Lloyd Kvam Venix Corp DLSLUG/GNHLUG library http://dlslug.org/library.html http://www.librarything.com/catalog/dlslug http://www.librarything.com/catalog/dlslug&sort=stamp http://www.librarything.com/rss/recent/dlslug From python at venix.com Fri Apr 20 00:30:54 2012 From: python at venix.com (Lloyd Kvam) Date: Thu, 19 Apr 2012 18:30:54 -0400 Subject: [python-win32] vb errors from Python COM object now include the traceback lines In-Reply-To: <1334867528.3782.126.camel@venix-laptop.venix.com> References: <1334867528.3782.126.camel@venix-laptop.venix.com> Message-ID: <1334874654.3782.152.camel@venix-laptop.venix.com> On Thu, 2012-04-19 at 16:32 -0400, Lloyd Kvam wrote: > I am hoping one of you can point me in the right direction. My > alternative appears to be (painfully) writing some VB code to discard > the traceback lines from Err.Description. I read more carefully through Python Programming on Win32 and came up with this code: """""""""""""""""""""""""""""""""""""""""""""""""""""""""" class DefaultDebugDispatcher( win32com.server.dispatcher.DefaultDebugDispatcher): def _HandleException_(self): excls,exself = sys.exc_info()[:2] if not IsCOMServerException(excls): raise COMException(description = str(exself), scode = winerror.E_INVALIDARG, ) raise useDispatcher = DefaultDebugDispatcher """""""""""""""""""""""""""""""""""""""""""""""""""""""""" I tried several other winerror codes, but they all wiped out my description. This seems to work for my purposes. There is some additional code that emails traces to me, but I snipped it since it makes little sense without a lot more context. Please let me know if I missed a better approach. Thanks very much for your attention. -- Lloyd Kvam Venix Corp DLSLUG/GNHLUG library http://dlslug.org/library.html http://www.librarything.com/catalog/dlslug http://www.librarything.com/catalog/dlslug&sort=stamp http://www.librarything.com/rss/recent/dlslug From skippy.hammond at gmail.com Fri Apr 20 07:52:11 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 20 Apr 2012 15:52:11 +1000 Subject: [python-win32] vb errors from Python COM object now include the traceback lines In-Reply-To: <1334874654.3782.152.camel@venix-laptop.venix.com> References: <1334867528.3782.126.camel@venix-laptop.venix.com> <1334874654.3782.152.camel@venix-laptop.venix.com> Message-ID: <4F90F98B.2060601@gmail.com> On 20/04/2012 8:30 AM, Lloyd Kvam wrote: > On Thu, 2012-04-19 at 16:32 -0400, Lloyd Kvam wrote: >> I am hoping one of you can point me in the right direction. My >> alternative appears to be (painfully) writing some VB code to discard >> the traceback lines from Err.Description. Hrm - I thought it had always been the case that if you throw an explicit COMException, then you shouldn't get the traceback - the traceback only appears for "other" exceptions, which presumably indicate the exception was unintended. > > I read more carefully through Python Programming on Win32 and came up > with this code: > > """""""""""""""""""""""""""""""""""""""""""""""""""""""""" > class DefaultDebugDispatcher( > win32com.server.dispatcher.DefaultDebugDispatcher): > def _HandleException_(self): > excls,exself = sys.exc_info()[:2] > if not IsCOMServerException(excls): > raise COMException(description = str(exself), > scode = winerror.E_INVALIDARG, > ) Which seems to backup my point - IsCOMServerException() is returning false, so the exception isn't a COMException, so you turn it into one and avoid the traceback etc. Note however that you could just also raise a COMException directly from the original point - ie, there should be no need to convert to a COMException if a COMException is thrown in the first place. How are you throwing the original? If you thought you were throwing a COMException then we would want to check you actually are if you still think so, dig into why IsCOMServerException is failing. Cheers, Mark From skippy.hammond at gmail.com Fri Apr 20 08:06:14 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 20 Apr 2012 16:06:14 +1000 Subject: [python-win32] comtypes.server.register is case sensitive to filenames, see registry PythonClass. In-Reply-To: <7132492.1334842325744.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net> References: <7132492.1334842325744.JavaMail.root@elwamui-darkeyed.atl.sa.earthlink.net> Message-ID: <4F90FCD6.30807@gmail.com> On 19/04/2012 11:32 PM, jeffwelch at earthlink.net wrote: > I was having intermittent problems creating a Python COM object that I am using as a test/learning exercise. What I finally noticed was that when I was command line registering the object I was not consistent in typing the name of the python file. > > > Executing the DOS command line: > python TestMsgBox.py -regserver > Yields the following registry entry: > HKEY_CLASSES_ROOT\CLSID\{a4c0208f-8888-11e1-ac67-b8ac6f92cf9d}\InprocServer32 > PythonClass = "TestMsgBox.TestMsgBox" > > > Executing the DOS command line: > python TestMsgBox.py -regserver Is the above correct, or did you mean to say "python testmsgbox.py" there? If you did then I can guess how comtypes would come to that conclusion - python itself will think the filename is "testmsgbox.py". pywin32 has code specifically to work around this - in win32com\server\register.py there is: moduleName = os.path.splitext(win32api.FindFiles(sys.argv[0])[0][8])[0] which will give back the actual filename rather than the one specified. I'd see if you can find a comtypes specific mailing-list and ask the question... ... > class TestMsgBox( comtypes.IUnknown ): > _case_insensitive_ = True Again, I know almost zero about comtypes, but I wouldn't expect the above to have any bearing on the case of the module filename - I'd guess that this controls whether the method/property names should be considered case sensitive (ie, whether yourobject.Foo() and yourobject.foo()) both call the same method. HTH, Mark > _reg_threading_ = "Both" > _reg_progid_ = "TestMsgBoxLib.TestMsgBox" > _reg_desc_ = "MessageBox sample for testing" > _reg_clsctx_ = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER > _reg_clsid_ = "{a4c0208f-8888-11e1-ac67-b8ac6f92cf9d}" > > if __name__ == "__main__": > from comtypes.server.register import UseCommandLine > UseCommandLine(TestMsgBox) > > I don't know if this was intended behavior but I had not seen it documented. > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From karra.etc at gmail.com Fri Apr 20 08:37:14 2012 From: karra.etc at gmail.com (Sriram ET.) Date: Fri, 20 Apr 2012 12:07:14 +0530 Subject: [python-win32] PyIMAPIFolder.DeleteFolder ?? In-Reply-To: <4F8D02CB.201@skippinet.com.au> References: <4F8CC51C.9030309@gmail.com> <4F8D02CB.201@skippinet.com.au> Message-ID: On Tue, Apr 17, 2012 at 11:12 AM, Mark Hammond wrote: > On 17/04/2012 3:37 PM, Sriram ET. wrote: > >> >> Hi Mark, is there anything I can do (like raise a feature request) or >> something that will put it somewhere in your roadmap? >> > > A feature request at sourceforce.net/projects/**pywin32would do that. > Done; just raised a feature request for this at: https://sourceforge.net/tracker/?func=detail&aid=3519735&group_id=78018&atid=551957 Cheers, and thanks for all the good work! -Sriram -------------- next part -------------- An HTML attachment was scrubbed... URL: From michel.gba at derivativepartners.com Fri Apr 20 09:36:41 2012 From: michel.gba at derivativepartners.com (michel.gba at derivativepartners.com) Date: Fri, 20 Apr 2012 09:36:41 +0200 Subject: [python-win32] Connecting to Bloomberg Message-ID: Dear Team, I want to connect to Bloomberg with Python 3.2. Looking on internet I found couple of programs written by diverse authors. I implemented by It does not work. I followed the following steps, I included the python code and the error messages: I will really appreciate if you could help me. (Please forward to the right person). Regards, Michel Step 1 : Install Bloomberg Desktop API v3 from API download page (file is contained in DAPI_2.zip) Step 2 : Download and install : ActiveState Python x86 (Key point : not the 64-bit version) Step 3 : (For safety) : Start menu > start > all programmes > bloomberg > api environment diagnostics > start diagnostic tool repair if needed. Ignore settings errors. Step 4 : In any directory, run the minimal.py file given below : python minimal.py -------------- minimal.py -------------- import win32com.client from pythoncom import PumpWaitingMessages from time import time class EventHandler: def OnProcessEvent(self, result)? event = win32com.client.gencache.EnsureDispatch(result) iterator = event.CreateMessageIterator() while iterator.Next(): print "EventType[%d] -> %s" % (event.EventType, iterator.Message.MessageTypeAsString,) session = win32com.client.DispatchWithEvents('blpapicom.Session.1' , EventHandler) ## Each one of these gives rise to another message session.Start() started = session.OpenService('//blp/mktdata') endTime = time() + 2 while True: PumpWaitingMessages() if endTime < time(): break Error Message: Traceback (most recent call last): File "C:\Python32\Pythondev\minimal.py", line 12, in session = win32com.client.DispatchWithEvents('blpapicom.Session.1' , EventHandler) File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 245, in DispatchWithEvents disp = Dispatch(clsid) File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221005, 'Invalid class string', None, None) ----------------------------------------------- Michel Gba Praktikant Derivative Partners Research AG Spl?genstrasse 10 8002 Z?rich, Schweiz tel: +41 (0) 44 515 27 79 fax: +41 (0) 43 305 05 31 mail: michel.gba at derivativepartners.com home: www.derivativepartners.com +++ all about structured products on www.payoff.ch +++ -------------- next part -------------- An HTML attachment was scrubbed... URL: From Jan.Wedel at ettex.de Fri Apr 20 11:45:38 2012 From: Jan.Wedel at ettex.de (Jan Wedel) Date: Fri, 20 Apr 2012 11:45:38 +0200 Subject: [python-win32] How to write a COM Server implementing interfaces from type lib? In-Reply-To: <4F7544DB.8010101@skippinet.com.au> Message-ID: Hi, sorry for the delay but we were and still are running short on time in this project so I eventually switched to comtypes (which has a lot other inconveniences compared to pythoncom but at least it did work with my special use case). Nonetheless, I already tried your suggestion but unfortunately it didn't work. This is the output of the code at the end of this mail using the typelib I had problems with: """ GUID before: {00000000-0000-0000-0000-000000000000} GUID after: {2E6664B0-69B5-4620-8CC4-9A3F790DED73} Traceback (most recent call last): File "record-test.py", line 19, in status = pythoncom.GetRecordFromTypeInfo(info) pywintypes.com_error: (-2147024809, 'Falscher Parameter.', None, None) """ Additionally, I have submitted my patched version of policy.py to support multiple typelibs. Pythoncom is really nice to use since it manages all the ctypes pointer stuff which in comtypes you have handle by yourself. But as I already explained, I needed to make a decision and by fighting with pointers to pointers to structs in python (!!!), I was able to get my COM server running. Anyways, thank you a lot for your help in the past. //Jan """ import time import pywintypes import pythoncom # Load typelibs TL_OPC_DA = pythoncom.LoadRegTypeLib('{3B540B51-0378-4551-ADCC-EA9B104302BF}', 3, 0, 0) status = None for i in range(TL_OPC_DA.GetTypeInfoCount()): info = TL_OPC_DA.GetTypeInfo(i); if info.GetDocumentation(-1)[0] == "tagOPCSERVERSTATUS": print "GUID before: ", info.GetTypeAttr()[0] cti = info.QueryInterface(pythoncom.IID_ICreateTypeInfo) cti.SetGuid(pythoncom.CreateGuid()) print "GUID after: ", info.GetTypeAttr()[0] status = pythoncom.GetRecordFromTypeInfo(info) print "GOT", status break status.ftStartTime = pywintypes.Time(self.start_time) status.ftCurrentTime = pywintypes.Time(time.time()) status.ftLastUpdateTime = pywintypes.Time(self.last_update_time) status.dwServerState = ServerState.RUNNING status.dwGroupCount = len(self.groups) status.dwBandWidth = self.band_width status.wMajorVersion = MAJOR_VERSION status.wMinorVersion = MINOR_VERSION status.wBuildNumber = BUILD_NUMBER status.wReserved = 0 status.szVendorInfo = VENDOR_INFO print "Done!" """ > -----Urspr?ngliche Nachricht----- > Von: Mark Hammond [mailto:mhammond at skippinet.com.au] > Gesendet: Freitag, 30. M?rz 2012 07:30 > An: Jan Wedel > Cc: python-win32 at python.org > Betreff: Re: [python-win32] How to write a COM Server implementing interfaces > from type lib? > > It seems I *can* make this work with the pythoncom test object. > > I created a structure with no GUID in a TLB with a name StructWithoutUUID. > > Then, I used the code at the end of this message as a quick hack to try out > the SetGuid and the output is: > > """ > as expected, failed to create the record normally: The structure > 'StructWithoutUUID' is not defined in module ' GUID before: {00000000-0000-0000-0000-000000000000} > GUID after: {EFC72B2F-84D1-4474-8D91-F59928A9C13E} > GOT com_struct(int_value=0, str_value=u'') """ > > So maybe you could check the test code you used - eg, make sure the ITypeInfo > you are using is the one you expect etc. > > I probably *could* hack this into win32com to do this magically behind the > scenes, but I'm not really sure it is worthwhile - most typelibs with > structures seems to have the GUID set correctly. Let's see if it gets you any > further without any other gross hacks, and if it does, I'll rethink that. > > The code I used to test is: > """ > import sys > import win32com.client > import pythoncom > > ob = win32com.client.Dispatch("PyCOMTest.PyCOMTest") > module = sys.modules[ob.__class__.__module__] > tlb = pythoncom.LoadRegTypeLib(module.CLSID, module.MajorVersion, > module.MinorVersion, module.LCID) > > try: > rec = win32com.client.Record("StructWithoutUUID", ob) > print "Hrm - this should have failed!" > except ValueError, exc: > print "as expected, failed to create the record normally:", exc > > for i in range(tlb.GetTypeInfoCount()): > info = tlb.GetTypeInfo(i); > if info.GetDocumentation(-1)[0] == "StructWithoutUUID": > print "GUID before: ", info.GetTypeAttr()[0] > cti = info.QueryInterface(pythoncom.IID_ICreateTypeInfo) > cti.SetGuid(pythoncom.CreateGuid()) > print "GUID after: ", info.GetTypeAttr()[0] > rec = pythoncom.GetRecordFromTypeInfo(info) > print "GOT", rec > rec.int_value = 123 > > break > """ > > Cheers, > > Mark > > > On 27/03/2012 7:06 PM, Jan Wedel wrote: > > I tried the following from the console: > > > > >>> import pythoncom > > > > Get the type lib: > > > > >>> TL_OPC_DA = > > pythoncom.LoadRegTypeLib('{3B540B51-0378-4551-ADCC-EA9B104302BF}', 3, > > 0, 0) >>> TL_OPC_DA > > > > Index 8 is the record I try to create: > > > > >>> TL_OPC_DA.GetTypeInfo(8) > > >>> recinfo = > > TL_OPC_DA.GetTypeInfo(8) > > > > Cast to ICreateTypeInfo: > > > > >>> icti = recinfo.QueryInterface(pythoncom.IID_ICreateTypeInfo) > > >>> icti > > > > > > Set random GUID: > > > > >>> icti.SetGuid(pythoncom.CreateGuid()) > > > > BAM! : > > > > >>> pythoncom.GetRecordFromTypeInfo(icti) > > Traceback (most recent call last): > > File "", line 1, in > > pywintypes.com_error: (-2147024809, 'Falscher Parameter.', None, None) > > > > Try another cast because I wasn't sure that GetRecordFromTypeInfo > > supports/checks the ICreateTypeInfo interface. > > > > >>> iti = icti.QueryInterface(pythoncom.IID_ITypeInfo) > > >>> iti > > > > > > BAM! : > > > > >>> pythoncom.GetRecordFromTypeInfo(iti) > > Traceback (most recent call last): > > File "", line 1, in > > pywintypes.com_error: (-2147024809, 'Falscher Parameter.', None, None) > > > > Unfortunately, as you can see, it doesn't work. Do you know if there > > is a way to get a more verbose error message or some COM debugging > > console to know what COM is actually complaining about? I mean, I'm > > pretty sure that it works as you assumed (Like COM tries to get the > > GUID from the TypeInfo and then calls GetRecordFromGuid which would > > explain why setting a GUID still doesnt work) but just to make sure, you > know? > > > > //Jan > > > > Am 27.03.2012 00:24, schrieb Mark Hammond: > >> On 26/03/2012 8:51 PM, Jan Wedel wrote: > >>>> I'm confident the E_INVALIDARG error is coming from COM itself. It > >>> > >>>> wouldn't surprise me at all to find GetRecordInfoFromTypeInfo > >>>> simply > >>> > >>>> uses the type info to fetch the GUID of the record then calls the > >>> > >>>> ...FromGuids method. > >>> > >>> > >>> > >>> Yeah, maybe. I just tried to find some explanation and found this: > >>> > >>> http://www.autohotkey.com/forum/topic84172.html > >>> > >>> > >>> > >>> This thread seems to be related and presents a solution. As far as I > >>> understand, COM is complaining because the UUID is missing and in > >>> this solution a random GUID is created and attached to the typeinfo... > >> > >> That's interesting and might well work. It could all be done from > >> pure Python as ICreateTypeInfo is exposed. > >> > >>>> It might be possible to write all the info needed to the generated > >>>> file, > >>> > >>>> but it would probably take a fair bit of work. If you look later > >>>> in > >>> > >>>> PyRecord.cpp, all the "set attribute" and "get attribute" code is > >>> > >>>> implemented by way of the IRecordInfo interface - eg, GetFieldNoCopy. > >>> > >>>> It might be possible to steal the code from comtypes, but I'm not > >>> > >>>> familiar with that. > >>> > >>> > >>> > >>> The question is, is it necessaey to use the C++ part at all? Would it be > >>> possible to just keep the Record stuff in pure python? Why would > >>> it be necessary to dynamically loade the TypeInfo from a DLL that > >>> most likely will not change that often? > >> > >> The problem is the code that knows what "something = > >> aRecord.someAtribute" does. It needs to know how to move the memory > >> around so the right thing happens - that is what GetFieldNoCopy does. > >> > >>> The thing is, I'm currently working on a customer project and > >>> unfortunately I need this stuff getting to work soon. I would really > >>> appreciate you applying a fix to the C++ layer of pythoncom if > >>> possible at all. But I also understand that you can't spend all your > >>> spare time on that problem. > >> > >> I'd be happy to apply a fix if I knew what the fix was. From pure > >> Python, you might be able to: > >> > >> * load the typelib > >> * find the type info for the guid. > >> * QI the type info for ICreateTypeInfo. > >> * Set the GUID to some random GUID. > >> * Call pythoncom.GetRecordFromTypeInfo with the modified typeinfo. > >> * Use the result object as normal. > >> > >>> So, if it's not easy for you to fix this, could you tell me what > >>> would be necessary to fix or work-around this? My "vision" is to > >>> manually create a static definition of all relevant structs somewhere > which might > >>> be just laborious work. > >> > >> The problem is how that static info is actually used rather than the > >> generation of it. Some code will need to use that static info to > >> support getting and setting attributes on the record. > >> > >>> My problem is that I don't know much about the internals of COM. Is > >>> it possible to write a pure python class that has the correct > >>> attributes and methods so I can return an instance of this class > >>> from a COM method of my server and the receiver and COM itself would > >>> be able to interpret it as the correct struct or does it require > >>> some native code? > >> > >> It would almost certainly require some native (or ctypes) code to do > >> it all statically without an IRecordInfo interface to perform the > >> heavy lifting. > >> > >> I'll try and find time to use one of the pywin32 test objects to see > >> if this can work by dynamically setting a GUID, but it is unlikely to > >> happen for a few days. > >> > >> Cheers, > >> > >> Mark > >>> > >>> > >>> > >>> //Jan > >>> > >>> ----- Originalnachricht ----- > >>> Von: "Mark Hammond" > >>> Gesendet: Sam, 24.3.2012 00:53 > >>> An: "Jan Wedel" > >>> Betreff: Re: AW: AW: AW: AW: [python-win32] How to write a COM > >>> Server implementing interfaces from type lib? > >>> > >>> I'm confident the E_INVALIDARG error is coming from COM itself. It > >>> wouldn't surprise me at all to find GetRecordInfoFromTypeInfo simply > >>> uses the type info to fetch the GUID of the record then calls the > >>> ...FromGuids method. > >>> > >>> It might be possible to write all the info needed to the generated > >>> file, but it would probably take a fair bit of work. If you look > >>> later in PyRecord.cpp, all the "set attribute" and "get attribute" > >>> code is implemented by way of the IRecordInfo interface - eg, > GetFieldNoCopy. > >>> It might be possible to steal the code from comtypes, but I'm not > >>> familiar with that. > >>> > >>> Cheers, > >>> > >>> Mark > >>> > >>> On 24/03/2012 2:39 AM, Jan Wedel wrote: > >>>>> Obviously this is a "dynamic" process - other languages/tools etc > >>>>> are likely to use these struct definitions at compile time > >>>> > >>>> What about writing all necessary information into the generated > >>>> type lib files like comtypes is doing it? Or do you need to have > >>>> some native objects? > >>>> > >>>>> (...)it might be worth poking around the MS docs and see if they > >>>>> offer any way to get an IRecordInfo given just the typelib info > >>>>> and the struct name, as that seems the only info we have at the > >>>>> time we need it. > >>>>> If we can find something I'll try and add the support and send > >>>>> you a custom built pythoncomxx.dll. > >>>> > >>>> There is some modification of the Record method necessary. In my > >>>> server I pass an object created by GetModuleForTypelib(...) to the > >>>> Record() method. Inside, I check if its a nodule. If yes, I load > >>>> the typelib using pythoncom.LoadRegTypeLib(...) (don't know if its > >>>> already cached somewhere, but it was my quick and dirty attempt). > >>>> I've checked the MS doc and found a second method to retrieve the > >>>> Record object. Using the returned library object, I used > >>>> pythoncom.GetRecordFromTypeInfo(tlib.GetTypeInfo(8)) to retrieve > >>>> the Record from the type info object instead of GetRecordFromGuids. > >>>> > >>>> The "8" is hard coded for testing and is the library index of the > >>>> Record. If this idea could work, it's probably worth to add the > >>>> index to the "RecordMap" when generating the file so we have an > >>>> alternative look-up key instead of the GUID. > >>>> > >>>> However, it doesn't work either and gives the following result: > >>>> > >>>> Traceback (most recent call last): > >>>> File "C:\Program Files > >>>> (x86)\Python\lib\site-packages\win32com\universal.py", line 179, in > >>>> dispatch > >>>> retVal = ob._InvokeEx_(meth.dispid, 0, meth.invkind, args, > >>>> None, None) > >>>> File "C:\Program Files > >>>> (x86)\Python\lib\site-packages\win32com\server\policy.py", line > >>>> 346, in _InvokeEx_ > >>>> return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > >>>> serviceProvider) > >>>> File "C:\Program Files > >>>> (x86)\Python\lib\site-packages\win32com\server\policy.py", line > >>>> 650, in _invokeex_ > >>>> return func(*args) > >>>> File "C:\temp\opc\PyOPCComServer.py", line 241, in GetStatus > >>>> status = Record("tagOPCSERVERSTATUS", GEN_TL_OPC_DA) > >>>> File "C:\Program Files > >>>> (x86)\Python\lib\site-packages\win32com\client\__init__.py", line > >>>> 403, in Record > >>>> return pythoncom.GetRecordFromTypeInfo(tlib.GetTypeInfo(8)) > >>>> com_error: (-2147024809, 'Falscher Parameter.', None, None) > >>>> > >>>> Which means E_INVALIDARG. I've checked the source code of > >>>> PyRecord.cpp and it says "This function will fail if the specified > >>>> type info does not have a guid defined". > >>>> > >>>> I don't know if this is a COM or PythonCom limitation... If it's > >>>> the latter, I would really appreciate fixing the C++ code. > >>>> Otherwise, it might help, having the whole definition inside the > >>>> generate python file as explained above. > >>>> > >>>> Thanks a lot for your help! > >>>> > >>>> //Jan > >>>> > >>>> > >>>> ----- Originalnachricht ----- > >>>> Von: "Mark Hammond" > >>>> Gesendet: Fre, 3/23/2012 2:43pm > >>>> An: "Jan Wedel" > >>>> Betreff: Re: AW: AW: AW: [python-win32] How to write a COM Server > >>>> implementing interfaces from type lib? > >>>> > >>>> So - looking at the source, the win32com.client.Record object > >>>> attempts to look up both the tlb guid and the record guid based on > >>>> the name using that RecordMap dict we talked about. From there, we > >>>> should wind up in win32com\src\PyRecord.cpp, where we use the > >>>> typelib info and the struct GUID to call the COM function > >>>> GetRecordInfoFromGuids(), which takes those GUIDs and returns an > >>>> IRecordInfo interface that tells us all the struct element names > >>>> and types etc. > >>>> > >>>> Obviously this is a "dynamic" process - other languages/tools etc > >>>> are likely to use these struct definitions at compile time, which > >>>> may explain why they have a NULL guid - they assume people wont > >>>> need to look them up at runtime using GetRecordInfoFromGuids. It > >>>> is late and I must hit bed, but it might be worth poking around the > >>>> MS docs and see if they offer any way to get an IRecordInfo given > >>>> just the typelib info and the struct name, as that seems the only > >>>> info we have at the time we need it. > >>>> If we can find something I'll try and add the support and send > >>>> you a custom built pythoncomxx.dll. > >>>> > >>>> Cheers, > >>>> > >>>> Mark > >>>> > >>>> On 24/03/2012 12:06 AM, Jan Wedel wrote: > >>>>> I tried to manually add the Records to the generated file to see > >>>>> if patching genpy.py would solve the problem: > >>>>> > >>>>> RecordMap = { > >>>>> u'tagOPCITEMVQT': '{00000000-0000-0000-0000-000000000000}', > >>>>> u'tagOPCSERVERSTATE': '{00000000-0000-0000-0000-000000000000}', > >>>>> u'tagOPCSERVERSTATUS': > >>>>> '{00000000-0000-0000-0000-000000000000}', > >>>>> } > >>>>> > >>>>> The client calls the GetStatus() method of my server which is > >>>>> implemented as follows: > >>>>> > >>>>> def GetStatus(self): > >>>>> """Returns the current server status""" > >>>>> print "GetStatus()" > >>>>> > >>>>> # return None > >>>>> status = Record("tagOPCSERVERSTATUS", self) > >>>>> > >>>>> status.ftStartTime = pywintypes.Time(self.start_time) > >>>>> status.ftCurrentTime = pywintypes.Time(time.time()) > >>>>> status.ftLastUpdateTime = > >>>>> pywintypes.Time(self.last_update_time) > >>>>> status.dwServerState = ServerState.RUNNING > >>>>> status.dwGroupCount = len(self.groups) > >>>>> status.dwBandWidth = self.band_width > >>>>> status.wMajorVersion = MAJOR_VERSION > >>>>> status.wMinorVersion = MINOR_VERSION > >>>>> status.wBuildNumber = BUILD_NUMBER > >>>>> status.wReserved = 0 > >>>>> status.szVendorInfo = VENDOR_INFO > >>>>> > >>>>> return status > >>>>> > >>>>> with the following result: > >>>>> > >>>>> GetStatus() > >>>>> pythoncom error: Failed to call the universal dispatcher > >>>>> > >>>>> Traceback (most recent call last): > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\universal.py",line 179, in > >>>>> dispatch > >>>>> retVal = ob._InvokeEx_(meth.dispid, 0, meth.invkind, args, > >>>>> None, None) > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\server\policy.py", line > >>>>> 346, in _InvokeEx_ > >>>>> return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > >>>>> serviceProvider) > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\server\policy.py", line > >>>>> 650, in _invokeex_ > >>>>> return func(*args) > >>>>> File "C:\temp\opc\PyOPCComServer.py", line 234, in GetStatus > >>>>> status = Record("tagOPCSERVERSTATUS", self) > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\client\__init__.py", line > >>>>> 399, in Record > >>>>> object = gencache.EnsureDispatch(object) > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\client\gencache.py", line > >>>>> 529, in EnsureDispatch > >>>>> disp = win32com.client.Dispatch(prog_id) > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\client\__init__.py", line > >>>>> 96, in Dispatch > >>>>> return __WrapDispatch(dispatch, userName, resultCLSID, > >>>>> typeinfo, clsctx=clsctx) > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\client\__init__.py", line > >>>>> 43, in __WrapDispatch > >>>>> return dynamic.Dispatch(dispatch, userName, WrapperClass, > >>>>> typeinfo, clsctx=clsctx) > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\client\dynamic.py", line > >>>>> 122, in Dispatch > >>>>> typeinfo = IDispatch.GetTypeInfo() > >>>>> AttributeError: EttexOPCServer instance has no attribute 'GetTypeInfo' > >>>>> > >>>>> pythoncom error: Failed to call the universal dispatcher > >>>>> > >>>>> Traceback (most recent call last): > >>>>> File "C:\Program Files > >>>>> (x86)\Python\lib\site-packages\win32com\universal.py", > >>>>> line 195, in dispatch > >>>>> WriteFromOutTuple(retVal, meth._gw_out_args, argPtr) > >>>>> TypeError: The VARIANT type is unknown (0x4024). > >>>>> > >>>>> If found an example of how to create a Record. However, it does > >>>>> use client COM and passes the object generated by Dispatch() to > >>>>> the Record constructor. What object should I pass on the server side? > >>>>> Obviously "self" doesn't work... > >>>>> > >>>>> Then I tried to return None instead which should leave the output > >>>>> arguments untouch, but I only get the "TypeError: The VARIANT type > >>>>> is unknown (0x4024)." message. The 0x4024 is 16420 and can be > >>>>> found in the vtable definition of the generated file: > >>>>> > >>>>> IOPCServer_vtables_ = [ > >>>>> (...) > >>>>> (( u'GetStatus' , u'ppServerStatus' , ), 1610678275, > >>>>> (1610678275, (), [ (16420, 2, None, None) , ], 1 , 1 , 4 , 0 , 24 > >>>>> , (3, 0, None, None) , 0 , )), > >>>>> (...) > >>>>> > >>>>> I was asking myself how does this 16420 from the vtable gets > >>>>> translated into a "Ptr Ptr tagOPCSERVERSTATUS"? How does the > >>>>> record definition know what fields it contains? Is is probably > >>>>> necessary to add some more information to the Record such as this > >>>>> number, e.g? Or does the internal COM libs uses the TypeLib > >>>>> information to resolve it? It tried to look into the source of > >>>>> this type error but the WriteFromOutTuple method is somewhere inside the > pythoncom dll... > >>>>> > >>>>> I'm really stuck here... > >>>>> > >>>>> //Jan > >>>>> > >>>>> > >>>>> > >>>>> ----- Originalnachricht ----- > >>>>> Von: "Mark Hammond" > >>>>> Gesendet: Fre, 3/23/2012 12:11pm > >>>>> An: "Jan Wedel" > >>>>> Betreff: Re: AW: AW: [python-win32] How to write a COM Server > >>>>> implementing interfaces from type lib? > >>>>> > >>>>> I haven't got the code in front of me, but in that place it would > >>>>> probably be OK to use the name. I'm slightly worried about the > >>>>> "global" > >>>>> resolution though - there's probably code that can find a record > >>>>> given just the GUID and without regard for which tlb it was > >>>>> defined in (ie, so the name itself need not be unique). In that > >>>>> case, a tuple of (typelib_guid, name) would probably be OK. > >>>>> > >>>>> Mark > >>>>> > >>>>> On 23/03/2012 7:54 PM, Jan Wedel wrote: > >>>>>> After I wrote my last mail, I did some further research on the > >>>>>> problem. In genpy.py where the python file is generated for the > >>>>>> type lib, I found this code: > >>>>>> > >>>>>> print>> stream, 'RecordMap = {' > >>>>>> for record in recordItems.itervalues(): > >>>>>> if str(record.clsid) == pythoncom.IID_NULL: > >>>>>> print>> stream, "\t###%s: %s, # Typedef disabled > >>>>>> because it doesn't have a non-null GUID" % (repr(record.doc[0]), > >>>>>> repr(str(record.clsid))) > >>>>>> else: > >>>>>> print>> stream, "\t%s: %s," % > >>>>>> (repr(record.doc[0]), repr(str(record.clsid))) > >>>>>> print>> stream, "}" > >>>>>> > >>>>>> I've checked the typelib with COMView, and all records, modules > >>>>>> and enums defined have the UUID {00000-...00000} assigned. Then > >>>>>> I've checked some random other type libs I've found on my > >>>>>> computer and it seems that they are always using {0000...0000}. I > >>>>>> don't know much about COM but I guess this must be OK. The type > >>>>>> lib I'm using is made by the OPC foundation and there must be a > >>>>>> numerous COM clients using it so it can't be that wrong, can it? > >>>>>> > >>>>>> The question is, is it possible to create a Record object in my > >>>>>> server class and return it without the need of having a unique > >>>>>> UUID assignedand without the need of beeing defined by genyp? > >>>>>> > >>>>>> If that doesn't work, I might also try to patch the genpy.py, but > >>>>>> it seems as if you rely on the CLSID being unique. in the > >>>>>> BuildOleItemsFromType method, there is the following code: > >>>>>> > >>>>>> elif infotype == pythoncom.TKIND_RECORD or infotype == > >>>>>> pythoncom.TKIND_UNION: > >>>>>> newItem = RecordItem(info, attr, doc) > >>>>>> recordItems[newItem.clsid] = newItem > >>>>>> > >>>>>> Because all records have the same clsid, they get overwritten by > >>>>>> each other. There probably must be some other identification > >>>>>> mechanism. Either we use an index or the record name itself... > >>>>>> But then COM methods must be aware of these type in input and > >>>>>> output parameters... > >>>>>> > >>>>>> Do have any suggestion on how to proceed (patch/work-around)? > >>>>>> > >>>>>> Thanks! > >>>>>> > >>>>>> //Jan > >>>>>> > >>>>>> > >>>>>> ----- Originalnachricht ----- > >>>>>> Von: "Mark Hammond" > >>>>>> Gesendet: Fre, 3/23/2012 12:30am > >>>>>> An: "Jan Wedel" > >>>>>> Cc: python-win32 at python.org > >>>>>> Betreff: Re: AW: [python-win32] How to write a COM Server > >>>>>> implementing interfaces from type lib? > >>>>>> > >>>>>> On 23/03/2012 3:54 AM, Jan Wedel wrote: > >>>>>>> I've actually managed to patch the policy.py to allow multiple > >>>>>>> typelibraries. > >>>>>>> > >>>>>>> Instead of having a definition for interfaces, type library id, > >>>>>>> version etc i've build this into one tuple. I've created a new > >>>>>>> attribute that can have multiple of these tuples. The head of my > >>>>>>> server class now looks like this: > >>>>>>> > >>>>>>> > >>>>>>> class EttexOPCServer: _reg_progid_ = "Ettex.OPC.Automation" > >>>>>>> _reg_desc_ = "ettex OPC DA Server" _reg_clsid_ = > >>>>>>> "{13B51E8D-4BC2-4DED-8D4E-4614692F88E6}" _reg_catids_ = [ > >>>>>>> '{63D5F432-CFE4-11D1-B2C8-0060083BA1FB}' ] > >>>>>>> > >>>>>>> _typelib_interfaces_ = [ > >>>>>>> ("{3B540B51-0378-4551-ADCC-EA9B104302BF}", > >>>>>>> 3, 0, 0, [ 'IOPCServer', 'IOPCItemProperties', ] ), > >>>>>>> ("{B28EEDB1-AC6F-11D1-84D5-00608CB8A7E9}", 1, 0, 0, [ > >>>>>>> 'IOPCCommon', 'IConnectionPointContainer' ] ), ] _reg_clsctx_ = > >>>>>>> pythoncom.CLSCTX_LOCAL_SERVER > >>>>>>> > >>>>>>> I had to patch three locations in policy.py so far and I would > >>>>>>> be happy to send you my changes if you like. > >>>>>> > >>>>>> That would be great - a patch on sourceforge would be best. > >>>>>> However, it > >>>>>> might be better to wait until we are sure it is working OK :) > >>>>>> > >>>>>> > >>>>>>> However it still doesn't > >>>>>>> work but I'm not sure if I have missed something in my patch or > >>>>>>> if it is a general problem in my server code or a bug in the > >>>>>>> framework. > >>>>>>> > >>>>>>> At least, the client successfully creates the object and tries > >>>>>>> to call a method of the interface but I get the following debug > output: > >>>>>>> > >>>>>>> GetStatus() pythoncom error: Failed to call the universal > >>>>>>> dispatcher > >>>>>>> > >>>>>>> Traceback (most recent call last): File "C:\Program Files > >>>>>>> (x86)\Python\lib\site-packages\win32com\universal.py", line 195, > >>>>>>> in dispatch WriteFromOutTuple(retVal, meth._gw_out_args, argPtr) > >>>>>>> TypeError: The VARIANT type is unknown (0x4024). pythoncom error: > >>>>>>> Unexpected gateway error > >>>>>>> > >>>>>>> Traceback (most recent call last): File "C:\Program Files > >>>>>>> (x86)\Python\lib\site-packages\win32com\universal.py", line 195, > >>>>>>> in dispatch WriteFromOutTuple(retVal, meth._gw_out_args, argPtr) > >>>>>>> TypeError: The VARIANT type is unknown (0x4024). GetErrorString > >>>>>>> -2147467259 0 pythoncom error: Failed to call the universal > >>>>>>> dispatcher > >>>>>>> > >>>>>>> (...) > >>>>>>> > >>>>>>> I've hat a lookat the definition of GetStatus. It requires a > >>>>>>> pointer to a pointer of type "tagOPCSERVERSTATUS" which is a > >>>>>>> record definition in the type library. But when I look at what > >>>>>>> has been generated by makepy, the record map looks pretty empty to me: > >>>>>>> > >>>>>>> RecordMap = { u'tagOPCITEMVQT': > >>>>>>> '{00000000-0000-0000-0000-000000000000}', } > >>>>>>> > >>>>>>> The type lib defines 10 records! I tried to import the typelib > >>>>>>> using comtypes and get that generated (excerpt): > >>>>>>> > >>>>>>> class tagOPCSERVERSTATUS(Structure): pass > >>>>>>> > >>>>>>> # values for enumeration 'tagOPCSERVERSTATE' OPC_STATUS_RUNNING > >>>>>>> = 1 OPC_STATUS_FAILED = 2 OPC_STATUS_NOCONFIG = 3 > >>>>>>> OPC_STATUS_SUSPENDED = > >>>>>>> 4 OPC_STATUS_TEST = 5 OPC_STATUS_COMM_FAULT = 6 > >>>>>>> tagOPCSERVERSTATE = c_int # enum tagOPCSERVERSTATUS._fields_ = [ > >>>>>>> ('ftStartTime', _FILETIME), ('ftCurrentTime', _FILETIME), > >>>>>>> ('ftLastUpdateTime', _FILETIME), ('dwServerState', > >>>>>>> tagOPCSERVERSTATE), ('dwGroupCount', c_ulong), ('dwBandWidth', > >>>>>>> c_ulong), ('wMajorVersion', c_ushort), ('wMinorVersion', > >>>>>>> c_ushort), ('wBuildNumber', c_ushort), ('wReserved', c_ushort), > >>>>>>> ('szVendorInfo', WSTRING), ] > >>>>>>> > >>>>>>> Is there a bug in makepy that prevents creating these records? > >>>>>> > >>>>>> It would seem so :) > >>>>>> > >>>>>>> If > >>>>>>> yes, can I fix it or can I manually change the generated file to > >>>>>>> support the records? > >>>>>> > >>>>>> I'm really not sure - you probably need to look at the existing > >>>>>> Record tests. The "PyCOMTest" test object (which is in the > >>>>>> source tree and needs you to build it using MSVC) has some > >>>>>> structs for testing. > >>>>>> > >>>>>> > >>>>>>> If not, how would I create and return such a pointer of a > >>>>>>> pointer in pythoncom? Is comtypes compatible with pythoncom so I > >>>>>>> could use the comtypes generated files? > >>>>>> > >>>>>> Unfortunately there isn't any compatibility between the 2. > >>>>>> > >>>>>> Cheers, > >>>>>> > >>>>>> Mark > >>>>>>> > >>>>>>> Thanks! > >>>>>>> > >>>>>>> //Jan > >>>>>>> > >>>>>>> ----- Originalnachricht ----- Von: "Jan > >>>>>>> Wedel" > >>>>>>> Gesendet: Don, 3/22/2012 1:51pm An: mhammond at skippinet.com.au Cc: > >>>>>>> python-win32 at python.org Betreff: Re: [python-win32] How to write > >>>>>>> a COM Server implementing interfaces from type lib? > >>>>>>> > >>>>>>> Hi Mark, > >>>>>>> > >>>>>>> thanks for your reply. > >>>>>>> > >>>>>>>> That's E_FAIL which is pretty generic. Doesn't sound like a > >>>>>>>> simple failure to QI for the correct interface. > >>>>>>> > >>>>>>> Yeah. The client says something like "Unknown Error" which makes > >>>>>>> it hard to tell what the problem actually is. > >>>>>>> > >>>>>>>> win32com should be able to do this given there is a tlb - see > >>>>>>>> the "pippo" samples. Further, using the debug facilities and > >>>>>>>> win32traceutil, you should be able to see the creation of the > >>>>>>>> object, the QIs on the object and any methods actually called. > >>>>>>>> But as mentioned, I doubt it is a QI failure. > >>>>>>> > >>>>>>> Yeah, there is a type library (OPC DA). Actually there are even > >>>>>>> two type libraries, each of them contains two Interface which my > >>>>>>> server needs to implement. > >>>>>>> > >>>>>>> I've had a look into policy.py and found that: > >>>>>>> > >>>>>>> def _build_typeinfos_(self): # Can only ever be one for now. > >>>>>>> (...) > >>>>>>> > >>>>>>> which means using _typelib_guid_ allows only one type lib, > >>>>>>> right? I could try to patch your code or do you think there is a > >>>>>>> general problem that would make it impossible having more than > >>>>>>> one typelib in your framework? > >>>>>>> > >>>>>>>> Have you tried contacting the author of the object? > >>>>>>> > >>>>>>> I am the author... I only use the 3rd party typelibs. I am > >>>>>>> writing the server that must support the interfaces so that > >>>>>>> other 3rd party clients can access the server component. > >>>>>>> > >>>>>>> I can reproduce the error using python the COMView tool trying > >>>>>>> to instanciate the Server. The problem is, that I don't see why. > >>>>>>> I've enabled debugging mode when registering the server. When > >>>>>>> using one of the 3rd party clients, rhe python trace collector > >>>>>>> shows the > >>>>>>> following: > >>>>>>> > >>>>>>> Object with win32trace dispatcher created (object=None) Entering > >>>>>>> constructor in >>>>>>> 0x0213B058>._QueryInterface_ with unsupported IID > >>>>>>> {00000003-0000-0000-C000-000000000046} > >>>>>>> ({00000003-0000-0000-C000-000000000046}) > >>>>>>> in >>>>>>> 0x0213B058>._QueryInterface_ with unsupported IID > >>>>>>> {0000001B-0000-0000-C000-000000000046} > >>>>>>> ({0000001B-0000-0000-C000-000000000046}) > >>>>>>> in >>>>>>> 0x0213B058>._QueryInterface_ with unsupported IID > >>>>>>> {00000018-0000-0000-C000-000000000046} > >>>>>>> ({00000018-0000-0000-C000-000000000046}) > >>>>>>> in >>>>>>> 0x0213B058>._QueryInterface_ with unsupported IID > >>>>>>> {4C1E39E1-E3E3-4296-AA86-EC938D896E92} > >>>>>>> ({4C1E39E1-E3E3-4296-AA86-EC938D896E92}) > >>>>>>> in >>>>>>> 0x0213B058>._InvokeEx_-AddConnection(1, 0) [1,0,None] Connection > >>>>>>> added. Active connections: 1 in >>>>>>> instance at 0x0213B058>._InvokeEx_-ReleaseConnection(1, 0, 1) > >>>>>>> [1,0,None] Connection released. Active connections: 0 > >>>>>>> > >>>>>>> The QI calls are standard COM calls, not application specific > >>>>>>> (AFAIK). You can see the "Entering constructor" message which is > >>>>>>> in my python constructor of the server. Just for fun, I > >>>>>>> implemented the IExternalConnection interface to see if the methods > are called. > >>>>>>> "Connection added. ..." is my output. But I can't see an further > >>>>>>> requests that shows what the problem is. Are there any calls in > >>>>>>> pythoncom that could fail and does not give debug output? > >>>>>>> > >>>>>>> My pythoncom server starts like that: > >>>>>>> > >>>>>>> class EttexOPCServer: _reg_progid_ = "Ettex.OPC.Automation" > >>>>>>> _reg_desc_ = "ettex OPC DA Server" _reg_clsid_ = > >>>>>>> "{13B51E8D-4BC2-4DED-8D4E-4614692F88E6}" _reg_catids_ = [ > >>>>>>> '{63D5F432-CFE4-11D1-B2C8-0060083BA1FB}' ] _com_interfaces_ = [ > >>>>>>> '{00000019-0000-0000-C000-000000000046}', # IExternalConnection > >>>>>>> (Is it really mandatory?) > >>>>>>> '{39C13A4D-011E-11D0-9675-0020AFD8ADB3}', # IOPCServer > >>>>>>> '{F31DFDE2-07B6-11D2-B2D8-0060083BA1FB}', # IOPCCommon > >>>>>>> '{39C13A72-011E-11D0-9675-0020AFD8ADB3}', # IOPCItemProperties > >>>>>>> '{B196B284-BAB4-101A-B69C-00AA00341D07}' # > >>>>>>> IConnectionPointContainer ] _typelib_guid_ = > >>>>>>> "{3B540B51-0378-4551-ADCC-EA9B104302BF}" _typelib_version_ = (3, > >>>>>>> 0) _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER > >>>>>>> > >>>>>>> _public_methods_ = [ 'Connect', 'Disconnect', 'GetErrorString' > >>>>>>> ] ## IExternalConnection methods _public_methods_ += [ > >>>>>>> 'AddConnection', 'ReleaseConnection' ] > >>>>>>> > >>>>>>> ################################################################ > >>>>>>> # ## COM Class Attributes > >>>>>>> ################################################################ > >>>>>>> # _public_attrs_ = [ 'ClientName', 'OPCGroups' ] > >>>>>>> > >>>>>>> ################################################################ > >>>>>>> # ## COM Class Read-Only Attributes > >>>>>>> ################################################################ > >>>>>>> # _readonly_attrs_ = [ 'OPCGroups' ] > >>>>>>> > >>>>>>> I don't have all interface methods implemented at the time but I > >>>>>>> guess that doesn't matter as long as not all type libs have been > >>>>>>> loaded, does it? > >>>>>>> > >>>>>>> If its not possible with pythoncom, is it possible with comtypes? > >>>>>>> I've tried that as well with nearly the same result ("Unknown > >>>>>>> error"): > >>>>>>> > >>>>>>> # OPC Data Access 3.00 Type Library opc_da_tl = > >>>>>>> comtypes.GUID("{3B540B51-0378-4551-ADCC-EA9B104302BF}") # OPC > >>>>>>> Common 1.10 Type Library opc_com_tl = > >>>>>>> comtypes.GUID("{B28EEDB1-AC6F-11D1-84D5-00608CB8A7E9}") > >>>>>>> > >>>>>>> GetModule((opc_da_tl, 3, 0)) GetModule((opc_com_tl, 1, 0)) > >>>>>>> > >>>>>>> import comtypes.gen.OPCDA as OpcDa import comtypes.gen.OPCCOMN > >>>>>>> as OpcCommon > >>>>>>> > >>>>>>> class EttexOPCServer2(OpcCommon.IOPCCommon, > >>>>>>> OpcCommon.IConnectionPointContainer, OpcDa.IOPCServer, > >>>>>>> OpcDa.IOPCItemProperties): _reg_progid_ = "Ettex.OPC.Automation2" > >>>>>>> _reg_desc_ = "ettex OPC DA Server 2" _reg_novers_progid_ = > >>>>>>> _reg_progid_ _reg_clsid_ = "{80A2B8F7-792E-43F4-95F8-CD6BB4B413AD}" > >>>>>>> _reg_catids_ = [ '{63D5F432-CFE4-11D1-B2C8-0060083BA1FB}' ] > >>>>>>> _reg_clsctx_ = comtypes.CLSCTX_LOCAL_SERVER _regcls_ = > >>>>>>> comtypes.server.localserver.REGCLS_MULTIPLEUSE > >>>>>>> > >>>>>>> _com_interfaces_ = [OpcCommon.IOPCCommon, > >>>>>>> OpcCommon.IConnectionPointContainer, OpcDa.IOPCServer, > >>>>>>> OpcDa.IOPCItemProperties] > >>>>>>> > >>>>>>> I don't know what to do. Is there anything more I can do to > >>>>>>> debug to find out WHAT exactly causes the error? Because as you > >>>>>>> can see, the pythoncom debug output doesn't show this error that > >>>>>>> is returned by the client. > >>>>>>> > >>>>>>> Thanks a lot! > >>>>>>> > >>>>>>> //Jan > >>>>>>> > >>>>>>> ----- Originalnachricht ----- Von: "Mark > >>>>>>> Hammond" Gesendet: Don, 3/22/2012 > >>>>>>> 12:29pm > >>>>>>> An: "Jan Wedel" Cc: python-win32 at python.org > >>>>>>> Betreff: Re: [python-win32] How to write a COM Server > >>>>>>> implementing interfaces from type lib? > >>>>>>> > >>>>>>> On 22/03/2012 2:53 AM, Jan Wedel wrote: > >>>>>>>> Hi, > >>>>>>>> > >>>>>>>> I'm currently having trouble to write a COM-Server that has > >>>>>>>> some special requirements: - It needs to derive from IUnknown - > >>>>>>>> It needs to implement multiple interface from two different > >>>>>>>> proprietary typelibs (dlls) - It needs to implement a custom > >>>>>>>> category > >>>>>>>> > >>>>>>>> At first I started with pythoncom. I used the attribute > >>>>>>>> _reg_catids_ to specify the category and _com_interfaces_ to > >>>>>>>> specify the interfaces I want to implement. The client > >>>>>>>> (proprietary 3rd party sw, no source) sees the server but > >>>>>>>> throws some 0x80004005 error on CoCreateInstance. > >>>>>>> > >>>>>>> That's E_FAIL which is pretty generic. Doesn't sound like a > >>>>>>> simple failure to QI for the correct interface. > >>>>>>> > >>>>>>> win32com should be able to do this given there is a tlb - see > >>>>>>> the "pippo" samples. Further, using the debug facilities and > >>>>>>> win32traceutil, you should be able to see the creation of the > >>>>>>> object, the QIs on the object and any methods actually called. > >>>>>>> But as mentioned, I doubt it is a QI failure. > >>>>>>> > >>>>>>>> I was hoping that I can just tell the COM dispatcher, "yes, I > >>>>>>>> have these interface implemented" and implement the methods > >>>>>>>> without really having the interface classes available. > >>>>>>>> > >>>>>>>> I read, that pythoncom can only create components that use > >>>>>>>> IDispatch so I guess the _com_interfaces_ idea won't work, will > >>>>>>>> it? > >>>>>>> > >>>>>>> As above, you should be able to fully implement them so long as > >>>>>>> makepy has been run. > >>>>>>> > >>>>>>>> Then I did some further research and found comtypes. I tried to > >>>>>>>> write a server stub again. I used GetModule to load the type > >>>>>>>> library containing the Interfaces, importing the generated > >>>>>>>> interface classes and let the main server class extend these > >>>>>>>> interfaces. > >>>>>>>> > >>>>>>>> The first problem was, that comtypes did not support the > >>>>>>>> _reg_catids_ attribute or anything similar so I had to add the > >>>>>>>> Implemented Categories key manually to the registry. Then, I > >>>>>>>> was able to see the server through the client, which obviously > >>>>>>>> filters by categories, but it still shows the same error as before. > >>>>>>>> > >>>>>>>> So, what is the correct/best way to implement a server that > >>>>>>>> needs to implement custom interfaces and categories? Or is it > >>>>>>>> possible at all using python? > >>>>>>> > >>>>>>> The fact you get the same error there implies something else is > >>>>>>> going wrong, but it is impossible to guess what. Have you tried > >>>>>>> contacting the author of the object? > >>>>>>> > >>>>>>> Mark > >>>>>>> > >>>>>>>> > >>>>>>>> Thanks! > >>>>>>>> > >>>>>>>> //Jan > >>>>>>>> > >>>>>>>> > >>>>>>>> > >>>>>>>> _______________________________________________ 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 python at venix.com Fri Apr 20 13:42:03 2012 From: python at venix.com (Lloyd Kvam) Date: Fri, 20 Apr 2012 07:42:03 -0400 Subject: [python-win32] vb errors from Python COM object now include the traceback lines In-Reply-To: <4F90F98B.2060601@gmail.com> References: <1334867528.3782.126.camel@venix-laptop.venix.com> <1334874654.3782.152.camel@venix-laptop.venix.com> <4F90F98B.2060601@gmail.com> Message-ID: <1334922123.3782.181.camel@venix-laptop.venix.com> On Fri, 2012-04-20 at 15:52 +1000, Mark Hammond wrote: > On 20/04/2012 8:30 AM, Lloyd Kvam wrote: > > On Thu, 2012-04-19 at 16:32 -0400, Lloyd Kvam wrote: > >> I am hoping one of you can point me in the right direction. My > >> alternative appears to be (painfully) writing some VB code to discard > >> the traceback lines from Err.Description. > > Hrm - I thought it had always been the case that if you throw an > explicit COMException, then you shouldn't get the traceback - the > traceback only appears for "other" exceptions, which presumably indicate > the exception was unintended. > The COMException is the code I added. Up until now I had not translated the Python exceptions into COMExceptions. This had worked OK. > > > > I read more carefully through Python Programming on Win32 and came up > > with this code: > > > > """""""""""""""""""""""""""""""""""""""""""""""""""""""""" > > class DefaultDebugDispatcher( > > win32com.server.dispatcher.DefaultDebugDispatcher): > > def _HandleException_(self): > > excls,exself = sys.exc_info()[:2] > > if not IsCOMServerException(excls): > > raise COMException(description = str(exself), > > scode = winerror.E_INVALIDARG, > > ) > > Which seems to backup my point - IsCOMServerException() is returning > false, so the exception isn't a COMException, so you turn it into one > and avoid the traceback etc. > > Note however that you could just also raise a COMException directly from > the original point - ie, there should be no need to convert to a > COMException if a COMException is thrown in the first place. The original code is meant to run on any supported OS. It's just normal Python. I do my development work using Linux. The COM object is created by simply using a module to wrap the application into a COM object using the pywin32 services. Up until now, the Python exceptions with their error messages simply percolated up to the VB GUI. > How are you throwing the original? If you thought you were throwing a > COMException then we would want to check you actually are if you still > think so, dig into why IsCOMServerException is failing. > > Cheers, > > Mark Thank you very, very much for your efforts integrating Python and Windows. The core application is around 14,000 lines of code. The wrapper module to turn it into a COM object for deployment in Windows is just under 600 lines. -- Lloyd Kvam Venix Corp DLSLUG/GNHLUG library http://dlslug.org/library.html http://www.librarything.com/catalog/dlslug http://www.librarything.com/catalog/dlslug&sort=stamp http://www.librarything.com/rss/recent/dlslug From timr at probo.com Fri Apr 20 18:55:29 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 20 Apr 2012 09:55:29 -0700 Subject: [python-win32] Connecting to Bloomberg In-Reply-To: References: Message-ID: <4F919501.1050206@probo.com> michel.gba at derivativepartners.com wrote: > > > I want to connect to Bloomberg with Python 3.2. > > Looking on internet I found couple of programs written by diverse > authors. I implemented by It does not work. > > I followed the following steps, I included the python code and the > error messages: > > I will really appreciate if you could help me. > > ... > > Step 1 : Install Bloomberg Desktop API v3 from API download page > (file is contained in DAPI_2.zip) > > Step 2 : Download and install : ActiveState Python x86 (Key point : > not the 64-bit version) > > Step 3 : (For safety) : > Are you on a 64-bit operating system? Are you entirely sure that the Bloomberg Desktop API v3 a 32-bit service? Remember that you can ONLY call a 32-bit in-process server from a 32-bit application, and a 64-bit server from a 64-bit application. You could check in the registry. If you find an entry under HKEY_CLASSES_ROOT\blpcomapi.Session.1 then you have a 64-bit version. If you find an entry under HKEY_CLASSES_ROOT\Wow6432Node\blpcomapi.Session.1 then you have a 32-bit version. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bgailer at gmail.com Fri Apr 20 22:43:41 2012 From: bgailer at gmail.com (bob gailer) Date: Fri, 20 Apr 2012 16:43:41 -0400 Subject: [python-win32] if self.quitting: raise BdbQuit Message-ID: <4F91CA7D.6010803@gmail.com> While debugging I get: [Dbg]>>> Traceback (most recent call last): File "N:\pipelines\parsers.py", line 111, in __init__ self.parserSequence.results = self.results File "N:\pipelines\parsers.py", line 111, in __init__ self.parserSequence.results = self.results File "D:\Python27\lib\bdb.py", line 48, in trace_dispatch return self.dispatch_line(frame) File "D:\Python27\lib\bdb.py", line 67, in dispatch_line if self.quitting: raise BdbQuit BdbQuit Why? What does this mean? -- Bob Gailer 919-636-4239 Chapel Hill NC From timr at probo.com Fri Apr 20 23:29:03 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 20 Apr 2012 14:29:03 -0700 Subject: [python-win32] if self.quitting: raise BdbQuit In-Reply-To: <4F91CA7D.6010803@gmail.com> References: <4F91CA7D.6010803@gmail.com> Message-ID: <4F91D51F.7070104@probo.com> bob gailer wrote: > While debugging I get: > > [Dbg]>>> Traceback (most recent call last): > File "N:\pipelines\parsers.py", line 111, in __init__ > self.parserSequence.results = self.results > File "N:\pipelines\parsers.py", line 111, in __init__ > self.parserSequence.results = self.results > File "D:\Python27\lib\bdb.py", line 48, in trace_dispatch > return self.dispatch_line(frame) > File "D:\Python27\lib\bdb.py", line 67, in dispatch_line > if self.quitting: raise BdbQuit > BdbQuit > > Why? What does this mean? What had you typed? When the debugger encounters an unexpected error, it sets that quitting flag. Later, in several places, if that flag is set, it raises the BdbQuit exception to cause everything to exit. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From dan at dr0x.com Sat Apr 21 11:39:38 2012 From: dan at dr0x.com (Dan) Date: Sat, 21 Apr 2012 02:39:38 -0700 Subject: [python-win32] pywin32 and Windows Filtering Platform? Message-ID: <4F92805A.8030304@dr0x.com> I have been developing in python for a few years now on unix. I'm dipping my feet into the windows world and am still a total newbie as far as python and windows goes. I am curious if I can access the Windows Filtering Platform api using Python and pywin32. As best as I can tell after a few hours of research is that it is possible but I am having troubles figuring out where to begin. If anyone can help by confirming that if it is or is not possible it would be great. If it is indeed possible can someone point me to some documentation or something that might help get me started? -Dan From mail at timgolden.me.uk Sun Apr 22 19:42:44 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 22 Apr 2012 18:42:44 +0100 Subject: [python-win32] Bug in pywin32 PyIADs? Message-ID: <4F944314.4030406@timgolden.me.uk> Could someone glance at this to confirm that it does indeed seem to be a bug before I start hunting up the chain of function calls to spot the issue, please? Steps are simple: 1) Use Python 3.2 and pywin32 217 2) Use the following code (obviously substituting some suitable domain): from win32com import adsi adsi.ADsGetObject("LDAP://dc=example,dc=com", adsi.IID_IADs) 3) Receive: "TypeError: expected bytes, str found" The error appears to be in a hasattr call in _get_good_ret inside the __init__.py of the adsi subpackage. I've also seen this in another circumstance where it doesn't make sense: in an isinstance call where the first param is an PyIADs object. Further information: this doesn't happen if you don't request the IID_IADs interface (and it defaults to a wrapped IDispatch) I assume that, somewhere up the chain of attribute handling from PyIADs upwards, the ytes/str error is occurring either specifically within the pywin32 code or implicitly as it passes something to Python itself. I've eyeballed the getattro code in PyIADs.cpp but I can't see anything absolutely obvious. As it happens I don't have a build environment set up here so I'll have to build Python & then pywin32 in order to drop into the debugger. I thought I'd ask first in case anyone else could spot something which I'd missed. Thanks TJG From rupole at hotmail.com Sun Apr 22 20:34:58 2012 From: rupole at hotmail.com (Roger Upole) Date: Sun, 22 Apr 2012 14:34:58 -0400 Subject: [python-win32] Bug in pywin32 PyIADs? References: <4F944314.4030406@timgolden.me.uk> Message-ID: "Tim Golden" wrote in message news:4F944314.4030406 at timgolden.me.uk... > Could someone glance at this to confirm that it does indeed > seem to be a bug before I start hunting up the chain of > function calls to spot the issue, please? > > Steps are simple: > > 1) Use Python 3.2 and pywin32 217 > > 2) Use the following code (obviously substituting some suitable domain): > > from win32com import adsi > adsi.ADsGetObject("LDAP://dc=example,dc=com", adsi.IID_IADs) > > 3) Receive: "TypeError: expected bytes, str found" > > The error appears to be in a hasattr call in _get_good_ret > inside the __init__.py of the adsi subpackage. I've also > seen this in another circumstance where it doesn't make sense: > in an isinstance call where the first param is an PyIADs object. > > Further information: this doesn't happen if you don't request > the IID_IADs interface (and it defaults to a wrapped IDispatch) > > I assume that, somewhere up the chain of attribute handling from PyIADs upwards, the ytes/str error is occurring either > specifically within the pywin32 code or implicitly as it passes something to Python itself. > I've eyeballed the getattro code in PyIADs.cpp but I can't see anything > absolutely obvious. > > As it happens I don't have a build environment set up here so I'll > have to build Python & then pywin32 in order to drop into the debugger. > I thought I'd ask first in case anyone else could spot something > which I'd missed. > > Thanks > > TJG The problem is in this code: PyObject* PyIADs_getattro(PyObject *ob, PyObject *obname) { char *name = PyString_AsString(obname); if (!name) return NULL; It should be using PYWIN_ATTR_CONVERT on the attribute name. Roger From mail at timgolden.me.uk Sun Apr 22 21:35:57 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 22 Apr 2012 20:35:57 +0100 Subject: [python-win32] Bug in pywin32 PyIADs? In-Reply-To: <4F94503E.8020203@timgolden.me.uk> References: <4F944314.4030406@timgolden.me.uk> <4F94503E.8020203@timgolden.me.uk> Message-ID: <4F945D9D.8070200@timgolden.me.uk> .... except that a recent change to distutils has broken the pywin32 setup.py. So I'll have to dig into that first before I can rebuild pywin32 before I can retest my own module. I feel like I have a hole in my bucket.... :) TJG On 22/04/2012 19:38, Tim Golden wrote: > On 22/04/2012 19:34, Roger Upole wrote: >> >> "Tim Golden" wrote in message >> news:4F944314.4030406 at timgolden.me.uk... >>> Could someone glance at this to confirm that it does indeed >>> seem to be a bug before I start hunting up the chain of >>> function calls to spot the issue, please? >>> >>> Steps are simple: >>> >>> 1) Use Python 3.2 and pywin32 217 >>> >>> 2) Use the following code (obviously substituting some suitable domain): >>> >>> from win32com import adsi >>> adsi.ADsGetObject("LDAP://dc=example,dc=com", adsi.IID_IADs) >>> >>> 3) Receive: "TypeError: expected bytes, str found" >>> >>> The error appears to be in a hasattr call in _get_good_ret >>> inside the __init__.py of the adsi subpackage. I've also >>> seen this in another circumstance where it doesn't make sense: >>> in an isinstance call where the first param is an PyIADs object. >>> >>> Further information: this doesn't happen if you don't request >>> the IID_IADs interface (and it defaults to a wrapped IDispatch) >>> >>> I assume that, somewhere up the chain of attribute handling from >>> PyIADs upwards, the ytes/str error is occurring either >>> specifically within the pywin32 code or implicitly as it passes >>> something to Python itself. >>> I've eyeballed the getattro code in PyIADs.cpp but I can't see anything >>> absolutely obvious. >>> >>> As it happens I don't have a build environment set up here so I'll >>> have to build Python& then pywin32 in order to drop into the debugger. >>> I thought I'd ask first in case anyone else could spot something >>> which I'd missed. >>> >>> Thanks >>> >>> TJG >> >> The problem is in this code: >> PyObject* PyIADs_getattro(PyObject *ob, PyObject *obname) >> { >> char *name = PyString_AsString(obname); >> if (!name) return NULL; >> >> It should be using PYWIN_ATTR_CONVERT on the attribute name. >> > > Thanks, Roger. I'll build a patch locally. > > TJG From skippy.hammond at gmail.com Mon Apr 23 08:49:36 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 23 Apr 2012 16:49:36 +1000 Subject: [python-win32] pywin32 and Windows Filtering Platform? In-Reply-To: <4F92805A.8030304@dr0x.com> References: <4F92805A.8030304@dr0x.com> Message-ID: <4F94FB80.6060407@gmail.com> The documentation is pretty sparse - you should look at the demo file win32comext\ifilter\filterDemo.py and look at the MS docs for the gory details... HTH, Mark On 21/04/2012 7:39 PM, Dan wrote: > I have been developing in python for a few years now on unix. I'm > dipping my feet into the windows world and am still a total newbie as > far as python and windows goes. I am curious if I can access the Windows > Filtering Platform api using Python and pywin32. As best as I can tell > after a few hours of research is that it is possible but I am having > troubles figuring out where to begin. If anyone can help by confirming > that if it is or is not possible it would be great. If it is indeed > possible can someone point me to some documentation or something that > might help get me started? > > -Dan > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From michel.gba at derivativepartners.com Mon Apr 23 10:40:02 2012 From: michel.gba at derivativepartners.com (michel.gba at derivativepartners.com) Date: Mon, 23 Apr 2012 10:40:02 +0200 Subject: [python-win32] Connecting to Bloomberg In-Reply-To: <4F919501.1050206@probo.com> References: <4F919501.1050206@probo.com> Message-ID: Hi Tim and all, Thanks for your reply... I thought would be helpful looking at the error code from win32, I got. Basically, I'm getting error in the _init_.py line 85, 95, 108 and 245. See below. I got this error in all programs I try to implement win32com.client module. I'm quite new Python user and I will appreciate your kind further help. Best Regards, Michel /************************************ Errror code ******************************************/ Traceback (most recent call last): File "C:\Python32\Pythondev\minimal.py", line 12, in session = win32com.client.DispatchWithEvents('blpapicom.Session.1' , EventHandler) File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 245, in DispatchWithEvents disp = Dispatch(clsid) File "C:\Python32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python32\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221005, 'Invalid class string', None, None) /****************************minimal.py*********************************************************/ import win32com.client from pythoncom import PumpWaitingMessages from time import time class EventHandler: def OnProcessEvent(self, result)? event = win32com.client.gencache.EnsureDispatch(result) iterator = event.CreateMessageIterator() while iterator.Next(): print "EventType[%d] -> %s" % (event.EventType, iterator.Message.MessageTypeAsString,) session = win32com.client.DispatchWithEvents('blpapicom.Session.1' , EventHandler) ## Each one of these gives rise to another message session.Start() started = session.OpenService('//blp/mktdata') endTime = time() + 2 while True: PumpWaitingMessages() if endTime < time(): break /*****************************************************************************************************/ Best Regards, Michel ----------------------------------------------- Michel Gba Praktikant Derivative Partners Research AG Spl?genstrasse 10 8002 Z?rich, Schweiz tel: +41 (0) 44 515 27 79 fax: +41 (0) 43 305 05 31 mail: michel.gba at derivativepartners.com home: www.derivativepartners.com +++ all about structured products on www.payoff.ch +++ -----Original Message----- From: python-win32-bounces+michel.gba=derivativepartners.com at python.org [mailto:python-win32-bounces+michel.gba=derivativepartners.com at python.org] On Behalf Of Tim Roberts Sent: Freitag, 20. April 2012 18:55 To: Python-Win32 List Subject: Re: [python-win32] Connecting to Bloomberg michel.gba at derivativepartners.com wrote: > > > I want to connect to Bloomberg with Python 3.2. > > Looking on internet I found couple of programs written by diverse > authors. I implemented by It does not work. > > I followed the following steps, I included the python code and the > error messages: > > I will really appreciate if you could help me. > > ... > > Step 1 : Install Bloomberg Desktop API v3 from API download page > (file is contained in DAPI_2.zip) > > Step 2 : Download and install : ActiveState Python x86 (Key point : > not the 64-bit version) > > Step 3 : (For safety) : > Are you on a 64-bit operating system? Are you entirely sure that the Bloomberg Desktop API v3 a 32-bit service? Remember that you can ONLY call a 32-bit in-process server from a 32-bit application, and a 64-bit server from a 64-bit application. You could check in the registry. If you find an entry under HKEY_CLASSES_ROOT\blpcomapi.Session.1 then you have a 64-bit version. If you find an entry under HKEY_CLASSES_ROOT\Wow6432Node\blpcomapi.Session.1 then you have a 32-bit version. -- 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 timr at probo.com Mon Apr 23 19:21:49 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 23 Apr 2012 10:21:49 -0700 Subject: [python-win32] Connecting to Bloomberg In-Reply-To: References: <4F919501.1050206@probo.com> Message-ID: <4F958FAD.5020208@probo.com> michel.gba at derivativepartners.com wrote: > Hi Tim and all, > Thanks for your reply... I thought would be helpful looking at the error code from win32, I got. > Basically, I'm getting error in the _init_.py line 85, 95, 108 and 245. See below. > I got this error in all programs I try to implement win32com.client module. > I'm quite new Python user and I will appreciate your kind further help. You didn't answer any of my questions. My current theory is that you are mixing a 32-bit application with a 64-bit DLL, or vice versa. I gave you instructions on how to check that in my original reply. > Are you on a 64-bit operating system? Are you entirely sure that the Bloomberg Desktop API v3 a 32-bit service? Remember that you can ONLY call a 32-bit in-process server from a 32-bit application, and a 64-bit server from a 64-bit application. > > You could check in the registry. If you find an entry under > HKEY_CLASSES_ROOT\blpcomapi.Session.1 > then you have a 64-bit version. If you find an entry under > HKEY_CLASSES_ROOT\Wow6432Node\blpcomapi.Session.1 > then you have a 32-bit version. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From i_pelvan at hotmail.com Tue Apr 24 00:09:16 2012 From: i_pelvan at hotmail.com (Deniz Pelvan) Date: Mon, 23 Apr 2012 22:09:16 +0000 Subject: [python-win32] Silent crashes in calls to a COM object in Python Message-ID: Hello guys,I am having trouble with the Python interpreter crashing silently (no exceptions or errors thrown) when I make a call to a very CPU-intensive method in my COM/ATL component using Pywin32. The method is an FFT analysis for audio files and hits about 25% CPU on a single core and runs for about 1 minutes. I have tested the COM method intensively via normal win32 applications and there are no problems with it (I can run the same method over and over again 1000s of times in a win32 app).- Also the same Python script (with a call to this COM method) will run successfully on different machines and will fail at the same machine only randomly (i.e. on some machines, it never fails, while on others, it has ~50% failure rate).?- This specific method is the most CPU-intensive one in the COM component and other methods do not fail on any of the machines.?Because of this, I think the problem might have something to do with either the CPU usage or a timeout feature on Python or pywin32. Are there any tools that would help me narrow down the cause or maybe increase the CPU/time limits for Python/PyWin32? I haven't seen anything in the documentation that'd help.Thanks in advanceDeniz Pelvan From skippy.hammond at gmail.com Tue Apr 24 03:08:12 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 24 Apr 2012 11:08:12 +1000 Subject: [python-win32] Silent crashes in calls to a COM object in Python In-Reply-To: References: Message-ID: <4F95FCFC.9070206@gmail.com> Python and pywin32 don't impose any time limits for timeouts and I can't think of what could cause this other than (say) an exception handler in your script that ignores exceptions and terminates the process. Even if Python actually crashed I'd expect Windows to show the "app crashed" dialog. If you have MSVC you could try running the python process under it to see if it reports anything strange. Mark On 24/04/2012 8:09 AM, Deniz Pelvan wrote: > > Hello guys,I am having trouble with the Python interpreter crashing > silently (no exceptions or errors thrown) when I make a call to a > very CPU-intensive method in my COM/ATL component using Pywin32. The > method is an FFT analysis for audio files and hits about 25% CPU on a > single core and runs for about 1 minutes. I have tested the COM > method intensively via normal win32 applications and there are no > problems with it (I can run the same method over and over again 1000s > of times in a win32 app).- Also the same Python script (with a call > to this COM method) will run successfully on different machines and > will fail at the same machine only randomly (i.e. on some machines, > it never fails, while on others, it has ~50% failure rate). - This > specific method is the most CPU-intensive one in the COM component > and other methods do not fail on any of the machines. Because of > this, I think the problem might have something to do with either the > CPU usage or a timeout feature on Python or pywin32. Are there any > tools that would help me narrow down the cause or maybe increase the > CPU/time limits for Python/PyWin32? I haven't seen anything in the > documentation that'd help.Thanks in advanceDeniz Pelvan > _______________________________________________ python-win32 mailing > list python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From i_pelvan at hotmail.com Tue Apr 24 06:55:38 2012 From: i_pelvan at hotmail.com (Deniz Pelvan) Date: Tue, 24 Apr 2012 04:55:38 +0000 Subject: [python-win32] Silent crashes in calls to a COM object in Python In-Reply-To: <4F95FCFC.9070206@gmail.com> References: , <4F95FCFC.9070206@gmail.com> Message-ID: Hello Mark,As I mentioned, I ran my COM interface with another Win32 test app under a MSVC debugger for hours without any problem. I attached a debugger to the Python process but with Python, the script goes all the way to that call, waits about a minute in that call and then without throwing any exceptions or errors, the script stops running (i.e. the next line in the script never gets called) and Python drops back to the prompt. Nothing gets caught by the debugger. I was wondering if there are any options either in the Python interpreter or in pywin32 (or maybe a debug version) that can show what is happening internally, especially over the COM dispatch...Thanks in advanceDeniz > Date: Tue, 24 Apr 2012 11:08:12 +1000 > From: skippy.hammond at gmail.com > To: i_pelvan at hotmail.com > CC: python-win32 at python.org > Subject: Re: [python-win32] Silent crashes in calls to a COM object in Python > > Python and pywin32 don't impose any time limits for timeouts and I can't > think of what could cause this other than (say) an exception handler in > your script that ignores exceptions and terminates the process. Even if > Python actually crashed I'd expect Windows to show the "app crashed" > dialog. If you have MSVC you could try running the python process under > it to see if it reports anything strange. > > Mark > > On 24/04/2012 8:09 AM, Deniz Pelvan wrote: > > > > Hello guys,I am having trouble with the Python interpreter crashing > > silently (no exceptions or errors thrown) when I make a call to a > > very CPU-intensive method in my COM/ATL component using Pywin32. The > > method is an FFT analysis for audio files and hits about 25% CPU on a > > single core and runs for about 1 minutes. I have tested the COM > > method intensively via normal win32 applications and there are no > > problems with it (I can run the same method over and over again 1000s > > of times in a win32 app).- Also the same Python script (with a call > > to this COM method) will run successfully on different machines and > > will fail at the same machine only randomly (i.e. on some machines, > > it never fails, while on others, it has ~50% failure rate). - This > > specific method is the most CPU-intensive one in the COM component > > and other methods do not fail on any of the machines. Because of > > this, I think the problem might have something to do with either the > > CPU usage or a timeout feature on Python or pywin32. Are there any > > tools that would help me narrow down the cause or maybe increase the > > CPU/time limits for Python/PyWin32? I haven't seen anything in the > > documentation that'd help.Thanks in advanceDeniz Pelvan > > _______________________________________________ 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: From mhammond at skippinet.com.au Tue Apr 24 07:07:39 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 24 Apr 2012 15:07:39 +1000 Subject: [python-win32] Silent crashes in calls to a COM object in Python In-Reply-To: References: , <4F95FCFC.9070206@gmail.com> Message-ID: <4F96351B.7000107@skippinet.com.au> On 24/04/2012 2:55 PM, Deniz Pelvan wrote: > Hello Mark, > As I mentioned, I ran my COM interface with another Win32 test app under > a MSVC debugger for hours without any problem. I attached a debugger to > the Python process but with Python, the script goes all the way to that > call, waits about a minute in that call and then without throwing any > exceptions or errors, the script stops running (i.e. the next line in > the script never gets called) and Python drops back to the prompt. > Nothing gets caught by the debugger. I'm not quite with you here - I assume Python is using an inproc version of your object, so the COM call made by Python is actually a direct call into your object. In that scenario, I can't see how execution will return to Python without your object actually returning. If it is not an inproc object, then it may be that the default COM marshaller is indeed timing out, but I'm not familiar with that or under what circumstances this will happen but it might be worth looking at what "apartment" things are running in, and/or any other differences between the environment your test app runs under and that of Python. I'm also not sure what prompt you are referring to - the Python prompt or a cmdline prompt? Either way, with the debugger you should be able to see the call to IDispatch::Invoke made by Python (hrm - but sadly you will probably need to build pywin32 yourself so you get debugging symbols). If you can see that call to Invoke(), you should be able to determine if that call never returns (in which case it is almost certainly the marshaller) or if it returns with an error code or 0. There isn't much else in Python or pywin32 that can help - depending on how you construct the COM object, there are one or 2 places where the Python code calls "dispatchobject.Invoke()" (or dispatchobject.InvokeTypes()) which is basically a direct call from the interpreter into win32com/src/PyIDispatch.cpp - the debugger is the best tool for that... Mark > I was wondering if there are any options either in the Python > interpreter or in pywin32 (or maybe a debug version) that can show what > is happening internally, especially over the COM dispatch... > Thanks in advance > Deniz > > > > Date: Tue, 24 Apr 2012 11:08:12 +1000 > > From: skippy.hammond at gmail.com > > To: i_pelvan at hotmail.com > > CC: python-win32 at python.org > > Subject: Re: [python-win32] Silent crashes in calls to a COM object > in Python > > > > Python and pywin32 don't impose any time limits for timeouts and I can't > > think of what could cause this other than (say) an exception handler in > > your script that ignores exceptions and terminates the process. Even if > > Python actually crashed I'd expect Windows to show the "app crashed" > > dialog. If you have MSVC you could try running the python process under > > it to see if it reports anything strange. > > > > Mark > > > > On 24/04/2012 8:09 AM, Deniz Pelvan wrote: > > > > > > Hello guys,I am having trouble with the Python interpreter crashing > > > silently (no exceptions or errors thrown) when I make a call to a > > > very CPU-intensive method in my COM/ATL component using Pywin32. The > > > method is an FFT analysis for audio files and hits about 25% CPU on a > > > single core and runs for about 1 minutes. I have tested the COM > > > method intensively via normal win32 applications and there are no > > > problems with it (I can run the same method over and over again 1000s > > > of times in a win32 app).- Also the same Python script (with a call > > > to this COM method) will run successfully on different machines and > > > will fail at the same machine only randomly (i.e. on some machines, > > > it never fails, while on others, it has ~50% failure rate). - This > > > specific method is the most CPU-intensive one in the COM component > > > and other methods do not fail on any of the machines. Because of > > > this, I think the problem might have something to do with either the > > > CPU usage or a timeout feature on Python or pywin32. Are there any > > > tools that would help me narrow down the cause or maybe increase the > > > CPU/time limits for Python/PyWin32? I haven't seen anything in the > > > documentation that'd help.Thanks in advanceDeniz Pelvan > > > _______________________________________________ python-win32 mailing > > > list python-win32 at python.org > > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > > > From i_pelvan at hotmail.com Tue Apr 24 23:14:31 2012 From: i_pelvan at hotmail.com (Deniz Pelvan) Date: Tue, 24 Apr 2012 21:14:31 +0000 Subject: [python-win32] Silent crashes in calls to a COM object in Python In-Reply-To: <4F96351B.7000107@skippinet.com.au> References: , <4F95FCFC.9070206@gmail.com> , <4F96351B.7000107@skippinet.com.au> Message-ID: Hello again Mark,I am not sure what you mean by direct call? The COM object is loaded inproc (i.e. the COM object is not in a service proc and I don't see any temp processes created by python or pywin32) but I thought you were using the IDispatch interface to find and load the dll & object rather than a direct interface call (which would require type library etc. knowledge). As for the test app, it is not using the IDispatch interface so the IDispatch might be causing trouble.The prompt I mentioned is the Python interpreter prompt, btw. I will try to dig deeper into the python interpreter with the debugger and see if there is anything else I can catch.?Thanks for the helpDeniz ---------------------------------------- > Date: Tue, 24 Apr 2012 15:07:39 +1000 > From: mhammond at skippinet.com.au > To: i_pelvan at hotmail.com > CC: python-win32 at python.org > Subject: Re: [python-win32] Silent crashes in calls to a COM object in Python > > On 24/04/2012 2:55 PM, Deniz Pelvan wrote: > > Hello Mark, > > As I mentioned, I ran my COM interface with another Win32 test app under > > a MSVC debugger for hours without any problem. I attached a debugger to > > the Python process but with Python, the script goes all the way to that > > call, waits about a minute in that call and then without throwing any > > exceptions or errors, the script stops running (i.e. the next line in > > the script never gets called) and Python drops back to the prompt. > > Nothing gets caught by the debugger. > > I'm not quite with you here - I assume Python is using an inproc version > of your object, so the COM call made by Python is actually a direct call > into your object. In that scenario, I can't see how execution will > return to Python without your object actually returning. > > If it is not an inproc object, then it may be that the default COM > marshaller is indeed timing out, but I'm not familiar with that or under > what circumstances this will happen but it might be worth looking at > what "apartment" things are running in, and/or any other differences > between the environment your test app runs under and that of Python. > > I'm also not sure what prompt you are referring to - the Python prompt > or a cmdline prompt? Either way, with the debugger you should be able > to see the call to IDispatch::Invoke made by Python (hrm - but sadly you > will probably need to build pywin32 yourself so you get debugging > symbols). If you can see that call to Invoke(), you should be able to > determine if that call never returns (in which case it is almost > certainly the marshaller) or if it returns with an error code or 0. > > There isn't much else in Python or pywin32 that can help - depending on > how you construct the COM object, there are one or 2 places where the > Python code calls "dispatchobject.Invoke()" (or > dispatchobject.InvokeTypes()) which is basically a direct call from the > interpreter into win32com/src/PyIDispatch.cpp - the debugger is the best > tool for that... > > Mark > > > > I was wondering if there are any options either in the Python > > interpreter or in pywin32 (or maybe a debug version) that can show what > > is happening internally, especially over the COM dispatch... > > Thanks in advance > > Deniz > > > > > > > Date: Tue, 24 Apr 2012 11:08:12 +1000 > > > From: skippy.hammond at gmail.com > > > To: i_pelvan at hotmail.com > > > CC: python-win32 at python.org > > > Subject: Re: [python-win32] Silent crashes in calls to a COM object > > in Python > > > > > > Python and pywin32 don't impose any time limits for timeouts and I can't > > > think of what could cause this other than (say) an exception handler in > > > your script that ignores exceptions and terminates the process. Even if > > > Python actually crashed I'd expect Windows to show the "app crashed" > > > dialog. If you have MSVC you could try running the python process under > > > it to see if it reports anything strange. > > > > > > Mark > > > > > > On 24/04/2012 8:09 AM, Deniz Pelvan wrote: > > > > > > > > Hello guys,I am having trouble with the Python interpreter crashing > > > > silently (no exceptions or errors thrown) when I make a call to a > > > > very CPU-intensive method in my COM/ATL component using Pywin32. The > > > > method is an FFT analysis for audio files and hits about 25% CPU on a > > > > single core and runs for about 1 minutes. I have tested the COM > > > > method intensively via normal win32 applications and there are no > > > > problems with it (I can run the same method over and over again 1000s > > > > of times in a win32 app).- Also the same Python script (with a call > > > > to this COM method) will run successfully on different machines and > > > > will fail at the same machine only randomly (i.e. on some machines, > > > > it never fails, while on others, it has ~50% failure rate). - This > > > > specific method is the most CPU-intensive one in the COM component > > > > and other methods do not fail on any of the machines. Because of > > > > this, I think the problem might have something to do with either the > > > > CPU usage or a timeout feature on Python or pywin32. Are there any > > > > tools that would help me narrow down the cause or maybe increase the > > > > CPU/time limits for Python/PyWin32? I haven't seen anything in the > > > > documentation that'd help.Thanks in advanceDeniz Pelvan > > > > _______________________________________________ python-win32 mailing > > > > list python-win32 at python.org > > > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > > > > > > > > From skippy.hammond at gmail.com Wed Apr 25 02:11:17 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 25 Apr 2012 10:11:17 +1000 Subject: [python-win32] Silent crashes in calls to a COM object in Python In-Reply-To: References: , <4F95FCFC.9070206@gmail.com> , <4F96351B.7000107@skippinet.com.au> Message-ID: <4F974125.9010202@gmail.com> On 25/04/2012 7:14 AM, Deniz Pelvan wrote: > > Hello again Mark,I am not sure what you mean by direct call? The COM > object is loaded inproc (i.e. the COM object is not in a service proc > and I don't see any temp processes created by python or pywin32) but > I thought you were using the IDispatch interface to find and load the > dll & object rather than a direct interface call (which would require > type library etc. knowledge). IDispatch is just an interface like any other. If you call an inproc interface, you are making a normal direct call across DLLs, almost as if you had linked to the DLL directly - just the mechanics of that "linking" change. > As for the test app, it is not using > the IDispatch interface so the IDispatch might be causing trouble. This sounds very likely. > The > prompt I mentioned is the Python interpreter prompt, btw. So it sounds like one of your IDispatch interfaces is prematurely returning S_OK - ie, nothing is crashing but your method is just returning before you expect it. Mark I will try > to dig deeper into the python interpreter with the debugger and see > if there is anything else I can catch. Thanks for the helpDeniz > ---------------------------------------- >> Date: Tue, 24 Apr 2012 15:07:39 +1000 From: >> mhammond at skippinet.com.au To: i_pelvan at hotmail.com CC: >> python-win32 at python.org Subject: Re: [python-win32] Silent crashes >> in calls to a COM object in Python >> >> On 24/04/2012 2:55 PM, Deniz Pelvan wrote: >>> Hello Mark, As I mentioned, I ran my COM interface with another >>> Win32 test app under a MSVC debugger for hours without any >>> problem. I attached a debugger to the Python process but with >>> Python, the script goes all the way to that call, waits about a >>> minute in that call and then without throwing any exceptions or >>> errors, the script stops running (i.e. the next line in the >>> script never gets called) and Python drops back to the prompt. >>> Nothing gets caught by the debugger. >> >> I'm not quite with you here - I assume Python is using an inproc >> version of your object, so the COM call made by Python is actually >> a direct call into your object. In that scenario, I can't see how >> execution will return to Python without your object actually >> returning. >> >> If it is not an inproc object, then it may be that the default COM >> marshaller is indeed timing out, but I'm not familiar with that or >> under what circumstances this will happen but it might be worth >> looking at what "apartment" things are running in, and/or any other >> differences between the environment your test app runs under and >> that of Python. >> >> I'm also not sure what prompt you are referring to - the Python >> prompt or a cmdline prompt? Either way, with the debugger you >> should be able to see the call to IDispatch::Invoke made by Python >> (hrm - but sadly you will probably need to build pywin32 yourself >> so you get debugging symbols). If you can see that call to >> Invoke(), you should be able to determine if that call never >> returns (in which case it is almost certainly the marshaller) or if >> it returns with an error code or 0. >> >> There isn't much else in Python or pywin32 that can help - >> depending on how you construct the COM object, there are one or 2 >> places where the Python code calls "dispatchobject.Invoke()" (or >> dispatchobject.InvokeTypes()) which is basically a direct call from >> the interpreter into win32com/src/PyIDispatch.cpp - the debugger is >> the best tool for that... >> >> Mark >> >> >>> I was wondering if there are any options either in the Python >>> interpreter or in pywin32 (or maybe a debug version) that can >>> show what is happening internally, especially over the COM >>> dispatch... Thanks in advance Deniz >>> >>> >>>> Date: Tue, 24 Apr 2012 11:08:12 +1000 From: >>>> skippy.hammond at gmail.com To: i_pelvan at hotmail.com CC: >>>> python-win32 at python.org Subject: Re: [python-win32] Silent >>>> crashes in calls to a COM object >>> in Python >>>> >>>> Python and pywin32 don't impose any time limits for timeouts >>>> and I can't think of what could cause this other than (say) an >>>> exception handler in your script that ignores exceptions and >>>> terminates the process. Even if Python actually crashed I'd >>>> expect Windows to show the "app crashed" dialog. If you have >>>> MSVC you could try running the python process under it to see >>>> if it reports anything strange. >>>> >>>> Mark >>>> >>>> On 24/04/2012 8:09 AM, Deniz Pelvan wrote: >>>>> >>>>> Hello guys,I am having trouble with the Python interpreter >>>>> crashing silently (no exceptions or errors thrown) when I >>>>> make a call to a very CPU-intensive method in my COM/ATL >>>>> component using Pywin32. The method is an FFT analysis for >>>>> audio files and hits about 25% CPU on a single core and runs >>>>> for about 1 minutes. I have tested the COM method intensively >>>>> via normal win32 applications and there are no problems with >>>>> it (I can run the same method over and over again 1000s of >>>>> times in a win32 app).- Also the same Python script (with a >>>>> call to this COM method) will run successfully on different >>>>> machines and will fail at the same machine only randomly >>>>> (i.e. on some machines, it never fails, while on others, it >>>>> has ~50% failure rate). - This specific method is the most >>>>> CPU-intensive one in the COM component and other methods do >>>>> not fail on any of the machines. Because of this, I think the >>>>> problem might have something to do with either the CPU usage >>>>> or a timeout feature on Python or pywin32. Are there any >>>>> tools that would help me narrow down the cause or maybe >>>>> increase the CPU/time limits for Python/PyWin32? I haven't >>>>> seen anything in the documentation that'd help.Thanks in >>>>> advanceDeniz Pelvan >>>>> _______________________________________________ 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 reckoner at gmail.com Sat Apr 28 18:21:46 2012 From: reckoner at gmail.com (reckoner) Date: Sat, 28 Apr 2012 09:21:46 -0700 Subject: [python-win32] PumpMessages in main thread called by embedded Python causes crash Message-ID: <4F9C191A.5040103@gmail.com> I have written some code that catches windows events that also includes the usual PumpMessages, and all of this works fine when I run it from the Python interpreter (Python version 2.6). However, when a separate application that has Python embedded calls the same code, the calling application crashes. I have tracked this down to the PumpMessages call in my code. My question is why does this work perfectly well from the interpreter, but cause a crash when called from the embedded Python running in a separate application. Note that I don't have access to the separate application in which the Python call is embedded and when it crashes it does not provide any kind of traceback. It took a long time to narrow it down to the PumpMessages call. Any advice appreciated. I am really stuck here. By the way, this is on Windows XP 32-bit. Thanks! From skippy.hammond at gmail.com Sun Apr 29 07:15:50 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sun, 29 Apr 2012 15:15:50 +1000 Subject: [python-win32] PumpMessages in main thread called by embedded Python causes crash In-Reply-To: <4F9C191A.5040103@gmail.com> References: <4F9C191A.5040103@gmail.com> Message-ID: <4F9CCE86.3080909@gmail.com> I don't know why it crashes exactly, but if the other app has its own event loop then things are going to get screwey - PumpMessages never returns (well, not until a WM_QUIT message is received), so their event loop will never run. I'd guess that their event loop and event handlers have some assumptions built in to it - eg, they might be assuming that their event loop as set something up that one of the message handlers relies on. You running your own event loop will prevent that setup from happening so one of their handlers will crash. Does that app work OK if you don't call PumpMessages? If so, a work around might be to check if you have a console, and if you don't, assume some other event loop must be running. Mark On 29/04/2012 2:21 AM, reckoner wrote: > > I have written some code that catches windows events that also includes > the usual PumpMessages, and all of this works fine when I run it from > the Python interpreter (Python version 2.6). However, when a separate > application that has Python embedded calls the same code, the calling > application crashes. I have tracked this down to the PumpMessages call > in my code. > > My question is why does this work perfectly well from the interpreter, > but cause a crash when called from the embedded Python running in a > separate application. Note that I don't have access to the separate > application in which the Python call is embedded and when it crashes it > does not provide any kind of traceback. It took a long time to narrow > it down to the PumpMessages call. > > Any advice appreciated. I am really stuck here. By the way, this is on > Windows XP 32-bit. > > Thanks! > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From reckoner at gmail.com Sun Apr 29 17:07:40 2012 From: reckoner at gmail.com (reckoner) Date: Sun, 29 Apr 2012 08:07:40 -0700 Subject: [python-win32] PumpMessages in main thread called by embedded Python causes crash In-Reply-To: <4F9CCE86.3080909@gmail.com> References: <4F9C191A.5040103@gmail.com> <4F9CCE86.3080909@gmail.com> Message-ID: <4F9D593C.2010503@gmail.com> Thanks for your reply. Yes, the app works fine if I don't PumpMessages in my own code. There is no console that the application fires up when it runs the embedded Python code. In this situation, how do I (or, can I?) pump for my own messages if the application is doing some other kind of event loop, as you describe? Thanks! On Saturday, April 28, 2012 10:15:50 PM, Mark Hammond wrote: > I don't know why it crashes exactly, but if the other app has its own > event loop then things are going to get screwey - PumpMessages never > returns (well, not until a WM_QUIT message is received), so their event > loop will never run. > > I'd guess that their event loop and event handlers have some assumptions > built in to it - eg, they might be assuming that their event loop as set > something up that one of the message handlers relies on. You running > your own event loop will prevent that setup from happening so one of > their handlers will crash. > > Does that app work OK if you don't call PumpMessages? If so, a work > around might be to check if you have a console, and if you don't, assume > some other event loop must be running. > > Mark > > On 29/04/2012 2:21 AM, reckoner wrote: >> >> I have written some code that catches windows events that also includes >> the usual PumpMessages, and all of this works fine when I run it from >> the Python interpreter (Python version 2.6). However, when a separate >> application that has Python embedded calls the same code, the calling >> application crashes. I have tracked this down to the PumpMessages call >> in my code. >> >> My question is why does this work perfectly well from the interpreter, >> but cause a crash when called from the embedded Python running in a >> separate application. Note that I don't have access to the separate >> application in which the Python call is embedded and when it crashes it >> does not provide any kind of traceback. It took a long time to narrow >> it down to the PumpMessages call. >> >> Any advice appreciated. I am really stuck here. By the way, this is on >> Windows XP 32-bit. >> >> Thanks! >> >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> http://mail.python.org/mailman/listinfo/python-win32 > > From mhammond at skippinet.com.au Mon Apr 30 00:48:58 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 30 Apr 2012 08:48:58 +1000 Subject: [python-win32] PumpMessages in main thread called by embedded Python causes crash In-Reply-To: <4F9D593C.2010503@gmail.com> References: <4F9C191A.5040103@gmail.com> <4F9CCE86.3080909@gmail.com> <4F9D593C.2010503@gmail.com> Message-ID: <4F9DC55A.2000101@skippinet.com.au> On 30/04/2012 1:07 AM, reckoner wrote: > Thanks for your reply. > > Yes, the app works fine if I don't PumpMessages in my own code. There is > no console that the application fires up when it runs the embedded > Python code. In this situation, how do I (or, can I?) pump for my own > messages if the application is doing some other kind of event loop, as > you describe? The event loop isn't generally where you handle messages - messages are generally handled in a WndProc or similar (ie, by using something like win32gui and its message handling support). You might also want to look into hooking messages (pythonwin has some support for that, and another package called PyHook might also help). Mark > > Thanks! > > > > On Saturday, April 28, 2012 10:15:50 PM, Mark Hammond wrote: >> I don't know why it crashes exactly, but if the other app has its own >> event loop then things are going to get screwey - PumpMessages never >> returns (well, not until a WM_QUIT message is received), so their event >> loop will never run. >> >> I'd guess that their event loop and event handlers have some assumptions >> built in to it - eg, they might be assuming that their event loop as set >> something up that one of the message handlers relies on. You running >> your own event loop will prevent that setup from happening so one of >> their handlers will crash. >> >> Does that app work OK if you don't call PumpMessages? If so, a work >> around might be to check if you have a console, and if you don't, assume >> some other event loop must be running. >> >> Mark >> >> On 29/04/2012 2:21 AM, reckoner wrote: >>> >>> I have written some code that catches windows events that also includes >>> the usual PumpMessages, and all of this works fine when I run it from >>> the Python interpreter (Python version 2.6). However, when a separate >>> application that has Python embedded calls the same code, the calling >>> application crashes. I have tracked this down to the PumpMessages call >>> in my code. >>> >>> My question is why does this work perfectly well from the interpreter, >>> but cause a crash when called from the embedded Python running in a >>> separate application. Note that I don't have access to the separate >>> application in which the Python call is embedded and when it crashes it >>> does not provide any kind of traceback. It took a long time to narrow >>> it down to the PumpMessages call. >>> >>> Any advice appreciated. I am really stuck here. By the way, this is on >>> Windows XP 32-bit. >>> >>> Thanks! >>> >>> _______________________________________________ >>> python-win32 mailing list >>> python-win32 at python.org >>> http://mail.python.org/mailman/listinfo/python-win32 >> >> From reckoner at gmail.com Mon Apr 30 02:49:57 2012 From: reckoner at gmail.com (reckoner) Date: Sun, 29 Apr 2012 17:49:57 -0700 Subject: [python-win32] PumpMessages in main thread called by embedded Python causes crash In-Reply-To: <4F9DC55A.2000101@skippinet.com.au> References: <4F9C191A.5040103@gmail.com> <4F9CCE86.3080909@gmail.com> <4F9D593C.2010503@gmail.com> <4F9DC55A.2000101@skippinet.com.au> Message-ID: <4F9DE1B5.9010101@gmail.com> On 4/29/2012 3:48 PM, Mark Hammond wrote: > On 30/04/2012 1:07 AM, reckoner wrote: >> Thanks for your reply. >> >> Yes, the app works fine if I don't PumpMessages in my own code. There is >> no console that the application fires up when it runs the embedded >> Python code. In this situation, how do I (or, can I?) pump for my own >> messages if the application is doing some other kind of event loop, as >> you describe? > > The event loop isn't generally where you handle messages - messages are > generally handled in a WndProc or similar (ie, by using something like > win32gui and its message handling support). You might also want to look > into hooking messages (pythonwin has some support for that, and another > package called PyHook might also help). > > Mark >> Yes, I use PyHook on another project, but here I need to hook more than mouse and keyboard messages. I need window-open/close, etc. According to this thread: http://stackoverflow.com/questions/6458812/python-ctypes-setwindowshookex-callback-function-never-called this is not possible directly and I have been successful using the pyAA (Microsoft Active Accessibility) bindings to catch these other messages, and this works beautifully otherwise, except for this case where the embedded application (not a GUI, BTW) will not let me pump messages to flush out the events that pyAA can catch. Any other ideas? The only other idea I have is to create a separate Python process that will listen for specific messages using pyAA and then return output on a socket that the application's embedded Python can later query. Thanks again. (I read your great book by the way!) From mhammond at skippinet.com.au Mon Apr 30 02:51:03 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 30 Apr 2012 10:51:03 +1000 Subject: [python-win32] PumpMessages in main thread called by embedded Python causes crash In-Reply-To: <4F9DE1B5.9010101@gmail.com> References: <4F9C191A.5040103@gmail.com> <4F9CCE86.3080909@gmail.com> <4F9D593C.2010503@gmail.com> <4F9DC55A.2000101@skippinet.com.au> <4F9DE1B5.9010101@gmail.com> Message-ID: <4F9DE1F7.4060904@skippinet.com.au> I'm afraid my only other idea is to contact the vendor of the other app and see if they can shed any light on the problem... Cheers, Mark On 30/04/2012 10:49 AM, reckoner wrote: > > > On 4/29/2012 3:48 PM, Mark Hammond wrote: >> On 30/04/2012 1:07 AM, reckoner wrote: >>> Thanks for your reply. >>> >>> Yes, the app works fine if I don't PumpMessages in my own code. There is >>> no console that the application fires up when it runs the embedded >>> Python code. In this situation, how do I (or, can I?) pump for my own >>> messages if the application is doing some other kind of event loop, as >>> you describe? >> >> The event loop isn't generally where you handle messages - messages are >> generally handled in a WndProc or similar (ie, by using something like >> win32gui and its message handling support). You might also want to look >> into hooking messages (pythonwin has some support for that, and another >> package called PyHook might also help). >> >> Mark >>> > > Yes, I use PyHook on another project, but here I need to hook more than > mouse and keyboard messages. I need window-open/close, etc. According to > this thread: > > http://stackoverflow.com/questions/6458812/python-ctypes-setwindowshookex-callback-function-never-called > > > this is not possible directly and I have been successful using the pyAA > (Microsoft Active Accessibility) bindings to catch these other messages, > and this works beautifully otherwise, except for this case where the > embedded application (not a GUI, BTW) will not let me pump messages to > flush out the events that pyAA can catch. > > Any other ideas? The only other idea I have is to create a separate > Python process that will listen for specific messages using pyAA and > then return output on a socket that the application's embedded Python > can later query. > > Thanks again. (I read your great book by the way!) > > > > > From arvind.kamble at gmail.com Mon Apr 30 09:03:52 2012 From: arvind.kamble at gmail.com (Aravind Kamble) Date: Mon, 30 Apr 2012 12:33:52 +0530 Subject: [python-win32] Win32api install problem Message-ID: Hi All, I am trying to install pywin32-217 for the first time on my Windows 7 64 bit machine. I have following installed on my machine, Python 2.7.3 MS Windows SDK for Windows 7 (7.1) Downloaded pywin32-217 from sourceforge When I run the setup.py as below c:\pywin32-217\python setup.py install I am getting following error Building pywin32 2.7.217.0 Traceback (most recent call last): File "setup.py", line 2428, in ] + File "setup.py", line 2224, in convert_data_files raise RuntimeError("No files match '%s'" % file) RuntimeError: No files match 'pythonwin\pywin\*.cfg' There are two .cfg files (default.cfg and IDLE.cfg) under pythonwin\pywin\. Please help how to get rid of this error and continue with installation. Regards Aravind -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Apr 30 09:41:42 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Apr 2012 08:41:42 +0100 Subject: [python-win32] Win32api install problem In-Reply-To: References: Message-ID: On 30/04/2012 08:03, Aravind Kamble wrote: > Hi All, > > I am trying to install pywin32-217 for the first time on my Windows 7 64 > bit machine. I have following installed on my machine, > > Python 2.7.3 > MS Windows SDK for Windows 7 (7.1) The SDK isn't usually needed. > Downloaded pywin32-217 from sourceforge Hopefully in this case either pywin32-217.win-amd64-py2.7.exe or pywin32-217.win32-py2.7.exe as appropriate :) See below. > > > When I run the setup.py as below > c:\pywin32-217\python setup.py install I've never needed to do this. Usually you would download the appropriate version of pywin32 as given above and It Just Works when you install, automatically finding your version of Python from the registry. > > I am getting following error > > Building pywin32 2.7.217.0 > Traceback (most recent call last): > File "setup.py", line 2428, in > ] + > File "setup.py", line 2224, in convert_data_files > raise RuntimeError("No files match '%s'" % file) > RuntimeError: No files match 'pythonwin\pywin\*.cfg' > > There are two .cfg files (default.cfg and IDLE.cfg) under pythonwin\pywin\. > > Please help how to get rid of this error and continue with installation. If my comments above don't help sorry, you'll have to wait until the smarter Windows guys pick this one up, doesn't normally take too long :) > > > Regards > Aravind > > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 -- Cheers. Mark Lawrence. From mail at timgolden.me.uk Mon Apr 30 09:42:06 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 30 Apr 2012 08:42:06 +0100 Subject: [python-win32] Win32api install problem In-Reply-To: References: Message-ID: <4F9E424E.5020600@timgolden.me.uk> On 30/04/2012 08:03, Aravind Kamble wrote: > Hi All, > > I am trying to install pywin32-217 for the first time on my Windows 7 64 > bit machine. I have following installed on my machine, > > Python 2.7.3 > MS Windows SDK for Windows 7 (7.1) > Downloaded pywin32-217 from sourceforge > > > When I run the setup.py as below > c:\pywin32-217\python setup.py install > > I am getting following error > > Building pywin32 2.7.217.0 > Traceback (most recent call last): > File "setup.py", line 2428, in > ] + > File "setup.py", line 2224, in convert_data_files > raise RuntimeError("No files match '%s'" % file) > RuntimeError: No files match 'pythonwin\pywin\*.cfg' > > There are two .cfg files (default.cfg and IDLE.cfg) under pythonwin\pywin\. > > Please help how to get rid of this error and continue with installation. Do you have / want to build from source? If not, download one of the binaries from Sourceforge and use that. If you do need to build from source, you'll have to patch the setup.py in the pywin32 sourceball to add a parameter anchor=0 to the calls to include_pattern and exclude_pattern within the convert_data_files function. (I was just about to get in touch with Mark H and offer a patch but I won't have time to do the mechanics until this afternoon at the earliest...) FWIW this is due to a recent-ish change to distutils which fixed a longstanding bugette. The effect was to tighten up the action of include|exclude_pattern calls so that they don't match against directory strings unless anchor is set to 0. Again, though, unless you *want* to build from source, you can just download a binary build. TJG From skippy.hammond at gmail.com Mon Apr 30 09:50:52 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 30 Apr 2012 17:50:52 +1000 Subject: [python-win32] Win32api install problem In-Reply-To: <4F9E424E.5020600@timgolden.me.uk> References: <4F9E424E.5020600@timgolden.me.uk> Message-ID: <4F9E445C.1020307@gmail.com> On 30/04/2012 5:42 PM, Tim Golden wrote: > On 30/04/2012 08:03, Aravind Kamble wrote: >> Hi All, >> >> I am trying to install pywin32-217 for the first time on my Windows 7 64 >> bit machine. I have following installed on my machine, >> >> Python 2.7.3 >> MS Windows SDK for Windows 7 (7.1) >> Downloaded pywin32-217 from sourceforge >> >> >> When I run the setup.py as below >> c:\pywin32-217\python setup.py install >> >> I am getting following error >> >> Building pywin32 2.7.217.0 >> Traceback (most recent call last): >> File "setup.py", line 2428, in >> ] + >> File "setup.py", line 2224, in convert_data_files >> raise RuntimeError("No files match '%s'" % file) >> RuntimeError: No files match 'pythonwin\pywin\*.cfg' >> >> There are two .cfg files (default.cfg and IDLE.cfg) under pythonwin\pywin\. >> >> Please help how to get rid of this error and continue with installation. > > Do you have / want to build from source? If not, download one > of the binaries from Sourceforge and use that. If you do need > to build from source, you'll have to patch the setup.py in > the pywin32 sourceball to add a parameter anchor=0 to the calls > to include_pattern and exclude_pattern within the convert_data_files > function. > > (I was just about to get in touch with Mark H and offer a patch but > I won't have time to do the mechanics until this afternoon at the > earliest...) Thanks for the clue - I just updated Python 2.7 from hg, verified the bug and also verified your fix seems to work. I've checked it in and pushed it. Thanks! Mark > > FWIW this is due to a recent-ish change to distutils which fixed a > longstanding bugette. The effect was to tighten up the action of > include|exclude_pattern calls so that they don't match against > directory strings unless anchor is set to 0. > > Again, though, unless you *want* to build from source, you can just > download a binary build. > > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From mail at timgolden.me.uk Mon Apr 30 09:56:22 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 30 Apr 2012 08:56:22 +0100 Subject: [python-win32] Win32api install problem In-Reply-To: <4F9E445C.1020307@gmail.com> References: <4F9E424E.5020600@timgolden.me.uk> <4F9E445C.1020307@gmail.com> Message-ID: <4F9E45A6.2000906@timgolden.me.uk> On 30/04/2012 08:50, Mark Hammond wrote: > On 30/04/2012 5:42 PM, Tim Golden wrote: >> (I was just about to get in touch with Mark H and offer a patch but >> I won't have time to do the mechanics until this afternoon at the >> earliest...) > > Thanks for the clue - I just updated Python 2.7 from hg, verified the > bug and also verified your fix seems to work. I've checked it in and > pushed it. Thanks for the quick turnaround. FWIW there appear to be other issues against Python trunk due to the *very* recent importlib changes. Before I dive in: are you able to build & install against Python's hg tip? I was getting an importlib error when trying to import pywintypes. I'll try to get a build environment up here (at work) to make sure I can reproduce. TJG From skippy.hammond at gmail.com Mon Apr 30 12:15:04 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 30 Apr 2012 20:15:04 +1000 Subject: [python-win32] Win32api install problem In-Reply-To: <4F9E45A6.2000906@timgolden.me.uk> References: <4F9E424E.5020600@timgolden.me.uk> <4F9E445C.1020307@gmail.com> <4F9E45A6.2000906@timgolden.me.uk> Message-ID: <4F9E6628.8090708@gmail.com> On 30/04/2012 5:56 PM, Tim Golden wrote: > On 30/04/2012 08:50, Mark Hammond wrote: >> On 30/04/2012 5:42 PM, Tim Golden wrote: >>> (I was just about to get in touch with Mark H and offer a patch but >>> I won't have time to do the mechanics until this afternoon at the >>> earliest...) >> >> Thanks for the clue - I just updated Python 2.7 from hg, verified the >> bug and also verified your fix seems to work. I've checked it in and >> pushed it. > > Thanks for the quick turnaround. FWIW there appear to be other issues > against Python trunk due to the *very* recent importlib changes. Before > I dive in: are you able to build & install against Python's hg tip? Haven't tried - I just tried the 2.7 branch. > I was getting an importlib error when trying to import pywintypes. > I'll try to get a build environment up here (at work) to make sure > I can reproduce. Hrmph - I'm not that surprised about that actually; pywintypes.py already is a hack built on a hack - hopefully it should turn out to be fairly shallow - but I might not get to it for a few days... Thanks! Mark > > > TJG >