Blame platform-demos/C/samples/menubar_basis.py
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="MenuBar Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(200, 200)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a builder to add the UI designed with Glade to the grid:
|
|
Packit |
1470ea |
builder = Gtk.Builder()
|
|
Packit |
1470ea |
# get the file (if it is there)
|
|
Packit |
1470ea |
try:
|
|
Packit |
1470ea |
builder.add_from_file("menubar_basis.ui")
|
|
Packit |
1470ea |
except:
|
|
Packit |
1470ea |
print("file not found")
|
|
Packit |
1470ea |
sys.exit()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# we use the method Gtk.Application.set_menubar(menubar) to add the menubar
|
|
Packit |
1470ea |
# to the application (Note: NOT the window!)
|
|
Packit |
1470ea |
self.set_menubar(builder.get_object("menubar"))
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|