Прикреплённый файл «winrun.py»
Загрузка 1 #!/usr/bin/python
2 # coding: utf-8
3 # vim: sw=4:et:ts=4
4 '''
5 Написать «оконную систему», состоящую из классов
6
7 * Экран (контейнер окон, позволяет манипулировать окнами)
8 o Список окон, определение окна-получателя события
9 o Глубина окон, изменение глубины окон
10 o Перемещение и изменение размера окон
11 * Окно (позволяет манипулировать своим содержимым)
12
13 winrun.py: запускаемый файл
14 '''
15 import pygame, sys, random
16 from win import *
17
18 class sscreen(screen):
19 def handler(self, event, pos):
20 if event.type == pygame.MOUSEMOTION and event.buttons[0]:
21 index = self.locate(pos)
22 if index >= 0:
23 nrect = self.windows[index].rect.move(event.rel)
24 if self.surface.get_rect().contains(nrect):
25 self.windows[index].rect.move_ip(event.rel)
26 self.windows[index].window.renew(self.surface.subsurface(self.windows[index].rect))
27 def proceed(self, event, pos):
28 '''Execute window manipulation'''
29 ret = False
30 if event.type == pygame.MOUSEMOTION and event.buttons[0]:
31 self.handler(event, pos)
32 ret = True
33 elif not screen.proceed(self, event, pos):
34 if event.type == pygame.KEYDOWN:
35 ret = True
36 # добавление/удаление окна
37 if event.key == 127:
38 scr.pop()
39 elif event.key == 277:
40 color=randcolor()
41 rect=randrect((20,20),scr.surface.get_size())
42 scr.append(rect, "basic", basic_window, bg=color)
43 elif event.type == pygame.MOUSEBUTTONDOWN:
44 ret = True
45 index = scr.locate(event.pos)
46 if index >= 0:
47 scr.top(index)
48 else:
49 ret=True
50 return ret
51
52 def randcolor():
53 return random.randint(0,255),random.randint(0,255),random.randint(0,255)
54
55 def randrect(min, max):
56 x=random.randint(0, max[0]-min[0]);
57 y=random.randint(0, max[1]-min[1]);
58 w=random.randint(min[0], max[0]-x);
59 h=random.randint(min[1], max[1]-y);
60 return pygame.Rect(x,y,w,h)
61
62 # Инициализировать PyGame
63 pygame.init()
64 # завести экран
65 world = pygame.display.set_mode((1024,768))
66 scr = sscreen(world)
67 oldpos, pos = (0,0), (0,0)
68 # Обработка событий:
69 while True:
70 event = pygame.event.wait()
71 # события, которые обрабатываем только мы
72 if event.type == pygame.QUIT: sys.exit()
73 if hasattr(event,"pos"):
74 oldpos, pos = pos, event.pos
75 # хочет ли экран обрабатывать событие?
76 if not scr.proceed(event, pos):
77 print >> sys.stderr, event, pos
78 # TODO перемещение окна
79 # TODO изменение размера окна
80 scr.redraw()
81 pygame.display.flip()
Прикреплённые файлы
Для ссылки на прикреплённый файл в тексте страницы напишите attachment:имяфайла, как показано ниже в списке файлов. Не используйте URL из ссылки «[получить]», так как он чисто внутренний и может измениться.- [получить | показать] (2011-09-26 11:35:38, 3.9 KB) [[attachment:win.py]]
- [получить | показать] (2011-09-26 11:35:38, 3.1 KB) [[attachment:winrun.py]]
Вам нельзя прикреплять файлы к этой странице.