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
|
#!/usr/bin/python3
'''
Helper program to draw a background image on each screen of the system.
'''
import sys
from PyQt4.QtCore import Qt
from PyQt4 import QtGui
def die(msg):
print(msg, file=sys.stderr)
sys.exit(1)
def create_window(wallpaper, geometry):
win = QtGui.QWidget()
wallpaper = wallpaper.scaled(geometry.size(),
Qt.KeepAspectRatioByExpanding,
Qt.SmoothTransformation)
palette = QtGui.QPalette()
palette.setBrush(win.backgroundRole(), QtGui.QBrush(wallpaper))
win.setPalette(palette)
win.setAttribute(Qt.WA_X11NetWmWindowTypeDesktop)
win.setGeometry(geometry)
win.show()
return win
def main():
if len(sys.argv) != 2:
die('usage: {} <path/to/wallpaper.png>'.format(sys.argv[0]))
path = sys.argv[1]
app = QtGui.QApplication(sys.argv)
wallpaper = QtGui.QPixmap(path)
if wallpaper.isNull():
die('Failed to load {}'.format(path))
desktop = app.desktop()
# Keep a trace of the windows to ensure they are not garbage collected
windows = []
for idx in range(desktop.screenCount()):
geometry = desktop.screenGeometry(idx)
win = create_window(wallpaper, geometry)
windows.append(win)
return app.exec_()
if __name__ == '__main__':
main()
|