annotate tools/rect_drawer.py @ 196:b63ecd5b9a45

Unbeak helper
author Neil Muller <neil@dip.sun.ac.za>
date Thu, 26 Aug 2010 08:27:29 +0200
parents f98bc17f5e67
children 640044d7ddda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
181
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
62 rect_thick = 3
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
63 draw_thick = 1
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
64
174
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
65 def __init__(self, state):
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
66 self.state = state
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
67 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
68 self.mode = 'draw'
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
69 self.rects = []
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
70 self.start_pos = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
71 self.end_pos = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
72 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
73 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
74
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
75 def draw_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 = 'draw'
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
77
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
78 def del_mode(self):
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
79 self.mode = 'del'
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
80 self.start_pos = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
81 self.end_pos = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
82
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
83 def draw(self, surface):
196
b63ecd5b9a45 Unbeak helper
Neil Muller <neil@dip.sun.ac.za>
parents: 181
diff changeset
84 self.state.draw(surface, None)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
85 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
86 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
87 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
88 self.end_pos[1] - self.start_pos[1])
181
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
89 frame_rect(surface, self.draw_color, rect, self.draw_thick)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
90 for (col, rect) in self.rects:
181
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
91 frame_rect(surface, col, rect, self.rect_thick)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
92
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
93 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
94 d = {}
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
95 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
96 d.setdefault(col, [])
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
97 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
98 return d
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
99
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
100 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
101 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
102 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
103 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
104 for r in d[col]:
179
39f75faf16cb Add trailing , for copy-n-paste
Neil Muller <neil@dip.sun.ac.za>
parents: 174
diff changeset
105 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
106 print
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
107
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
108 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
109 if self.mode == 'del':
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
110 pos = e.pos
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
111 cand = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
112 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
113 if rect.collidepoint(pos):
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
114 cand = (col, rect)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
115 break
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
116 if cand:
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
117 self.rects.remove(cand)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
118 self.invalidate()
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
119 elif self.mode == 'draw':
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
120 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
121 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
122
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
123 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
124 if self.mode == 'draw':
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
125 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
126 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
127 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
128 rect.normalize()
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
129 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
130 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
131
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
132 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
133 if self.mode == 'draw':
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
134 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
135 self.invalidate()
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
136
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
137
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
138 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
139 # 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
140 # background image
174
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
141 if len(sys.argv) < 2:
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
142 print 'Please provide a scene name'
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
143 sys.exit(0)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
144 pygame.display.init()
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
145 pygame.font.init()
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
146 display = pygame.display.set_mode((1000, 600))
196
b63ecd5b9a45 Unbeak helper
Neil Muller <neil@dip.sun.ac.za>
parents: 181
diff changeset
147 state = initial_state()
174
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
148 try:
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
149 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
150 state.do_check = None
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
151 except KeyError:
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
152 print 'Invalid scene name'
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
153 sys.exit(1)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
154 app = RootWidget(display)
174
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
155 image = AppImage(state)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
156 app.add(image)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
157 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
158 app.add(draw)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
159 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
160 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
161 app.add(delete)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
162 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
163 palette = AppPalette(image)
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
164 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
165 app.add(palette)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
166 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
167 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
168 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
169 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
170 app.add(quit_but)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
171 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
172 app.run()