/
proc_desktop.py
92 lines (80 loc) · 2.7 KB
/
proc_desktop.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
import time
import os
import datetime
from common import *
from window import *
from bitmap import Bitmap
from painter import Painter
from message import get_message, put_message
ICON_MARGIN = 20
ICON_SIZE = 64
ICON_SIDE = (ICON_MARGIN + ICON_SIZE)
TASK_BAR_HEIGHT = 36
TIME_MARGIN = 20
class Desktop(Window):
def __init__(self, width, height):
super(Desktop, self).__init__(
0, 0, width, height,
WND_ONLY_CLIENT | WND_KEEP_BOTTOM | WND_KEEP_INACTIVE)
self.im = Bitmap('img/cheetah.png')
dirname = 'img/desktop-icons'
self.icons = [Bitmap(os.path.join(dirname, fname)).scaledToWidth(ICON_SIZE)
for fname in os.listdir(dirname)
if fname.startswith('icon-')]
self.proc_names = ['pa', 'pb', 'pc']
self.cur_icon = None
self.wnds = []
def on_create(self, ev):
self.put_message('REGISTER_WINDOWS_CHANGE')
def on_paint(self, ev):
painter = Painter(self)
painter.draw_bitmap(0, 0, self.im)
for i, icon in enumerate(self.icons):
x = ICON_MARGIN
y = ICON_MARGIN + i * (ICON_SIZE + ICON_MARGIN)
if i == self.cur_icon:
rc = Rect(x, y, ICON_SIZE, ICON_SIZE)
dx = ICON_SIZE / 10
rc.adjust(-dx, -dx, dx, dx)
painter.fill_rect(rc, SteelBlue)
painter.draw_bitmap(x, y, icon)
def on_mouse_press(self, ev):
x, y = ev['x'], ev['y']
row = y / (ICON_SIZE + 2 * ICON_MARGIN)
col = x / (ICON_SIZE + 2 * ICON_MARGIN)
rc = Rect(ICON_MARGIN, ICON_MARGIN + row * ICON_SIDE,
ICON_SIZE, ICON_SIZE)
if not rc.contains(x, y):
if self.cur_icon is not None:
self.cur_icon = None
self.update()
return
if col == 0 and row < len(self.icons):
if self.cur_icon == row:
self.put_message('OPEN_PROC', name=self.proc_names[row])
self.cur_icon = None
else:
self.cur_icon = row
self.update()
def on_windows_changed(self, ev):
return
wnds = ev['wnds']
new_wnds = []
for w in self.wnds:
if w in wnds:
new_wnds.append(w)
for w in wnds:
if w not in self.wnds:
new_wnds.append(w)
self.wnds = new_wnds
self.update()
def main(video_mem, qt_callback):
put_message(QUEUE_ID_GUI, {
'type': 'GET_SCREEN_INFO',
'pid': Desktop.__name__
})
msg = get_message(Desktop.__name__)
width = msg['width']
height = msg['height']
wnd = Desktop(width, height)
wnd.exec_()