我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gi.repository.Gtk.Application()。
def do_startup(self): """ Initialize Gtk.Application Framework """ Gtk.Application.do_startup(self) #Connect Preferences action action = Gio.SimpleAction.new("preferences", None) action.connect("activate", self.on_preferences) self.add_action(action) #Connect About action action = Gio.SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) #Connect Quit action action = Gio.SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.add_action(action) self.set_app_menu(self.menubuilder.get_object("app-menu"))
def do_command_line(self, cl): Gtk.Application.do_command_line(self, cl) if len(cl.get_arguments()) > 1: filename = " ".join(cl.get_arguments()[1:]) # 'cos fuck Gtk... from scc.gui.importexport.dialog import Dialog if Dialog.determine_type(filename) is not None: ied = Dialog(self) def i_told_you_to_quit(*a): sys.exit(0) ied.window.connect('destroy', i_told_you_to_quit) ied.show(self.window) # Skip first screen and try to import this file ied.import_file(filename) else: sys.exit(1) else: self.activate() return 0
def do_startup(self): Gtk.Application.do_startup(self) action = Gio.SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) action = Gio.SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.add_action(action) action = Gio.SimpleAction.new("open_configuration", None) action.connect("activate", self.on_open_configuration) self.add_action(action) action = Gio.SimpleAction.new("save_configuration", None) action.connect("activate", self.on_save_configuration) self.add_action(action) action = Gio.SimpleAction.new("save_as_configuration", None) action.connect("activate", self.on_save_as_configuration) self.add_action(action) builder = Gtk.Builder.new_from_file("menu.xml", ) self.set_app_menu(builder.get_object("app-menu"))
def do_startup(self): Gtk.Application.do_startup(self) signal.signal(signal.SIGINT, signal.SIG_DFL) action = Gio.SimpleAction.new('about', None) action.connect('activate', self.on_about) self.add_action(action) action = Gio.SimpleAction.new('quit', None) action.connect('activate', self.on_quit) self.add_action(action) self.add_accelerator('<Primary>q', 'app.quit') app_menu = Gio.Menu.new() app_menu.append(_('About'), 'app.about') app_menu.append(_('Quit'), 'app.quit') self.set_app_menu(app_menu)
def do_command_line(self, args): ''' GTK.Application command line handler called if Gio.ApplicationFlags.HANDLES_COMMAND_LINE is set. must call the self.do_activate() to get the application up and running. ''' Gtk.Application.do_command_line(self, args) # call the default commandline handler # make a command line parser parser = argparse.ArgumentParser(prog='gui') # add a -c/--color option parser.add_argument('-q', '--quit-after-init', dest='quit_after_init', action='store_true', help='initialize application (e.g. for macros initialization on system startup) and quit') # parse the command line stored in args, but skip the first element (the filename) self.args = parser.parse_args(args.get_arguments()[1:]) # call the main program do_activate() to start up the app self.do_activate() return 0
def test_cantRegisterAfterRun(self): """ It is not possible to register a C{Application} after the reactor has already started. """ reactor = gireactor.GIReactor(useGtk=False) self.addCleanup(self.unbuildReactor, reactor) app = Gio.Application( application_id='com.twistedmatrix.trial.gireactor', flags=Gio.ApplicationFlags.FLAGS_NONE) def tryRegister(): exc = self.assertRaises(ReactorAlreadyRunning, reactor.registerGApplication, app) self.assertEqual(exc.args[0], "Can't register application after reactor was started.") reactor.stop() reactor.callLater(0, tryRegister) ReactorBuilder.runReactor(self, reactor)
def main(): mark_time("in main()") root_logger = logging.getLogger() root_logger.addHandler(logging.StreamHandler()) if '--debug' in sys.argv: root_logger.setLevel(logging.DEBUG) else: root_logger.setLevel(logging.INFO) # Tell GTK+ to use out translations locale.bindtextdomain('gtimelog', LOCALE_DIR) locale.textdomain('gtimelog') # Tell Python's gettext.gettext() to use our translations gettext.bindtextdomain('gtimelog', LOCALE_DIR) gettext.textdomain('gtimelog') # Make ^C terminate the process signal.signal(signal.SIGINT, signal.SIG_DFL) # Run the app app = Application() mark_time("app created") sys.exit(app.run(sys.argv))
def __init__(self): Gtk.Application.__init__(self, application_id="org.gnome.IconRequests", flags=Gio.ApplicationFlags.FLAGS_NONE) GLib.set_application_name(_("Icon Requests")) GLib.set_prgname("Icon Requests") Gtk.Settings.get_default().set_property( "gtk-application-prefer-dark-theme", settings.get_is_night_mode()) self.menu = Gio.Menu() cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/IconRequests/css/style.css') cssProvider = Gtk.CssProvider() screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() try: cssProvider.load_from_file(cssProviderFile) styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) logging.debug("Loading css file ") except Exception as e: logging.error("Error message %s" % str(e))
def _do_startup(self): """Initialize application structure""" logger.info("Application modules initialization...") # set application actions action = Gio.SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) action = Gio.SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.add_action(action) action = Gio.SimpleAction.new("settings", None) action.connect("activate", self.on_settings) self.add_action(action) # init application modules self.parser = ImageParser(self, os.path.join(self.path["data"], "images", "test.svg")) self.mainwin = MainWindow(self) self.setwindow = SettingsWindow(self) self.aboutdialog = AboutDialog(self) self.mainwin.update_image_list() # set application menu builder = Gtk.Builder.new_from_resource(self.resource_path + "ui/menu.ui") self.set_app_menu(builder.get_object("app-menu")) logger.info("Application modules initialization complete") # show window logger.info("Application GUI startup") self.mainwin.gui["window"].show_all() self.mainwin.update_preview()
def do_shutdown(self): logger.info("Exit aniwall application") if self.mainwin is not None: self.mainwin.save_gui_state() Gtk.Application.do_shutdown(self) # noinspection PyMethodMayBeStatic
def __init__(self): Gtk.Application.__init__(self, application_id="org.gnome.Authenticator", flags=Gio.ApplicationFlags.FLAGS_NONE) GLib.set_application_name(_("Gnome Authenticator")) GLib.set_prgname("Gnome Authenticator") self.observable = ApplicaitonObservable() self.menu = Gio.Menu() self.db = Database() result = GK.unlock_sync("org.gnome.Authenticator", None) if result == GK.Result.CANCELLED: self.quit() Gtk.Settings.get_default().set_property( "gtk-application-prefer-dark-theme", settings.get_is_night_mode()) if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20: cssFileName = "org.gnome.Authenticator-post3.20.css" else: cssFileName = "org.gnome.Authenticator-pre3.20.css" cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/Authenticator/%s' % cssFileName) cssProvider = Gtk.CssProvider() screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() try: cssProvider.load_from_file(cssProviderFile) styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) logging.debug("Loading css file ") except Exception as e: logging.error("Error message %s" % str(e))
def do_startup(self): Gtk.Application.do_startup(self) self.generate_menu()
def on_shortcuts(self, *args): """ Shows keyboard shortcuts """ shortcuts = Application.shortcuts_dialog() if shortcuts: shortcuts.set_transient_for(self.win) shortcuts.show()
def on_about(self, *args): """ Shows about dialog """ dialog = Application.about_dialog() dialog.set_transient_for(self.win) dialog.run() dialog.destroy()
def __init__(self): Gtk.Application.__init__(self)
def do_startup(self): Gtk.Application.do_startup(self)
def do_startup(self, *a): Gtk.Application.do_startup(self, *a) self.load_profile_list() self.setup_widgets() if self.app.config['gui']['enable_status_icon']: self.setup_statusicon() self.set_daemon_status("unknown", True)
def __init__(self): Gtk.Application.__init__(self, application_id = "com.github.aboudzakaria.stickies")
def __init__(self, *args, **kwargs): # super(*args, **kwargs) Gtk.Application.__init__(self, *args, application_id="nz.winters.sbrickapp", flags=Gio.ApplicationFlags.NON_UNIQUE, **kwargs) self.window = None self.config = None self.configFile = "sbricks.json" self.add_main_option("config", ord("c"), GLib.OptionFlags.OPTIONAL_ARG, GLib.OptionArg.STRING, "Config File", None) self.connect('handle-local-options', self.on_handle_local_options)
def __init__(self): Gtk.Application.__init__(self, application_id="org.gabmus.mastodon-gtk", flags=Gio.ApplicationFlags.FLAGS_NONE) self.connect("activate", self.activateCb)
def do_startup(self): # start the application Gtk.Application.do_startup(self)
def __init__(self, name: str = 'application', *args, **kwargs) -> None: super().__init__(name=name, *args, **kwargs) self.widget = Gtk.Application() # type: Gtk.Application self.is_qt, self.is_gtk = False, True # type: bool
def do_startup(self): Gtk.Application.do_startup(self) action = Gio.SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) action = Gio.SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.add_action(action)
def __init__(self): Gtk.Application.__init__(self, application_id=Application.ID, flags=Gio.ApplicationFlags.FLAGS_NONE) self._window = None self._shortcuts_window = None self._info_dialog = None self._verbosity = logging.WARNING self.add_main_option_entries([ Application._get_option("v", "verbose", "Be verbose: show info messages"), Application._get_option("d", "debug", "Enable debugging: show debug messages") ]) self.connect('handle-local-options', self.handle_local_options)
def do_startup(self): Gtk.Application.do_startup(self) self._setup_logging() self._load_resource() self._load_settings() self._load_css() self._setup_locale() self._load_ui() self._setup_actions() self._load_appmenu()
def do_activate(self): Gtk.Application.do_activate(self) if not self._window: self._window = widgets.Window(self, self._builder, Application.TITLE, self._settings) self._window.present()
def on_menu_shortcuts(self, action, value): builder = Gtk.Builder() builder.set_translation_domain(Application.DOMAIN) builder.add_from_resource(self._get_resource_path('gtk.shortcuts.ui')) shortcuts_dialog = widgets.ShortcutsDialog(builder, self._window) shortcuts_dialog.present()
def _load_resource(self): self._resource = Gio.resource_load( Environment.get_data(Application.ID + '.gresource') ) Gio.Resource._register(self._resource)
def _setup_locale(self): relpath = Environment.get_locale() locale.bindtextdomain(Application.DOMAIN, relpath)
def _load_ui(self): # Create builder to load UI self._builder = Gtk.Builder() self._builder.set_translation_domain(Application.DOMAIN) self._builder.add_from_resource(self._get_resource_path('gtk.glade'))
def _load_appmenu(self): builder = Gtk.Builder() builder.set_translation_domain(Application.DOMAIN) builder.add_from_resource(self._get_resource_path('gtk.menu.ui')) self.set_app_menu(builder.get_object('app-menu'))
def _get_resource_path(self, path): return "/{}/{}".format(Application.ID.replace('.', '/'), path)
def do_startup(self): print("Starting up...") Gtk.Application.do_startup(self) menu = Gio.Menu() for action, is_menu_item, callback in self._actions: if is_menu_item: menu.append(action.capitalize(), "app.%s" % action) simple_action = Gio.SimpleAction.new(action, None) simple_action.connect('activate', callback) self.add_action(simple_action) self.set_app_menu(menu)
def __init__(self, uri, show_gui=True): Gtk.Application.__init__(self, application_id='org.gnome.chromecast-player', flags=Gio.ApplicationFlags.FLAGS_NONE) GLib.set_application_name("Chromecast Player") GLib.set_prgname('chromecast-player') self.connect("activate", self._on_activate, uri) self.cast = None self.mc = None self.get_chromecast_config() self.uri = None self.play_now = True if uri else False self.play_uri = [] self.serverthread = None self.subtitlethread = None self.local_port = 0 self.show_gui = show_gui self.imagethread = None self.transcode_options = None self.playlist_manager = None if uri and not isinstance(uri, (list, tuple)): self.uri = [uri] elif uri: self.uri = uri self.loaded = False self.loc_file = None self.stop_worker = False self.is_playing = False self.is_paused = False self.is_idle = False self.is_disconnected = False self.playlist_counter = 0 self.seeking = False self.overwrite = False self.continue_playing = False self.volume_changing = False
def do_shutdown(self): Gtk.Application.do_shutdown(self) if self.window: self.window.destroy()
def do_startup(self): Gtk.Application.do_startup(self) action = Gio.SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) action = Gio.SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.add_action(action) builder = Gtk.Builder.new_from_string(MENU_XML, -1) self.set_app_menu(builder.get_object("app-menu"))
def __init__ (self): """ Interface initialisation This function opens the window, calls back through the core, to get the configuration, to load the initial interface. The configuration tells the interface what to set up in the initial startup. """ Gtk.Application.__init__(self, application_id="org.ascension.ascension", flags=Gio.ApplicationFlags.FLAGS_NONE) self.connect("activate", self.on_activate)
def init (self, config): """ Abstraction for command to open GUI. For Gtk+-3.0, this just maps to the built in Gtk.Application.run () command. For other GUI libraries, this will invoke the same. In this case, it triggers the activate hook. """ # Import config object into this object's namespace self.config = config self.run ()
def on_activate (self, data=None): """ Activate Gtk.Application """ debug ("Activating Gtk.Application", True) debug ("creating main window", False) self.window = window = Gtk.ApplicationWindow () debug ("binding window to Application", False) self.add_window (window) winspec = self.config.get_interface ().split () window.resize (int(winspec[2]), int(winspec[3])) window.move (int(winspec[0]), int(winspec [1])) window.connect('delete-event', self.save_state) window.show_all ()
def do_startup(self): Gtk.Application.do_startup(self) builder = Gtk.Builder() builder.add_from_resource(get_resource_path('ui/about.ui')) builder.add_from_resource(get_resource_path('ui/menu.ui')) self.app_menu = builder.get_object('app-menu') self.about_dialog = builder.get_object('about-dialog') action = Gio.SimpleAction.new('connect', None) action.connect('activate', self._on_connect) self.add_action(action) action = Gio.SimpleAction.new('about', None) action.connect('activate', self._on_about) self.add_action(action) action = Gio.SimpleAction.new('quit', None) action.connect('activate', self._on_quit) self.add_action(action) self.set_app_menu(self.app_menu) self.mark_busy()
def do_activate(self): Gtk.Application.do_activate(self) self._connect(self.host, self.username) self.unmark_busy()
def do_command_line(self, command_line): Gtk.Application.do_command_line(self, command_line) show_preferences = False if '--preferences' in command_line.get_arguments(): show_preferences = True self.do_activate(show_preferences) return 0
def __init__(self): Gtk.Application.__init__(self, application_id="org.gabmus.gesturemanager", flags=Gio.ApplicationFlags.FLAGS_NONE) self.connect("activate", self.activateCb)
def main(): application = Application() try: ret = application.run(sys.argv) except SystemExit as e: ret = e.code sys.exit(ret)
def test_gApplicationActivate(self): """ L{Gio.Application} instances can be registered with a gireactor. """ reactor = gireactor.GIReactor(useGtk=False) self.addCleanup(self.unbuildReactor, reactor) app = Gio.Application( application_id='com.twistedmatrix.trial.gireactor', flags=Gio.ApplicationFlags.FLAGS_NONE) self.runReactor(app, reactor)
def test_gtkApplicationActivate(self): """ L{Gtk.Application} instances can be registered with a gtk3reactor. """ reactor = gtk3reactor.Gtk3Reactor() self.addCleanup(self.unbuildReactor, reactor) app = Gtk.Application( application_id='com.twistedmatrix.trial.gtk3reactor', flags=Gio.ApplicationFlags.FLAGS_NONE) self.runReactor(app, reactor)
def test_portable(self): """ L{gireactor.PortableGIReactor} doesn't support application registration at this time. """ reactor = gireactor.PortableGIReactor() self.addCleanup(self.unbuildReactor, reactor) app = Gio.Application( application_id='com.twistedmatrix.trial.gireactor', flags=Gio.ApplicationFlags.FLAGS_NONE) self.assertRaises(NotImplementedError, reactor.registerGApplication, app)
def test_noQuit(self): """ Older versions of PyGObject lack C{Application.quit}, and so won't allow registration. """ reactor = gireactor.GIReactor(useGtk=False) self.addCleanup(self.unbuildReactor, reactor) # An app with no "quit" method: app = object() exc = self.assertRaises(RuntimeError, reactor.registerGApplication, app) self.assertTrue(exc.args[0].startswith( "Application registration is not"))