Let's say that I open up some word file with a macro that opens up a dialog with some buttons.
Is there a way to find those buttons automatically and press them (when having only the PID)?
Currently, I'm using pywinauto to automate the GUI testing. If there's a way to do it with pywinauto that would be great.
Thanks.
To summarize all the comments:
It's possible to enumerate all the windows and their controls using methods .windows() (for top-level windows), immediate .children() and all the .descendants() (the whole subtree as a plain list). You can even filter children and descendants by class_name, control_type, content_only and/or title.
Example:
print(app.windows()[0].descendants(control_type='Edit'))
Related
Ctrl+Escape is a global Windows shortcut for opening main system menu. But I would like my Qt application to use this shortcut without triggering Windows main menu. I know it is probably a bad idea to override system shortcuts in general, but I would like to use this shortcut is a very limited use case.
This usecase is as follows. I have a popup window containing several rows or items. This window is opened by Ctrl+Tab and while the user holds Ctrl and keep pressing Tab, the current rows are cycled through. When the user releases Ctrl, the current row is used for some operation... But sometimes it happens that user presses Ctrl+Tab and then realizes he does not want to continue. He usually presses Escape while still holding Ctrl. And then it triggers Windows system menu and normal user gets confused, choleric user get angry... which is a bad thing. In other words I would like to be able to close the popup window when user presses Ctrl+Escape. How to do that? It is even possible?
If I write the code using this shortcut like any other short, it does not work and it always triggers Windows main menu.
As I understand it, Qt will typically not receive the key event if the underlying window system has intercepted it. For example even QtCreator cannot override system-wide shortcuts.
This question is almost a duplicate of: C++/Qt Global Hotkeys
While that question is asking specifically to capture shortcuts in a hidden/background application, I think the basic concept is the same -- capture shortcuts before the window system processes them.
From that answer, UGlobalHotkey seems pretty good, and the How to use System-Wide Hotkeys in your Qt application blog post could be useful for your limited-use case (but read the comments on that blog post about fixing the example).
Also found:
https://github.com/mitei/qglobalshortcut
https://github.com/Skycoder42/QHotkey (looks like a more detailed version of above)
I am trying to automate a self made GUI in python with pywinauto.
I am starting the application with app = Application().start(...) and get the window with dlg = app.top_window_().
In the next step I want to double-click an item from a list. But I do not know how.
I tried to use the Inspect.exe. By clicking on "navigate to children" I get the list which has no name. Clicking again on "navigate to children" shows the name of the item I want to click.
So, how can I refer to this item?
I thought about something like dlg.itemname.double_click(button='left')? I can only find examples in which they are pressing menu entries.
From what you're describing I can assume you use Application(backend="uia") (or must use) because Inspect.exe uses UI Automation technology which is supported by UIA backend in pywinauto.
And yes, you're almost right about double click. This should look so:
dlg.itemname.double_click_input(button='left')
# or
dlg.itemname.click_input(button='left', double=True)
How would I know? Detecting items as separate controls are typical for UIA backend.
For default Win32 backend (what you can see in Spy++ tool) a list view or a list box always have virtual items that are accessible by wrapper methods only, not as separate controls.
I am developing the GUI for my application using wxpython and have most of the features down, except in the main frame/window I want to have a box for choosing a file (in this case, the input will have to be an excel file). Something similar to the standard filebrowser that is accessed whenever you choose "open" from a menu.
Below is an image to show exactly what I want...
You probably want a wx.FileDialog. It provides access to the default file dialog of the OS your app is running in. You can see an example of how it's used in the wxPython demo package. This tutorial also has some screenshots and sample code:
http://www.blog.pythonlibrary.org/2010/06/26/the-dialogs-of-wxpython-part-1-of-2/
The screenshot you show appears to be an interface to actually open the dialog. You can easily create that using sizers and basic widgets. Then just bind the open button to a handler that will show the dialog.
You might also want to take a look at the FileBrowseButton from wx.lib.filebrowsebutton (also in the demo).
There are a few other related widgets which you might be interested in too: wx.DirDialog, MultiDirDialog or wx.GenericDirDialog.
Assuming you know the basics of wxPython you can use wx.GenericDirCtrl and wx.ListCtrl to make nice browser
In python, I enumerate top-level windows through EnumWindows, and also I enumerate the processes through EnumProcesses.
Then in the python script, I put all the window handles which belongs to the same pid into one list (I did this through GetWindowThreadProcessId).
Later I found out something: there are 3 window handles which belong to notepad.exe, but I only open one text file.
Why?
Besides, I tried to set the text window as the foreground window through SetForegroundWindow, I passed the three window handles to this function, and two work.
How could this be ?
Processes sometimes create invisible windows for their own purposes. You should ignore them (use IsWindowVisible function).
To investigate this kind of things your best friend is Spy++, that comes with several versions of Visual Studio, if you can get it.
According to it, notepad.exe creates three top-level windows:
The visible main window, class name "Notepad", overlapped.
A hidden, disabled, pop-up window, class name "MSCTFIME UI", caption "M".
Another hidden, disabled, pop-up window, class name "IME", caption "Default IME".
The two hidden windows are used internally by notepad to implement the IME (Input Method Editor), the GUI to type complex scripts.
Many programs create top-level hidden windows for a lot of things. For what you intend, you can ignore them all and use only the visible ones.
I want to embed a window into another window, kind of like this:
EDIT: Screenshots deleted, sorry!
That is a wingdows program and was not made with GTK tough.
I tried using plugs and sockets, but apparently I can't put a gtk.Window (a toplevel window) on a plug.
Is it possible? If so, how? If not, what do you think I should do instead?
gtk.Window is derived from gtk.Bin, so it can only contain one single child. This again can be used in the following way:
Load both windows (e.g. from Glade files)
Remove the child from the second window, but save a reference to the child
Add the child somewhere in the first window
The second step would look like this:
childWidget = secondWindow.get_child()
secondWindow.remove(childWidget)
I'm using this approach to add plugin windows as tabs in one of my PyGTK applications. That means main window and plugins can be designed separately in Glade, and also implemented independently. Of course you're free to add the child widget anywhere you want.