Reputation: 49
i want to set blocked the window behind dialog to prevent the user do click or modify any content of the window while the dialog are running, and when the user close de dialog then set unlocked the window behind dialog.
import gtk;
window = gtk.Window();
window.set_title("Window Behind Dialog");
window.set_default_size(426,240);
textentry = gtk.TextView();
window.add(textentry);
window.show_all();
dialog = gtk.Window();
dialog.set_title("Dialog");
dialog.set_default_size(256,144);
label = gtk.Label("Unlock the window behind when this dialog get close");
dialog.add(label);
dialog.show_all();
gtk.main();
Which method is used for it, in Gtk or PyGtk?, for example:
window.set_disabled_to_all_events();
or
window.set_disabled();
or
window.events_disabled(True);
or
window.set_blocked(True);
Upvotes: 4
Views: 1306
Reputation: 1091
If you have a window manager that honors modal windows, you could use set_modal
on the dialog window.
If not, you could use set_sensitive
on the parent window. Call this with False
when the dialog is shown, and with True
when the dialog is hidden or destroyed.
I've added Gtk3 examples below. I recommend that you switch to PyGObject and Python 3 before investing too much effort in a deprecated toolkit.
Modal window example:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
window = Gtk.Window(title="Hello World")
window.connect("destroy", Gtk.main_quit)
window.add(Gtk.TextView())
window.show_all()
dialog = Gtk.Window(title="Dialog")
dialog.set_transient_for(window)
dialog.set_modal(True)
dialog.show()
Gtk.main()
Or using explicit set_sensitive
:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
window = Gtk.Window(title="Hello World")
window.connect("destroy", Gtk.main_quit)
window.add(Gtk.TextView())
window.show_all()
dialog = Gtk.Window(title="Dialog")
dialog.set_transient_for(window)
window.set_sensitive(False)
def destroy_cb(widget, data):
data.set_sensitive(True)
dialog.connect("destroy", destroy_cb, window)
dialog.show()
Gtk.main()
Upvotes: 5