4
If we execute the code below, a window will be created with a button inside, that every clicked will open another window (Window2)... How do I not allow a second instance of Window2? I want to do this without using modal().
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from gi.repository import Gtk
class Main(Gtk.Window):
def __init__(self):
button = Gtk.Button('Click')
Gtk.Window.__init__(self, title = 'Main Window')
button.connect('clicked', Window2)
self.connect('delete-event', Gtk.main_quit)
self.set_default_size(300, 200)
self.add(button)
self.show_all()
class Window2(Gtk.Window):
def __init__(self, widget):
button = Gtk.Button('Exit')
Gtk.Window.__init__(self, title = 'Window2')
button.connect('clicked', Gtk.main_quit)
self.set_default_size(300, 200)
self.add(button)
self.show_all()
if __name__ == '__main__':
Main()
Gtk.main()
Read this Design Pattern: http://pt.wikipedia.org/wiki/Singleton so you can adapt your code to Singleton
– Diego Vieira
@Diegovieira In this particular case, I don’t think you need to use Singleton (just change the behavior of the button), but if you want to give an answer covering the general case, feel free! (by title, this question is likely to attract many visitors.. P)
– mgibsonbr