Gdk.Cursor
Gdk.Cursor鼠标指针样式
![这里写图片描述](https://img-blog.csdn.net/20160802162036111)
Methods
方法修饰词 | 方法名及参数 |
---|
static | new (cursor_type) |
static | new_for_display (display, cursor_type) |
static | new_from_name (display, name) |
static | new_from_pixbuf (display, pixbuf, x, y) |
static | new_from_surface (display, surface, x, y) |
| get_cursor_type () |
| get_display () |
| get_image () |
| get_surface () |
| ref () |
| unref () |
Virtual Methods
Properties
Name | Type | Flags | Short Description |
---|
cursor-type | Gdk.CursorType | r/w/co | Standard cursor type |
display | Gdk.Display | r/w/co | Display of this cursor |
Signals
例子
代码:
TITLE = "Cursor"
DESCRIPTION = """
A Gdk.Cursor represents a cursor. Its contents are private.
"""
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, GLib
import os
cursors = (
{'group': 'General', 'name': None},
{'group': None, 'name': 'default'},
{'group': None, 'name': 'none'},
{'group': 'Link & Status', 'name': None},
{'group': None, 'name': 'context-menu'},
{'group': None, 'name': 'help'},
{'group': None, 'name': 'pointer'},
{'group': None, 'name': 'progress'},
{'group': None, 'name': 'wait'},
{'group': 'Selection', 'name': None},
{'group': None, 'name': 'cell'},
{'group': None, 'name': 'crosshair'},
{'group': None, 'name': 'text'},
{'group': None, 'name': 'vertical-text'},
{'group': 'Drag & Drop', 'name': None},
{'group': None, 'name': 'alias'},
{'group': None, 'name': 'copy'},
{'group': None, 'name': 'move'},
{'group': None, 'name': 'no-drop'},
{'group': None, 'name': 'not-allowed'},
{'group': None, 'name': 'grab'},
{'group': None, 'name': 'grabbing'},
{'group': 'Resize & Scrolling', 'name': None},
{'group': None, 'name': 'all-scroll'},
{'group': None, 'name': 'col-resize'},
{'group': None, 'name': 'row-resize'},
{'group': None, 'name': 'n-resize'},
{'group': None, 'name': 'e-resize'},
{'group': None, 'name': 's-resize'},
{'group': None, 'name': 'w-resize'},
{'group': None, 'name': 'ne-resize'},
{'group': None, 'name': 'nw-resize'},
{'group': None, 'name': 'se-resize'},
{'group': None, 'name': 'sw-resize'},
{'group': None, 'name': 'ew-resize'},
{'group': None, 'name': 'ns-resize'},
{'group': None, 'name': 'nesw-resize'},
{'group': None, 'name': 'nwse-resize'},
{'group': 'Zoom', 'name': None},
{'group': None, 'name': 'zoom-in'},
{'group': None, 'name': 'zoom-out'},
)
class CursorWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Cursor demo")
self.connect("delete-event", Gtk.main_quit)
self.set_default_size(500, 500)
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.add(sw)
box = Gtk.VBox()
box.margin_start = 20
box.margin_end = 20
box.margin_bottom = 10
sw.add(box)
for item in cursors:
if item["group"]:
section = self.add_section(box, item["group"])
else:
self.add_button(section, item["name"])
self.show_all()
Gtk.main()
@staticmethod
def set_cursor(button, cursor):
toplevel = button.get_toplevel()
window = toplevel.get_window()
window.set_cursor(cursor)
@staticmethod
def add_section(box, heading):
label = Gtk.Label(heading)
label.set_xalign(0)
label.set_margin_top(10)
label.set_margin_bottom(10)
box.pack_start(label, False, False, 0)
section = Gtk.FlowBox()
section.set_halign(Gtk.Align.START)
section.set_selection_mode(Gtk.SelectionMode.NONE)
section.set_min_children_per_line(2)
section.set_max_children_per_line(20)
box.pack_start(section, False, False, 0)
return section
def add_button(self, section, css_name):
display = section.get_display()
cursor = Gdk.Cursor.new_from_name(display, css_name)
if not cursor:
image = Gtk.Image.new_from_icon_name("image-missing", Gtk.IconSize.MENU)
else:
path = os.path.join(os.path.dirname(__file__), "Data/%s_cursor.png" % css_name.replace("-", "_"))
image = Gtk.Image.new_from_file(path)
image.set_size_request(32, 32)
button = Gtk.Button()
button.add(image)
button.get_style_context().add_class("image-button")
button.connect("clicked", self.set_cursor, cursor)
button.set_tooltip_text(css_name)
section.add(button)
def main():
CursorWindow()
if __name__ == "__main__":
main()
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728