Mercurial > boomslang
annotate tools/rect_drawer.py @ 179:39f75faf16cb
Add trailing , for copy-n-paste
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Wed, 25 Aug 2010 15:07:44 +0200 |
parents | a2d041e0ab83 |
children | f98bc17f5e67 |
rev | line source |
---|---|
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
1 # Quickly hacked together helper for working out |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
2 # interactive regions in Suspended Sentence |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
3 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
4 import sys |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
5 import os.path |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
6 |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
7 script_path = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
8 sys.path.append(script_path) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
9 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
10 from albow.root import RootWidget |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
11 from albow.utils import frame_rect |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
12 from albow.widget import Widget |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
13 from albow.controls import Button |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
14 from albow.palette_view import PaletteView |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
15 from pygame.locals import SWSURFACE |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
16 import pygame |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
17 from pygame.colordict import THECOLORS |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
18 |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
19 from gamelib.state import initial_state |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
20 from gamelib import constants |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
21 |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
22 constants.DEBUG = True |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
23 |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
24 |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
25 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
26 class AppPalette(PaletteView): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
27 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
28 sel_width = 5 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
29 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
30 colors = [ |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
31 'red', 'maroon1', 'palevioletred1', 'moccasin', 'orange', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
32 'honeydew', 'yellow', 'gold', 'goldenrod', 'brown', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
33 'blue', 'purple', 'darkorchid4', 'thistle', 'skyblue1', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
34 'green', 'palegreen1', 'darkgreen', 'aquamarine', 'darkolivegreen', |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
35 ] |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
36 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
37 def __init__(self, app_image): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
38 self.image = app_image |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
39 super(AppPalette, self).__init__((35, 35), 5, 5, margin=2) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
40 self.selection = 0 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
41 self.image.rect_color = pygame.color.Color(self.colors[self.selection]) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
42 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
43 def num_items(self): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
44 return len(self.colors) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
45 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
46 def draw_item(self, surface, item_no, rect): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
47 d = -2 * self.sel_width |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
48 r = rect.inflate(d, d) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
49 surface.fill(pygame.color.Color(self.colors[item_no]), r) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
50 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
51 def click_item(self, item_no, event): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
52 self.selection = item_no |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
53 self.image.rect_color = pygame.color.Color(self.colors[item_no]) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
54 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
55 def item_is_selected(self, item_no): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
56 return self.selection == item_no |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
57 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
58 |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
59 |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
60 class AppImage(Widget): |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
61 |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
62 def __init__(self, state): |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
63 self.state = state |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
64 super(AppImage, self).__init__(pygame.rect.Rect(0, 0, 800, 600)) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
65 self.mode = 'draw' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
66 self.rects = [] |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
67 self.start_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
68 self.end_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
69 self.draw_color = pygame.color.Color('white') |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
70 self.rect_color = pygame.color.Color('white') |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
71 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
72 def draw_mode(self): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
73 self.mode = 'draw' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
74 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
75 def del_mode(self): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
76 self.mode = 'del' |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
77 self.start_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
78 self.end_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
79 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
80 def draw(self, surface): |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
81 self.state.draw(surface) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
82 if self.mode == 'draw' and self.start_pos: |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
83 rect = pygame.rect.Rect(self.start_pos[0], self.start_pos[1], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
84 self.end_pos[0] - self.start_pos[0], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
85 self.end_pos[1] - self.start_pos[1]) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
86 frame_rect(surface, self.draw_color, rect, 2) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
87 for (col, rect) in self.rects: |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
88 frame_rect(surface, col, rect, 1) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
89 |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
90 def _make_dict(self): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
91 d = {} |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
92 for col, rect in self.rects: |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
93 d.setdefault(col, []) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
94 d[col].append(rect) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
95 return d |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
96 |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
97 def print_rects(self): |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
98 d = self._make_dict() |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
99 for (num, col) in enumerate(d): |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
100 print 'Rect %d : ' % num |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
101 for r in d[col]: |
179
39f75faf16cb
Add trailing , for copy-n-paste
Neil Muller <neil@dip.sun.ac.za>
parents:
174
diff
changeset
|
102 print ' (%d, %d, %d, %d),' % (r.x, r.y, r.w, r.h) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
103 print |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
104 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
105 def mouse_down(self, e): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
106 if self.mode == 'del': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
107 pos = e.pos |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
108 cand = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
109 for (col, rect) in self.rects: |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
110 if rect.collidepoint(pos): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
111 cand = (col, rect) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
112 break |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
113 if cand: |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
114 self.rects.remove(cand) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
115 self.invalidate() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
116 elif self.mode == 'draw': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
117 self.start_pos = e.pos |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
118 self.end_pos = e.pos |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
119 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
120 def mouse_up(self, e): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
121 if self.mode == 'draw': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
122 rect = pygame.rect.Rect(self.start_pos[0], self.start_pos[1], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
123 self.end_pos[0] - self.start_pos[0], |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
124 self.end_pos[1] - self.start_pos[1]) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
125 rect.normalize() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
126 self.rects.append((self.rect_color, rect)) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
127 self.start_pos = self.end_pos = None |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
128 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
129 def mouse_drag(self, e): |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
130 if self.mode == 'draw': |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
131 self.end_pos = e.pos |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
132 self.invalidate() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
133 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
134 |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
135 if __name__ == "__main__": |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
136 # FIXME: should load an actual scene with current things, not just a |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
137 # background image |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
138 if len(sys.argv) < 2: |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
139 print 'Please provide a scene name' |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
140 sys.exit(0) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
141 pygame.display.init() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
142 pygame.font.init() |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
143 display = pygame.display.set_mode((1000, 600)) |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
144 state = initial_state(None) |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
145 try: |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
146 state.set_current_scene(sys.argv[1]) |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
147 state.do_check = None |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
148 except KeyError: |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
149 print 'Invalid scene name' |
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
150 sys.exit(1) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
151 app = RootWidget(display) |
174
a2d041e0ab83
Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents:
165
diff
changeset
|
152 image = AppImage(state) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
153 app.add(image) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
154 draw = Button('Draw Rect', action=image.draw_mode) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
155 app.add(draw) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
156 draw.rect.move_ip(810, 0) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
157 delete = Button('Del Rect', action=image.del_mode) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
158 app.add(delete) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
159 delete.rect.move_ip(810, 50) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
160 palette = AppPalette(image) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
161 palette.rect.move_ip(810, 100) |
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
162 app.add(palette) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
163 print_rects = Button("Print rects", action=image.print_rects) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
164 app.add(print_rects) |
165
9b3bba5e65f3
add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents:
162
diff
changeset
|
165 print_rects.rect.move_ip(810, 300) |
162
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
166 quit_but = Button("Quit", action=app.quit) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
167 app.add(quit_but) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
168 quit_but.rect.move_ip(810, 500) |
225e3a4b1e85
Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff
changeset
|
169 app.run() |