Python gi.repository.Gdk 模块,SELECTION_PRIMARY 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用gi.repository.Gdk.SELECTION_PRIMARY

项目:mama    作者:maateen    | 项目源码 | 文件源码
def read_clipboard(self):
        """
        @description: A function to make mama reads the selected
        text
        """
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)

        text = clipboard.wait_for_text()
        if text:
            text = text.replace("'", ' ')
            TextToSpeech(self.config, text)
        else:
            TextToSpeech('Nothing in the clipboard')
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def __on_copy_activate(self, widget):
        """
        Provides dirty clipboard hack to get selection from inside of WebKit
        :param widget:
        """
        primary_selection = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
        selection_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        # It does wait some short time for that text, it seems to update every now and then
        # Can get selection from anywhere in the system, no real way to tell
        selection_clipboard.set_text(primary_selection.wait_for_text(), -1)