PyGobject(八十一)Gdk.Cursor

Gdk.Cursor

Gdk.Cursor鼠标指针样式

这里写图片描述

Methods

方法修饰词方法名及参数
staticnew (cursor_type)
staticnew_for_display (display, cursor_type)
staticnew_from_name (display, name)
staticnew_from_pixbuf (display, pixbuf, x, y)
staticnew_from_surface (display, surface, x, y)
get_cursor_type ()
get_display ()
get_image ()
get_surface ()
ref ()
unref ()

Virtual Methods

Properties

NameTypeFlagsShort Description
cursor-typeGdk.CursorTyper/w/coStandard cursor type
displayGdk.Displayr/w/coDisplay of this cursor

Signals

NameShort Description

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/11
# section 129
# 
# author: xiaosanyu
# website: yuxiaosan.tk \
#          http://blog.csdn.net/a87b01c14
# created: 16/7/11

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值