PyGobject(九十九)Cairo系列——环形加载图标

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/6
# section 149
TITLE = "Waiting"
DESCRIPTION = """
In this examle, we use transparency effect to create a waiting demo.
We will draw 8 lines that will gradually fade out creating an illusion
that a line is moving. Such effects are often used to inform users,
that a lengthy task is going on behind the scenes.
An example is streaming video over the internet.
"""

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib

import cairo
import math

trs = (
    (0.0, 0.15, 0.30, 0.5, 0.65, 0.80, 0.9, 1.0),
    (1.0, 0.0, 0.15, 0.30, 0.5, 0.65, 0.8, 0.9),
    (0.9, 1.0, 0.0, 0.15, 0.3, 0.5, 0.65, 0.8),
    (0.8, 0.9, 1.0, 0.0, 0.15, 0.3, 0.5, 0.65),
    (0.65, 0.8, 0.9, 1.0, 0.0, 0.15, 0.3, 0.5),
    (0.5, 0.65, 0.8, 0.9, 1.0, 0.0, 0.15, 0.3),
    (0.3, 0.5, 0.65, 0.8, 0.9, 1.0, 0.0, 0.15),
    (0.15, 0.3, 0.5, 0.65, 0.8, 0.9, 1.0, 0.0,)
)


class PyApp(Gtk.Window):
    def __init__(self):
        super(PyApp, self).__init__()
        self.set_title("Waiting")
        self.set_size_request(250, 150)
        self.connect("destroy", Gtk.main_quit)
        self.darea = Gtk.DrawingArea()
        self.darea.connect("draw", self.draw)
        self.add(self.darea)
        self.count = 0
        GLib.timeout_add(100, self.on_timer)
        self.show_all()

    def on_timer(self):
        self.count += 1
        self.darea.queue_draw()
        return True

    def draw(self, drawingArea, cr):
        w = drawingArea.get_allocated_width()
        h = drawingArea.get_allocated_height()
        cr.set_line_width(3)
        cr.set_line_cap(cairo.LINE_CAP_ROUND)
        cr.translate(w / 2, h / 2)
        for i in range(8):
            cr.set_source_rgba(0, 0, 0, trs[self.count % 8][i])
            cr.move_to(0.0, -10.0)
            cr.line_to(0.0, -40.0)
            cr.rotate(math.pi / 4)
            cr.stroke()


def main():
    PyApp()
    Gtk.main()


if __name__ == "__main__":
    main()





代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

sanxiaochengyu

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

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

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

打赏作者

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

抵扣说明:

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

余额充值