From bgailer at gmail.com Mon Mar 4 23:29:47 2019 From: bgailer at gmail.com (bob gailer) Date: Mon, 4 Mar 2019 23:29:47 -0500 Subject: [python-win32] proper coding declaration Message-ID: <24f72bdb-8bb9-e1fc-eda6-ef20492ec8b2@gmail.com> my python file starts with # -*- coding: utf-8 -*- There is a unicode character 2501 in the file I am editing with python for windows 3.7 build 224 Saving the file results in an error: 'latin-1' codec can't encode character \u2501 What am I doing wrong? -- Bob Gailer --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From raf at raf.org Mon Mar 4 23:45:35 2019 From: raf at raf.org (raf at raf.org) Date: Tue, 5 Mar 2019 15:45:35 +1100 Subject: [python-win32] proper coding declaration In-Reply-To: <24f72bdb-8bb9-e1fc-eda6-ef20492ec8b2@gmail.com> References: <24f72bdb-8bb9-e1fc-eda6-ef20492ec8b2@gmail.com> Message-ID: <20190305044535.zkybp33wvb55kbiy@raf.org> bob gailer wrote: > my python file starts with # -*- coding: utf-8 -*- > > There is a unicode character 2501 in the file > > I am editing with python for windows 3.7 build 224 > > Saving the file results in an error: 'latin-1' codec can't encode character > \u2501 > > What am I doing wrong? > > -- > Bob Gailer Just guessing but maybe the problem is that it's not a UTF8 file and Python is falling back to latin1 (because it knows it isn't ASCII). You say there is a unicode character in it (\u2501). But that character, encoded in UTF-8 is 0xE2 0x94 0x81. Try changing the charset declaration to match the actual unicode encoding that it is using. Not sure what it is but possibly UTF-16. cheers, raf From code at wizofe.uk Fri Mar 8 12:08:46 2019 From: code at wizofe.uk (Ioannis Valasakis) Date: Fri, 08 Mar 2019 17:08:46 +0000 Subject: [python-win32] COM Photoshop - Exception occurred Message-ID: <1695e47529c.f808833136594.8297922422319030665@wizofe.uk> Hi all,? I am following the above tutorial for interfacing Python with Photoshop on Windows. https://evanmccall.wordpress.com/2015/03/09/how-to-develop-photoshop-tools-in-python/#comments I am using the following version of Python 2.7.16 (v2.7.16:413a49145e) [MSC v.1500 64 bit (AMD64)].? I had different kind of errors even with simple actions like app.Save(file, psd_opt) but I got rid of them when I installed Python 2.7.16 on Windows 10. The previous errors were coming from Python 2.7.15 on Windows 7. Currently, that this is the error I am getting and I can't seem to understand why, as I've seen online examples using the exact same code and it works. >>> desc.putReference(cTID("null"), ref) >>> desc.putBoolean(cTID("MkVs"), False) >>> app.executeAction(cTID("slct"), desc, 3) Traceback (most recent call last): ? File "", line 1, in ? File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__ ??? ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Adobe Photoshop', u'Illegal argument - argument 1\n- Required value is missing', None, 0, -2147220262), None) Thank you for the help i -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Sun Mar 10 00:43:05 2019 From: timr at probo.com (Tim Roberts) Date: Sat, 9 Mar 2019 21:43:05 -0800 Subject: [python-win32] COM Photoshop - Exception occurred In-Reply-To: <1695e47529c.f808833136594.8297922422319030665@wizofe.uk> References: <1695e47529c.f808833136594.8297922422319030665@wizofe.uk> Message-ID: On Mar 8, 2019, at 9:08 AM, Ioannis Valasakis wrote: > > ... > Currently, that this is the error I am getting and I can't seem to understand why, as I've seen online examples using the exact same code and it works. > > >>> desc.putReference(cTID("null"), ref) > >>> desc.putBoolean(cTID("MkVs"), False) > >>> app.executeAction(cTID("slct"), desc, 3) > Traceback (most recent call last): > File "", line 1, in > File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__ > ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1) > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Adobe Photoshop', u'Illegal argument - argument 1\n- Required value is missing', None, 0, -2147220262), None) Different versions of Photoshop? Could the ?slct? action refer to a plugin that isn?t present on your Windows 10 system? The key point is that this is almost certainly going to end up being a Photoshop issue, not a Python issue. ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3870 bytes Desc: not available URL: From vernondcole at gmail.com Thu Mar 14 14:28:37 2019 From: vernondcole at gmail.com (Vernon D. Cole) Date: Thu, 14 Mar 2019 12:28:37 -0600 Subject: [python-win32] Do we need dotnet 3.5? Message-ID: I am trying to build a build machine (actually a script to build build machines) capable of creating a pywin32 distribution. (I need to test the distribution I am trying to fix.) Somewhere in there it seems that I need to have .net3.5 installed. I have been struggling with this all morning, and have come to the conclusion that I cannot install it on a Windows server operating system without having the distribution media mounted on a CD drive. That seems like a bad idea. Is the package actually needed for some reason? -- Vernon Cole -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Thu Mar 14 15:55:13 2019 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Thu, 14 Mar 2019 14:55:13 -0500 Subject: [python-win32] Do we need dotnet 3.5? In-Reply-To: References: Message-ID: Have you looked at this? https://stackoverflow.com/questions/23631675/install-net-3-5-framework-on-windows-server-2012-without-dvd On Thu, Mar 14, 2019 at 1:29 PM Vernon D. Cole wrote: > I am trying to build a build machine (actually a script to build build > machines) capable of creating a pywin32 distribution. (I need to test the > distribution I am trying to fix.) > > Somewhere in there it seems that I need to have .net3.5 installed. I have > been struggling with this all morning, and have come to the conclusion that > I cannot install it on a Windows server operating system without having the > distribution media mounted on a CD drive. > > That seems like a bad idea. > > Is the package actually needed for some reason? > -- > Vernon Cole > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ahmedmatar at me.com Fri Mar 15 09:25:16 2019 From: ahmedmatar at me.com (Ahmed Matar) Date: Fri, 15 Mar 2019 13:25:16 +0000 Subject: [python-win32] Performing ReplyAll to outlook email message Message-ID: Hi, I am trying to perform a reply all to an email message that I have passed into my python script. import win32com.client __OUTLOOK = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") __MSG = __OUTLOOK.OpenSharedItem(sys.argv[1]) emailBody = __MSG.Body print(emailBody) responseToEmail = ?Hi, thanks for your email, I have received it? #what I would like to do now is do a ?Reply all? with my reponse being ?ResponseToEmail? Any ideas if this is possible? -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Mar 15 18:53:56 2019 From: timr at probo.com (Tim Roberts) Date: Fri, 15 Mar 2019 15:53:56 -0700 Subject: [python-win32] Performing ReplyAll to outlook email message In-Reply-To: References: Message-ID: <7d5b533f-ffb7-6435-eb61-89c1ae69d915@probo.com> Ahmed Matar via python-win32 wrote: > > I am trying to perform a reply all to an email message that I have > passed into my python script. > ... > > #what I would like to do now is do a ?Reply all? with my reponse being > ?ResponseToEmail? > > > Any ideas if this is possible? Sure, it's possible, but you have to do it all "the hard way". Create a new message, copy the Receipts list into the new message, set your body, send it.? Not a lot of code, but it's a little tedious. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3980 bytes Desc: S/MIME Cryptographic Signature URL: From vernondcole at gmail.com Fri Mar 15 22:32:58 2019 From: vernondcole at gmail.com (Vernon D. Cole) Date: Fri, 15 Mar 2019 20:32:58 -0600 Subject: [python-win32] Do we need dotnet 3.5? In-Reply-To: References: Message-ID: Thanks for the link. That method did not seem to work on Windows Server 2016. I have found a solution that seems to work correctly, if not very efficiently, on Windows 10. Since I doubt that Windows Server machines will be called on very often to build pywin32, I am leaving the script with a little message telling the unfortunate user to install dotNET 3.5 manually. Still I wonder what part of our build system requires something so obsolete. On Thu, Mar 14, 2019 at 1:55 PM Denis Akhiyarov wrote: > Have you looked at this? > https://stackoverflow.com/questions/23631675/install-net-3-5-framework-on-windows-server-2012-without-dvd > > On Thu, Mar 14, 2019 at 1:29 PM Vernon D. Cole > wrote: > >> I am trying to build a build machine (actually a script to build build >> machines) capable of creating a pywin32 distribution. (I need to test the >> distribution I am trying to fix.) >> >> Somewhere in there it seems that I need to have .net3.5 installed. I have >> been struggling with this all morning, and have come to the conclusion that >> I cannot install it on a Windows server operating system without having the >> distribution media mounted on a CD drive. >> >> That seems like a bad idea. >> >> Is the package actually needed for some reason? >> -- >> Vernon Cole >> >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> https://mail.python.org/mailman/listinfo/python-win32 >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at AnythingPeaceful.org Sun Mar 17 18:41:04 2019 From: tom at AnythingPeaceful.org (Tom Parker) Date: Sun, 17 Mar 2019 16:41:04 -0600 Subject: [python-win32] Python code to drop file onto GUI, using pywin32 Message-ID: Here's my issue: Given a filename and a GUI, I need some Python code (on Windows) to drop the file onto the GUI. The GUI (third-party) already accepts files via drag and drop (using OLE, but not WM_DROPFILE). I was thinking pywin32 might be the right tool to use, but I don't know where to get started. Thanks for any pointers you can provide. - Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From webguy at totalrewind.com Mon Mar 18 02:24:34 2019 From: webguy at totalrewind.com (kurt) Date: Mon, 18 Mar 2019 00:24:34 -0600 Subject: [python-win32] How to get target of folder shortcuts Message-ID: <20190318002434.00006709@totalrewind.com> Hello, I'm trying to get the target filename of windows shortcuts. The code below works great for regular shortcuts, but errors out on "folder shortcuts". (for what I mean, see: https://superuser.com/questions/456399/what-different-types-of-shortcut-are-there/639967#639967) The code below works great for regular .lnk shortcuts, but folder shortcuts give me: [...] persistFile.Load(fname,STGM_READ) pywintypes.com_error: (-2147024891, 'Access is denied.', None, None) The quirk with folder shortcuts is they have some DOS attributes set, which I suspect could be causing me trouble. Is there, perhaps, something I need to do to get my IPersistFile to ignore file attributes? Or is this error a result of something else? ----- teh code def linkinfo(path): """ returns (isLink,targetPath) """ path=os.path.abspath(path) targetPath=path fname=path isLink=False desktop=shell.SHGetDesktopFolder() _,pidl,_=desktop.ParseDisplayName(None,None,path) shell_item =shell.SHCreateShellItem(None,None,pidl) attrs=shell_item.GetAttributes(shellcon.SFGAO_LINK|shellcon.SFGAO_FOLDER) isLink=attrs&shellcon.SFGAO_LINK>0 isFolder=attrs&shellcon.SFGAO_FOLDER>0 if isLink and not fname.endswith('URL'): shellLink=pythoncom.CoCreateInstance(shell.CLSID_ShellLink,None,pythoncom.CLSCTX_INPROC_SERVER,shell.IID_IShellLink) persistFile=shellLink.QueryInterface(pythoncom.IID_IPersistFile) if isFolder: fname=fname+os.sep+'target.lnk' persistFile.Load(fname,STGM_READ) targetPath,findData=shellLink.GetPath(0) return isLink,targetPath From timr at probo.com Mon Mar 18 12:54:57 2019 From: timr at probo.com (Tim Roberts) Date: Mon, 18 Mar 2019 09:54:57 -0700 Subject: [python-win32] How to get target of folder shortcuts In-Reply-To: <20190318002434.00006709@totalrewind.com> References: <20190318002434.00006709@totalrewind.com> Message-ID: <38215e36-e34e-0d54-bb23-0fc826010ecd@probo.com> kurt wrote: > Hello, I'm trying to get the target filename of windows shortcuts. The > code below works great for regular shortcuts, but errors out on "folder > shortcuts". > ... > The code below works great for regular .lnk shortcuts, but folder > shortcuts give me: > [...] > persistFile.Load(fname,STGM_READ) > pywintypes.com_error: (-2147024891, 'Access is denied.', None, None) > > The quirk with folder shortcuts is they have some DOS attributes set, > which I suspect could be causing me trouble. Is there, perhaps, > something I need to do to get my IPersistFile to ignore file attributes? Your code works for me, although the SFGAO_FOLDER bit is not set for my folder shortcut.? If you do a "dir" of the folder where the link lives, what do you see?? Is it actually a .lnk file of about a kilobyte? There are no DOS attributes on my folder shortcut.? What do you see? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3980 bytes Desc: S/MIME Cryptographic Signature URL: From kuree.offsec at gmail.com Mon Mar 18 20:33:38 2019 From: kuree.offsec at gmail.com (Kuree Kafir) Date: Mon, 18 Mar 2019 20:33:38 -0400 Subject: [python-win32] runas analog Message-ID: Hello, I am trying to implement something similar to the runas /netonly command in python. handle = win32security.LogonUser(userName, domain, password, win32con.LOGON32_LOGON_NEW_CREDENTIALS, win32con.LOGON32_PROVIDER_DEFAULT) win32security.ImpersonateLoggedOnUser(handle) These two commands succeed, and I can see the credentials in memory, but when I attempt to call something like os.system("cmd.exe") and attempt to authenticate, the security context previous created is not presented, and authentication fails. How do I correctly call CreateProcess using the impersonation session that I just created? kuree -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Tue Mar 19 01:22:27 2019 From: vernondcole at gmail.com (Vernon D. Cole) Date: Mon, 18 Mar 2019 23:22:27 -0600 Subject: [python-win32] runas analog In-Reply-To: References: Message-ID: Perhaps ShellExecuteEx will do what you are wishing for? I found a good formula for starting a process as an administrator and it is packaged in a small module tries to emulate a "sudo" command. You might look at the code around line 76. Starting a subprocess in Windows is somewhat of a black art, I fear. On Mon, Mar 18, 2019 at 7:16 PM Kuree Kafir wrote: > Hello, > > I am trying to implement something similar to the runas /netonly command > in python. > > handle = win32security.LogonUser(userName, domain, password, > win32con.LOGON32_LOGON_NEW_CREDENTIALS, win32con.LOGON32_PROVIDER_DEFAULT) > win32security.ImpersonateLoggedOnUser(handle) > > These two commands succeed, and I can see the credentials in memory, but > when I attempt to call something like os.system("cmd.exe") and attempt to > authenticate, the security context previous created is not presented, and > authentication fails. > > How do I correctly call CreateProcess using the impersonation session that > I just created? > > kuree > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.f.mcneill at gmail.com Mon Mar 25 22:51:08 2019 From: benjamin.f.mcneill at gmail.com (Benjamin McNeill) Date: Mon, 25 Mar 2019 20:51:08 -0600 Subject: [python-win32] chapter 5 : implementing com objects with python Message-ID: Hello, I am trying to get this com server to work in VBA. I can register and deregister the server but I can not call it from vba. Any suggestions? I am using windows 10 and office 365 with python3.7. thanks! --Ben # SimpleCOMServer.py - A sample COM server - almost as small as they come! # # We simply expose a single method in a Python COM object. class PythonUtilities: _public_methods_ = ['SplitString'] _reg_progid_ = "PythonDemos.Utilities" # NEVER copy the following ID # Use "print(pythoncom.CreateGuid())" to make a new one. _reg_clsid_ = "{7D2089C4-CD6A-44BD-A6DC-CA3B3A8A8712}" def SplitString(self, val, item=None): import string if item: item = str(item) return string.split(str(val), item) # Add code so that when this script is run by # Python.exe, it self-registers. if __name__ == '__main__': print("Registering COM server...") import win32com.server.register win32com.server.register.UseCommandLine(PythonUtilities) -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Mar 26 21:01:14 2019 From: timr at probo.com (Tim Roberts) Date: Tue, 26 Mar 2019 18:01:14 -0700 Subject: [python-win32] chapter 5 : implementing com objects with python In-Reply-To: References: Message-ID: <8d5d5d19-53f9-e9eb-082b-cb58cb920676@probo.com> Benjamin McNeill wrote: > > Hello,? I am trying to get this com server to work in VBA.? I can > register and deregister the server but I can not call it from vba.? > Any suggestions?? I am using windows 10 and office 365 with python3.7. Remember that the bit-size must match.? I don't actually know whether Office 365 is a 32-bit app or a 64-bit app, but your version of Python must match. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3980 bytes Desc: S/MIME Cryptographic Signature URL: From vernondcole at gmail.com Wed Mar 27 08:20:28 2019 From: vernondcole at gmail.com (Vernon D. Cole) Date: Wed, 27 Mar 2019 06:20:28 -0600 Subject: [python-win32] almost there -- running "py -2 setup.py install" Message-ID: I have been working for a while on writing a script to provision a machine to be able to build pywin32 using downloadable components, the most important of which is the VCforPython27 compiler package. It seems that in packaging that compiler, at least one header file needed to build pywin32 was left out. Here is where my last attempt failed: ... > C:\Users\vagrant\pywin32>py -2 setup.py install > Building pywin32 2.7.224.1 > running install > running build > running build_py > running build_ext > Skipping mapi: The header 'edkmdb.h' can not be located. > Skipping exchange: The header 'edkmdb.h' can not be located. > Skipping exchdapi: No 64-bit library for utility functions available. > building 'win32ui' extension > c:\Program Files (x86)\Common Files\Microsoft\Visual C++ for > Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /W3 /GS- /DNDEBUG /MD > -DDISTUTILS_BUILD -D_CRT_SECURE_NO_WARNINGS -Icom/win32com/src/include > -Iwin32/src -IC:\Python27\include -IC:\Python27\PC "-IC:\Program Files > (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows > Kits\8.1\include\shared" /TpPythonwin/dbgthread.cpp > /Fobuild\temp.win-amd64-2.7\Release\Pythonwin/dbgthread.obj -DBUILD_PYW > -D_AFXDLL -D_AFXEXT -D_MBCS /Zi > /Fdbuild\temp.win-amd64-2.7\Release\win32ui_vc.pdb /EHsc /wd4163 > dbgthread.cpp > c:\users\vagrant\pywin32\pythonwin\stdafx.h(18) : fatal error C1083: > Cannot open include file: 'afxwin.h': No such file or directory > error: command 'c:\\Program Files (x86)\\Common Files\\Microsoft\\Visual > C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2 > > The offending file is pythonwin/stdafx.h which calls for several afx*.h files. Can these headers safely be ignored and skipped over, like the edk* ones are? If not, can someone refer me to a suitable source for the definitions? There is a folder with the missing library names in Visual Studio 2017 Build Tools, but I suspect that it would not have the correct values for version 9, would it? -- Vernon Cole -------------- next part -------------- An HTML attachment was scrubbed... URL: From kaweit at 126.com Tue Mar 26 23:31:36 2019 From: kaweit at 126.com (Kaweit) Date: Wed, 27 Mar 2019 11:31:36 +0800 (CST) Subject: [python-win32] ExportAsFixedFormat's ValueError Message-ID: <8d2eefa.351d.169bd340262.Coremail.kaweit@126.com> Hello? i make a question: doc.ExportAsFixedFormat(output, constants.wdExportFormatPDF,Item=constants.wdExportDocumentWithMarkup, CreateBookmarks =constants.wdExportCreateHeadingBookmarks) but "ValueError",the argument was wrong. Cloud you help me? I think I need a Win32com Docutment. -- Best regards Kaweit -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Mar 27 13:21:44 2019 From: timr at probo.com (Tim Roberts) Date: Wed, 27 Mar 2019 10:21:44 -0700 Subject: [python-win32] ExportAsFixedFormat's ValueError In-Reply-To: <8d2eefa.351d.169bd340262.Coremail.kaweit@126.com> References: <8d2eefa.351d.169bd340262.Coremail.kaweit@126.com> Message-ID: <4cf60d97-8500-fc65-6798-e381cbe3f7c8@probo.com> Kaweit wrote: > > i make a question: > doc.ExportAsFixedFormat(output, > constants.wdExportFormatPDF,|Item||=||constants.wdExportDocumentWithMarkup, > CreateBookmarks ||=||constants.wdExportCreateHeadingBookmarks)| > ? ? ?but "ValueError",the argument was wrong.? Cloud you help me? I > think I need a Win32com Docutment. This is not a win32com issue, it is a Word issue.? And it would have been easier if you had told us that you were using Word instead of making us guess.? We don't know were "ExportAsFixedFormat" comes from. Why didn't you cut-and-paste us the exact error message?? Did it tell you which argument was wrong?? What, exactly, is "output"? It would be helpful to see the code leading up to this as well. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3980 bytes Desc: S/MIME Cryptographic Signature URL: From redstone-cold at 163.com Thu Mar 28 10:08:32 2019 From: redstone-cold at 163.com (Zhao Lee) Date: Thu, 28 Mar 2019 22:08:32 +0800 (CST) Subject: [python-win32] hook the left mouse button down event on any window Message-ID: <307132e.bd.169c4a181d5.Coremail.redstone-cold@163.com> I originally posted the question here , please help ,thank you ! I want to hook the left mouse button down event on any window, my code as following : import win32guiimport win32uiimport win32condef onMousePressed(self): print('onMousePressed', win32gui.GetCursorPos())def listener(): windowHandle = win32gui.WindowFromPoint(win32gui.GetCursorPos()) clickedWindow = win32ui.CreateWindowFromHandle(windowHandle) clickedWindow.HookMessage(onMousePressed, win32con.WM_LBUTTONDOWN) # print('-------------registerMouseEvent', clickedWindow)whileTrue: listener() However , the onMousePressed function was never called when clicked, what is wrong ? P.S. I know some similar projects such as PyUserInput, mouse, pynput, just want to know why my code didn't work. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Mar 29 15:35:41 2019 From: timr at probo.com (Tim Roberts) Date: Fri, 29 Mar 2019 12:35:41 -0700 Subject: [python-win32] hook the left mouse button down event on any window In-Reply-To: <307132e.bd.169c4a181d5.Coremail.redstone-cold@163.com> References: <307132e.bd.169c4a181d5.Coremail.redstone-cold@163.com> Message-ID: Zhao Lee wrote: > I originally posted the question here > , > please help ,thank you ! > > > I want to hook the left mouse button down event on any window, my code > as following : > |importwin32guiimportwin32uiimportwin32condefonMousePressed(self):print('onMousePressed',win32gui.GetCursorPos())deflistener():? > ?windowHandle =win32gui.WindowFromPoint(win32gui.GetCursorPos())? > ?clickedWindow =win32ui.CreateWindowFromHandle(windowHandle)? > ?clickedWindow.HookMessage(onMousePressed,win32con.WM_LBUTTONDOWN)# > print('-------------registerMouseEvent', clickedWindow)whileTrue:? > ?listener()| > > However , the |onMousePressed|?function was never called when clicked, > what is wrong ? > > P.S. I know some similar projects such as PyUserInput > , mouse > , pynput > , > just want to know why my code didn't work. > Your code came across badly formatted, so I can't tell exactly what you wrote.? You aren't actually calling listener() from within a continuous, tight CPU loop, are you?? This function is going to get called thousands and thousands of times a second. This is very poor practice, and it's part of the reason these other modules exist. You attach to an external window, install your mouse message hook, then your function exits, the window object is deleted, and the hook is released. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3980 bytes Desc: S/MIME Cryptographic Signature URL: From redstone-cold at 163.com Fri Mar 29 23:39:48 2019 From: redstone-cold at 163.com (Zhao Lee) Date: Sat, 30 Mar 2019 11:39:48 +0800 (CST) Subject: [python-win32] hook the left mouse button down event on any window In-Reply-To: References: <307132e.bd.169c4a181d5.Coremail.redstone-cold@163.com> Message-ID: <475aeec1.13.169ccae99a2.Coremail.redstone-cold@163.com> Thanks for reply! My code is well formated at https://stackoverflow.com/questions/55399565/hook-the-left-mouse-button-down-event-on-any-window or the following : import win32gui import win32ui import win32con def onMousePressed(self): print('onMousePressed', win32gui.GetCursorPos()) def listener(): windowHandle = win32gui.WindowFromPoint(win32gui.GetCursorPos()) clickedWindow = win32ui.CreateWindowFromHandle(windowHandle) clickedWindow.HookMessage(onMousePressed, win32con.WM_LBUTTONDOWN) # print('-------------registerMouseEvent', clickedWindow) while True: listener() time.sleep(8) what is wrong and what's the good practice ? Thanks so much ! ?2019?03?30 03?35?, "Tim Roberts"??: Zhao Lee wrote: > I originally posted the question here > , > please help ,thank you ! > > > I want to hook the left mouse button down event on any window, my code > as following : > |importwin32guiimportwin32uiimportwin32condefonMousePressed(self):print('onMousePressed',win32gui.GetCursorPos())deflistener(): > windowHandle =win32gui.WindowFromPoint(win32gui.GetCursorPos()) > clickedWindow =win32ui.CreateWindowFromHandle(windowHandle) > clickedWindow.HookMessage(onMousePressed,win32con.WM_LBUTTONDOWN)# > print('-------------registerMouseEvent', clickedWindow)whileTrue: > listener()| > > However , the |onMousePressed| function was never called when clicked, > what is wrong ? > > P.S. I know some similar projects such as PyUserInput > , mouse > , pynput > , > just want to know why my code didn't work. > Your code came across badly formatted, so I can't tell exactly what you wrote. You aren't actually calling listener() from within a continuous, tight CPU loop, are you? This function is going to get called thousands and thousands of times a second. This is very poor practice, and it's part of the reason these other modules exist. You attach to an external window, install your mouse message hook, then your function exits, the window object is deleted, and the hook is released. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Sat Mar 30 15:24:25 2019 From: timr at probo.com (Tim Roberts) Date: Sat, 30 Mar 2019 12:24:25 -0700 Subject: [python-win32] hook the left mouse button down event on any window In-Reply-To: <475aeec1.13.169ccae99a2.Coremail.redstone-cold@163.com> References: <307132e.bd.169c4a181d5.Coremail.redstone-cold@163.com> <475aeec1.13.169ccae99a2.Coremail.redstone-cold@163.com> Message-ID: <0191EC4E-AD8F-42CB-9FF1-876F3A1403CB@probo.com> On Mar 29, 2019, at 8:39 PM, Zhao Lee wrote: > > import win32gui > import win32ui > import win32con > > def onMousePressed(self): > print('onMousePressed', win32gui.GetCursorPos()) > > def listener(): > windowHandle = win32gui.WindowFromPoint(win32gui.GetCursorPos()) > clickedWindow = win32ui.CreateWindowFromHandle(windowHandle) > clickedWindow.HookMessage(onMousePressed, win32con.WM_LBUTTONDOWN) > # print('-------------registerMouseEvent', clickedWindow) > > while True: > listener() > time.sleep(8) > > what is wrong and what's the good practice ? I TOLD you what is wrong. Let?s follow the flow. Every 8 seconds you call listener. It does the following, very quickly: * Fetch the window under the cursor, assuming the cursor is over a window. * Create a Python window object around that window handle * Install a hook to catch button down messages for that specific window * Function exits, the window object is destroyed, and the hook is uninstalled Then you go back to sleep. While you are alseep, there is no hook. The only time you have a hook is the few milliseconds between your HookMessage call and when the function returns. The right answer is to use a package like pyHook to install a global hook. This is exactly what it is for. https://stackoverflow.com/questions/165495/detecting-mouse-clicks-in-windows-using-python ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3870 bytes Desc: not available URL: From jpahto at gmail.com Sun Mar 31 12:43:56 2019 From: jpahto at gmail.com (Juha-Pekka Ahto) Date: Sun, 31 Mar 2019 19:43:56 +0300 Subject: [python-win32] Solidworks win32com AttributeError Message-ID: Hello, I'm sending question to this list regarding Solidworks and win32com AttributeError. I have created a modules from Solidworks tlb-files and am trying to get basic functions to work. One such is a GetTitle from IModelDoc2. On the generated module, it's defined as: def GetTitle(self): 'Get design table title' # Result is a Unicode object return self._oleobj_.InvokeTypes(8, LCID, 1, (8, 0), (),) Traceback (most recent call last): sw = File "C:/Users/Juha-Pekka Ahto/Desktop/CustomPropertyManager/CustomPropertyManager.py", line 24, in uniString = swModel.GetTitle() swModel = File "C:\Users\JUHA-P~1\AppData\Local\Temp\gen_py\3.7\83A33D31-27C5-11CE-BFD4-00400513BB57x0x24x0.py", line 34657, in GetTitle return self._oleobj_.InvokeTypes(65607, LCID, 1, (8, 0), (),) File "C:\Python37\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__ raise AttributeError("%s.%s" % (self._username_, attr)) AttributeError: SldWorks.Application.24.InvokeTypes -------------- next part -------------- An HTML attachment was scrubbed... URL: