PyGobject(八十)Gtk.Clipboard
2016-08-02 16:16
519 查看
GtkClipboard
Methods
Virtual Methods
Properties
Signals
例子
![](http://img.blog.csdn.net/20160802135349585)
![](http://img.blog.csdn.net/20160802161243530)
代码:
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
Methods
Virtual Methods
Properties
Signals
例子
Gtk.Clipboard
Gtk.Clipboard剪贴板Methods
方法修饰词 | 方法名及参数 |
---|---|
static | get (selection) |
static | get_default (display) |
static | get_for_display (display, selection) |
clear () | |
get_display () | |
get_owner () | |
request_contents (target, callback, *user_data) | |
request_image (callback, *user_data) | |
request_rich_text (buffer, callback, *user_data) | |
request_targets (callback, *user_data) | |
request_text (callback, *user_data) | |
request_uris (callback, *user_data) | |
set_can_store (targets) | |
set_image (pixbuf) | |
set_text (text, len) | |
store () | |
wait_for_contents (target) | |
wait_for_image () | |
wait_for_rich_text (buffer) | |
wait_for_targets () | |
wait_for_text () | |
wait_for_uris () | |
wait_is_image_available () | |
wait_is_rich_text_available (buffer) | |
wait_is_target_available (target) | |
wait_is_text_available () | |
wait_is_uris_available () |
Virtual Methods
Properties
Name | Type | Flags | Short Description |
---|
Signals
Name | Short Description |
---|---|
owner-change | The ::owner-change signal is emitted when GTK+ receives an event that indicates that the ownership of the selection associated with clipboard has changed. |
例子
不知道怎么样才能粘贴系统中剪切的图片。如用QQ剪切的图片代码:
#!/usr/bin/env python3 # Created by xiaosanyu at 16/6/16 # section 128 TITLE = "Clipboard" DESCRIPTION = """ The Gtk.Clipboard object represents a clipboard of data shared between different processes or between different widgets in the same process. Each clipboard is identified by a name encoded as a Gdk.Atom. (Conversion to and from strings can be done with Gdk.Atom.intern() and Gdk.Atom.name().) The default clipboard corresponds to the “CLIPBOARD” atom; another commonly used clipboard is the “PRIMARY” clipboard, which, in X, traditionally contains the currently selected text. """ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk items = ["edit-cut", "edit-paste", "edit-copy"] class ClipboardWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Clipboard Example") grid = Gtk.Grid() # self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) atom = Gdk.atom_intern('CLIPBOARD', True) self.clipboard = Gtk.Clipboard.get(atom) # None: all available targets should be saved. self.clipboard.set_can_store(None) self.entry = Gtk.Entry() button_copy_text = Gtk.Button("Copy Text") button_paste_text = Gtk.Button("Paste Text") grid.attach(self.entry, 0, 0, 1, 1) grid.attach(button_copy_text, 1, 0, 1, 1) grid.attach(button_paste_text, 2, 0, 1, 1) button_copy_text.connect("clicked", self.copy_text) button_paste_text.connect("clicked", self.paste_text) for i, item in enumerate(items): image = Gtk.Image.new_from_icon_name(item, Gtk.IconSize.MENU) button_copy_image = Gtk.Button("Copy Image") grid.attach(image, 0, i + 1, 1, 1) grid.attach(button_copy_image, 1, i + 1, 1, 1) button_copy_image.connect("clicked", self.copy_image, image) self.image = Gtk.Image() button_paste_image = Gtk.Button("Paste Image") grid.attach(self.image, 0, 4, 1, 1) grid.attach(button_paste_image, 1, 4, 2, 1) button_paste_image.connect("clicked", self.paste_image) self.add(grid) def copy_text(self, widget): self.clipboard.set_text(self.entry.get_text(), -1) def paste_text(self, widget): selection = self.clipboard.wait_for_contents(Gdk.atom_intern('UTF8_STRING', True)) print(selection.get_text()) text = self.clipboard.wait_for_text() if text is not None: self.entry.set_text(text) else: print("No text on the clipboard.") def copy_image(self, widget, image): image_type = image.get_storage_type() if image_type == Gtk.ImageType.PIXBUF: self.clipboard.set_image(image.get_pixbuf()) elif image_type == Gtk.ImageType.ICON_NAME: name, size = image.get_icon_name() pixbuf = Gtk.IconTheme.get_default().load_icon(name, size, 0) self.clipboard.set_image(pixbuf) else: print("No image has been pasted yet.") # clear the image self.image.set_from_pixbuf(None) def paste_image(self, widget): # print(self.clipboard.wait_for_targets()) selection = self.clipboard.wait_for_contents(Gdk.atom_intern('image/png', True)) pixbuf = selection.get_pixbuf() # pixbuf = self.clipboard.wait_for_image() if pixbuf is not None: self.image.set_from_pixbuf(pixbuf) else: print("no image") def main(): win = ClipboardWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() if __name__ == "__main__": main()
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
相关文章推荐
- Python开发环境Wing IDE使用手册之GTK和PyGObject
- PyGobject(十五)布局容器之Button篇——Gtk.ScaleButton
- PyGobject(六十一)Gtk.Widget
- PyGobject(七十五)Gtk.Widget之Gtk.Scrollbar
- PyGobject(十六)布局容器之Button篇——Gtk.VolumeButton
- PyGobject(七十六)Gtk.Widget之Gtk.Spinner
- PyGobject(六十三)Gtk.Widget之Gtk.AccelLabel
- PyGobject(七十七)Gtk.Widget之Gtk.Switch
- PyGobject(六十四)Gtk.Widget之Gtk.Arrow
- PyGobject(一百一十)代码整合及GtkSource安装使用
- PyGobject(六十五)Gtk.Widget之Gtk.Image
- PyGobject(五)布局容器之Button篇——Gtk.Button
- PyGobject(六)布局容器之Button篇——Gtk.ColorButton
- PyGobject(六十六)Gtk.Widget之Gtk.Calendar
- PyGobject(七)布局容器之Button篇——Gtk.FontButton
- PyGobject(六十七)Gtk.Widget之Gtk.CellView
- PyGobject(八十三)Gtk.SizeGroup
- PyGobject(六十八)Gtk.Widget之Gtk.DrawingArea
- PyGobject(八)布局容器之Button篇——Gtk.LinkButton
- PyGobject(六十九)Gtk.Widget之Gtk.LevelBar