-
Notifications
You must be signed in to change notification settings - Fork 0
/
bullshit.py
executable file
·94 lines (72 loc) · 2.3 KB
/
bullshit.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import os
import sys
import cairo
import gobject
import time
import threading
import argparse
global image
class sleep_and_die(threading.Thread):
def __init__(self, time):
self.time = time
super(sleep_and_die, self).__init__()
def run(self):
time.sleep(self.time)
gtk.main_quit()
def expose(widget, event):
global image
cr = widget.window.cairo_create()
# Sets the operator to clear which deletes everything below where
# an object is drawn
cr.set_operator(cairo.OPERATOR_CLEAR)
# Makes the mask fill the entire window
cr.rectangle(0.0, 0.0, *widget.get_size())
# Deletes everything in the window (since the compositing operator
# is clear and mask fills the entire window
cr.fill()
# Set the compositing operator back to the default
cr.set_operator(cairo.OPERATOR_OVER)
# Load image
cr.set_source_surface(image, 0, 0)
cr.paint()
def main():
global image
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--image', type=str,
default="./images/bullshit.png",
required=False)
parser.add_argument('-t', '--time', type=int,
default=5, required=False)
args = parser.parse_args()
try:
image = cairo.ImageSurface.create_from_png(
os.path.expanduser(args.image))
except cairo.Error:
sys.stderr.write('file "%s" not found\n' % args.image)
sys.exit(2)
gobject.threads_init()
win = gtk.Window()
win.connect("destroy", lambda q: gtk.main_quit())
win.set_decorated(False)
win.set_position(gtk.WIN_POS_MOUSE)
win.set_skip_taskbar_hint(True)
win.set_size_request(image.get_width(), image.get_height())
win.set_keep_above(True)
# Makes the window paintable, so we can draw directly on it
win.set_app_paintable(True)
# This sets the windows colormap, so it supports transparency.
# This will only work if the wm support alpha channel
screen = win.get_screen()
rgba = screen.get_rgba_colormap()
win.set_colormap(rgba)
win.connect('expose-event', expose)
win.show()
t = sleep_and_die(args.time)
t.start()
gtk.main()
if __name__ == "__main__":
main()