Python gi.repository.Gtk 模块,Application() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gi.repository.Gtk.Application()

项目:yt-browser    作者:juanfgs    | 项目源码 | 文件源码
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"))
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
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
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
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"))
项目:dri-config    作者:TingPing    | 项目源码 | 文件源码
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)
项目:razerCommander    作者:GabMus    | 项目源码 | 文件源码
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
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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)
项目:pytimetrack    作者:fhackerz    | 项目源码 | 文件源码
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))
项目:Icon-Requests    作者:bil-elmoussaoui    | 项目源码 | 文件源码
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))
项目:aniwall    作者:worron    | 项目源码 | 文件源码
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()
项目:aniwall    作者:worron    | 项目源码 | 文件源码
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
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
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))
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def do_startup(self):
        Gtk.Application.do_startup(self)
        self.generate_menu()
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def on_shortcuts(self, *args):
        """
            Shows keyboard shortcuts
        """
        shortcuts = Application.shortcuts_dialog()
        if shortcuts:
            shortcuts.set_transient_for(self.win)
            shortcuts.show()
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def on_about(self, *args):
        """
            Shows about dialog
        """
        dialog = Application.about_dialog()
        dialog.set_transient_for(self.win)
        dialog.run()
        dialog.destroy()
项目:mama    作者:maateen    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Application.__init__(self)
项目:mama    作者:maateen    | 项目源码 | 文件源码
def do_startup(self):
        Gtk.Application.do_startup(self)
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
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)
项目:stickies    作者:aboudzakaria    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Application.__init__(self,
            application_id = "com.github.aboudzakaria.stickies")
项目:stickies    作者:aboudzakaria    | 项目源码 | 文件源码
def do_startup(self):
        Gtk.Application.do_startup(self)
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
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)
项目:mastodon-gtk    作者:GabMus    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id="org.gabmus.mastodon-gtk",
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        self.connect("activate", self.activateCb)
项目:mastodon-gtk    作者:GabMus    | 项目源码 | 文件源码
def do_startup(self):
        # start the application
        Gtk.Application.do_startup(self)
项目:whither    作者:Antergos    | 项目源码 | 文件源码
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
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
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)
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
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)
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
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()
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
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()
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
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()
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
def _load_resource(self):
        self._resource = Gio.resource_load(
            Environment.get_data(Application.ID + '.gresource')
        )
        Gio.Resource._register(self._resource)
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
def _setup_locale(self):
        relpath = Environment.get_locale()
        locale.bindtextdomain(Application.DOMAIN, relpath)
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
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'))
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
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'))
项目:mcg    作者:coderkun    | 项目源码 | 文件源码
def _get_resource_path(self, path):
        return "/{}/{}".format(Application.ID.replace('.', '/'), path)
项目:ez_gpg    作者:sgnn7    | 项目源码 | 文件源码
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)
项目:chromecast-player    作者:wa4557    | 项目源码 | 文件源码
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
项目:dri-config    作者:TingPing    | 项目源码 | 文件源码
def do_shutdown(self):
        Gtk.Application.do_shutdown(self)
        if self.window:
            self.window.destroy()
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
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"))
项目:steemportal    作者:colibrae    | 项目源码 | 文件源码
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)
项目:steemportal    作者:colibrae    | 项目源码 | 文件源码
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 ()
项目:steemportal    作者:colibrae    | 项目源码 | 文件源码
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 ()
项目:luminance    作者:craigcabrey    | 项目源码 | 文件源码
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()
项目:luminance    作者:craigcabrey    | 项目源码 | 文件源码
def do_activate(self):
        Gtk.Application.do_activate(self)

        self._connect(self.host, self.username)

        self.unmark_busy()
项目:draobpilc    作者:awamper    | 项目源码 | 文件源码
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
项目:gestureManager    作者:GabMus    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id="org.gabmus.gesturemanager",
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        self.connect("activate", self.activateCb)
项目:gestureManager    作者:GabMus    | 项目源码 | 文件源码
def do_startup(self):
        # start the application
        Gtk.Application.do_startup(self)
项目:razerCommander    作者:GabMus    | 项目源码 | 文件源码
def main():
    application = Application()

    try:
        ret = application.run(sys.argv)
    except SystemExit as e:
        ret = e.code

    sys.exit(ret)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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"))