def startup(self, application): "Configure the application during the startup" self.ui = MainWindow(self, self.settings, self.btsupport) # Add the actions related to the app menu action = Gio.SimpleAction(name='about') action.connect('activate', self.on_app_about_activate) self.add_action(action) action = Gio.SimpleAction(name='preferences') action.connect('activate', self.on_app_preferences_activate) self.add_action(action) action = Gio.SimpleAction(name='quit') action.connect('activate', self.on_app_quit_activate) self.add_action(action) # Add the app menu builder = Gtk.Builder() builder.add_from_file(FILE_UI_APPMENU) menubar = builder.get_object('app-menu') self.set_app_menu(menubar)
class Application(Gtk.Application): def __init__(self, settings, btsupport): super(self.__class__, self).__init__(application_id=APP_ID) self.settings = settings self.btsupport = btsupport self.connect('activate', self.activate) self.connect('startup', self.startup) def startup(self, application): "Configure the application during the startup" self.ui = MainWindow(self, self.settings, self.btsupport) # Add the actions related to the app menu action = Gio.SimpleAction(name='about') action.connect('activate', self.on_app_about_activate) self.add_action(action) action = Gio.SimpleAction(name='preferences') action.connect('activate', self.on_app_preferences_activate) self.add_action(action) action = Gio.SimpleAction(name='quit') action.connect('activate', self.on_app_quit_activate) self.add_action(action) # Add the app menu builder = Gtk.Builder() builder.add_from_file(FILE_UI_APPMENU) menubar = builder.get_object('app-menu') self.set_app_menu(menubar) def activate(self, application): "Execute the application" self.ui.run() def on_app_about_activate(self, action, data): "Show the about dialog from the app menu" self.ui.on_toolbAbout_clicked(self) def on_app_preferences_activate(self, action, data): "Show the preferences dialog from the app menu" self.ui.on_toolbPreferences_clicked(self) def on_app_quit_activate(self, action, data): "Quit the application from the app menu" self.ui.on_winMain_delete_event(self, None)