I want main window to "gray, freeze, stop working", when some other window is opened. Is there some default way to do it? Pretty much the same as gtk.Dialog is working.
EDIT: Currently I'm just replacing all contents by a text line, but I guess there should be better way.
You really shouldn't try to make a program become unresponsive.
If what you want to do is stop the user from using the window, make the dialog modal: gtk.Dialog.set_modal(True)
Related
When I open my popup for second time, my main window also works and this grab_set() and grab_release() is a temporary but I want it permanent. I want a code that makes disable the previous window for all the time until I close the program. please if you know help me.
My current situation is that I open a process, which opens in a random location (thats how this process works).
I have the process PID so I need to somehow focus this window, and move it to the center of my screen.
Im doing something wrong as I can't even set focus on that window... tried it with different apps and got the same result...
The way I select the window -
appl = pywinauto.application.Application()
appl.connect(process=824)
app_dialog = appl.top_window_()
app_dialog.Minimize()
app_dialog.Maximize()
##app_dialog.SetFocus() ##doesn't work aswell
##pywinauto.win32functions.SetForegroundWindow(app_dialog)## doesn't work
Thanks for reading :)
Can't say why it doesn't work with pywinauto...
Got it to work with win32gui as the answer here- Python Window Activation
long yet efficient ;)
Method app_dialog.set_focus() should work in pywinauto 0.6.2. If not, it might be a bug. Is your application publicly available somehow? I'd like to reproduce it on my side. Are you trying to activate a background window while you have modal dialog on top of it?
Second case is a wrong usage of SetForegroundWindow(...). It should give a handle, but you pass WindowSpecification object app_dialog. Right way is the following:
handle = app_dialog.wrapper_object().handle
pywinauto.win32functions.SetForegroundWindow(handle)
PyQt4/5 on OSX El Capitan
I have a QMessageBox/QDialog which I want to be modal and want to block input from other GUI items while a process is running. The QDialog should provide the user the option to cancel the said process, but not allow him or her to do anything else with the GUI in the meantime.
Once the process is finished, it should close the QDialog and enable input to the main application again. Because things should happen in the background while the dialog is shown, I am not using exec_() to display the dialog.
Here is a simple example of my code:
self.openingDialog = QtWidgets.QMessageBox(self.main_window)
self.openingDialog.setText(_(u"Opening experiment. Please wait"))
self.openingDialog.setStandardButtons(QtWidgets.QMessageBox.Cancel)
self.openingDialog.reject.connect(<some_function>)
self.openingDialog.show()
self.openingDialog.raise_()
... [Perform process] ...
self.openingDialog.done(0)
self.openingDialog.close()
self.openingDialog.deleteLater()
Everything works nicely in the sense that the dialog box is shown, and that no interaction is possible with other GUI elements while it is displayed. However, when has process is finished, the dialog box is automatically closed but it is still not possible to interact with other GUI elements afterwards. The GUI does not respond to mouse clicks, menu items are not accessible, and you can't even click the close button, so the application needs to be Force Quit.
What am I doing wrong in automatically closing the QDialog?
Ok, I have found sort of a workaround, although I don't think it is an elegant solution.
If I set the window modality to 'window modal' instead of 'application modal' by using:
self.openingDialog.setWindowModality(QtCore.Qt.WindowModal)
then the application regains focus and accessibility after the dialog has been closed by the program.
Still this doesn't solve the problem when the dialog is an application modal, but for now this serves my needs.
In tkinter I am creating a Toplevel widget to prompt the user with "Are you sure you want to exit?" every time they try to exit my application. While this is happening, I want the Toplevel widget to have full focus of my application and the user to be unable to click anything on the root window, if possible.
While trying to figure out to do this, I discovered grabs and the ability to set the focus of the application. What is the difference between these two things?
Thanks in advance.
Focus means that your window will receive all keyboard events until some other window gets the focus. A grab tells the window manager that your window should have the focus until you explicitly tell it that it is allowed to take it away (ungrab).
I am learning python and for GUI model using wxpython, as I am new to programing get stuck every time.
My issue is I have a GUI (main window)with two buttons,when user clicks button1 it opens sub window (seperate python script), I want to close or destroy main window before opening sub window.
self.Destroy()
subprocess.call("python newframe.py",shell=True)
#It will not close main window
What will be the wrong i am trying to do , and please explain what is proper method.
Looking for suggestions thanks .
Sorry for my english .
subprocess.call() wait subprocess to exit. -> button callback will never return until subprogram exit. This keep main window to close. Use subprocess.Popen() which does not wait subprocess.
self.Destroy()
subprocess.Popen('python newframe.py', shell=True)
You shouldn't close the main frame or you'll actually exit the application. Instead you should Hide the main frame and just Show the sub-frame. Then when you close the sub-frame, you can re-show the main frame. I personally think using Pubsub is the easiest way to accomplish this. Here's a link to a tutorial that shows how to do it:
http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/
You could also pass a reference to the main frame when you instantiate the sub-frame or call something like GetTopWindow() or GetParent(), but I really recommend Pubsub for this.