Pygobject (99) Cairo series--Ring loading icon

Source: Internet
Author: User
Tags cairo gtk

Example

Example


Code:

#!/usr/bin/env Python3 # Created by Xiaosanyu on 16/7/6 # section 149 TITLE = ' waiting ' DESCRIPTION = "" "In this Examle,
We use the transparency effect to create a waiting demo. We'll draw 8 lines that would gradually fade out creating a illusion this a line is moving.
Such effects are often used to inform users, that's lengthy the task is going on behind the scenes.
An example is streaming 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 Self.connect ("Destroy", GTK). Main_quit) Self.darea = Gtk.drawingarea () self.darea.connect ("Draw", Self.draw) Self.add (self.dare
        a) Self.count = 0 Glib.timeout_add (MB, 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 ()





Code download address: http://download.csdn.net/detail/a87b01c14/9594728

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.