From i.am.songoku at gmail.com Sun Apr 2 23:06:00 2017 From: i.am.songoku at gmail.com (Krishnan Shankar) Date: Mon, 3 Apr 2017 08:36:00 +0530 Subject: [python-win32] In Python and Windows environment how to supress certain key press and send some other key event for it Message-ID: Hi All, I was trying to build a VIM like shortcuts in windows. For example, IF i press CAPSLOCK & h: It should "{Left}" move one to left. If CAPSLOCK & b: It should "{Ctrl Down}{Left}{Ctrl Up}" move one word left etc. I was successful in sending the key event. I used libraries like, 1. pynput 2. keyboard for the same. But i was unable to supress the Initial key event (ex: Caplock & h) I tried using the keyboard to listen for key press events and supress them as below. >>>>> import keyboard def move_one_left(): """ Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event :return: """ keyboard.send(75) def move_one_word_left(): """ Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event :return: """ keyboard.send('ctrl+left') def main(): """ This is the main loop which reads the key pressed. According to the hotkey registered the function hooked is called. The corresponding function will be the wrapped combination send back. For example: CAPS + b is wrapped to Moving to left. The main loop exits when Ctrl + c is done. So that is not registered. :return: """ try: # Start of the main loop # Registering the hotkeys # CAPS LOCK + H keyboard.add_hotkey('caps lock+h', move_one_left, suppress=True) # CAPS LOCK + B keyboard.add_hotkey('caps lock+b', move_one_word_left, suppress=True) while True: # Read the key pressed print (keyboard.read_key()) except KeyboardInterrupt: print("User has exited the program") if __name__ == "__main__": main() <<<<< This is working for sending the event for key press but the initial keypress is also being send. The supress=True is not working. Am I doing something wrong or is there any better way to supress the initial key event and send another key event in place of that. Regards, Krishnan -------------- next part -------------- An HTML attachment was scrubbed... URL: From webguy at totalrewind.com Thu Apr 6 15:38:45 2017 From: webguy at totalrewind.com (Kurt Eilander) Date: Thu, 6 Apr 2017 13:38:45 -0600 Subject: [python-win32] CreateDesktop() and displaying a window on it Message-ID: Hey all, I'm trying to get system modal functionality like the UAC dialog. According to http://developex.com/blog/system-modal-back/ the thing to do is to create and switch to a new desktop. Therefore, I'm doing: hDeskOld=win32service.GetThreadDesktop(win32api.GetCurrentThreadId()) hDesk=win32service.CreateDesktop("SysModalDesktop",0,win32con.GENERIC_ALL,None) hDesk.SwitchDesktop() # switch to the new desktop try: root=Tk() app=SysmodalDialog(root,title,message,img) app.mainloop() except Exception,e: print e hDeskOld.SwitchDesktop() # switch back hDesk.CloseDesktop() # done The tk stuff inside the try works fine on its own. If I replace the Tk stuff with time.sleep(5.0), then desktops switch fine as well. The problem is I can't get the tk app to show on the new desktop (and therefore mainloop() blocks and I can't get back out of it!) I tried changing Tk() to Tk(screenName="SysModalDesktop") but that didn't make a difference. How do I make my window go to the right desktop?? -Kurt From theheadlesssourceman at gmail.com Thu Apr 6 15:29:02 2017 From: theheadlesssourceman at gmail.com (k) Date: Thu, 6 Apr 2017 13:29:02 -0600 Subject: [python-win32] CreateDesktop() and displaying a window on it Message-ID: <8efdf6e3-79a9-1e9d-4571-a5a5325f741b@gmail.com> Hey all, I'm trying to get system modal functionality like the UAC dialog. According to http://developex.com/blog/system-modal-back/ the thing to do is to create and switch to a new desktop. Therefore, I'm doing: hDeskOld=win32service.GetThreadDesktop(win32api.GetCurrentThreadId()) hDesk=win32service.CreateDesktop("SysModalDesktop",0,win32con.GENERIC_ALL,None) hDesk.SwitchDesktop() # switch to the new desktop try: root=Tk() app=SysmodalDialog(root,title,message,img) app.mainloop() except Exception,e: print e hDeskOld.SwitchDesktop() # switch back hDesk.CloseDesktop() # done The tk stuff inside the try works fine on its own. If I replace the Tk stuff with time.sleep(5.0), then desktops switch fine as well. The problem is I can't get the tk app to show on the new desktop (and therefore mainloop() blocks and I can't get back out of it!) I tried changing Tk() to Tk(screenName="SysModalDesktop") but that didn't make a difference. How do I make my window go to the right desktop?? -Kurt From eryksun at gmail.com Thu Apr 6 20:14:18 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 7 Apr 2017 00:14:18 +0000 Subject: [python-win32] CreateDesktop() and displaying a window on it In-Reply-To: References: Message-ID: On Thu, Apr 6, 2017 at 7:38 PM, Kurt Eilander wrote: > Hey all, > > I'm trying to get system modal functionality like the UAC dialog. > > According to http://developex.com/blog/system-modal-back/ the thing to do is > to create and switch to a new desktop. > > Therefore, I'm doing: > > hDeskOld=win32service.GetThreadDesktop(win32api.GetCurrentThreadId()) SwitchDesktop affects which desktop has input focus. SetThreadDesktop affects which desktop is used by the current thread. You need to open a handle to the current input desktop to switch back to it at the end. I'm far from a Tk expert. I don't know how to close out the resources it uses to be able to call SetThreadDesktop. I'm not going to bother figuring this out to get this working on the main thread. I'll just create a new thread; pass it the handle for the new desktop; save the existing input desktop; set the thread desktop; and switch the input desktop. Then on teardown switch back to the original input desktop and close the desktop handles. Since I can't reliably call SetThreadDesktop to restore the worker thread's desktop before the thread exits, there's some asynchronous overlap when the thread and its resources haven't been destroyed yet. To address the potential for getting ERROR_BUSY when calling CloseDesktop from the main thread, I'm adding a retry loop that defaults to 10 attempts, with a delay of 0.1s. It shouldn't need more than 2 attempts. import sys import time import tkinter import threading import winerror import win32con import win32api import win32service def close_desktop(hDesk, numtries=10): for i in range(numtries): try: return hDesk.CloseDesktop() except win32service.error as e: if e.winerror != winerror.ERROR_BUSY or i == numtries - 1: raise time.sleep(0.1) def dialog(hDesk, title='SysModalDialog', message='', img=None): hDeskInputOld = win32service.OpenInputDesktop(0, False, win32con.DESKTOP_SWITCHDESKTOP) try: hDesk.SetThreadDesktop() hDesk.SwitchDesktop() try: root = tkinter.Tk() #root.mainloop() app = SysmodalDialog(root, title, message, img) app.mainloop() finally: hDeskInputOld.SwitchDesktop() finally: close_desktop(hDeskInputOld) def main(): hDesk = win32service.CreateDesktop("SysModalDesktop", 0, win32con.GENERIC_ALL, None) try: t = threading.Thread(target=dialog, args=(hDesk,)) t.start() t.join() finally: close_desktop(hDesk) return 0 if __name__ == '__main__': sys.exit(main()) From timr at probo.com Fri Apr 7 12:35:30 2017 From: timr at probo.com (Tim Roberts) Date: Fri, 7 Apr 2017 09:35:30 -0700 Subject: [python-win32] CreateDesktop() and displaying a window on it In-Reply-To: References: Message-ID: <555fcb15-daab-a70f-aa85-d9fa57dcbf78@probo.com> Kurt Eilander wrote: > According to http://developex.com/blog/system-modal-back/ the thing to > do is to create and switch to a new desktop. > > Therefore, I'm doing: > > hDeskOld=win32service.GetThreadDesktop(win32api.GetCurrentThreadId()) > hDesk=win32service.CreateDesktop("SysModalDesktop",0,win32con.GENERIC_ALL,None) > > hDesk.SwitchDesktop() # switch to the new desktop > try: > root=Tk() > app=SysmodalDialog(root,title,message,img) > app.mainloop() > except Exception,e: > print e > hDeskOld.SwitchDesktop() # switch back > hDesk.CloseDesktop() # done > > The tk stuff inside the try works fine on its own. > If I replace the Tk stuff with time.sleep(5.0), then desktops switch > fine as well. > > The problem is I can't get the tk app to show on the new desktop (and > therefore mainloop() blocks and I can't get back out of it!) I see Eryk provided the explanation, but all I had to do to make your example work was add hDesk.SetThreadDesktop() just after your SwitchDesktop call. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From eryksun at gmail.com Fri Apr 7 13:14:43 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 7 Apr 2017 17:14:43 +0000 Subject: [python-win32] CreateDesktop() and displaying a window on it In-Reply-To: <555fcb15-daab-a70f-aa85-d9fa57dcbf78@probo.com> References: <555fcb15-daab-a70f-aa85-d9fa57dcbf78@probo.com> Message-ID: On Fri, Apr 7, 2017 at 4:35 PM, Tim Roberts wrote: > I see Eryk provided the explanation, but all I had to do to make your > example work was add > hDesk.SetThreadDesktop() > just after your SwitchDesktop call. That didn't work for me before. It was causing my Windows 10 system to get stuck on a blank desktop. The SetThreadDesktop call was failing, which I assumed was because tkinter was automatically creating an invisible window or hook in the main thread. That's why I used a new thread as a workaround. But just now it worked. Go figure. From cmhulbert at gmail.com Wed Apr 12 01:21:37 2017 From: cmhulbert at gmail.com (Caleb Hulbert) Date: Wed, 12 Apr 2017 05:21:37 +0000 Subject: [python-win32] Can't access all the buttons available in a GUI Program Message-ID: Hello all, I am attempting to automate a client program that I have, and have been using win32gui to access the windows and children. I have been fairly successful, and can automate quite a bit by sending text or click to the children with SendMessage or PostMessage. I am stuck with certain controls though, as I know they exist on the gui, and I can see and interact with them, however, they are nowhere to be seen in any children, and further SendMessage does not interact with them, even if I specific the correct point in the window. Further, the Inspect tool does not recognize them at all. I believe they are ActiveX controls, though I'm not 100% positive (does anyone know a way to check?). Any help would be amazing! Best, Caleb -------------- next part -------------- An HTML attachment was scrubbed... URL: From reckoner at gmail.com Sun Apr 16 08:19:16 2017 From: reckoner at gmail.com (reckoner) Date: Sun, 16 Apr 2017 05:19:16 -0700 Subject: [python-win32] Programmatically switch desktops in windows 10? Message-ID: <4c0bd2c1-1c9b-d97e-719f-957de87b9c5c@gmail.com> Windows 10 has multiple desktops built-in. Is it it possible to programmatically switch between desktops? How about programmatically moving an active window between desktops? Thanks! From timr at probo.com Mon Apr 17 02:59:54 2017 From: timr at probo.com (Tim Roberts) Date: Sun, 16 Apr 2017 23:59:54 -0700 Subject: [python-win32] Programmatically switch desktops in windows 10? In-Reply-To: <4c0bd2c1-1c9b-d97e-719f-957de87b9c5c@gmail.com> References: <4c0bd2c1-1c9b-d97e-719f-957de87b9c5c@gmail.com> Message-ID: On Apr 16, 2017, at 5:19 AM, reckoner wrote: > > Windows 10 has multiple desktops built-in. Is it it possible to > programmatically switch between desktops? How about programmatically > moving an active window between desktops? Yes The interface is COM based, called IVirtualDesktopManager. There are several C# examples on the Interwebs. You create an instance of CLSID aa509086-5ca9-4c25-8f95-589d3c07b48a and fetch an IVirtualDesktopManager interface from that. ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gowrishankarmandya at gmail.com Mon Apr 24 15:12:49 2017 From: gowrishankarmandya at gmail.com (gowri shankar) Date: Mon, 24 Apr 2017 21:12:49 +0200 Subject: [python-win32] To control commercial software CST through python Message-ID: Dear all, I want to control a commercial numerical solver CST through python. Usually, CST can be controlled using MATLAB. CST accepts both COM and VBA macros from MATLAB. As VBA is difficult and time consuming to program, i was successful in connecting the CST through COM interface from MATLAB. The sample snapshot of the commands are as below: *********************************************************************** * cst = actxserver('CSTStudio.application') % to open the CST* * mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst'); %to open a particular file* * a=20;* * b=20;* * c=72;* * %To store the parameters* * mws.invoke('StoreParameter','a',a); %These are the COM interface commands from MATLAB to CST* * mws.invoke('StoreParameter','b',b);* * mws.invoke('StoreParameter','c',c);* * %To rebuild * * invoke(mws,'Rebuild');* * %%Setting only the required boudnary conditions only* * bound=invoke(mws,'Boundary'); %These are the COM interface commands from MATLAB to CST* * bound.invoke('Zmin','magnetic');* * bound.invoke('Zmax','magnetic');* * %% Set the frequency range* * solver=invoke(mws,'Solver');* * invoke(solver,'FrequencyRange',freMin,freMax);* * Esolver=invoke(mws,'EigenmodeSolver');* * invoke(Esolver,'Reset');* * invoke(Esolver,'SetMeshType','Tetrahedral Mesh');* * invoke(Esolver,'SetNumberOfModes',noOfMode);* * invoke(Esolver,'Start'); %Run the solver* * noOfModesCalculated=invoke(Esolver,'GetNumberOfModesCalculated');* * for j=1:noOfModesCalculated* * eigenFreq(j)=invoke(Esolver,'GetModeFrequencyInHz',j);* * end* * invoke(mws,'Save'); %Save the file* * invoke(mws, 'Quit'); %closes the file* * release(mws); * * invoke(cst, 'Quit'); % closes the CST application* * release(cst);* * dos(['taskkill /F /IM ' '"CST DESIGN ENVIRONMENT.exe"']);* ************************************************************************** MATLAB commands work perfectly wihtout any fuss. *I have translated the above code in python but i was able to talk to CST with only first 2-3 commands i.e* ********************************* *import win32com.client* *cst = win32com.client.Dispatch("CSTStudio.Application")* *#Opens a new CST file* *mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');* *#mws=cst.NewMWS()* *###Below this commands i got error or sometimes it didn't give any error but just it didn't worked* *mws.StoreParameter('len2',10.1)* *mwssolver=mws.Solver()* *mws.Solver.Start()* ******************************* I tried different online forums for help and i was unsuccessful in getting any clue how to move forward. Erros messages didnt revealed any information. I even checked and compared the COM commands used to control Excel from MATLAB and Python. But, still i am not able to progress any further. Moreover, the commercial software guys wont help me in doing with python. Furthermore, i used combrowse.py and make.py to access the different objects of the interface but they are all hidden for CST. Can someone suggest me how should i move ahead, are there any examples available for controlling a windows application through MATLAB and python so that i can understand the co-relation between the commands between the two. Any help in this regard is highly appreciated. Regards, GOWRISHANKAR.T.H -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Apr 25 12:48:05 2017 From: timr at probo.com (Tim Roberts) Date: Tue, 25 Apr 2017 09:48:05 -0700 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: Message-ID: gowri shankar wrote: > ************************************************************************** > > MATLAB commands work perfectly wihtout any fuss. > *I have translated the above code in python but i was able to talk to > CST with only first 2-3 commands i.e* > ********************************* > /import win32com.client/ > /cst = win32com.client.Dispatch("CSTStudio.Application")/ > /#Opens a new CST file/ > /mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');/ You can't use backslashes like that in a Python string literal. You need to use one of following: mws = cst.OpenFile('D:/Gowrishankar/PDF/cuboid.cst') mws = cst.OpenFile('D:\\Gowrishankar\\PDF\\cuboid.cst') mws = cst.OpenFile(r'D:\Gowrishankar\PDF\cuboid.cst') -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From j.orponen at 4teamwork.ch Tue Apr 25 13:00:49 2017 From: j.orponen at 4teamwork.ch (Joni Orponen) Date: Tue, 25 Apr 2017 19:00:49 +0200 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: Message-ID: On Tue, Apr 25, 2017 at 6:48 PM, Tim Roberts wrote: > gowri shankar wrote: > > ************************************************************ > ************** > > > > MATLAB commands work perfectly wihtout any fuss. > > *I have translated the above code in python but i was able to talk to > > CST with only first 2-3 commands i.e* > > ********************************* > > /import win32com.client/ > > /cst = win32com.client.Dispatch("CSTStudio.Application")/ > > /#Opens a new CST file/ > > /mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');/ > > You can't use backslashes like that in a Python string literal. You > need to use one of following: > > mws = cst.OpenFile('D:/Gowrishankar/PDF/cuboid.cst') > mws = cst.OpenFile('D:\\Gowrishankar\\PDF\\cuboid.cst') > mws = cst.OpenFile(r'D:\Gowrishankar\PDF\cuboid.cst') > Using os.path.join() is also a valid alternative pattern for operational safety and consistency. import os os.path.join( 'D:', os.path.sep, 'Gowrishankar', 'PDF', 'cuboid.cst') >>> 'D:\\Gowrishankar\\PDF\\cuboid.cst' -- Joni Orponen -------------- next part -------------- An HTML attachment was scrubbed... URL: From gowrishankarmandya at gmail.com Thu Apr 27 09:18:39 2017 From: gowrishankarmandya at gmail.com (gowri shankar) Date: Thu, 27 Apr 2017 15:18:39 +0200 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: Message-ID: Thanks for the suggestion guys. But, my problem is, i am able to open CST from Python but other commands which works in MATLAB don't work in python. ****************MATLAB commands****************** * cst = actxserver('CSTStudio.application') % to open the CST* * mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst'); %to open a particular file* ****************Python commands************************* *import win32com.client* *cst = win32com.client.Dispatch("CSTStudio.Application")* *#Opens a new CST file* *mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');* * a=20;* * b=20;* * c=72;* * %To store the parameters* *I was not able to convert these following MATLAB commands into python. I got errors. * * mws.invoke('StoreParameter','a',a); %These are the COM interface commands from MATLAB to CST* * mws.invoke('StoreParameter','b',b);* * mws.invoke('StoreParameter','c',c);* * %To rebuild * * invoke(mws,'Rebuild');* * %%Setting only the required boudnary conditions only* * bound=invoke(mws,'Boundary'); %These are the COM interface commands from MATLAB to CST* * bound.invoke('Zmin','magnetic');* * bound.invoke('Zmax','magnetic');* * %% Set the frequency range* * solver=invoke(mws,'Solver');* * invoke(solver,'FrequencyRange',freMin,freMax);* * Esolver=invoke(mws,'EigenmodeSolver');* * invoke(Esolver,'Reset');* * invoke(Esolver,'SetMeshType','Tetrahedral Mesh');* * invoke(Esolver,'SetNumberOfModes',noOfMode);* * invoke(Esolver,'Start'); %Run the solver* * noOfModesCalculated=invoke(Esolver,'GetNumberOfModesCalculated');* * for j=1:noOfModesCalculated* * eigenFreq(j)=invoke(Esolver,'GetModeFrequencyInHz',j);* * end* * invoke(mws,'Save'); %Save the file* * invoke(mws, 'Quit'); %closes the file* * release(mws); * * invoke(cst, 'Quit'); % closes the CST application* * release(cst);* * dos(['taskkill /F /IM ' '"CST DESIGN ENVIRONMENT.exe"']);* "I tried different online forums for help and i was unsuccessful in getting any clue how to move forward. Error messages didn't revealed any information. I even checked and compared the COM commands used to control Excel from MATLAB and Python. But, still i am not able to progress any further. Moreover, the commercial software guys wont help me in doing with python. Furthermore, i used combrowse.py and make.py to access the different objects of the interface but they are all hidden for CST. Can someone suggest me how should i move ahead, are there any examples available for controlling a windows application through MATLAB and python so that i can understand the co-relation between the commands between the two. Any help in this regard is highly appreciated." Regards, GOWRISHANKAR.T.H Contact No:+4917641783894 On Tue, Apr 25, 2017 at 7:00 PM, Joni Orponen wrote: > On Tue, Apr 25, 2017 at 6:48 PM, Tim Roberts wrote: > >> gowri shankar wrote: >> > ************************************************************ >> ************** >> > >> > MATLAB commands work perfectly wihtout any fuss. >> > *I have translated the above code in python but i was able to talk to >> > CST with only first 2-3 commands i.e* >> > ********************************* >> > /import win32com.client/ >> > /cst = win32com.client.Dispatch("CSTStudio.Application")/ >> > /#Opens a new CST file/ >> > /mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');/ >> >> You can't use backslashes like that in a Python string literal. You >> need to use one of following: >> >> mws = cst.OpenFile('D:/Gowrishankar/PDF/cuboid.cst') >> mws = cst.OpenFile('D:\\Gowrishankar\\PDF\\cuboid.cst') >> mws = cst.OpenFile(r'D:\Gowrishankar\PDF\cuboid.cst') >> > > Using os.path.join() is also a valid alternative pattern for operational > safety and consistency. > > import os > > os.path.join( > 'D:', > os.path.sep, > 'Gowrishankar', > 'PDF', > 'cuboid.cst') > > >>> 'D:\\Gowrishankar\\PDF\\cuboid.cst' > > -- > Joni Orponen > > _______________________________________________ > 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 timr at probo.com Thu Apr 27 13:43:58 2017 From: timr at probo.com (Tim Roberts) Date: Thu, 27 Apr 2017 10:43:58 -0700 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: Message-ID: gowri shankar wrote: > > /*I was not able to convert these following MATLAB commands into > python. I got errors.* / > / mws.invoke('StoreParameter','a',a); %These are the COM interface > commands from MATLAB to CST/ > / mws.invoke('StoreParameter','b',b);/ > / mws.invoke('StoreParameter','c',c);/ > / %To rebuild / > / invoke(mws,'Rebuild');/ > /... > / > > I tried different online forums for help and i was unsuccessful in > getting any clue how to move forward. Error messages didn't revealed > any information. I even checked and compared the COM commands used to > control Excel from MATLAB and Python. But, still i am not able to > progress any further. You are still only giving us about 1/4 of the information we need in order to help you. It doesn't do any good to show is the MATLAB code you started with. We need to see the Python code you created, and we need to see the error messages you get. The COM error messages might seem inscrutable to you, but the large negative numbers in there are specific COM error codes. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Apr 27 21:33:53 2017 From: timr at probo.com (Tim Roberts) Date: Thu, 27 Apr 2017 18:33:53 -0700 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: Message-ID: <307a3e55-f14f-0e4f-02c0-e3cb38d7c51d@probo.com> gowri shankar wrote: > > Thanks for bringing out my inadequacies. By the by i am using Python > 2.7.8 |Anaconda 2.1.0 (64-bit). > Here are the error codes for the same: > > import win32com.client > *cst* = win32com.client.Dispatch("CSTStudio.Application") > #Opens a new CST file > *mws*=*cst*.OpenFile('D:\Gowrishankar\PDF\cuboid.cst') > ############## > *mws.StoreParameter('len2',10.1) > * > *mws.StoreParameter("s",5)* > ##I don't get any error message for them. And usually this should > store a variable and its values in CST but it didn't do > *Esolver=mws.EigenmodeSolver()* > *### I got the following error message* > Traceback (most recent call last): > File "", line 1, in > File "C:\Anaconda\lib\site-packages\win32com\client\dynamic.py", > line 192, in __call__ > return > self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) > pywintypes.com_error: (-2147352573, 'Mitglied nicht gefunden.', None, > None) That's 0x80020003, DISP_E_MEMBERNOTFOUND, meaning that it did not find the name in its dispatch table. Are you absolutely sure you have the spelling correct? Could it be EigenModeSolver, for example? Capitalization matters. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Apr 28 02:36:41 2017 From: timr at probo.com (Tim Roberts) Date: Thu, 27 Apr 2017 23:36:41 -0700 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: <307a3e55-f14f-0e4f-02c0-e3cb38d7c51d@probo.com> Message-ID: <6F555913-A680-45D8-9EB6-BF7BDAC31078@probo.com> On Apr 27, 2017, at 11:17 PM, gowri shankar wrote: > > I checked both the ways without any success. By the by, mws.EigenmodeSolver() works perfectly in MATLAB. Does the object name changes with different language. It's not impossible. You're using late binding here, which has to find the entry points by doing a text search. However, the web seems to indicate that your spelling is correct. > Can you please suggest any literature or source where i can learn more on COM . There are an infinite number of books and websites on COM; the technology has been around for more than 20 years. However, the different language bindings do have different requirements and implications, so a C++-based book will be good background information, but won't help specifically with Python. As an experiment, you might try using EnsureDispatch instead of just Dispatch. from win32com.client.genache import EnsureDispatch That creates and saves a Python module to interface to the object. Sometimes having that module can be helpful in debugging. ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Apr 28 02:36:29 2017 From: timr at probo.com (Tim Roberts) Date: Thu, 27 Apr 2017 23:36:29 -0700 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: Message-ID: On Apr 27, 2017, at 12:02 PM, gowri shankar > wrote: Thanks for bringing out my inadequacies. By the by i am using Python 2.7.8 |Anaconda 2.1.0 (64-bit). Here are the error codes for the same: import win32com.client cst = win32com.client.Dispatch("CSTStudio.Application") #Opens a new CST file mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst') That string is still wrong, by the way. You NEED to fix the backslashes. ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From max at landaeus.com Fri Apr 28 07:17:42 2017 From: max at landaeus.com (Max Landaeus) Date: Fri, 28 Apr 2017 13:17:42 +0200 Subject: [python-win32] To control commercial software CST through python In-Reply-To: References: Message-ID: <378c8579-b4f1-25bf-01a9-0a0b0e6a4cbf@landaeus.com> Hi, I wrote some code to control CST a couple of years ago. It was quite difficult to interface via COM, since some commands simply refused to work. What I did in the end was to as few com-calls as possible and did the rest in VB. Even if VB is a terrible language the end result was more stable. Among other things I wrote code to remotely create matching networks in the Schematics (DS canvas). Then I created a class in Python to generate VB code on the fly, saved it as a VB-file and used the DS.RunScript(path) command to get CST to generate the network. This worked well. One more thing: I found that I had to use the DS._FlagAsMethod before I used the actual command. I.e I had to do: DS._FlagAsMethod("RunScript") DS.RunScript(script_file_name) That helped to get many commands to work - but not all. BR, Max On 2017-04-24 21:12, gowri shankar wrote: > Dear all, > I want to control a commercial numerical solver CST > through python. Usually, CST can be controlled using MATLAB. CST > accepts both COM and VBA macros from MATLAB. As VBA is difficult and > time consuming to program, i was successful in connecting the CST > through COM interface from MATLAB. The sample snapshot of the commands > are as below: > *********************************************************************** > / cst = actxserver('CSTStudio.application') % to open the CST/ > /mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst'); %to open a > particular file/ > / a=20;/ > / b=20;/ > / c=72;/ > / %To store the parameters/ > / mws.invoke('StoreParameter','a',a); %These are the COM interface > commands from MATLAB to CST/ > / mws.invoke('StoreParameter','b',b);/ > / mws.invoke('StoreParameter','c',c);/ > / %To rebuild / > / invoke(mws,'Rebuild');/ > / > / > / %%Setting only the required boudnary conditions only/ > / bound=invoke(mws,'Boundary'); %These are the COM interface > commands from MATLAB to CST/ > / bound.invoke('Zmin','magnetic');/ > / bound.invoke('Zmax','magnetic');/ > / > / > / %% Set the frequency range/ > / solver=invoke(mws,'Solver');/ > / invoke(solver,'FrequencyRange',freMin,freMax);/ > / > / > / Esolver=invoke(mws,'EigenmodeSolver');/ > / invoke(Esolver,'Reset');/ > / invoke(Esolver,'SetMeshType','Tetrahedral Mesh'); > / > / invoke(Esolver,'SetNumberOfModes',noOfMode);/ > / invoke(Esolver,'Start'); %Run the solver > / > /noOfModesCalculated=invoke(Esolver,'GetNumberOfModesCalculated');/ > / for j=1:noOfModesCalculated/ > /eigenFreq(j)=invoke(Esolver,'GetModeFrequencyInHz',j);/ > / end/ > / > / > / invoke(mws,'Save'); %Save the file/ > / invoke(mws, 'Quit'); %closes the file/ > / release(mws); / > / invoke(cst, 'Quit'); % closes the CST application/ > / release(cst);/ > / dos(['taskkill /F /IM ' '"CST DESIGN ENVIRONMENT.exe"']);/ > > ************************************************************************** > MATLAB commands work perfectly wihtout any fuss. > *I have translated the above code in python but i was able to talk to > CST with only first 2-3 commands i.e* > ********************************* > /import win32com.client/ > /cst = win32com.client.Dispatch("CSTStudio.Application")/ > /#Opens a new CST file/ > /mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst');/ > / > / > /#mws=cst.NewMWS()/ > / > / > /###*Below this commands i got error or sometimes it didn't give any > error but just it didn't worked*/ > /mws.StoreParameter('len2',10.1)/ > /mwssolver=mws.Solver()/ > /mws.Solver.Start()/ > ******************************* > I tried different online forums for help and i was unsuccessful in > getting any clue how to move forward. Erros messages didnt revealed > any information. I even checked and compared the COM commands used to > control Excel from MATLAB and Python. But, still i am not able to > progress any further. Moreover, the commercial software guys wont help > me in doing with python. Furthermore, i used combrowse.py and make.py > to access the different objects of the interface but they are all > hidden for CST. Can someone suggest me how should i move ahead, are > there any examples available for controlling a windows application > through MATLAB and python so that i can understand the co-relation > between the commands between the two. Any help in this regard is > highly appreciated. > > > Regards, > GOWRISHANKAR.T.H > > > > _______________________________________________ > 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 mysecretrobotfactory at gmail.com Fri Apr 28 11:48:01 2017 From: mysecretrobotfactory at gmail.com (Michael C) Date: Fri, 28 Apr 2017 08:48:01 -0700 Subject: [python-win32] manual for pywin32 Message-ID: Hi all, is there a manual for this module? I can't seem to find any! -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Apr 28 14:02:43 2017 From: timr at probo.com (Tim Roberts) Date: Fri, 28 Apr 2017 11:02:43 -0700 Subject: [python-win32] manual for pywin32 In-Reply-To: References: Message-ID: <24073f36-7876-e483-cc24-3554070abf06@probo.com> Michael C wrote: > Hi all, is there a manual for this module? I can't seem to find any! I'm skeptical that you looked at all. Google "pywin32 documentation". Pywin32 is very large, since it is trying to expose most of the incredibly vast Win32 API. Was there something specific you were after? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mysecretrobotfactory at gmail.com Fri Apr 28 20:40:34 2017 From: mysecretrobotfactory at gmail.com (Michael C) Date: Fri, 28 Apr 2017 17:40:34 -0700 Subject: [python-win32] Screenshot a given window instead of the whole desktop Message-ID: Hi all: I have my own code that samples pixel colour, https://pastebin.com/4EMd765h and now I am trying to add the feature of saving the Device Context to a .bmp file, so I found this code https://books.google.ca/books?id=9MS9BQAAQBAJ however there is one problem: The book example screenshots the whole desktop and I only want a screenshot of a given window. Is there a way to modify the black hat example into something that only screenshot a window given its handle? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From mysecretrobotfactory at gmail.com Sat Apr 29 16:10:53 2017 From: mysecretrobotfactory at gmail.com (Michael C) Date: Sat, 29 Apr 2017 13:10:53 -0700 Subject: [python-win32] win32gui.SetPixel error Message-ID: fill the radar scan points with red.py", line 66, in win32gui.SetPixel(desktop_dc, x,y, rgb ) pywintypes.error: (0, 'SetPixel', 'No error message is available') Hi all: I am trying to paint a few pixels in the color of red. However, when I ran this win32gui.SetPixel(desktop_dc, x,y, rgb ) I get the error message above. How can I fix this? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From mysecretrobotfactory at gmail.com Sat Apr 29 17:14:33 2017 From: mysecretrobotfactory at gmail.com (Michael C) Date: Sat, 29 Apr 2017 14:14:33 -0700 Subject: [python-win32] win32gui.SetPixel error In-Reply-To: References: Message-ID: Oh I found out my code accidentally give negative values to the function. :( Thanks all! On Sat, Apr 29, 2017 at 1:10 PM, Michael C wrote: > fill the radar scan points with red.py", line 66, in > win32gui.SetPixel(desktop_dc, x,y, rgb ) > pywintypes.error: (0, 'SetPixel', 'No error message is available') > > > > > Hi all: > > I am trying to paint a few pixels in the color of red. However, when I > ran this > > win32gui.SetPixel(desktop_dc, x,y, rgb ) > > > I get the error message above. How can I fix this? Thanks! > -------------- next part -------------- An HTML attachment was scrubbed... URL: