GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-xlib/examples/threadtest.py at master · python-xlib/python-xlib

Expand file tree

/

threadtest.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
59 lines (45 loc) · 1.53 KB
/

threadtest.py

Copy path

File metadata and controls

executable file
·
59 lines (45 loc) · 1.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/python
# Python 2/3 compatibility.
from __future__ import print_function
import sys
import os
# Change path so we find Xlib
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from Xlib import display, X, threaded
import time
import thread
def redraw(win, gc):
# win.clear_area()
win.fill_rectangle(gc, 20, 20, 60, 60)
def blink(display, win, gc, cols):
while 1:
time.sleep(2)
print('Changing color', cols[0])
gc.change(foreground = cols[0])
cols = (cols[1], cols[0])
redraw(win, gc)
display.flush()
def main():
d = display.Display()
root = d.screen().root
colormap = d.screen().default_colormap
red = colormap.alloc_named_color("red").pixel
blue = colormap.alloc_named_color("blue").pixel
background = colormap.alloc_named_color("white").pixel
window = root.create_window(100, 100, 100, 100, 1,
X.CopyFromParent, X.InputOutput,
X.CopyFromParent,
background_pixel = background,
event_mask = X.StructureNotifyMask | X.ExposureMask)
window.map()
gc = window.create_gc(foreground = red)
thread.start_new_thread(blink, (d, window, gc, (blue, red)))
while 1:
event = d.next_event()
if event.type == X.Expose:
if event.count == 0:
redraw(window, gc)
elif event.type == X.DestroyNotify:
sys.exit(0)
if __name__ == "__main__":
main()
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.