I am using Ubuntu 13.04 with Unity.
I created an Application Indicator using the AppIndicator class in Python, with a gtk.Menu attached to it. The menu is showing some status information about GIT repositories that I don't want to be updated as long as the menu is not visible. Instead, when the user clicks on the AppIndicator and the menu becomes visible, I would like to get notified and update the information shown.
So far, I could not find a signal emitted by the Menu whenver it pops up. Nor does the AppIndicator have a signal emitted when it gets clicked. In fact, there is already this question but the answers only discuss if AppIndicator has (or should have) the appropriate signal. But what about the gtk.Menu itself?
So, my question is, how can I get notified that my menu becomes visible?
This question is to old to go into details but if you still interested you can monitor the DBus system in ubuntu so you can catch when the call is done to you menu, you can even track submenu if you are into that.
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'm using the latest version (to date) of pywinauto; and also using PyInspect (uia) to identify controls.
I'm automating controls on an application, and part of the process is to check a few boxes on a window that pops up after triggering the window to appear from a menu selection (like Edit->Settings).
The problem is, pywinauto doesn't seem to be able to detect the new window. I see successfully opens; and can see the window and elements as a sub (child?) window of the application in PyInspect.
I've tried wait methods, thinking the automation is occurring too fast- but to no avail. something like:
mysettings = app['app-name'].child_window(title_re="my target settings window", class_name="#32770").wait('exists', timeout=10)
this will just timeout. And if I print control identifiers, "my target settings window" is never included.
app['app-name'].print_control_identifiers()
I also tried set_focus on top_window.. that didn't work either. My conclusion is that pywinauto is having trouble detect that it is there. Any thoughts on this?
I was able to resolve this issue of pywinauto detecting the child window, and the issue that immediately followed: accessing the child window.
First, I was able to get pywinauto to detect the new window by defining backend='uia' in the application definition, like this:
app = application.Application(backend='uia')
I previously just had:
app = application.Application()
My next issue was accessing elements on the child window. I could not access the window directly, as I may have anticipated:
app['my app']['child window']['textbox'].set_edit_text("hello world")
Instead, this code worked:
app['my app'].child_window(title='child window name').Edit1.set_edit_text("hello world")
While I have resolved my issue, I have noticed that after defining backend='uia', the process now executes much slower than before. If anyone who stumbles across this has any feedback in that regard (or optimizing my efforts above), please contribute.
Thanks
This question already has answers here:
Python code to automate desktop activities in windows
(6 answers)
Closed 5 years ago.
I love automating daily tasks using AutoHotKey and Python. I like using my keyboard instead of my mouse, so I tend to make hotkeys with AutoHotKey that do various actions that you'd otherwise need to use the mouse for, or that you'd need to use too many keyboard actions to do.
But there are some actions that I don't succeed in automating. For example, the dropdown menu for changing the number of monitors that a VM uses in VMWare Workstation. I think that one thing that would really help me with this automation task, and possibly with more in the future, is to be able to simulate menu item clicks.
Is this possible? I want to fool a program into thinking that one of its menu items were clicked. I know to program in Python and AutoHotKey. Is it possible at all, and specifically in these two languages?
Presuming that this is Windows, if the app is using standard HMENU items you can do one of two things with (relatively) minimal effort
If there is a hotkey, like Ctrl+S for Save, you could just send Ctrl+S to the window using the SendKeys API (https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx)
If there isn't, you can try to find which WM_COMMAND is sent to the window after the item is selected. You can use Spy++ from Microsoft (https://msdn.microsoft.com/en-us/library/dd460756.aspx) to get the code and then do a PostMessage to that window with the code.
Mind you, you'll need to be sure that you do a FindWindow to get the right HWND handle to send it to.
Best of luck :)
Edit Followup: Quick tutorial on how to use Spy++ with Notepad.exe
Start Spy++
NOTE: There are two of them, spyxx.exe and spyxx_amd64.exe. If one doesn't log messages - use the other
NOTE: if you started Spy++ first, hit F5 to refresh the window list AFTER Notepad.exe starts
Spy++ main menu > Search > Find Window
on the "Window search" dialog, click and hold on the "target" icon next to "finder tool"
drag your cursor over the Notepad title bar
Spy++ will show Caption: "Untitled - Notepad" and Class: "Notepad"
Click "OK"
You will now see Notepad in the window list
Right-click on that entry and select "Messages"
To control the flow, Main Menu > Messages > Logging Options, Messages Tab
Clear All, only select WM_COMMAND, click ok
in Notepad, go to the Main Menu > Edit > Go to
in Spy++, you will see a line reading "WM_COMMAND wNotifyCode: 0 (sent from a menu) wID:24"
Result: Now we know that if you were to PostMessage(WM_COMMAND, MAKE_WPARAM(0,24), HWND of any Notepad.exe on the system), the "Go to" window would appear.
I am writing a program with a main menu, and several buttons that open different windows of the application. After the main menu pops up, I have rigged the code so that a popup window comes up right on top of the main menu. The popup tells you to visit the settings menu, and gives you a checkbox that says "Don't show this window again". The idea is that if you tick that box, the popup will never popup again. The popup window is a function called reminder().
Early on in the program I call the reminder() function to get it to popup. The checkbox is linked to a function called reminder_toggled(). I need to know how I would write the reminder_toggled() function to make sure that the reminder() function does not run ever again. If any additional info is required just post a comment, I'll be checking this post every 5 minutes.
Thanks StackOverflow :)
Instead of calling reminder_toggled() function whenever the checkbox (say reminder_checkbox) is toggled, reminder() function should first check whether the reminder_checkbox is checked before executing further
def reminder():
if reminder_checkbox.get_active():
.
.
.
(get_active() documentation)
Moreover, the reminder_checkbox's state should be stored in a config file on exit & loaded on startup of app.
I have a root window with a panel on it. Then there is this function, in which I create a TopLevel (another window) for asking input from user. I'm trying to find some way to make it compulsory for user to either enter input and click OK or cancel to dismiss the window before being able to access the root window. It's like when an error message pops up, you can't just ignore it and do other things in the root window. Does anyone have any suggestion for me?
Have a look at Dialog Windows. You can use widget.wait_window(window) to achieve this.
You can do what is called a grab, which forces all events into the window of your choice. There are several methods for managing grab, including grab_set and grab_release.
For an example, see NiceGrab.
When working with grabs, exercise extreme care. It's possible to lock up your computer if you do a global grab and then have a bug that prevents you from releasing it. During development I will often implement a timer that kills the program after a minute or so, so if I lock everything up it will be automatically released after a short wait.