Skip to content

Instantly share code, notes, and snippets.

@vojtechtrefny
Last active August 29, 2015 14:14
Show Gist options
  • Save vojtechtrefny/ed5ac485585484483b6c to your computer and use it in GitHub Desktop.
Save vojtechtrefny/ed5ac485585484483b6c to your computer and use it in GitHub Desktop.
from gi.repository import Gtk, Gdk
class DialogExample(Gtk.Dialog):
def __init__(self, parent):
Gtk.Dialog.__init__(self, "My Dialog", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(150, 100)
box = self.get_content_area()
css = """
GtkComboBox {
-GtkComboBox-appears-as-list: 1;
}
"""
style_provider = Gtk.CssProvider()
style_provider.load_from_data(css)
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
combo1 = Gtk.ComboBoxText()
combo1.set_entry_text_column(0)
combo1.set_active(0)
for i in ["a", "b", "c", "d"]:
combo1.append_text(i)
box.add(combo1)
self.show_all()
class DialogWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Dialog Example")
self.set_border_width(6)
button = Gtk.Button("Open dialog")
button.connect("clicked", self.on_button_clicked)
self.add(button)
def on_button_clicked(self, widget):
dialog = DialogExample(self)
response = dialog.run()
if response == Gtk.ResponseType.OK:
print("The OK button was clicked")
elif response == Gtk.ResponseType.CANCEL:
print("The Cancel button was clicked")
dialog.destroy()
win = DialogWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment