コード例 #1
0
ファイル: application.py プロジェクト: GNOME/gnome-news
class Application(Gtk.Application):
    @log
    def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id='org.gnome.News',
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        GLib.set_application_name(_("News"))
        GLib.set_prgname('gnome-news')
        self.settings = Gio.Settings.new('org.gnome.News')

        cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/News/theme/Adwaita.css')
        cssProvider = Gtk.CssProvider()
        cssProvider.load_from_file(cssProviderFile)
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        styleContext.add_provider_for_screen(screen, cssProvider,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)

        self._window = None
        self._about_dialog = None

        delete_action = Gio.SimpleAction.new('delete_channel', parameter_type=GLib.VariantType.new('i'))
        self.add_action(delete_action)

        self.create_cache()

    @log
    def create_cache(self):
        if not os.path.isdir(CACHE_PATH):
            GLib.mkdir_with_parents(CACHE_PATH, 0o0755)

    @log
    def do_startup(self):
        actions = ["about", "quit"]

        for action_name in actions:
            action = Gio.SimpleAction.new(action_name, None)
            action.connect("activate", getattr(self, action_name))
            self.add_action(action)

        Gtk.Application.do_startup(self)

    @log
    def quit(self, action=None, param=None):
        self._window.destroy()

    @log
    def about(self, action, param):
        def on_destroy(window):
            self._about_dialog = None

        if not self._about_dialog:
            self._about_dialog = AboutDialog(self._window)

        self._about_dialog.connect("destroy", on_destroy)
        self._about_dialog.present()

    def do_activate(self):
        if not self._window:
            self._window = Window(self)

        self._window.present()
コード例 #2
0
ファイル: application.py プロジェクト: isabella232/gnome-news
class Application(Gtk.Application):
    @log
    def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id='org.gnome.News',
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        GLib.set_application_name(_("News"))
        GLib.set_prgname('gnome-news')
        self.settings = Gio.Settings.new('org.gnome.News')

        cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/News/theme/Adwaita.css')
        cssProvider = Gtk.CssProvider()
        cssProvider.load_from_file(cssProviderFile)
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        styleContext.add_provider_for_screen(screen, cssProvider,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)

        self._window = None
        self._about_dialog = None

        delete_action = Gio.SimpleAction.new('delete_channel', parameter_type=GLib.VariantType.new('i'))
        self.add_action(delete_action)

        self.create_cache()

    @log
    def create_cache(self):
        if not os.path.isdir(CACHE_PATH):
            GLib.mkdir_with_parents(CACHE_PATH, 0o0755)

    @log
    def do_startup(self):
        actions = ["about", "quit"]

        for action_name in actions:
            action = Gio.SimpleAction.new(action_name, None)
            action.connect("activate", getattr(self, action_name))
            self.add_action(action)

        self.set_accels_for_action("app.quit", ["<Primary>q"])

        Gtk.Application.do_startup(self)

    @log
    def quit(self, action=None, param=None):
        self._window.destroy()

    @log
    def about(self, action, param):
        def on_destroy(window):
            self._about_dialog = None

        if not self._about_dialog:
            self._about_dialog = AboutDialog(self._window)

        self._about_dialog.connect("destroy", on_destroy)
        self._about_dialog.present()

    def do_activate(self):
        if not self._window:
            self._window = Window(self)

        self._window.present()
コード例 #3
0
ファイル: application.py プロジェクト: kunaaljain/gnome-news
class Application(Gtk.Application):
    @log
    def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id='org.gnome.News',
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        GLib.set_application_name(_("News"))
        GLib.set_prgname('gnome-news')
        self.settings = Gio.Settings.new('org.gnome.News')

        cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/News/application.css')
        cssProvider = Gtk.CssProvider()
        cssProvider.load_from_file(cssProviderFile)
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        styleContext.add_provider_for_screen(screen, cssProvider,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)

        self._window = None
        self._about_dialog = None

        delete_action = Gio.SimpleAction.new('delete_channel', parameter_type=GLib.VariantType.new('i'))
        self.add_action(delete_action)

        self.create_cache()

    @log
    def create_cache(self):
        cache_full_path = os.path.expanduser(CACHE_PATH)
        if not os.path.isdir(cache_full_path):
            os.mkdir(cache_full_path)

    @log
    def do_startup(self):
        Gtk.Application.do_startup(self)

    @log
    def quit(self, action=None, param=None):
        self._window.destroy()

    @log
    def about(self, action, param):
        def on_destroy(window):
            self._about_dialog = None

        if not self._about_dialog:
            self._about_dialog = AboutDialog(self)

        self._about_dialog.connect("destroy", on_destroy)
        self._about_dialog.present()

    def do_activate(self):
        if not self.get_app_menu():
            builder = Gtk.Builder()
            builder.add_from_resource("/org/gnome/News/Menu.ui")
            menu = builder.get_object("app-menu")
            self.set_app_menu(menu)
            for action_name in ["about", "quit"]:
                action = Gio.SimpleAction.new(action_name, None)
                action.connect("activate", getattr(self, action_name))
                self.add_action(action)

        if not self._window:
            self._window = Window(self)

        self._window.present()