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

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

项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def copy_code(self, *args):
        """
            Copy code shows the code box for a while (10s by default)
        """
        self.timer = 0
        code = self.account.get_code()
        try:
            clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
            self.window.notification.set_message(
                _('Code "{0}" copied to clipboard'.format(str(code))))
            self.window.notification.show()
            clipboard.clear()
            clipboard.set_text(code, len(code))
            logging.debug("Secret code copied to clipboard")
        except Exception as e:
            logging.error(str(e))
        self.revealer.set_reveal_child(True)
        GLib.timeout_add_seconds(1, self.update_timer)
项目:nom    作者:frnsys    | 项目源码 | 文件源码
def get_clipboard_html():
    """returns html in clipboard, if any"""
    if 'darwin' in sys.platform:
        if NSPasteboard is None:
            raise Exception('AppKit not found, first run `pip install pyobjc`')
        pb = NSPasteboard.generalPasteboard()
        return pb.stringForType_('public.html')

    elif 'linux' in sys.platform:
        if Gtk is None:
            raise Exception('Could not import GTK, is it installed on this system?')
        cb = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        html_target = Gdk.Atom.intern('text/html', False)
        targets = cb.wait_for_targets()[1]
        if html_target not in targets:
            return None
        return cb.wait_for_contents(html_target).get_data()

    else:
        raise Exception('Platform "{}" is not supported'.format(sys.platform))
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def on_quit(self, *args):
        """
        Close the application, stops all threads
        and clear clipboard for safety reasons
        """
        try:
            clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
            clipboard.clear()
        except Exception as e:
            logging.error(str(e))
        if self.win:
            self.win.save_window_state()
            self.win.destroy()
        self.quit()
项目:jcchess    作者:johncheetham    | 项目源码 | 文件源码
def copy_text_to_clipboard(text):
    # get the clipboard
    clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    # put the FEN data on the clipboard
    clipboard.set_text(text, -1)
    # make our data available to other applications
    clipboard.store()
项目:jcchess    作者:johncheetham    | 项目源码 | 文件源码
def get_text_from_clipboard():
    # get the clipboard
    clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    # read the text from the clipboard
    text = clipboard.wait_for_text()
    return text
项目:pyspc    作者:carlosqsilva    | 项目源码 | 文件源码
def __init__(self, parent):
        Gtk.Dialog.__init__(self, "File Dialog", parent, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        self.set_default_size(500, 550)
        box = self.get_content_area()

        self.verticalbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
        box.add(self.verticalbox)

        self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

        from_file = Gtk.Button("From File")
        from_file.connect("clicked", self.on_file)
        from_clipboard = Gtk.Button("Clipboard")
        from_clipboard.connect("clicked", self.on_clipboard)

        hbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=True)
        hbox1.pack_start(from_file, True, True, 0)
        hbox1.pack_start(from_clipboard, True, True, 0)
        self.verticalbox.pack_start(hbox1, False, False, 0)

        # Just holding the Place for real treeview widget
        self.scrollable_treelist = Gtk.Label()
        self.verticalbox.pack_start(self.scrollable_treelist, True, True, 0)

        self.show_all()
项目: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)
项目:bcloud    作者:wangYanJava    | 项目源码 | 文件源码
def update_clipboard(self, text):
        '''?????????????'''
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        clipboard.set_text(text, -1)
        self.toast(_('{0} copied to clipboard'.format(text)))
项目:SolStudio    作者:alianse777    | 项目源码 | 文件源码
def connect(self):
        # Connect function
        self.win.connect('key_release_event', self.on_key_pressed)
        # File menu
        self.builder.get_object("menu_file_new").connect("activate", self.new)
        self.builder.get_object("menu_file_open").connect("activate", self.open)
        self.builder.get_object("menu_file_save").connect("activate", self.save)
        self.builder.get_object("menu_file_save-as").connect("activate", self.save_as)
        self.builder.get_object("menu_file_exit").connect("activate", self.exit)

        #Edit menu
        self.builder.get_object("menu_edit_format").connect("activate",self.format)
        self.builder.get_object("menu_edit_cut").connect("activate", self.cut)
        self.builder.get_object("menu_edit_copy").connect("activate", self.copy)
        self.builder.get_object("menu_edit_paste").connect("activate", self.paste)

        #View menu
        self.builder.get_object("menu_view_gas").connect("activate", self.show_gas)

        #Compile button
        self.builder.get_object("compile_button").connect("pressed", self.compile)

        #Copy web3 button
        self.builder.get_object("button_copy").connect("pressed", self.copy_web3)

        #Buffer
        self.buff[self.ws] = self.builder.get_object("code")
        self.buff[self.ws].connect("changed", self.changed)

        self.tags = get_tags(self.buff[self.ws])
        self.cb =Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        # END Connect function
项目:input-paste    作者:RPing    | 项目源码 | 文件源码
def __init__(self):
        # create a new window
        window = Gtk.Window()
        window.set_position(Gtk.WindowPosition.CENTER)
        window.set_name('window')
        window.set_title("Input Helper")
        window.set_decorated(False)

        window.set_default_size(300, 40)
        window.connect("destroy", self.destroy)

        self.entry = Gtk.Entry()
        self.entry.set_name('entry')
        self.entry.connect("key_press_event", self.on_key_press)

        self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

        style_provider = Gtk.CssProvider()
        base_dir = os.path.abspath(os.path.dirname(__file__))
        css_path = os.path.join(base_dir, 'input_paste.css')
        style_provider.load_from_file(Gio.File.new_for_path(css_path))
        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(),
            style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )

        window.add(self.entry)
        window.show_all()
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def on_pastego(widget):

    clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

    text = clipboard.wait_for_text()
    if text != None:
        widget.set_text(text)
        widget.activate()

    return True
项目:PyGObject-examples    作者:VatsalP    | 项目源码 | 文件源码
def __init__(self):
        self.builder = Gtk.Builder()
        self.builder.add_from_file("simpletexteditor.glade")
        self.builder.connect_signals(self)

        self.window = self.builder.get_object("window")
        self.textview = self.builder.get_object("textview")
        self.textbuffer = self.builder.get_object("textbuffer")
        self.about = self.builder.get_object("about_page")
        self.fileopen = self.builder.get_object("fileopen")
        self.filesave = self.builder.get_object("filesave")
        self.fontchooser = self.builder.get_object("fontchooser")
        # notsave is msgdialog for asking
        # if user wants to save current textbuffer
        self.notsave = self.builder.get_object("notsave")
        self.notsavetwo = self.builder.get_object("notsavetwo")

        self.currentfile = ""
        self.path = pathlib.PurePath(self.currentfile)
        if self.path.parts:
            self.window.set_title(self.path.parts[-1])
        else:
            self.window.set_title("Untitled document")


        self.filechanged = False
        self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
项目:mate-menu    作者:ubuntu-mate    | 项目源码 | 文件源码
def on_drag_data_get( self, widget, context, selection, targetType, time ):
        if targetType == self.TARGET_TYPE_FAV:
            selection.set(Gdk.SELECTION_CLIPBOARD, 8, str(widget.position))
项目:poseidon    作者:sidus-dev    | 项目源码 | 文件源码
def pass_generator(self):

    if self.tabs[self.current_page][0]\
    .scrolled_window.get_name() != "webview": return True

    window = build_window(self, 0, 0)
    window.set_titlebar(build_headerbar(_("Password Generator"), None, 1))

    entry = make_box("{} (Def: 32) (Max: 99999)".format(_("Password Length")), 5, 1)
    button = Gtk.Button(label=_("Generate"))
    copy = Gtk.Button(label=_("Copy"))
    result = Gtk.TextView()
    result.set_top_margin(10)
    result.set_left_margin(10)
    result.set_wrap_mode(Gtk.WrapMode.WORD)
    scrolled_window = Gtk.ScrolledWindow()
    scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
    scrolled_window.set_size_request(400, 200)
    scrolled_window.add(result)

    bt_grid = Gtk.Grid()
    bt_grid.set_column_spacing(10)
    bt_grid.attach(button, 1, 0, 1, 1)
    bt_grid.attach(copy, 2, 0, 1, 1)
    bt_grid.set_column_homogeneous(True)

    grid = Gtk.Grid()
    grid.attach(entry, 0, 0, 1, 1)
    grid.attach(scrolled_window, 0, 1, 1, 1)
    grid.attach(bt_grid, 0, 2, 1, 1)

    entry.set_property("margin-bottom", 15)
    bt_grid.set_property("margin-top", 15)
    grid.set_property("margin", 15)

    window.add(grid)
    window.show_all()

    clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

    for i in entry:
        if type(i) == Gtk.Entry: entry = i

    button.connect("clicked", lambda x: pass_generate(entry.get_text(), 32, result))
    copy.connect("clicked", lambda x: clipboard.set_text(result.get_buffer().\
    get_text(result.get_buffer().get_start_iter(),result.get_buffer().get_end_iter(), False), -1))