From ALONMA at il.ibm.com Wed May 1 15:02:43 2013 From: ALONMA at il.ibm.com (Alon Marx) Date: Wed, 1 May 2013 16:02:43 +0300 Subject: [python-win32] AUTO: Alon Marx is out of the office (returning 06/05/2013) Message-ID: I am out of the office until 06/05/2013. I will be on vacation on May 1-5 (Wednesday to Sunday), with no internet connection and limited phone connection. For any urgent issues please contact Ohad. Note: This is an automated response to your message "python-win32 Digest, Vol 122, Issue 1" sent on 01/05/2013 13:00:04. This is the only notification you will receive while this person is away. From roeckeg at co.thurston.wa.us Thu May 2 19:11:34 2013 From: roeckeg at co.thurston.wa.us (NWViking) Date: Thu, 2 May 2013 10:11:34 -0700 (PDT) Subject: [python-win32] Unable to install PyWin32 with Python 2.6.2 and 2.6.3 In-Reply-To: <166165.58186.qm@web56402.mail.re3.yahoo.com> References: <166165.58186.qm@web56402.mail.re3.yahoo.com> Message-ID: <1367514694519-5015887.post@n6.nabble.com> I found this solution on stackoverflow: Had the above noted errors with my python27 pywin32 installation that got installed after my installation of ArcGIS on a windows2008 R2 server (trying to centralize our scripts). Found that for me, I had to start a command line window with run as adminstrator (right click to get that option in windows) and then run the following command line from the c:\arcpy27\arcgis10.1>python c:/arcpy27/arcgis10.1/scripts/pywin32_postinstall.py -install I see a lot of people have run into this issue and I tried multiple things, but this was finally the solution that managed to get pywin32 installed. Thanks so much for your solution. Took me a couple of install and uninstalls before I finally ran across your solution and modified it for my version. -- View this message in context: http://python.6.x6.nabble.com/Unable-to-install-PyWin32-with-Python-2-6-2-and-2-6-3-tp1956312p5015887.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From michaelwtsn4 at gmail.com Sat May 4 00:04:39 2013 From: michaelwtsn4 at gmail.com (Michael Watson) Date: Fri, 3 May 2013 18:04:39 -0400 Subject: [python-win32] Memory Leak in Threaded COM Object Message-ID: I am creating a COM client within a thread and performing several operations with this client. Each thread is spawned from a server that uses Python's socketserver module which has built-in threading support. When I am loading and using this COM object there is an expected spike in memory usage by python.exe. With 10 concurrent threads there is a peak in memory usage of about 500Mb. However when the operations are finished and the COM object is apparently released, there are 50Mb of additional memory used by the process than before. If I then spawn 10 additional threads using the same server there are 13Mb additional used by python.exe after those COM objects are closed. Eventually every 10 additional concurrent threads adds approximately 6Mb after they are done. When I end the entire python.exe process, all the memory is released. I have simplified the following code to mimic how the socketserver uses threadding and the problem is the exact same. import win32com.clientimport threadingimport pythoncom def CreateTom(): pythoncom.CoInitialize() tom = win32com.client.Dispatch("TOM.Document") tom.Dataset.Load("FileName") tom.Clear() pythoncom.CoUninitialize() for i in range(50): t = threading.Thread(target = CreateTom) t.daemon = False t.start() I understand that I will unlikely get any support here around the specific COM library (it is an IBM product used in Market Research known as the TablesObjectModel). However I want to know if there is anything, ANYTHING, additional that I can do to release this memory. I have read about Apartments in COM but it sounds like pythoncom.CoInitialize should take care of this for me. Any help would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Andrew.MacIntyre at acma.gov.au Mon May 6 03:01:24 2013 From: Andrew.MacIntyre at acma.gov.au (Andrew MacIntyre) Date: Mon, 6 May 2013 01:01:24 +0000 Subject: [python-win32] Memory Leak in Threaded COM Object [SEC=UNOFFICIAL] In-Reply-To: References: Message-ID: Stab in the dark: after calling the Clear() method on object "tom" in method CreateTom, use "del tom" or "tom = None" to try and lose any remnant COM references before pythoncom.CoUninitialize() is called. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre Operations Branch tel: +61 2 6219 5356 Communications Infrastructure Division fax: +61 2 6253 3277 Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au http://www.acma.gov.au/ From: python-win32 [mailto:python-win32-bounces+andrew.macintyre=acma.gov.au at python.org] On Behalf Of Michael Watson Sent: Saturday, 4 May 2013 8:05 AM To: python-win32 at python.org Subject: [python-win32] Memory Leak in Threaded COM Object I am creating a COM client within a thread and performing several operations with this client. Each thread is spawned from a server that uses Python's socketserver module which has built-in threading support. When I am loading and using this COM object there is an expected spike in memory usage by python.exe. With 10 concurrent threads there is a peak in memory usage of about 500Mb. However when the operations are finished and the COM object is apparently released, there are 50Mb of additional memory used by the process than before. If I then spawn 10 additional threads using the same server there are 13Mb additional used by python.exe after those COM objects are closed. Eventually every 10 additional concurrent threads adds approximately 6Mb after they are done. When I end the entire python.exe process, all the memory is released. I have simplified the following code to mimic how the socketserver uses threadding and the problem is the exact same. import win32com.client import threading import pythoncom def CreateTom(): pythoncom.CoInitialize() tom = win32com.client.Dispatch("TOM.Document") tom.Dataset.Load("FileName") tom.Clear() pythoncom.CoUninitialize() for i in range(50): t = threading.Thread(target = CreateTom) t.daemon = False t.start() I understand that I will unlikely get any support here around the specific COM library (it is an IBM product used in Market Research known as the TablesObjectModel). However I want to know if there is anything, ANYTHING, additional that I can do to release this memory. I have read about Apartments in COM but it sounds like pythoncom.CoInitialize should take care of this for me. Any help would be appreciated. NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From michaelwtsn4 at gmail.com Mon May 6 17:15:19 2013 From: michaelwtsn4 at gmail.com (Michael Watson) Date: Mon, 6 May 2013 11:15:19 -0400 Subject: [python-win32] python-win32 Digest, Vol 122, Issue 5 In-Reply-To: References: Message-ID: Thank you. I have tried both del() and setting the value to None. Neither worked. On May 6, 2013 6:25 AM, wrote: > Send python-win32 mailing list submissions to > python-win32 at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-win32 > or, via email, send a message with subject or body 'help' to > python-win32-request at python.org > > You can reach the person managing the list at > python-win32-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of python-win32 digest..." > > > Today's Topics: > > 1. Re: Memory Leak in Threaded COM Object [SEC=UNOFFICIAL] > (Andrew MacIntyre) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 6 May 2013 01:01:24 +0000 > From: "Andrew MacIntyre" > To: "python-win32 at python.org" > Subject: Re: [python-win32] Memory Leak in Threaded COM Object > [SEC=UNOFFICIAL] > Message-ID: > > > > Content-Type: text/plain; charset="us-ascii" > > Stab in the dark: after calling the Clear() method on object "tom" in > method CreateTom, use "del tom" or "tom = None" to try and lose any remnant > COM references before pythoncom.CoUninitialize() is called. > > -------------------------> "These thoughts are mine alone!" <--------- > Andrew MacIntyre Operations Branch > tel: +61 2 6219 5356 Communications Infrastructure Division > fax: +61 2 6253 3277 Australian Communications & Media Authority > email: andrew.macintyre at acma.gov.au > http://www.acma.gov.au/ > > From: python-win32 [mailto:python-win32-bounces+andrew.macintyre= > acma.gov.au at python.org] On Behalf Of Michael Watson > Sent: Saturday, 4 May 2013 8:05 AM > To: python-win32 at python.org > Subject: [python-win32] Memory Leak in Threaded COM Object > > > I am creating a COM client within a thread and performing several > operations with this client. Each thread is spawned from a server that uses > Python's socketserver module which has built-in threading support. > > When I am loading and using this COM object there is an expected spike in > memory usage by python.exe. With 10 concurrent threads there is a peak in > memory usage of about 500Mb. However when the operations are finished and > the COM object is apparently released, there are 50Mb of additional memory > used by the process than before. If I then spawn 10 additional threads > using the same server there are 13Mb additional used by python.exe after > those COM objects are closed. Eventually every 10 additional concurrent > threads adds approximately 6Mb after they are done. When I end the entire > python.exe process, all the memory is released. > > I have simplified the following code to mimic how the socketserver uses > threadding and the problem is the exact same. > > import win32com.client > > import threading > > import pythoncom > > > > def CreateTom(): > > pythoncom.CoInitialize() > > tom = win32com.client.Dispatch("TOM.Document") > > tom.Dataset.Load("FileName") > > tom.Clear() > > pythoncom.CoUninitialize() > > > > for i in range(50): > > t = threading.Thread(target = CreateTom) > > t.daemon = False > > t.start() > > I understand that I will unlikely get any support here around the specific > COM library (it is an IBM product used in Market Research known as the > TablesObjectModel). However I want to know if there is anything, ANYTHING, > additional that I can do to release this memory. I have read about > Apartments in COM but it sounds like pythoncom.CoInitialize should take > care of this for me. Any help would be appreciated. > > NOTICE: This email message is for the sole use of the intended recipient(s) > and may contain confidential and privileged information. Any unauthorized > review, use, disclosure or distribution is prohibited. If you are not the > intended recipient, please contact the sender by reply email and destroy > all > copies of the original message. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/python-win32/attachments/20130506/219c365e/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > ------------------------------ > > End of python-win32 Digest, Vol 122, Issue 5 > ******************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Tue May 7 02:41:52 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 07 May 2013 10:41:52 +1000 Subject: [python-win32] Memory Leak in Threaded COM Object In-Reply-To: References: Message-ID: <51884DD0.1040603@gmail.com> On 4/05/2013 8:04 AM, Michael Watson wrote: > I am creating a COM client within a thread and performing several > operations with this client. Each thread is spawned from a server that > uses Python's |socketserver| module which has built-in threading support. > > When I am loading and using this COM object there is an expected spike > in memory usage by python.exe. With 10 concurrent threads there is a > peak in memory usage of about 500Mb. However when the operations are > finished and the COM object is apparently released, there are 50Mb of > additional memory used by the process than before. If I then spawn 10 > additional threads using the same server there are 13Mb additional used > by python.exe after those COM objects are closed. Eventually every 10 > additional concurrent threads adds approximately 6Mb after they are > done. When I end the entire python.exe process, all the memory is released. > > I have simplified the following code to mimic how the socketserver uses > |threadding| and the problem is the exact same. > > |import win32com.client > import threading > import pythoncom > > def CreateTom(): > pythoncom.CoInitialize() > tom= win32com.client.Dispatch("TOM.Document") > tom.Dataset.Load("FileName") > tom.Clear() > pythoncom.CoUninitialize() > > for iin range(50): > t= threading.Thread(target= CreateTom) > t.daemon= False > t.start()| > > I understand that I will unlikely get any support here around the > specific COM library (it is an IBM product used in Market Research known > as the TablesObjectModel). However I want to know if there is anything, > ANYTHING, additional that I can do to release this memory. I have read > about Apartments in COM but it sounds like pythoncom.CoInitialize should > take care of this for me. Any help would be appreciated. You say that deleting the object itself doesn't work in your test-case - so the problem may turn out to be in the COM object itself. To determine if this is the case, it might be worth seeing if you can reproduce the problem with other COM objects - even Python implemented ones. If the object itself leaks, you should also be able to show this increased memory usage simply by performing the same steps in sequence rather than simultaneously. HTH, Mark From ckkart at hoc.net Wed May 8 15:29:38 2013 From: ckkart at hoc.net (Christian K.) Date: Wed, 8 May 2013 13:29:38 +0000 (UTC) Subject: [python-win32] how to create a instance of PyIMAPISession by hand Message-ID: The following code has been suggested to me to get a handle to Outlook's mapi session. from win32com.client import Dispatch from win32com.mapi import mapi app = Dispatch('Outlook.Application') app.GetNamespace('MAPI').Session.MAPIOBJECT The MAPIOBJECT would then have to be cast to a IMAPISession object. How would I do that? By calling the PyIMAPISesison constructor with MAPIOBJECT as argument? Unfortunately I was not able to find the PyIMAPISession class in the pywin32 namespace nor when digging through the source. Any hints are very much appreciated. Christian From skippy.hammond at gmail.com Wed May 8 15:59:15 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 08 May 2013 23:59:15 +1000 Subject: [python-win32] how to create a instance of PyIMAPISession by hand In-Reply-To: References: Message-ID: <518A5A33.3080900@gmail.com> On 8/05/2013 11:29 PM, Christian K. wrote: > > The following code has been suggested to me to get a handle to Outlook's > mapi session. > > > from win32com.client import Dispatch > from win32com.mapi import mapi > app = Dispatch('Outlook.Application') > app.GetNamespace('MAPI').Session.MAPIOBJECT > > The MAPIOBJECT would then have to be cast to a IMAPISession object. How > would I do that? By calling the PyIMAPISesison constructor with MAPIOBJECT > as argument? Unfortunately I was not able to find the PyIMAPISession class > in the pywin32 namespace nor when digging through the source. > > It should be something like: from win32com.mapi import mapi session = app.GetNamespace('MAPI').Session.MAPIOBJECT.QueryInterface(mapi.IID_IMAPISession) Note that a good resource for working with MAPI from pywin32 is the spambayes project, and particularly: https://github.com/smontanaro/spambayes/blob/master/spambayes/Outlook2000/msgstore.py For reasons that escape me now, it does things differently - after creating the Outlook.app object, it does: mapi.MAPIInitialize(None) logonFlags = (mapi.MAPI_NO_MAIL | mapi.MAPI_EXTENDED | mapi.MAPI_USE_DEFAULT) self.session = mapi.MAPILogonEx(0, None, None, logonFlags) to get the session. Note however that that code was written against Office 2000, so some things - especially work-arounds etc - may well have changed HTH, Mark From cyrfer at gmail.com Thu May 9 17:54:35 2013 From: cyrfer at gmail.com (John Grant) Date: Thu, 9 May 2013 08:54:35 -0700 Subject: [python-win32] hook to obtain WM_GESTURE Message-ID: Hi, I would like to obtain multi-touch events in my Python code (running inside Blender's python environment). I have looked around the web for a python module that works with py 3.3 (others work with py 2.x), but I have not found one. So, I'm trying to build one. I believe I can use the 'ctypes' to call the function I need, GetGestureInfo. This function requires 2 parameters as input, the lParam from WndProc and a pointer to the GESTUREINFO structure. * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my python code.* I see it is possible to pass structures as pointers using ctypes as well. *** The problem seems to be obtaining the lParam from WndProc. *** My idea is to provide a callback function (again using ctypes to declare this callback) and use the SetWindowsHookEx function, passing my callback and the WH_CALLWNDPROC hook ID. Does this sound like it will work? I read somewhere that my callback needs to be in a DLL. I'm not sure if the Blender python environment will count as existing in a DLL. I hope I will not need to learn how to build a python module from a C DLL just to put the callback in a DLL. I signed up for the ML here because it seems like this is the best place for Windows expertise concerning Python. I saw a few emails on this list about hooks and callbacks. I've used the IDE with pywin32 for years - its the best! Many thanks for any help on this critical task for my 1st python consulting gig. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu May 9 18:46:49 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 9 May 2013 09:46:49 -0700 Subject: [python-win32] hook to obtain WM_GESTURE In-Reply-To: References: Message-ID: <518BD2F9.2000908@probo.com> John Grant wrote: > > I would like to obtain multi-touch events in my Python code (running > inside Blender's python environment). I have looked around the web for > a python module that works with py 3.3 (others work with py 2.x), but > I have not found one. So, I'm trying to build one. > > I believe I can use the 'ctypes' to call the function I need, > GetGestureInfo. That gets you gestures, but not multitouch. If all you need is the zoom, pan and rotate gestures and a two-finger tap, this will do it. For more complicated gestures, most solutions are custom right now. > This function requires 2 parameters as input, the lParam from WndProc > and a pointer to the GESTUREINFO structure. > > * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my > python code.* > I see it is possible to pass structures as pointers using ctypes as well. The structure doesn't have any pointers, so this should be straightforward. > *** The problem seems to be obtaining the lParam from WndProc. *** > > My idea is to provide a callback function (again using ctypes to > declare this callback) and use the SetWindowsHookEx function, passing > my callback and the WH_CALLWNDPROC hook ID. > > Does this sound like it will work? No, a Windows hook is the wrong answer. That lets you intercept messages from other processes (which is why hooks need to be in a DLL -- the DLL actually gets copied and injected into the processes being hooked). In your case, I assume you're trying to intercept gestures in a window within your own process. Is that right? As long as you have the window handle, all you need to do is subclass the window. That means you make yourself the wndproc for that window, so you get first shot at all the messages. Here's an example that shows how to do this in wxPython, but you can eliminate the wxPython part of it. The key point is using win32gui.SetWindowLong to load your own function in win32con.GWL_WNDPROC, and remembering the return value so you can call the original function. http://wiki.wxpython.org/HookingTheWndProc -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cyrfer at gmail.com Thu May 9 20:13:08 2013 From: cyrfer at gmail.com (John Grant) Date: Thu, 9 May 2013 11:13:08 -0700 Subject: [python-win32] hook to obtain WM_GESTURE In-Reply-To: <518BD2F9.2000908@probo.com> References: <518BD2F9.2000908@probo.com> Message-ID: Hi Tim, Thanks for the great explanations. Yes, you are right, I am trying to intercept gestures in a window within the same process. The Blender application framework has a WndProc in C, and Blender supports extending itself with user-supplied Python scripts. I am trying to add gesture support with Python so I can avoid modifying the Blender C code. I'm reading through the wxPython article. It looks like a perfect fit for my problem. It shows everything I need to do, and using ctypes! Thanks! Although, I am stuck trying to get the HWND from Blender. It seems they have not exposed the handle yet. I'm looking for win32 API that might provide it to me, or a list of windows associated with the process. I guess I have to remove my callback as soon as the WM_DESTROY message is emitted, and reinstantiate the oldWndProc. That makes sense. I'm glad that is shown in the article. I just browsed the Blender C source code and they also use "SetWindowLongPtr" for GWLP_USERDATA, but not for GWLP_WNDPROC. I think everything will work out fine when I find the HWND. Thanks for the expert help. John On Thu, May 9, 2013 at 9:46 AM, Tim Roberts wrote: > John Grant wrote: > > > > I would like to obtain multi-touch events in my Python code (running > > inside Blender's python environment). I have looked around the web for > > a python module that works with py 3.3 (others work with py 2.x), but > > I have not found one. So, I'm trying to build one. > > > > I believe I can use the 'ctypes' to call the function I need, > > GetGestureInfo. > > That gets you gestures, but not multitouch. If all you need is the > zoom, pan and rotate gestures and a two-finger tap, this will do it. > For more complicated gestures, most solutions are custom right now. > > > > This function requires 2 parameters as input, the lParam from WndProc > > and a pointer to the GESTUREINFO structure. > > > > * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my > > python code.* > > I see it is possible to pass structures as pointers using ctypes as well. > > The structure doesn't have any pointers, so this should be straightforward. > > > > *** The problem seems to be obtaining the lParam from WndProc. *** > > > > My idea is to provide a callback function (again using ctypes to > > declare this callback) and use the SetWindowsHookEx function, passing > > my callback and the WH_CALLWNDPROC hook ID. > > > > Does this sound like it will work? > > No, a Windows hook is the wrong answer. That lets you intercept > messages from other processes (which is why hooks need to be in a DLL -- > the DLL actually gets copied and injected into the processes being > hooked). In your case, I assume you're trying to intercept gestures in > a window within your own process. Is that right? As long as you have > the window handle, all you need to do is subclass the window. That > means you make yourself the wndproc for that window, so you get first > shot at all the messages. > > Here's an example that shows how to do this in wxPython, but you can > eliminate the wxPython part of it. The key point is using > win32gui.SetWindowLong to load your own function in > win32con.GWL_WNDPROC, and remembering the return value so you can call > the original function. > http://wiki.wxpython.org/HookingTheWndProc > > -- > 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 cyrfer at gmail.com Thu May 9 22:52:17 2013 From: cyrfer at gmail.com (John Grant) Date: Thu, 9 May 2013 13:52:17 -0700 Subject: [python-win32] hook to obtain WM_GESTURE In-Reply-To: References: <518BD2F9.2000908@probo.com> Message-ID: I believe found access to the HWND. mHWND = ctypes.windll.user32.GetActiveWindow() On Thu, May 9, 2013 at 11:13 AM, John Grant wrote: > Hi Tim, > > Thanks for the great explanations. > > Yes, you are right, I am trying to intercept gestures in a window within > the same process. The Blender application framework has a WndProc in C, and > Blender supports extending itself with user-supplied Python scripts. I am > trying to add gesture support with Python so I can avoid modifying the > Blender C code. > > I'm reading through the wxPython article. It looks like a perfect fit for > my problem. It shows everything I need to do, and using ctypes! Thanks! > > Although, I am stuck trying to get the HWND from Blender. It seems they > have not exposed the handle yet. I'm looking for win32 API that might > provide it to me, or a list of windows associated with the process. > > I guess I have to remove my callback as soon as the WM_DESTROY message is > emitted, and reinstantiate the oldWndProc. That makes sense. I'm glad that > is shown in the article. > > I just browsed the Blender C source code and they also use > "SetWindowLongPtr" for GWLP_USERDATA, but not for GWLP_WNDPROC. I think > everything will work out fine when I find the HWND. > > Thanks for the expert help. > John > > > On Thu, May 9, 2013 at 9:46 AM, Tim Roberts wrote: > >> John Grant wrote: >> > >> > I would like to obtain multi-touch events in my Python code (running >> > inside Blender's python environment). I have looked around the web for >> > a python module that works with py 3.3 (others work with py 2.x), but >> > I have not found one. So, I'm trying to build one. >> > >> > I believe I can use the 'ctypes' to call the function I need, >> > GetGestureInfo. >> >> That gets you gestures, but not multitouch. If all you need is the >> zoom, pan and rotate gestures and a two-finger tap, this will do it. >> For more complicated gestures, most solutions are custom right now. >> >> >> > This function requires 2 parameters as input, the lParam from WndProc >> > and a pointer to the GESTUREINFO structure. >> > >> > * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my >> > python code.* >> > I see it is possible to pass structures as pointers using ctypes as >> well. >> >> The structure doesn't have any pointers, so this should be >> straightforward. >> >> >> > *** The problem seems to be obtaining the lParam from WndProc. *** >> > >> > My idea is to provide a callback function (again using ctypes to >> > declare this callback) and use the SetWindowsHookEx function, passing >> > my callback and the WH_CALLWNDPROC hook ID. >> > >> > Does this sound like it will work? >> >> No, a Windows hook is the wrong answer. That lets you intercept >> messages from other processes (which is why hooks need to be in a DLL -- >> the DLL actually gets copied and injected into the processes being >> hooked). In your case, I assume you're trying to intercept gestures in >> a window within your own process. Is that right? As long as you have >> the window handle, all you need to do is subclass the window. That >> means you make yourself the wndproc for that window, so you get first >> shot at all the messages. >> >> Here's an example that shows how to do this in wxPython, but you can >> eliminate the wxPython part of it. The key point is using >> win32gui.SetWindowLong to load your own function in >> win32con.GWL_WNDPROC, and remembering the return value so you can call >> the original function. >> http://wiki.wxpython.org/HookingTheWndProc >> >> -- >> 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 cyrfer at gmail.com Fri May 10 02:12:57 2013 From: cyrfer at gmail.com (John Grant) Date: Thu, 9 May 2013 17:12:57 -0700 Subject: [python-win32] hook to obtain WM_GESTURE In-Reply-To: References: <518BD2F9.2000908@probo.com> Message-ID: Hi Tim, et al, I am testing the ctypes technique to intercept messages for my process, as Tim pointed out I need to do using the SetWindowsLongPtr function. I am seeing slightly unexpected results. My goal was to make a pass-through implementation, so my callback does not disrupt the application. I wanted to print to the shell to show my callback was involved. I am seeing print statements, but the behavior of the application is slightly different. Reverse mouse wheel seems to behave differently in the application. Also, sometimes I see an exception in the shell (OSError: exception...access violation reading 0xblahblah). Does anyone see an error with the way I am calling the "oldWndProc" or the print statement in the code below? Maybe the way I have defined the return argument for SetWindowLongPtrW is incorrect? Thanks for any help, John from ctypes import * import ctypes import ctypes.wintypes from ctypes import c_long, c_int # some shortcut definitions GetActiveWindow = windll.user32.GetActiveWindow GetActiveWindow.restype = ctypes.wintypes.HWND LRESULT = ctypes.wintypes.LPARAM WNDPROC = WINFUNCTYPE(LRESULT, ctypes.wintypes.HWND, ctypes.wintypes.UINT, ctypes.wintypes.WPARAM, ctypes.wintypes.LPARAM) SetWindowLongPtrW = ctypes.windll.user32.SetWindowLongPtrW SetWindowLongPtrW.restype = WNDPROC CallWindowProc = ctypes.windll.user32.CallWindowProcW CallWindowProc.restype = LRESULT #proc type GWL_WNDPROC = int(-4) #msg types in case we need them WM_DESTROY = int('0x0002', 16) WM_KEYDOWN = int('0x0100', 16) WM_SIZE = int('0x0005', 16) WM_CLOSE = int('0x0010', 16) WM_GESTURE = int('0x0119', 16) WM_TOUCH = int('0x0240', 16) WM_GESTURENOTIFY = int('0x011A', 16) WM_TIMER = int('0x0113', 16) WM_MOUSEMOVE = int('0x0200', 16) WM_MOUSEWHEEL = int('0x020A', 16) WM_KEYUP = int('0x0101', 16) WM_KEYDOWN = int('0x0101', 16) # middle mouse button from GetAsyncKeyState() VK_MBUTTON = int('0x04',16) # ---- Multi Touch Support Class --- # # you should have only one instance of this class per OS window, # because it adds a member function as the Windows message handler for the hWnd passed. class MTHandler(object): def __init__(self, hWnd): self.mHWND = hWnd self.newWndProc = WNDPROC(self.MyWndProc) self.oldWndProc = SetWindowLongPtrW(self.mHWND, GWL_WNDPROC, self.newWndProc) self.inControl = True def _mouse_handler(self, msg, wParam, lParam): print('hello mouse move') def _gesture_handler(msg, wParam, lParam): print('hello gesture') def _touch_handler(msg, wParam, lParam): print('hello touch') def MyWndProc(self, hWnd, msg, wParam, lParam): print('hello wndproc', msg, wParam, lParam) #if (msg == WM_MOUSEMOVE) or (msg==WM_MOUSEWHEEL): # _mouse_handler(msg, wParam, lParam) #elif msg == WM_GESTURE: # _gesture_handler(msg, wParam, lParam) #elif msg == WM_TOUCH: # _touch_handler(msg, wParam, lParam) # source: # http://wiki.wxpython.org/HookingTheWndProc # # Restore the old WndProc. Notice the use of wxin32api # instead of win32gui here. This is to avoid an error due to # not passing a callable object. if msg == WM_CLOSE: if self.inControl: self.cleanup() if msg == WM_DESTROY: if self.inControl: self.cleanup() return CallWindowProc(self.oldWndProc, self.mHWND, msg, wParam, lParam) def cleanup(self): SetWindowLongPtrW(self.mHWND, GWL_WNDPROC, self.oldWndProc) self.inControl = False def __del__(self): if self.inControl: self.cleanup() # ---- end Multi Touch Support Class --- # On Thu, May 9, 2013 at 1:52 PM, John Grant wrote: > I believe found access to the HWND. > mHWND = ctypes.windll.user32.GetActiveWindow() > > > > On Thu, May 9, 2013 at 11:13 AM, John Grant wrote: > >> Hi Tim, >> >> Thanks for the great explanations. >> >> Yes, you are right, I am trying to intercept gestures in a window within >> the same process. The Blender application framework has a WndProc in C, and >> Blender supports extending itself with user-supplied Python scripts. I am >> trying to add gesture support with Python so I can avoid modifying the >> Blender C code. >> >> I'm reading through the wxPython article. It looks like a perfect fit for >> my problem. It shows everything I need to do, and using ctypes! Thanks! >> >> Although, I am stuck trying to get the HWND from Blender. It seems they >> have not exposed the handle yet. I'm looking for win32 API that might >> provide it to me, or a list of windows associated with the process. >> >> I guess I have to remove my callback as soon as the WM_DESTROY message is >> emitted, and reinstantiate the oldWndProc. That makes sense. I'm glad that >> is shown in the article. >> >> I just browsed the Blender C source code and they also use >> "SetWindowLongPtr" for GWLP_USERDATA, but not for GWLP_WNDPROC. I think >> everything will work out fine when I find the HWND. >> >> Thanks for the expert help. >> John >> >> >> On Thu, May 9, 2013 at 9:46 AM, Tim Roberts wrote: >> >>> John Grant wrote: >>> > >>> > I would like to obtain multi-touch events in my Python code (running >>> > inside Blender's python environment). I have looked around the web for >>> > a python module that works with py 3.3 (others work with py 2.x), but >>> > I have not found one. So, I'm trying to build one. >>> > >>> > I believe I can use the 'ctypes' to call the function I need, >>> > GetGestureInfo. >>> >>> That gets you gestures, but not multitouch. If all you need is the >>> zoom, pan and rotate gestures and a two-finger tap, this will do it. >>> For more complicated gestures, most solutions are custom right now. >>> >>> >>> > This function requires 2 parameters as input, the lParam from WndProc >>> > and a pointer to the GESTUREINFO structure. >>> > >>> > * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my >>> > python code.* >>> > I see it is possible to pass structures as pointers using ctypes as >>> well. >>> >>> The structure doesn't have any pointers, so this should be >>> straightforward. >>> >>> >>> > *** The problem seems to be obtaining the lParam from WndProc. *** >>> > >>> > My idea is to provide a callback function (again using ctypes to >>> > declare this callback) and use the SetWindowsHookEx function, passing >>> > my callback and the WH_CALLWNDPROC hook ID. >>> > >>> > Does this sound like it will work? >>> >>> No, a Windows hook is the wrong answer. That lets you intercept >>> messages from other processes (which is why hooks need to be in a DLL -- >>> the DLL actually gets copied and injected into the processes being >>> hooked). In your case, I assume you're trying to intercept gestures in >>> a window within your own process. Is that right? As long as you have >>> the window handle, all you need to do is subclass the window. That >>> means you make yourself the wndproc for that window, so you get first >>> shot at all the messages. >>> >>> Here's an example that shows how to do this in wxPython, but you can >>> eliminate the wxPython part of it. The key point is using >>> win32gui.SetWindowLong to load your own function in >>> win32con.GWL_WNDPROC, and remembering the return value so you can call >>> the original function. >>> http://wiki.wxpython.org/HookingTheWndProc >>> >>> -- >>> 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 Fri May 10 02:59:14 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 9 May 2013 17:59:14 -0700 Subject: [python-win32] hook to obtain WM_GESTURE In-Reply-To: References: <518BD2F9.2000908@probo.com> <518C43E0.7060906@probo.com> Message-ID: <518C4662.2080608@probo.com> John Grant wrote: > > I was not sure if I could initialize a Python integer with a hex like > I can in C. The explicit "cast" was to make sure the default type was > not float or unsigned. Python does not have unsigned types. Numbers are either integers (infinitely large) or floats. > I am seeing an exception that only shows up for some mouse events, > sometimes. I can usually reproduce it for a middle-mouse click. The > error message is difficult to read as it streams by on the console > window (shell), but I've seen a couple things that make me think one > of my callbacks is prototyped incorrectly. These are the things I've > been able to read while the output quickly streams by. > "long int too long" > "callback .... in line XXX of ctypes.c" Hmmm. Not sure I can explain that. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cyrfer at gmail.com Fri May 10 06:29:10 2013 From: cyrfer at gmail.com (John Grant) Date: Thu, 9 May 2013 21:29:10 -0700 Subject: [python-win32] hook to obtain WM_GESTURE In-Reply-To: <518C4662.2080608@probo.com> References: <518BD2F9.2000908@probo.com> <518C43E0.7060906@probo.com> <518C4662.2080608@probo.com> Message-ID: I think I finally have a fix. I believe I needed to specify the argtypes for the function objects loaded by importing ctypes. I did not get the correct behavior when only specifying the return types. One issue may be that my return type for 'SetWindowLongPtrW' was a function signature that I declared with ctypes. This return type might need to match the argtype of 'CallWindowProc', which was an int. Now they are both WNDPROC (declared with ctypes). Thanks for all the help. I feel like I learned a magic trick. John On Thu, May 9, 2013 at 5:59 PM, Tim Roberts wrote: > John Grant wrote: > > > > I was not sure if I could initialize a Python integer with a hex like > > I can in C. The explicit "cast" was to make sure the default type was > > not float or unsigned. > > Python does not have unsigned types. Numbers are either integers > (infinitely large) or floats. > > > > I am seeing an exception that only shows up for some mouse events, > > sometimes. I can usually reproduce it for a middle-mouse click. The > > error message is difficult to read as it streams by on the console > > window (shell), but I've seen a couple things that make me think one > > of my callbacks is prototyped incorrectly. These are the things I've > > been able to read while the output quickly streams by. > > "long int too long" > > "callback .... in line XXX of ctypes.c" > > Hmmm. Not sure I can explain that. > > -- > 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 ynotlayabout at gmail.com Fri May 10 14:27:32 2013 From: ynotlayabout at gmail.com (Mye Nyme) Date: Fri, 10 May 2013 08:27:32 -0400 Subject: [python-win32] com proxy Message-ID: <518CE7B4.5090900@gmail.com> hopefully, someone here can either help or point me in the right direction. As some of you know, I used speech recognition in order to be able to work with computers. I'm looking for a way to direct the action of speech recognition onto a Linux machine. There are two components speech and commands. The way many of us create commands is via a NaturallySpeaking Python link. That link is created by a com interface. The first step in making action show up in a Linux environment is to move this NaturallySpeaking Python link to the Linux side. In order to do this, I would need a proxy to bridge the COM interface to the Linux environment. one) does that kind of bridge exists? Two) if not, is it possible to build it? 3) (and you knew this was coming) feel like helping a bunch of crips? 3a) there are some political benefits nfpc. I'm thinking about operating in a Windows host Linux virtual machine environment. Not over any great extent of network. I choose the window hosts because that way we get the best performance out of speech recognition and if it's just running a virtual machine, it's pretty stable and safe from attack. --- eric From vernondcole at gmail.com Fri May 10 17:26:27 2013 From: vernondcole at gmail.com (Vernon D. Cole) Date: Fri, 10 May 2013 16:26:27 +0100 Subject: [python-win32] com proxy In-Reply-To: <518CE7B4.5090900@gmail.com> References: <518CE7B4.5090900@gmail.com> Message-ID: Eric: Interesting timing. I assume you and your fellow "bunch of crips" are motion impaired. I happen to be in Africa just now working on the polio vaccination effort in an attempt to reduce additions to your group. My mother-in-law (a polio victim) was quadriplegic and used breathing assistance, and ran a telephone answering service for 17 years. Her voice was her world. I wish she had something as nice as a computer that could understand speech. Now to the subject... As we speak I am frantically crunching on a Python proxy to bridge a COM link to the Linux environment. The specific COM link I am fighting with (and for) is the COM interface to the ADO database engine. I am attempting to build a remote ADO module which talks to a Windows host which performs the COM calls to talk to a database server. I am getting pretty close -- close enough that the django test routine running on Ubuntu can create and load a database and start running tests against it -- before it runs into some kind of timeout or thread exhaustion error. I am trying to use Pyro4 as the network communication layer. Is this something you can use? Not yet, but it may be a starting point. Stay in touch, please. -- Vernon Cole On Fri, May 10, 2013 at 1:27 PM, Mye Nyme wrote: > hopefully, someone here can either help or point me in the right direction. > > As some of you know, I used speech recognition in order to be able to work > with computers. I'm looking for a way to direct the action of speech > recognition onto a Linux machine. There are two components speech and > commands. The way many of us create commands is via a NaturallySpeaking > Python link. That link is created by a com interface. The first step in > making action show up in a Linux environment is to move this > NaturallySpeaking Python link to the Linux side. In order to do this, I > would need a proxy to bridge the COM interface to the Linux environment. > > one) does that kind of bridge exists? > Two) if not, is it possible to build it? > 3) (and you knew this was coming) feel like helping a bunch of crips? > 3a) there are some political benefits nfpc. > > I'm thinking about operating in a Windows host Linux virtual machine > environment. Not over any great extent of network. I choose the window > hosts because that way we get the best performance out of speech > recognition and if it's just running a virtual machine, it's pretty stable > and safe from attack. > > --- eric > ______________________________**_________________ > 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 ynotlayabout at gmail.com Fri May 10 17:42:17 2013 From: ynotlayabout at gmail.com (Mye Nyme) Date: Fri, 10 May 2013 11:42:17 -0400 Subject: [python-win32] com proxy In-Reply-To: References: <518CE7B4.5090900@gmail.com> Message-ID: <518D1559.2030400@gmail.com> On 5/10/2013 11:26 AM, Vernon D. Cole wrote: > Eric: > Interesting timing. I assume you and your fellow "bunch of crips" > are motion impaired. I happen to be in Africa just now working on the > polio vaccination effort in an attempt to reduce additions to your > group. My mother-in-law (a polio victim) was quadriplegic and used > breathing assistance, and ran a telephone answering service for 17 > years. Her voice was her world. I wish she had something as nice as a > computer that could understand speech. polio is tough. It has vanished from us in the first world so completely we don't think about it being a problem elsewhere. It may still be possible for speech recognition to work for her but it would require some significant annotationto handle the rest of the accessibility problems found in the rest of NaturallySpeaking, talk to me off list and I will see if I can find help FYI, nuance is just as hostile to the disabled as almost every other software company. They just happen to advertise a side effect of NaturallySpeaking as accessibility. > Now to the subject... As we speak I am frantically crunching on a > Python proxy to bridge a COM link to the Linux environment. > The specific COM link I am fighting with (and for) is the COM > interface to the ADO database engine. I am attempting to build a > remote ADO module which talks to a Windows host which performs the COM > calls to talk to a database server. I am getting pretty close -- close > enough that the django test routine running on Ubuntu can create and > load a database and start running tests against it -- before it runs > into some kind of timeout or thread exhaustion error. I am trying to > use Pyro4 as the network communication layer. > Is this something you can use? Not yet, but it may be a starting > point. Stay in touch, please.. if you look on source Forge for natlink, like, here http://sourceforge.net/projects/natlink/ you'll see what we are doing. I'm hoping your attempts can be generalized to serve both of our needs. I will put this on the queue of things I need to pay attention to. As for the source of our cripple nature, most of us were programmers. A few are arthritic or accident injury types. I'm working on a new method of programming using speech recognition. The symbol translation stuff is working pretty good but I really need some form of templating system to help me build code from complex objects. For example, the time module. How would you speak the time module in a high-level way and given the right assumptions, generate the right code. The second would be how you reverse the process so that you can edit the English text to fix an error or change logic and then generate code again. Interesting stuff > -- > Vernon Cole > > > > On Fri, May 10, 2013 at 1:27 PM, Mye Nyme > wrote: > > hopefully, someone here can either help or point me in the right > direction. > > As some of you know, I used speech recognition in order to be able > to work with computers. I'm looking for a way to direct the action > of speech recognition onto a Linux machine. There are two > components speech and commands. The way many of us create commands > is via a NaturallySpeaking Python link. That link is created by a > com interface. The first step in making action show up in a Linux > environment is to move this NaturallySpeaking Python link to the > Linux side. In order to do this, I would need a proxy to bridge > the COM interface to the Linux environment. > > one) does that kind of bridge exists? > Two) if not, is it possible to build it? > 3) (and you knew this was coming) feel like helping a bunch of crips? > 3a) there are some political benefits nfpc. > > I'm thinking about operating in a Windows host Linux virtual > machine environment. Not over any great extent of network. I > choose the window hosts because that way we get the best > performance out of speech recognition and if it's just running a > virtual machine, it's pretty stable and safe from attack. > > --- eric > _______________________________________________ > 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 ckkart at hoc.net Mon May 20 02:52:19 2013 From: ckkart at hoc.net (Christian K.) Date: Sun, 19 May 2013 21:52:19 -0300 Subject: [python-win32] debugging outlook addin Message-ID: I need to debug an outlook addin written in python which crashes outlook in a reproducible manner. How could I do that? Is it possible to have the addin loaded from within a pdb session? The addin uses the mapi msgstore wrappers from the spambayes project. The crash occurs while the addin is starting a background job in a thread. MAPIInitialize is called by the new thread as required by the msdn docs. The thread then is busy for some tens of seconds exporting mailitems by calling MailItem.Save provided by the OOM. In general this works fine, but on one system outlook crashes after a while without any python traceback. Sometimes the problem will disappear, especially when I insert print statements in the export loop (heisenbug?). Thasnk, Christian From anthonyandriano at gmail.com Fri May 24 01:46:01 2013 From: anthonyandriano at gmail.com (Anthony Andriano) Date: Thu, 23 May 2013 17:46:01 -0600 Subject: [python-win32] win32com getElementsByClassName error Message-ID: I'm trying to navigate through in intranet site using python. Everything works as expected until I try to get an element. >>> import win32com.client >>> ie = win32com.client.DispatchEx("InternetExplorer.Application") >>> ie.visible = 1 >>> ie.Navigate(url) # I waited long enough by inspection >>> toButton = ie.Document.getElementsByClassName(className)[1] Which results in: TypeError: getElementsByClassName() takes exactly 1 argument (2 given) Is it passing self to the function? I don't even know what self is in this context. Trying to get an element by ID works just fine with getElementByID, but the element I need to click doesn't have an ID. I also can't get the click() method to work even when I can get the right object. Is it supposed to be as easy as obj.click()? -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Fri May 24 07:36:03 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 24 May 2013 15:36:03 +1000 Subject: [python-win32] win32com getElementsByClassName error In-Reply-To: References: Message-ID: <519EFC43.1070208@gmail.com> Are you using IE9? It looks like that is causing some problems which I've not dug into. See https://sourceforge.net/p/pywin32/bugs/608/ for another example of a very similar error... On 24/05/2013 9:46 AM, Anthony Andriano wrote: > I'm trying to navigate through in intranet site using python. Everything > works as expected until I try to get an element. > > >>> import win32com.client > >>> ie = win32com.client.DispatchEx("InternetExplorer.Application") > >>> ie.visible = 1 > >>> ie.Navigate(url) > # I waited long enough by inspection > >>> toButton = ie.Document.getElementsByClassName(className)[1] > > Which results in: > TypeError: getElementsByClassName() takes exactly 1 argument (2 given) > > Is it passing self to the function? I don't even know what self is in > this context. Trying to get an element by ID works just fine with > getElementByID, but the element I need to click doesn't have an ID. > > I also can't get the click() method to work even when I can get the > right object. Is it supposed to be as easy as obj.click()? > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From jeremy.kloth at gmail.com Tue May 28 20:26:47 2013 From: jeremy.kloth at gmail.com (Jeremy Kloth) Date: Tue, 28 May 2013 12:26:47 -0600 Subject: [python-win32] win32com support for pointer in-parameters Message-ID: I have been struggling with getting pointer parameters to work with the COM interface for VirtualBox. In particular, the IFramebuffer interface. I cannot seem to get the following to give the expected results: interface IFramebuffer : IDispatch { // snipped to just the interesting definition HRESULT RequestResize ( [in] ULONG aScreenId, [in] ULONG aPixelFormat, [in] BYTE * aVRAM, [in] ULONG aBitsPerPixel, [in] ULONG aBytesPerLine, [in] ULONG aWidth, [in] ULONG aHeight, [out, retval] BOOL * aFinished ); }; The type for aVRAM ends up being (correctly) VT_BYREF | VT_UI1. Unfortunately PyIDispatch (incorrectly) converts the parameter to just VT_UI1. The offending code path is: PyGatewayBase::Invoke() -> invoke_setup() -> PyCom_PyObjectFromVariant() -> VariantCopyInd(). My not so informed understanding is that pythoncom considers all VT_BYREF parameters as out-type parameters whereas, in this case at least, it is not always such. Indeed, in this case, the aVRAM parameter needs to be the *address* not the *value* for an object to implement IFramebuffer properly. Note that the object implementing IFramebuffer is passed as argument to another function much the same way as event listeners. I believe the fix involves PyIDispatch somehow using the type information to determine which parameters are not out-type and then to not dereference those. Any direction with this is greatly appreciated. Jeremy Kloth -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed May 29 03:49:07 2013 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 29 May 2013 11:49:07 +1000 Subject: [python-win32] win32com support for pointer in-parameters In-Reply-To: References: Message-ID: <51A55E93.50505@gmail.com> Yeah, pywin32 will see a byref ui1 and pass the address of an integer filled with the value of the integer objects. However, I'm not really sure what you are expecting this to do - passing the address of a Python integer object clearly isn't correct - or to put it another way - what exact are you hoping to pass as this parameter? We could probably special-case VT_BYREF | VT_UI1 when a Python "buffer" object is passed and pass the address of that buffer - this already happens for a VT_ARRAY | VT_UI1 - but whether that would solve your problem depends on how you actually intend using that param... Mark. On 29/05/2013 4:26 AM, Jeremy Kloth wrote: > I have been struggling with getting pointer parameters to work with the > COM interface for VirtualBox. In particular, the IFramebuffer > interface. I cannot seem to get the following to give the expected results: > > interface IFramebuffer : IDispatch > { > // snipped to just the interesting definition > HRESULT RequestResize ( > [in] ULONG aScreenId, > [in] ULONG aPixelFormat, > [in] BYTE * aVRAM, > [in] ULONG aBitsPerPixel, > [in] ULONG aBytesPerLine, > [in] ULONG aWidth, > [in] ULONG aHeight, > [out, retval] BOOL * aFinished > ); > }; > > The type for aVRAM ends up being (correctly) VT_BYREF | VT_UI1. > Unfortunately PyIDispatch (incorrectly) converts the parameter to just > VT_UI1. The offending code path is: PyGatewayBase::Invoke() -> > invoke_setup() -> PyCom_PyObjectFromVariant() -> VariantCopyInd(). > > My not so informed understanding is that pythoncom considers all > VT_BYREF parameters as out-type parameters whereas, in this case at > least, it is not always such. Indeed, in this case, the aVRAM parameter > needs to be the *address* not the *value* for an object to implement > IFramebuffer properly. > > Note that the object implementing IFramebuffer is passed as argument to > another function much the same way as event listeners. > > I believe the fix involves PyIDispatch somehow using the type > information to determine which parameters are not out-type and then to > not dereference those. > > Any direction with this is greatly appreciated. > > Jeremy Kloth > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From milan.kase at gmail.com Wed May 29 19:34:16 2013 From: milan.kase at gmail.com (=?ISO-8859-2?Q?Milan_Ka=B9e?=) Date: Wed, 29 May 2013 19:34:16 +0200 Subject: [python-win32] Strange order of OnEnter/LeaveScript site methods in application hosting Python active scripting engine Message-ID: Hello, a user of our application which can host various active scripting engines reported problems when using the application together with Python active scripting engine. I traced the problem down to the order in which the engine calls the site's OnEnterScript/OnLeaveScript methods. The usual scenario with other engines (including MS JScript and VBScript) is: 1. OnEnterScript 2. ...executing script... 3. OnLeaveScript However with Python engine, after calling IActiveScript.SetScriptState(SCRIPTSTATE_CONNECTED) the scenario is following: 1. OnEnterScript 2. OnLeaveScript 3. OnEnterScript 4. ...executing script... 5. OnLeaveScript One would expect either the first scenario or in case the events are raised multiple times, then the calls should be nested (as stated in MSDN, http://msdn.microsoft.com/en-us/library/9c1cww48(v=vs.94).aspx). Is the Python's way of calling these methods intentional or is it a bug? Thanks, Milan -------------- next part -------------- An HTML attachment was scrubbed... URL: From milan.kase at gmail.com Thu May 30 21:33:17 2013 From: milan.kase at gmail.com (=?ISO-8859-2?Q?Milan_Ka=B9e?=) Date: Thu, 30 May 2013 21:33:17 +0200 Subject: [python-win32] Strange order of OnEnter/LeaveScript site methods in application hosting Python active scripting engine In-Reply-To: <51A6F459.9060708@gmail.com> References: <51A6F459.9060708@gmail.com> Message-ID: I tried to take stack dumps (attached bellow) and it seems that the first pair of calls is coming from CompileInScriptedSection while the second pair is from ExecInScriptedSection. Do you have a clue what's going on here? 0.00000000 *** OnEnterScript *** 0.00142864 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ 0.00142864 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) 0.00142864 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ 0.00142864 return func(*args) 0.00142864 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 610, in SetScriptState 0.00142864 self.Run() 0.00142864 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 788, in Run 0.00142864 self.ExecutePendingScripts() 0.00142864 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 736, in ExecutePendingScripts 0.00142864 self.DoExecutePendingScripts() 0.00142864 File "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", line 237, in DoExecutePendingScripts 0.00142864 if self.CompileInScriptedSection(codeBlock, "exec"): 0.00142864 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 872, in CompileInScriptedSection 0.00142864 self.BeginScriptedSection() 0.00142864 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 972, in BeginScriptedSection 0.00142864 win32api.OutputDebugString("".join(traceback.format_stack())) 0.00574597 *** OnLeaveScript *** 0.00618566 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ 0.00618566 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) 0.00618566 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ 0.00618566 return func(*args) 0.00618566 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 610, in SetScriptState 0.00618566 self.Run() 0.00618566 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 788, in Run 0.00618566 self.ExecutePendingScripts() 0.00618566 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 736, in ExecutePendingScripts 0.00618566 self.DoExecutePendingScripts() 0.00618566 File "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", line 237, in DoExecutePendingScripts 0.00618566 if self.CompileInScriptedSection(codeBlock, "exec"): 0.00618566 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 880, in CompileInScriptedSection 0.00618566 self.EndScriptedSection() 0.00618566 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 979, in EndScriptedSection 0.00618566 win32api.OutputDebugString("".join(traceback.format_stack())) 0.00675985 *** OnEnterScript *** 0.00718076 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ 0.00718076 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) 0.00718076 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ 0.00718076 return func(*args) 0.00718076 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 610, in SetScriptState 0.00718076 self.Run() 0.00718076 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 788, in Run 0.00718076 self.ExecutePendingScripts() 0.00718076 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 736, in ExecutePendingScripts 0.00718076 self.DoExecutePendingScripts() 0.00718076 File "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", line 238, in DoExecutePendingScripts 0.00718076 self.ExecInScriptedSection(codeBlock, globs) 0.00718076 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 899, in ExecInScriptedSection 0.00718076 self.BeginScriptedSection() 0.00718076 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 972, in BeginScriptedSection 0.00718076 win32api.OutputDebugString("".join(traceback.format_stack())) 3.00900340 *** OnLeaveScript *** 3.00964451 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ 3.00964451 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) 3.00964451 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ 3.00964451 return func(*args) 3.00964451 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 610, in SetScriptState 3.00964451 self.Run() 3.00964451 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 788, in Run 3.00964451 self.ExecutePendingScripts() 3.00964451 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 736, in ExecutePendingScripts 3.00964451 self.DoExecutePendingScripts() 3.00964451 File "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", line 238, in DoExecutePendingScripts 3.00964451 self.ExecInScriptedSection(codeBlock, globs) 3.00964451 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 905, in ExecInScriptedSection 3.00964451 self.EndScriptedSection() 3.00964451 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 979, in EndScriptedSection 3.00964451 win32api.OutputDebugString("".join(traceback.format_stack())) 3.01041079 pythoncom error: 3.01048589 Unexpected exception in gateway method 'SetScriptSite' 3.01056170 3.01062036 3.01094675 Traceback (most recent call last): 3.01094675 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ 3.01094675 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) 3.01094675 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ 3.01094675 return func(*args) 3.01094675 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 580, in SetScriptSite 3.01094675 self.lcid = site.GetLCID() 3.01094675 AttributeError: 'NoneType' object has no attribute 'GetLCID' 3.01102114 pythoncom error: 3.01107931 Unexpected gateway error 3.01122880 3.01147223 3.01194453 Traceback (most recent call last): 3.01194453 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in _InvokeEx_ 3.01194453 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) 3.01194453 File "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ 3.01194453 return func(*args) 3.01194453 File "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line 580, in SetScriptSite 3.01194453 self.lcid = site.GetLCID() 3.01194453 AttributeError: 'NoneType' object has no attribute 'GetLCID' 2013/5/30 Mark Hammond > Apart from the engine being called with no script to execute for some > reason, it may be that an event handler is being added, which causes Python > to execute things twice - once to "build" the event handler, and again when > it is actually executed. > > Either way, if you check out win32comext/axscript/client/**framework.py > and look for ApplyInScriptedSection(), you will find where these calls > originate from. If you can print (or otherwise arrange to see) what the > code is, it might give us more of a clue. > > HTH, > > Mark > > > On 30/05/2013 3:34 AM, Milan Ka?e wrote: > >> Hello, >> a user of our application which can host various active scripting >> engines reported problems when using the application together with >> Python active scripting engine. I traced the problem down to the order >> in which the engine calls the site's OnEnterScript/OnLeaveScript methods. >> >> The usual scenario with other engines (including MS JScript and >> VBScript) is: >> 1. OnEnterScript >> 2. ...executing script... >> 3. OnLeaveScript >> >> However with Python engine, after calling >> IActiveScript.SetScriptState(**SCRIPTSTATE_CONNECTED) the scenario is >> following: >> 1. OnEnterScript >> 2. OnLeaveScript >> 3. OnEnterScript >> 4. ...executing script... >> 5. OnLeaveScript >> >> One would expect either the first scenario or in case the events are >> raised multiple times, then the calls should be nested (as stated in >> MSDN, http://msdn.microsoft.com/en-**us/library/9c1cww48(v=vs.94).**aspx >> ). >> Is the Python's way of calling these methods intentional or is it a bug? >> >> Thanks, >> Milan >> >> >> ______________________________**_________________ >> 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 Fri May 31 01:27:41 2013 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 31 May 2013 09:27:41 +1000 Subject: [python-win32] Strange order of OnEnter/LeaveScript site methods in application hosting Python active scripting engine In-Reply-To: References: <51A6F459.9060708@gmail.com> Message-ID: <51A7E06D.7010600@skippinet.com.au> On 31/05/2013 5:33 AM, Milan Ka?e wrote: > I tried to take stack dumps (attached bellow) and it seems that the > first pair of calls is coming from CompileInScriptedSection while the > second pair is from ExecInScriptedSection. Do you have a clue what's > going on here? Right - script blocks are compiled before they are executed. I really can't remember why the compilation step does this - what problem is it causing you? Mark > > 0.00000000*** OnEnterScript *** > 0.00142864 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in > _InvokeEx_ > 0.00142864 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > serviceProvider) > 0.00142864 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in > _invokeex_ > 0.00142864 return func(*args) > 0.00142864 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 610, in SetScriptState > 0.00142864 self.Run() > 0.00142864 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 788, in Run > 0.00142864 self.ExecutePendingScripts() > 0.00142864 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 736, in ExecutePendingScripts > 0.00142864 self.DoExecutePendingScripts() > 0.00142864 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", > line 237, in DoExecutePendingScripts > 0.00142864 if self.CompileInScriptedSection(codeBlock, "exec"): > 0.00142864 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 872, in CompileInScriptedSection > 0.00142864 self.BeginScriptedSection() > 0.00142864 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 972, in BeginScriptedSection > 0.00142864 win32api.OutputDebugString("".join(traceback.format_stack())) > 0.00574597*** OnLeaveScript *** > 0.00618566 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in > _InvokeEx_ > 0.00618566 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > serviceProvider) > 0.00618566 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in > _invokeex_ > 0.00618566 return func(*args) > 0.00618566 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 610, in SetScriptState > 0.00618566 self.Run() > 0.00618566 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 788, in Run > 0.00618566 self.ExecutePendingScripts() > 0.00618566 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 736, in ExecutePendingScripts > 0.00618566 self.DoExecutePendingScripts() > 0.00618566 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", > line 237, in DoExecutePendingScripts > 0.00618566 if self.CompileInScriptedSection(codeBlock, "exec"): > 0.00618566 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 880, in CompileInScriptedSection > 0.00618566 self.EndScriptedSection() > 0.00618566 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 979, in EndScriptedSection > 0.00618566 win32api.OutputDebugString("".join(traceback.format_stack())) > 0.00675985*** OnEnterScript *** > 0.00718076 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in > _InvokeEx_ > 0.00718076 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > serviceProvider) > 0.00718076 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in > _invokeex_ > 0.00718076 return func(*args) > 0.00718076 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 610, in SetScriptState > 0.00718076 self.Run() > 0.00718076 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 788, in Run > 0.00718076 self.ExecutePendingScripts() > 0.00718076 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 736, in ExecutePendingScripts > 0.00718076 self.DoExecutePendingScripts() > 0.00718076 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", > line 238, in DoExecutePendingScripts > 0.00718076 self.ExecInScriptedSection(codeBlock, globs) > 0.00718076 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 899, in ExecInScriptedSection > 0.00718076 self.BeginScriptedSection() > 0.00718076 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 972, in BeginScriptedSection > 0.00718076 win32api.OutputDebugString("".join(traceback.format_stack())) > 3.00900340*** OnLeaveScript *** > 3.00964451 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in > _InvokeEx_ > 3.00964451 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > serviceProvider) > 3.00964451 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in > _invokeex_ > 3.00964451 return func(*args) > 3.00964451 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 610, in SetScriptState > 3.00964451 self.Run() > 3.00964451 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 788, in Run > 3.00964451 self.ExecutePendingScripts() > 3.00964451 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 736, in ExecutePendingScripts > 3.00964451 self.DoExecutePendingScripts() > 3.00964451 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\pyscript.py", > line 238, in DoExecutePendingScripts > 3.00964451 self.ExecInScriptedSection(codeBlock, globs) > 3.00964451 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 905, in ExecInScriptedSection > 3.00964451 self.EndScriptedSection() > 3.00964451 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 979, in EndScriptedSection > 3.00964451 win32api.OutputDebugString("".join(traceback.format_stack())) > 3.01041079pythoncom error: > 3.01048589Unexpected exception in gateway method 'SetScriptSite' > 3.01056170 > 3.01062036 > 3.01094675Traceback (most recent call last): > 3.01094675 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in > _InvokeEx_ > 3.01094675 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > serviceProvider) > 3.01094675 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in > _invokeex_ > 3.01094675 return func(*args) > 3.01094675 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 580, in SetScriptSite > 3.01094675 self.lcid = site.GetLCID() > 3.01094675AttributeError: 'NoneType' object has no attribute 'GetLCID' > 3.01102114pythoncom error: > 3.01107931Unexpected gateway error > 3.01122880 > 3.01147223 > 3.01194453Traceback (most recent call last): > 3.01194453 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 324, in > _InvokeEx_ > 3.01194453 return self._invokeex_(dispid, lcid, wFlags, args, kwargs, > serviceProvider) > 3.01194453 File > "C:\Python27\lib\site-packages\win32com\server\policy.py", line 585, in > _invokeex_ > 3.01194453 return func(*args) > 3.01194453 File > "C:\Python27\lib\site-packages\win32comext\axscript\client\framework.py", line > 580, in SetScriptSite > 3.01194453 self.lcid = site.GetLCID() > 3.01194453AttributeError: 'NoneType' object has no attribute 'GetLCID' > > > > 2013/5/30 Mark Hammond > > > Apart from the engine being called with no script to execute for > some reason, it may be that an event handler is being added, which > causes Python to execute things twice - once to "build" the event > handler, and again when it is actually executed. > > Either way, if you check out > win32comext/axscript/client/__framework.py and look for > ApplyInScriptedSection(), you will find where these calls originate > from. If you can print (or otherwise arrange to see) what the code > is, it might give us more of a clue. > > HTH, > > Mark > > > On 30/05/2013 3:34 AM, Milan Ka?e wrote: > > Hello, > a user of our application which can host various active scripting > engines reported problems when using the application together with > Python active scripting engine. I traced the problem down to the > order > in which the engine calls the site's OnEnterScript/OnLeaveScript > methods. > > The usual scenario with other engines (including MS JScript and > VBScript) is: > 1. OnEnterScript > 2. ...executing script... > 3. OnLeaveScript > > However with Python engine, after calling > IActiveScript.SetScriptState(__SCRIPTSTATE_CONNECTED) the > scenario is > following: > 1. OnEnterScript > 2. OnLeaveScript > 3. OnEnterScript > 4. ...executing script... > 5. OnLeaveScript > > One would expect either the first scenario or in case the events are > raised multiple times, then the calls should be nested (as stated in > MSDN, > http://msdn.microsoft.com/en-__us/library/9c1cww48(v=vs.94).__aspx > ). > Is the Python's way of calling these methods intentional or is > it a bug? > > Thanks, > Milan > > > _________________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/__mailman/listinfo/python-win32 > > > >