Based on a question I read and responded to on Reddit, I've been investigating using the relatively new Windows UI Automation framework via Python (and pywin32) to query custom widgets inside a Google Chrome window. UISpy shows me the control I'm interested in, but the naming conventions and lack of window classes make me believe the UI Automation framework is the only way to access it. I was able to get as far as generating a COM stub for the UI Automation library via PythonWin and the Makepy utility, but couldn't actually instantiate the COM object. I don't have a lot of experience with COM, outside of following along in Mark Hammond's "Python Programming on Win32" to drive Excel via COM with Python. I found an article describing how to instantiate the COM object from C/C++ but I wasn't able to get much from it.
I think I can follow along with the API documentation if I can just figure out how to instantiate the object.
You can use the awesome comtypes package to easily use the IUIAutomation COM interface from CPython scripts.
Here's a very simple demo I wrote:
https://github.com/billagee/test-polyglot/blob/master/printDesktopUiaElementName/ms-ui-automation-com-api/python/comtypes/print_desktop_uia_element_name.py
Try win32com.client.gencache, particularly GetModuleForCLSID(["e22ad333-b25f-460c-83d0-0581107395c9") - the clsid for the Win32 implementation of IUIAutomation.
Related
I am trying to create a site which auto generates python code and is presented to the user in an ide style where they can edit it then run it live using brython.
I am having trouble setting up the ide part I found brython console but that won't work for editing things. So my question is are there any existing implementations I can use?
I think you want an extensible web IDE. An IDE that runs in the browser that expects you to build on top of, so that you can likely get the text out of it to provide to Brython. I'd try searching for terms like these:
extensible web IDE
web IDE framework
IDE framework in JavaScript
et c.
My python application need to import photos from iPhone/Android and copy it to local hard disk. This is Windows application and need to use Windows auto play handler and COM. I have seen some example that implement it using c# language (link is here) but I don't know how to do this using Python.
Further Googling tells python has comtypes library to use COM on windows platform but I do not find any detail documentation on how to get it done.
I have my own application on python 2.7. I want to control an outside .exe application.
I'm able to launch such an application, klm.exe as:
from win32com.client import *
ExtApp = Dispatch("Wscript.Shell")
ExtApp.Run("E:\XYZ\ABC\klm")
But I want to have full control of this outside .exe application as it has tabs, radio buttons, push buttons, etc.
Is there a way to do so?
But I want to have full control of this outside .exe application as it has tabs, radio buttons, push buttons, etc.
Is there a way to do so?
Yes, multiple ways, depending on the application.
Since you're already using COM (although I'm not sure why you're using it just to launch apps)… does the app have a COM automation (IDispatch) interface? If so, there will probably be documentation showing how to use it from VB# (or VBScript or C# or …), which you can easily adapt to Python and win32com. (For an example of such an application, see the Outlook automation docs.)
If there's no COM automation interface, there may still be a lower-level COM interface, which is almost as easy to use via win32com, but it usually won't provide any access to the GUI controls; instead, you'll be talking to the same lower-level functionality that the GUI uses. (For a good example, see Apple's iTunes COM Interface.)
If there's no COM support at all, the simplest thing to do is to automate it via Windows WM_* events. There are some examples of doing that in the pywin32 documentation, but there are also a lot of higher-level wrappers, like AutoPy and pywinauto/swapy, and so on that will make things a whole lot easier. There are dozens of these, free and commercial, and even more if you're willing to step outside of Python and use a different scripting system, and SO is not a good place to discuss the pros and cons of each.
Finally, you can always ignore the app's windows and just automate the system mouse… but this is almost always a silly thing to do.
So I'm trying to create an automatic installer using Python. How would I go about interacting with native Windows applications that I launch? I am currently launching them using subprocess.call. Would I need to use Win32com? IronPython? Call a VB script from Python?
I've been trying to look into COM objects, but all I see are default Microsoft applications.
If the application supports COM, use COM using win32com. This tutorial helped me a lot. If it does not, you can use something like pywinauto or similar software. It is usually described as module for GUI testing. SendKeys comes handy for non-standard GUIs as a last resort.
Ranorex Spy is very helpful tool for identifying GUI elements.
Some of my colleagues also use compiled AutoHotkey scripts.
I have an existing VS-2008 Windows application with back-end MySQL Server 5.5. The existing application uses Crystal Reports for reporting. I want to get rid of Crystal Reports and want to use another tool that seamlessly integrates with VS-2010 Express. I want to remove reporting options from my existing application and want to write a new WPF reporting application using VS-2010 Express. I want a free tool but as I am using MySQL, tools like SSRS are not useful for me.
What are the options? I am planning the other way round by writing a Python reporting application powered by any open-source Python reporting tool.
For WPF you can use http://wpfreports.codeplex.com/ for simple reports or follow this article instructions to make you own: http://janrep.blog.codeplant.net/post/WPF-Multipage-Reports-Part-I.aspx
I've used SSRS, but only the RDLC part (you can use it with any datasource), but not very happy with the results and WPF does not have a native RDLC ReportViewer.
Also check this related question What's the best approach to printing/reporting from WPF?
Why not have both? IronPython is a python implementation on top of .NET. It allows you to write code that is totally python, but gives you access to all of .NET, including WPF.
For a quick look at what this looks like, here is a basic WPF project using ironpython.