Beispiel #1
0
    def __init__(self):
        super().__init__()

        self.set_application_id(version.APP_ID)
        self.set_flags(Gio.ApplicationFlags.HANDLES_COMMAND_LINE)

        screen = Gdk.Screen.get_default()
        css_provider = Gtk.CssProvider()
        css_provider.load_from_path(common.CSS_PATH)
        style_context = Gtk.StyleContext()
        style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)

        gtk_settings = Gtk.Settings.get_default()
        gtk_settings.props.gtk_application_prefer_dark_theme = True

        self._window = None
        self._editor = editor.Editor()
        self._previewer = previewer.Previewer()
        self._merger = merger.Merger()
        self._merger.connect("merge", self.merge_items)
        self._items_processors = ItemsProcessors()
        self._items_processors.add_processor(self._editor)
        self._items_processors.add_processor(self._previewer)
        self._items_processors.add_processor(self._merger)

        self._main_toolbox = MainToolbox()
        self._main_toolbox.prefs_btn.connect("clicked", lambda b: self.show_prefs())
        self._main_toolbox.about_btn.connect("clicked", lambda b: self.show_about())
        self._main_toolbox.quit_btn.connect("clicked", lambda b: self.quit())
        self._main_toolbox.restart_btn.connect("clicked", self._restart_daemon)
        self._main_toolbox.close_btn.connect("clicked", lambda b: self.hide(reset_search=True))
        self._main_toolbox.track_btn.connect("clicked", lambda b: gpaste_client.track(b.get_active()))
        self._main_toolbox.track_btn.set_active(gpaste_client.get_prop("Active"))
        self._main_toolbox.help_btn.connect("clicked", lambda b: shortcuts_window.show_or_false(self._window))

        self._history_items = HistoryItems()

        self._search_box = SearchBox()
        self._search_box.connect("search-changed", self._on_search_changed)
        self._search_box.connect("search-index", lambda sb, i: self._on_search_changed(sb, search_index=i))
        self._search_box.entry.connect("activate", self._on_entry_activated)

        self._items_view = ItemsView()
        self._items_view.connect("item-activated", self._on_item_activated)
        self._items_view.connect("item-entered", self._on_item_entered)
        self._items_view.connect("item-left", lambda iv, i: self.selection_changed())
        self._items_view.listbox.connect("selected-rows-changed", lambda iv: self.selection_changed())
        self._items_view.bind(self._history_items)

        gpaste_client.connect("ShowHistory", self.toggle)
        gpaste_client.connect("Tracking", lambda t: self._main_toolbox.track_btn.set_active(t))
        common.APPLICATION = self

        keybinder = KeybinderGtk()
        keybinder.register(
            common.SETTINGS[common.SHOW_CLIPBOARD_PREVIEW], lambda *_, **__: GLib.idle_add(clipboard_preview.toggle)
        )
        keybinder.start()
Beispiel #2
0
    def do_startup(self):
        Gtk.Application.do_startup(self)

        actions = [
            [
                'delete', 'app.delete', common.DELETE_ITEM,
                self._on_delete_action
            ],
            [
                'show_histories', 'app.show_histories', common.SHOW_HISTORIES,
                self.show_histories_manager
            ],
            [
                'focus_search', 'app.focus_search', common.FOCUS_SEARCH,
                lambda _, __: self._search_box.entry.grab_focus()
            ],
            [
                'reset_search', 'app.reset_search', common.RESET_SEARCH,
                self._on_reset_search_action
            ],
            [
                'editor_wrap_text', 'app.editor_wrap_text',
                common.EDITOR_WRAP_TEXT_SHORTCUT, self._on_editor_wrap_action
            ],
            [
                'open_item', 'app.open_item', common.OPEN_ITEM,
                self._on_open_item
            ],
            [
                'backup_history', 'app.backup_history', common.BACKUP_HISTORY,
                self._on_backup_history
            ],
            [
                'keep_search', 'app.keep_search', common.KEEP_SEARCH_AND_CLOSE,
                lambda _, __: self.hide(False)
            ],
            ['hide', 'app.hide', common.HIDE_APP, lambda _, __: self.hide()],
            ['quit', 'app.quit', common.QUIT_APP, lambda _, __: self.quit()],
            [
                'show_help', 'app.show_help', common.SHOW_HELP,
                lambda _, __: shortcuts_window.show_or_false(self._window)
            ],
            [
                'load_all_history', 'app.load_all_history',
                common.LOAD_ALL_HISTORY,
                lambda _, __: self._items_view.load_rest_items()
            ]
        ]

        for name, target, key, callback in actions:
            self._bind_action(name, target, key, callback)

        if common.SETTINGS[common.STARTUP_NOTIFICATION]:
            utils.notify(
                body=_('%s is now running, press <b>%s</b> to use it.' %
                       (version.APP_NAME,
                        gpaste_client.SETTINGS['show-history'])))
Beispiel #3
0
    def do_startup(self):
        Gtk.Application.do_startup(self)

        actions = [
            ["delete", "app.delete", common.DELETE_ITEM, self._on_delete_action],
            ["show_histories", "app.show_histories", common.SHOW_HISTORIES, self.show_histories_manager],
            [
                "focus_search",
                "app.focus_search",
                common.FOCUS_SEARCH,
                lambda _, __: self._search_box.entry.grab_focus(),
            ],
            ["reset_search", "app.reset_search", common.RESET_SEARCH, self._on_reset_search_action],
            ["editor_wrap_text", "app.editor_wrap_text", common.EDITOR_WRAP_TEXT_SHORTCUT, self._on_editor_wrap_action],
            ["open_item", "app.open_item", common.OPEN_ITEM, self._on_open_item],
            ["backup_history", "app.backup_history", common.BACKUP_HISTORY, self._on_backup_history],
            ["keep_search", "app.keep_search", common.KEEP_SEARCH_AND_CLOSE, lambda _, __: self.hide(False)],
            ["hide", "app.hide", common.HIDE_APP, lambda _, __: self.hide()],
            ["quit", "app.quit", common.QUIT_APP, lambda _, __: self.quit()],
            [
                "show_help",
                "app.show_help",
                common.SHOW_HELP,
                lambda _, __: shortcuts_window.show_or_false(self._window),
            ],
            [
                "load_all_history",
                "app.load_all_history",
                common.LOAD_ALL_HISTORY,
                lambda _, __: self._items_view.load_rest_items(),
            ],
        ]

        for name, target, key, callback in actions:
            self._bind_action(name, target, key, callback)

        if common.SETTINGS[common.STARTUP_NOTIFICATION]:
            utils.notify(
                body=_(
                    "%s is now running, press <b>%s</b> to use it."
                    % (version.APP_NAME, gpaste_client.SETTINGS["show-history"])
                )
            )
Beispiel #4
0
    def __init__(self):
        super().__init__()

        self.set_application_id(version.APP_ID)
        self.set_flags(Gio.ApplicationFlags.HANDLES_COMMAND_LINE)

        screen = Gdk.Screen.get_default()
        css_provider = Gtk.CssProvider()
        css_provider.load_from_path(common.CSS_PATH)
        style_context = Gtk.StyleContext()
        style_context.add_provider_for_screen(screen, css_provider,
                                              Gtk.STYLE_PROVIDER_PRIORITY_USER)

        gtk_settings = Gtk.Settings.get_default()
        gtk_settings.props.gtk_application_prefer_dark_theme = True

        self._window = None
        self._editor = editor.Editor()
        self._previewer = previewer.Previewer()
        self._merger = merger.Merger()
        self._merger.connect('merge', self.merge_items)
        self._items_processors = ItemsProcessors()
        self._items_processors.add_processor(self._editor)
        self._items_processors.add_processor(self._previewer)
        self._items_processors.add_processor(self._merger)

        self._main_toolbox = MainToolbox()
        self._main_toolbox.prefs_btn.connect('clicked',
                                             lambda b: self.show_prefs())
        self._main_toolbox.about_btn.connect('clicked',
                                             lambda b: self.show_about())
        self._main_toolbox.quit_btn.connect('clicked', lambda b: self.quit())
        self._main_toolbox.restart_btn.connect('clicked', self._restart_daemon)
        self._main_toolbox.close_btn.connect(
            'clicked', lambda b: self.hide(reset_search=True))
        self._main_toolbox.track_btn.connect(
            'clicked', lambda b: gpaste_client.track(b.get_active()))
        self._main_toolbox.track_btn.set_active(
            gpaste_client.get_prop('Active'))
        self._main_toolbox.help_btn.connect(
            'clicked', lambda b: shortcuts_window.show_or_false(self._window))

        self._history_items = HistoryItems()

        self._search_box = SearchBox()
        self._search_box.connect('search-changed', self._on_search_changed)
        self._search_box.connect(
            'search-index',
            lambda sb, i: self._on_search_changed(sb, search_index=i))
        self._search_box.entry.connect('activate', self._on_entry_activated)

        self._items_view = ItemsView()
        self._items_view.connect('item-activated', self._on_item_activated)
        self._items_view.connect('item-entered', self._on_item_entered)
        self._items_view.connect('item-left',
                                 lambda iv, i: self.selection_changed())
        self._items_view.listbox.connect('selected-rows-changed',
                                         lambda iv: self.selection_changed())
        self._items_view.bind(self._history_items)

        gpaste_client.connect('ShowHistory', self.toggle)
        gpaste_client.connect(
            'Tracking', lambda t: self._main_toolbox.track_btn.set_active(t))
        common.APPLICATION = self

        keybinder = KeybinderGtk()
        keybinder.register(
            common.SETTINGS[common.SHOW_CLIPBOARD_PREVIEW],
            lambda *_, **__: GLib.idle_add(clipboard_preview.toggle))
        keybinder.start()