-
Notifications
You must be signed in to change notification settings - Fork 6
/
clipping.py
executable file
·60 lines (41 loc) · 1.47 KB
/
clipping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# - coding: utf-8 -
# Copyright (C) 2010 Toms Bauģis <toms.baugis at gmail.com>
"""
Clipping demo - two labels in different colors are put on each other
but before painting the area is clipped so that first label gets 0 -> mouse_x
width and the other mouse_x -> window width
"""
from gi.repository import Gtk as gtk
from lib import graphics
class Scene(graphics.Scene):
def __init__(self):
graphics.Scene.__init__(self, framerate=30)
self.connect("on-enter-frame", self.on_enter_frame)
def on_enter_frame(self, scene, context):
g = graphics.Graphics(context)
g.save_context()
g.rectangle(0, 0, self.mouse_x, self.height)
g.clip()
g.move_to(20, 100)
g.show_label("Hello", font_desc="Sans Serif 150", color="#fff")
g.restore_context()
g.save_context()
g.rectangle(self.mouse_x, 0, self.width, self.height)
g.clip()
g.move_to(20, 100)
g.show_label("Hello", font_desc="Sans Serif 150", color="#000")
g.restore_context()
self.redraw()
class BasicWindow:
def __init__(self):
window = gtk.Window()
window.set_default_size(600, 500)
window.connect("delete_event", lambda *args: gtk.main_quit())
window.add(Scene())
window.show_all()
if __name__ == '__main__':
window = BasicWindow()
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL) # gtk3 screws up ctrl+c
gtk.main()