~bennabiy/+junk/python-xlib

« back to all changes in this revision

Viewing changes to .pc/python3.patch/examples/threadtest.py

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura, Ramkumar Ramachandra, Andrew Shadura
  • Date: 2015-08-13 08:14:19 UTC
  • mfrom: (6.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150813081419-hdefinnghp2iydkx
Tags: 0.14+20091101-3
[ Ramkumar Ramachandra ]
* Remove useless debugging output (Closes: #565996)

[ Andrew Shadura ]
* Switch to 3.0 (quilt) format.
* Rename patches.
* Use debhelper 9 in its short form.
* Use pybuild.
* Bump Standards-Version.
* Don't build or install PostScript documentation and info files.
* Use system-provided texi2html instead of a shipped version
  (Closes: #795057).
* Update debian/copyright (Closes: #795057).
* Don't install Makefile or texi2html with the documentation.
* Set executable bit for examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import sys
 
4
import os
 
5
 
 
6
sys.path[1:1] = [os.path.join(sys.path[0], '..')]
 
7
 
 
8
from Xlib import display, X, threaded
 
9
import time
 
10
import thread
 
11
 
 
12
def redraw(win, gc):
 
13
    # win.clear_area()
 
14
    win.fill_rectangle(gc, 20, 20, 60, 60)
 
15
 
 
16
def blink(display, win, gc, cols):
 
17
    while 1:
 
18
        time.sleep(2)
 
19
        print 'Changing color', cols[0]
 
20
        gc.change(foreground = cols[0])
 
21
        cols = (cols[1], cols[0])
 
22
        redraw(win, gc)
 
23
        display.flush()
 
24
 
 
25
def main():
 
26
    d = display.Display()
 
27
    root = d.screen().root
 
28
 
 
29
    colormap = d.screen().default_colormap
 
30
 
 
31
    red = colormap.alloc_named_color("red").pixel
 
32
    blue = colormap.alloc_named_color("blue").pixel
 
33
    background = colormap.alloc_named_color("white").pixel
 
34
 
 
35
    window = root.create_window(100, 100, 100, 100, 1,
 
36
                                X.CopyFromParent, X.InputOutput,
 
37
                                X.CopyFromParent,
 
38
                                background_pixel = background,
 
39
                                event_mask = X.StructureNotifyMask | X.ExposureMask)
 
40
    window.map()
 
41
 
 
42
    gc = window.create_gc(foreground = red)
 
43
 
 
44
    thread.start_new_thread(blink, (d, window, gc, (blue, red)))
 
45
 
 
46
    while 1:
 
47
        event = d.next_event()
 
48
        if event.type == X.Expose:
 
49
            if event.count == 0:
 
50
                redraw(window, gc)
 
51
        elif event.type == X.DestroyNotify:
 
52
            sys.exit(0)
 
53
 
 
54
if __name__ == "__main__":
 
55
    main()