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