python类Application()的实例源码

gtkui.py 文件源码 项目:yt-browser 作者: juanfgs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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"))
app.py 文件源码 项目:sc-controller 作者: kozec 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
main.py 文件源码 项目:sbrick-controller 作者: wintersandroid 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 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"))
__main__.py 文件源码 项目:dri-config 作者: TingPing 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)
__main__.py 文件源码 项目:razerCommander 作者: GabMus 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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
test_gireactor.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 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)
main.py 文件源码 项目:pytimetrack 作者: fhackerz 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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))
application.py 文件源码 项目:Icon-Requests 作者: bil-elmoussaoui 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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))
application.py 文件源码 项目:aniwall 作者: worron 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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()
application.py 文件源码 项目:aniwall 作者: worron 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
application.py 文件源码 项目:Gnome-Authenticator 作者: bil-elmoussaoui 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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))
application.py 文件源码 项目:Gnome-Authenticator 作者: bil-elmoussaoui 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def do_startup(self):
        Gtk.Application.do_startup(self)
        self.generate_menu()
application.py 文件源码 项目:Gnome-Authenticator 作者: bil-elmoussaoui 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def on_shortcuts(self, *args):
        """
            Shows keyboard shortcuts
        """
        shortcuts = Application.shortcuts_dialog()
        if shortcuts:
            shortcuts.set_transient_for(self.win)
            shortcuts.show()
application.py 文件源码 项目:Gnome-Authenticator 作者: bil-elmoussaoui 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def on_about(self, *args):
        """
            Shows about dialog
        """
        dialog = Application.about_dialog()
        dialog.set_transient_for(self.win)
        dialog.run()
        dialog.destroy()
mama-manager.py 文件源码 项目:mama 作者: maateen 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self):
        Gtk.Application.__init__(self)
mama-manager.py 文件源码 项目:mama 作者: maateen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def do_startup(self):
        Gtk.Application.do_startup(self)
app.py 文件源码 项目:sc-controller 作者: kozec 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
main.py 文件源码 项目:stickies 作者: aboudzakaria 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self):
        Gtk.Application.__init__(self,
            application_id = "com.github.aboudzakaria.stickies")
main.py 文件源码 项目:stickies 作者: aboudzakaria 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def do_startup(self):
        Gtk.Application.do_startup(self)
main.py 文件源码 项目:sbrick-controller 作者: wintersandroid 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)
main.py 文件源码 项目:mastodon-gtk 作者: GabMus 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id="org.gabmus.mastodon-gtk",
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        self.connect("activate", self.activateCb)
main.py 文件源码 项目:mastodon-gtk 作者: GabMus 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def do_startup(self):
        # start the application
        Gtk.Application.do_startup(self)
application.py 文件源码 项目:whither 作者: Antergos 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
main.py 文件源码 项目:Ebook-Viewer 作者: michaldaniel 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 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)
application.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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)
application.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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()
application.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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()
application.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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()
application.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _load_resource(self):
        self._resource = Gio.resource_load(
            Environment.get_data(Application.ID + '.gresource')
        )
        Gio.Resource._register(self._resource)
application.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _setup_locale(self):
        relpath = Environment.get_locale()
        locale.bindtextdomain(Application.DOMAIN, relpath)


问题


面经


文章

微信
公众号

扫码关注公众号