annotate pyntnclick/tools/rect_drawer.py @ 813:3a875256f795 pyntnclick

better visible handling
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 27 Jan 2013 17:33:04 +0200
parents 2dd400a7c16d
children 9f542ef6e498
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
537
5b9f371c2bb8 PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents: 524
diff changeset
4 from pygame.locals import (K_LEFT, K_RIGHT, K_UP, K_DOWN,
5b9f371c2bb8 PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents: 524
diff changeset
5 K_a, K_t, K_d, K_i, K_r, K_o, K_b, K_z,
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
6 QUIT, MOUSEBUTTONDOWN, MOUSEMOTION,
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
7 MOUSEBUTTONUP, KEYDOWN)
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
8 import pygame
712
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
9 import os
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
10
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
11 import pyntnclick.constants
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
12 from pyntnclick.i18n import _
662
6daaeffb37d1 The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents: 661
diff changeset
13 from pyntnclick.widgets.text import LabelWidget, TextButton
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
14 from pyntnclick.widgets.base import Container, Button, TranslucentImage
708
9b6d68ba627e Partially hook up file chooser code
Neil Muller <neil@dip.sun.ac.za>
parents: 703
diff changeset
15 from pyntnclick.widgets.filechooser import FileChooser
690
4a933444c99b The return of the rects to the rect drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 689
diff changeset
16 from pyntnclick.tools.utils import draw_rect_image
174
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
17
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
18 DRAW, CYCLE, DELETE, IMAGE = range(4)
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
19
174
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
20
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
21 class RectDrawerError(Exception):
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
22 """Raised when initilaization failed"""
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
23
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
24
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
25 class RectDrawerConstants(pyntnclick.constants.GameConstants):
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
26 debug = True
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
27 menu_width = 200
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
28 menu_button_height = 25
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
29 zoom = 4
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
30 zoom_step = 100
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
31
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
32 constants = RectDrawerConstants()
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
33
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
34
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
35 class ColourButton(Button):
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
36 """Button for selecting a colour"""
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
37
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
38 sel_colour = pygame.color.Color(255, 255, 255)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
39 unsel_colour = pygame.color.Color(128, 128, 128)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
40
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
41 padding = 2
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
42 border = 3
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
43
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
44 def __init__(self, rect, gd, colour, palette, size=None):
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
45 super(ColourButton, self).__init__(rect, gd, size=size)
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
46 self._colour = pygame.color.Color(colour)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
47 self._button_rect = self.rect.inflate(-self.padding, -self.padding)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
48 self._colour_rect = self._button_rect.inflate(-self.border,
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
49 -self.border)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
50 self.selected = False
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
51 self._palette = palette
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
52 self.add_callback('clicked', self.fix_selection)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
53
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
54 def fix_selection(self, ev, widget):
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
55 self._palette.cur_selection.selected = False
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
56 self.selected = True
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
57 self._palette.cur_selection = self
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
58
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
59 def draw(self, surface):
813
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
60 if self.visible:
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
61 self.do_prepare()
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
62 surface.fill(pygame.color.Color(0, 0, 0), self.rect)
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
63 if self.selected:
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
64 surface.fill(self.sel_colour, self._button_rect)
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
65 else:
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
66 surface.fill(self.unsel_colour, self._button_rect)
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
67 surface.fill(self._colour, self._colour_rect)
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
68
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
69
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
70 class AppPalette(Container):
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
71
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
72 but_size = 35
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
73
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
74 colors = [
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
75 '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
76 '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
77 '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
78 '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
79 ]
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
80
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
81 def __init__(self, pos, gd, app_image, size=None):
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
82 self.image = app_image
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
83 super(AppPalette, self).__init__(pos, gd, size=size)
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
84 self.selection = 0
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
85 self.image.rect_color = pygame.color.Color(self.colors[self.selection])
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
86
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
87 x, y = pos
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
88 for num, col in enumerate(self.colors):
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
89 if (x - self.rect.left + self.but_size) >= self.rect.width:
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
90 x = self.rect.left
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
91 y += self.but_size
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
92 button = ColourButton((x, y),
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
93 gd, col, self, size=(self.but_size, self.but_size))
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
94 x += self.but_size
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
95 if num == 0:
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
96 self.cur_selection = button
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
97 button.fix_selection(None, None)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
98 button.add_callback('clicked', self.click_item, num)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
99 self.add(button)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
100 # Fix height
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
101 self.rect.height = y + self.but_size - self.rect.top
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
102
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
103 def click_item(self, ev, widget, number):
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
104 self.selection = number
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
105 self.image.rect_color = pygame.color.Color(self.colors[number])
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
106
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
107
662
6daaeffb37d1 The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents: 661
diff changeset
108 class AppImage(Container):
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
109
181
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
110 rect_thick = 3
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
111 draw_thick = 1
f98bc17f5e67 Add attributes for drawing rects
Neil Muller <neil@dip.sun.ac.za>
parents: 179
diff changeset
112
708
9b6d68ba627e Partially hook up file chooser code
Neil Muller <neil@dip.sun.ac.za>
parents: 703
diff changeset
113 def __init__(self, parent, gd, state, scene, detail):
174
a2d041e0ab83 Make tool use scenes, not images
Neil Muller <neil@dip.sun.ac.za>
parents: 165
diff changeset
114 self.state = state
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
115 super(AppImage, self).__init__((0, 0), gd, size=constants.screen)
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
116 self.mode = DRAW
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
117 self._scene = scene
708
9b6d68ba627e Partially hook up file chooser code
Neil Muller <neil@dip.sun.ac.za>
parents: 703
diff changeset
118 self._parent = parent
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
119 self._detail = detail
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
120 self.rects = []
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
121 self.images = []
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
122 self.start_pos = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
123 self.end_pos = None
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
124 self.rect_color = pygame.color.Color('white')
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
125 self.current_image = None
199
4821c290286d Image loading
Neil Muller <neil@dip.sun.ac.za>
parents: 198
diff changeset
126 self.place_image_menu = None
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
127 self.close_button = LabelWidget((0, 0), gd, _('Close'))
243
0ea4661d134c Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents: 238
diff changeset
128 self.close_button.fg_color = (0, 0, 0)
0ea4661d134c Show close button area in helper
Neil Muller <neil@dip.sun.ac.za>
parents: 238
diff changeset
129 self.close_button.bg_color = (0, 0, 0)
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
130 self.draw_rects = True
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
131 self.draw_things = True
312
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
132 self.draw_thing_rects = True
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
133 self.draw_images = True
504
f3dbe35b6e4b Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents: 503
diff changeset
134 self.trans_images = False
275
d78ce15bccc8 Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 268
diff changeset
135 self.draw_toolbar = True
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
136 self.old_mouse_pos = None
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
137 self.zoom_display = False
510
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
138 self.draw_anim = False
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
139 self.zoom_offset = (600, 600)
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
140 self.clear_display = False
718
ab489f7e87f8 Make filechooser widget presistent, to avoid constantly descending directory trees
Neil Muller <neil@dip.sun.ac.za>
parents: 717
diff changeset
141 self.filechooser = None
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
142 if self._detail:
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
143 w, h = self._scene.get_detail_size()
524
a91cb4bffd5d Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents: 523
diff changeset
144 rect = pygame.rect.Rect(0, 0, w, h)
a91cb4bffd5d Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents: 523
diff changeset
145 self.close_button.rect.midbottom = rect.midbottom
a91cb4bffd5d Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents: 523
diff changeset
146 self.offset = (0, 0)
a91cb4bffd5d Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents: 523
diff changeset
147 else:
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
148 self.offset = (-self._scene.OFFSET[0],
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
149 -self._scene.OFFSET[1])
323
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
150 self.find_existing_intersects()
689
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
151 self.add_callback(MOUSEBUTTONDOWN, self.mouse_down)
690
4a933444c99b The return of the rects to the rect drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 689
diff changeset
152 self.add_callback(MOUSEBUTTONUP, self.mouse_up)
689
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
153 self.add_callback(MOUSEMOTION, self.mouse_move)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
154 self.add_callback(KEYDOWN, self.key_down)
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
155
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
156 def get_mode_name(self):
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
157 """Return the translated mode name"""
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
158 # We do things this way to avoid defining translated strings
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
159 # at import time
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
160 if self.mode == DRAW:
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
161 return _("draw")
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
162 elif self.mode == CYCLE:
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
163 return _("cycle")
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
164 elif self.mode == DELETE:
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
165 return _("delete")
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
166 elif self.mode == IMAGE:
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
167 return _("image")
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
168 else:
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
169 raise RuntimeError("Invalid mode")
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
170
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
171 def _print_thing(self, thing, interact_name):
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
172 """Helper to avoid repeated translations"""
798
b3b73fd2be07 Fix another typo
Neil Muller <neil@dip.sun.ac.za>
parents: 797
diff changeset
173 print (_("Thing %(thing)s Interact %(interact)s") %
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
174 {'thing': thing.name, 'interact': interact_name})
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
175
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
176 def _print_rects(self, rect1, rect2):
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
177 """Helper to avoid repeated translations"""
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
178 print _(" Rects"), rect1, rect2
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
179
323
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
180 def find_existing_intersects(self):
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
181 """Parse the things in the scene for overlaps"""
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
182 scene = self._scene
323
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
183 # Pylint hates this function
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
184 for thing in scene.things.itervalues():
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
185 for interact_name in thing.interacts:
780
0548894408a8 'Fix' rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 748
diff changeset
186 thing._set_interact(interact_name)
323
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
187 if hasattr(thing.rect, 'collidepoint'):
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
188 thing_rects = [thing.rect]
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
189 else:
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
190 thing_rects = thing.rect
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
191 for thing2 in scene.things.itervalues():
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
192 if thing is thing2:
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
193 continue
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
194 for interact2_name in thing2.interacts:
780
0548894408a8 'Fix' rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 748
diff changeset
195 thing2._set_interact(interact2_name)
323
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
196 if hasattr(thing2.rect, 'collidepoint'):
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
197 thing2_rects = [thing2.rect]
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
198 else:
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
199 thing2_rects = thing2.rect
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
200 for my_rect in thing_rects:
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
201 for other_rect in thing2_rects:
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
202 if my_rect.colliderect(other_rect):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
203 print _('Existing Intersecting rects')
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
204 self._print_thing(thing, interact_name)
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
205 self._print_thing(thing2, interact2_name)
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
206 self._print_rects(my_rect, other_rect)
323
0630a37cb371 Print existing intersection in scene on startup
Neil Muller <neil@dip.sun.ac.za>
parents: 321
diff changeset
207 print
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
208
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
209 def find_intersecting_rects(self, d):
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
210 """Find if any rect collections intersect"""
747
960af9761fb0 apostrophe abuse
Stefano Rivera <stefano@rivera.za.net>
parents: 737
diff changeset
211 # I loath N^X brute search algorithms, but whatever, hey
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
212 scene = self._scene
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
213 for (num, col) in enumerate(d):
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
214 rect_list = d[col]
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
215 for thing in scene.things.itervalues():
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
216 for interact_name in thing.interacts:
780
0548894408a8 'Fix' rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 748
diff changeset
217 thing._set_interact(interact_name)
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
218 if hasattr(thing.rect, 'collidepoint'):
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
219 thing_rects = [thing.rect]
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
220 else:
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
221 thing_rects = thing.rect
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
222 for other_rect in thing_rects:
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
223 for my_rect in rect_list:
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
224 if my_rect.colliderect(other_rect):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
225 print _('Intersecting rects')
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
226 print _(" Object %s") % num
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
227 self._print_thing(thing, interact_name)
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
228 self._print_rects(my_rect, other_rect)
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
229 if thing.INITIAL:
780
0548894408a8 'Fix' rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 748
diff changeset
230 thing._set_interact(thing.INITIAL)
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
231 print
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
232 for (num2, col2) in enumerate(d):
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
233 if num2 == num:
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
234 continue
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
235 other_list = d[col2]
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
236 for my_rect in rect_list:
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
237 for other_rect in other_list:
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
238 if my_rect.colliderect(other_rect):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
239 print _('Intersecting rects'),
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
240 print (_(' Object %(object1)s and %(object2)s') %
797
Stefano Rivera <stefano@rivera.za.net>
parents: 794
diff changeset
241 {'object1': num, 'object2': num2})
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
242 self._print_rects(my_rect, other_rect)
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
243 print
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
244 print
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
245
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
246 def toggle_things(self, ev, widget):
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
247 self.draw_things = not self.draw_things
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
248
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
249 def toggle_thing_rects(self, ev, widget):
312
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
250 self.draw_thing_rects = not self.draw_thing_rects
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
251 scene = self._scene
312
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
252 for thing in scene.things.itervalues():
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
253 if not self.draw_thing_rects:
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
254 if not hasattr(thing, 'old_colour'):
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
255 thing.old_colour = thing._interact_hilight_color
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
256 thing._interact_hilight_color = None
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
257 else:
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
258 thing._interact_hilight_color = thing.old_colour
a0d66c0f5a89 Add toggle thing rects option
Neil Muller <neil@dip.sun.ac.za>
parents: 286
diff changeset
259
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
260 def toggle_images(self, ev, widget):
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
261 self.draw_images = not self.draw_images
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
262 for image in self.images:
813
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
263 image.set_visible(self.draw_images)
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
264 if self.current_image:
813
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
265 self.current_image.set_visible(self.draw_images)
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
266 self.invalidate()
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
267
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
268 def toggle_trans_images(self, ev, widget):
504
f3dbe35b6e4b Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents: 503
diff changeset
269 self.trans_images = not self.trans_images
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
270 for image in self.images:
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
271 image.translucent = self.trans_images
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
272 if self.current_image:
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
273 self.current_image.translucent = self.trans_images
504
f3dbe35b6e4b Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents: 503
diff changeset
274 self.invalidate()
f3dbe35b6e4b Add 'translucent image mode'
Neil Muller <neil@dip.sun.ac.za>
parents: 503
diff changeset
275
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
276 def toggle_rects(self, ev, widget):
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
277 self.draw_rects = not self.draw_rects
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
278
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
279 def toggle_toolbar(self, ev, widget):
275
d78ce15bccc8 Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 268
diff changeset
280 self.draw_toolbar = not self.draw_toolbar
d78ce15bccc8 Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 268
diff changeset
281
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
282 def toggle_zoom(self, ev, widget):
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
283 self.zoom_display = not self.zoom_display
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
284 self.invalidate()
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
285
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
286 def toggle_anim(self, ev, widget):
510
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
287 self.draw_anim = not self.draw_anim
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
288
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
289 def draw_mode(self, ev, widget):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
290 self.mode = DRAW
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
291
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
292 def del_mode(self, ev, widget):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
293 self.mode = DELETE
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
294 self.start_pos = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
295 self.end_pos = None
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
296
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
297 def invalidate(self):
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
298 self.clear_display = True
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
299
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
300 def draw(self, surface):
813
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
301 if not self.visible:
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
302 return
737
69a0349dce8e Fix rect_drawer to call prepare
Neil Muller <neil@mcp.home.test>
parents: 719
diff changeset
303 self.do_prepare()
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
304 if self.clear_display:
812
2dd400a7c16d Only clear working around to prevent toolbar flickering
Neil Muller <neil@dip.sun.ac.za>
parents: 811
diff changeset
305 surface.fill(pygame.color.Color(0, 0, 0),
813
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
306 pygame.Rect(0, 0, constants.screen[0],
3a875256f795 better visible handling
Neil Muller <neil@dip.sun.ac.za>
parents: 812
diff changeset
307 constants.screen[1]))
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
308 self.clear_display = False
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
309
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
310 if self.zoom_display:
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
311 base_surface = surface.copy()
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
312 self.do_unzoomed_draw(base_surface)
537
5b9f371c2bb8 PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents: 524
diff changeset
313 zoomed = pygame.transform.scale(base_surface,
703
cbf6d4573785 Fix bug in zooming code
Neil Muller <neil@dip.sun.ac.za>
parents: 701
diff changeset
314 (constants.zoom * base_surface.get_width(),
cbf6d4573785 Fix bug in zooming code
Neil Muller <neil@dip.sun.ac.za>
parents: 701
diff changeset
315 constants.zoom * base_surface.get_height()))
537
5b9f371c2bb8 PEP-8 cleanup of tools
Stefano Rivera <stefano@rivera.za.net>
parents: 524
diff changeset
316 area = pygame.rect.Rect(self.zoom_offset[0], self.zoom_offset[1],
811
a0fd258cd5d7 Correctly crop zoomed image
Neil Muller <neil@dip.sun.ac.za>
parents: 809
diff changeset
317 constants.screen[0], constants.screen[1])
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
318 surface.blit(zoomed, (0, 0), area)
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
319 else:
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
320 self.do_unzoomed_draw(surface)
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
321
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
322 def do_unzoomed_draw(self, surface):
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
323 if self.draw_things:
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
324 self._scene.draw(surface)
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
325 else:
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
326 self._scene.draw_background(surface)
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
327 if self._detail:
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
328 # We duplicate draw logic here, so we zoom the close
524
a91cb4bffd5d Make close button helper in rect_drawer zoom correctly
Neil Muller <neil@dip.sun.ac.za>
parents: 523
diff changeset
329 # button correctly
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
330 self.close_button.draw(surface)
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
331 if self.mode == DRAW and self.start_pos and self.draw_rects:
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
332 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
333 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
334 self.end_pos[1] - self.start_pos[1])
321
e5f3a97ee812 Fix rect drawing bug
Neil Muller <neil@dip.sun.ac.za>
parents: 320
diff changeset
335 rect.normalize()
690
4a933444c99b The return of the rects to the rect drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 689
diff changeset
336 draw_rect_image(surface, self.rect_color, rect, self.draw_thick)
268
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
337 if self.draw_rects:
e4ea9def56b2 Add some toggle options to helper script
Neil Muller <neil@dip.sun.ac.za>
parents: 250
diff changeset
338 for (col, rect) in self.rects:
690
4a933444c99b The return of the rects to the rect drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 689
diff changeset
339 draw_rect_image(surface, col, rect, self.rect_thick)
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
340 for image in self.images:
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
341 image.draw(surface)
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
342 if self.current_image and self.mode == IMAGE:
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
343 self.current_image.draw(surface)
275
d78ce15bccc8 Crew quarters background and toolbar on the rect tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 268
diff changeset
344 if self.draw_toolbar:
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
345 tb_surf = surface.subsurface(0, constants.screen[1]
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
346 - constants.button_size,
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
347 constants.screen[0],
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
348 constants.button_size).convert_alpha()
276
75f4ee46ac58 Better (and fixed) rect tool with toolbar overlay.
Jeremy Thurgood <firxen@gmail.com>
parents: 275
diff changeset
349 tb_surf.fill(pygame.color.Color(127, 0, 0, 191))
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
350 surface.blit(tb_surf, (0, constants.screen[1]
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
351 - constants.button_size))
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
352
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
353 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
354 d = {}
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
355 for col, rect in self.rects:
213
20998c650ce1 Fixed rect_drawer tool and adjusted JIM message background.
Jeremy Thurgood <firxen@gmail.com>
parents: 200
diff changeset
356 col = (col.r, col.g, col.b)
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
357 d.setdefault(col, [])
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
358 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
359 return d
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
360
689
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
361 def print_objs(self, ev, widget):
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
362 d = self._make_dict()
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
363 self.find_intersecting_rects(d)
165
9b3bba5e65f3 add some features to rect helper. now vaguely useful
Neil Muller <neil@dip.sun.ac.za>
parents: 162
diff changeset
364 for (num, col) in enumerate(d):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
365 print _('Rect %d : ') % num
279
c67a4a4d78f6 Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 276
diff changeset
366 for rect in d[col]:
c67a4a4d78f6 Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 276
diff changeset
367 r = rect.move(self.offset)
179
39f75faf16cb Add trailing , for copy-n-paste
Neil Muller <neil@dip.sun.ac.za>
parents: 174
diff changeset
368 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
369 print
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
370 for i, image in enumerate(self.images):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
371 print _('Image %d') % i
279
c67a4a4d78f6 Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 276
diff changeset
372 rect = image.rect
c67a4a4d78f6 Compensate for offset in rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 276
diff changeset
373 r = rect.move(self.offset)
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
374 print ' (%d, %d, %d, %d),' % (r.x, r.y, r.w, r.h)
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
375 print
320
c295b06b27f8 Warn about intersecting existing things and other drawn rects
Neil Muller <neil@dip.sun.ac.za>
parents: 312
diff changeset
376 print
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
377
700
22e1893152c5 Comment out crash button
Neil Muller <neil@dip.sun.ac.za>
parents: 699
diff changeset
378 def image_load(self, ev, widget):
718
ab489f7e87f8 Make filechooser widget presistent, to avoid constantly descending directory trees
Neil Muller <neil@dip.sun.ac.za>
parents: 717
diff changeset
379 if self.filechooser is None:
806
b39f01012a74 Instantiate the file chooser with a (non-existent) size
Stefano Rivera <stefano@rivera.za.net>
parents: 805
diff changeset
380 self.filechooser = FileChooser((0, 0), self.gd, None, os.curdir,
718
ab489f7e87f8 Make filechooser widget presistent, to avoid constantly descending directory trees
Neil Muller <neil@dip.sun.ac.za>
parents: 717
diff changeset
381 self.do_load_image)
ab489f7e87f8 Make filechooser widget presistent, to avoid constantly descending directory trees
Neil Muller <neil@dip.sun.ac.za>
parents: 717
diff changeset
382 else:
ab489f7e87f8 Make filechooser widget presistent, to avoid constantly descending directory trees
Neil Muller <neil@dip.sun.ac.za>
parents: 717
diff changeset
383 self.filechooser.refresh()
ab489f7e87f8 Make filechooser widget presistent, to avoid constantly descending directory trees
Neil Muller <neil@dip.sun.ac.za>
parents: 717
diff changeset
384 self.invalidate()
719
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
385 self._parent.paused = True
718
ab489f7e87f8 Make filechooser widget presistent, to avoid constantly descending directory trees
Neil Muller <neil@dip.sun.ac.za>
parents: 717
diff changeset
386 self._parent.add(self.filechooser)
712
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
387
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
388 def do_load_image(self, filename):
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
389 try:
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
390 self.current_image = TranslucentImage((0, 0), self.gd,
712
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
391 pygame.image.load(filename))
717
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
392 if not self.draw_images:
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
393 # Selecting an image makes image visible
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
394 self.toggle_images(None, None)
3b2d1adca59c Pull a bunch of draw logic out of rect_drawer and over to the widgets
Neil Muller <neil@dip.sun.ac.za>
parents: 715
diff changeset
395 self.current_image.translucent = self.trans_images
712
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
396 self.place_image_menu.enabled = True
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
397 self.current_image.rect = self.current_image.rect.move(
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
398 constants.screen[0] + constants.menu_width,
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
399 constants.screen[1])
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
400 self.image_mode(None, None)
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
401 except pygame.error, e:
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
402 print 'Unable to load image %s (reason %s)' % (filename, e)
198
e73d78d6dd83 Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents: 197
diff changeset
403
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
404 def image_mode(self, ev, widget):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
405 self.mode = IMAGE
198
e73d78d6dd83 Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents: 197
diff changeset
406 self.start_pos = None
e73d78d6dd83 Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents: 197
diff changeset
407 self.end_pos = None
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
408 # So we do the right thing for off screen images
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
409 self.old_mouse_pos = None
198
e73d78d6dd83 Stubs for ftuture functionality
Neil Muller <neil@dip.sun.ac.za>
parents: 197
diff changeset
410
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
411 def cycle_mode(self, ev, widget):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
412 self.mode = CYCLE
510
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
413
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
414 def _conv_pos(self, mouse_pos):
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
415 if self.zoom_display:
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
416 pos = ((mouse_pos[0] + self.zoom_offset[0]) / constants.zoom,
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
417 (mouse_pos[1] + self.zoom_offset[1]) / constants.zoom)
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
418 else:
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
419 pos = mouse_pos
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
420 return pos
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
421
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
422 def _check_limits(self, offset):
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
423 if offset[0] < 0:
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
424 offset[0] = 0
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
425 if offset[1] < 0:
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
426 offset[1] = 0
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
427 width, height = constants.screen
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
428 if offset[0] > constants.zoom * width - width:
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
429 offset[0] = constants.zoom * width - width
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
430 if offset[1] > constants.zoom * height - height:
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
431 offset[1] = constants.zoom * height - height
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
432
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
433 def _make_zoom_offset(self, pos):
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
434 zoom_pos = (pos[0] * constants.zoom, pos[1] * constants.zoom)
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
435 offset = [zoom_pos[0] - constants.screen[0] / 2,
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
436 zoom_pos[1] - constants.screen[1] / 2]
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
437 self._check_limits(offset)
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
438 self.zoom_offset = tuple(offset)
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
439
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
440 def _move_zoom(self, x, y):
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
441 offset = list(self.zoom_offset)
576
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
442 offset[0] += constants.zoom_step * x
1b1ab71535bd Classify constants, which involves a whole bunch of XXX comments
Stefano Rivera <stefano@rivera.za.net>
parents: 550
diff changeset
443 offset[1] += constants.zoom_step * y
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
444 self._check_limits(offset)
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
445 self.zoom_offset = tuple(offset)
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
446
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
447 def key_down(self, ev, widget):
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
448 if self.mode == IMAGE and self.current_image:
482
2bef605a0ef2 Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents: 323
diff changeset
449 # Move the image by 1 pixel
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
450 cur_pos = self.current_image.rect.center
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
451 if ev.key == K_LEFT:
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
452 self.current_image.rect.center = (cur_pos[0] - 1, cur_pos[1])
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
453 elif ev.key == K_RIGHT:
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
454 self.current_image.rect.center = (cur_pos[0] + 1, cur_pos[1])
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
455 elif ev.key == K_UP:
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
456 self.current_image.rect.center = (cur_pos[0], cur_pos[1] - 1)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
457 elif ev.key == K_DOWN:
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
458 self.current_image.rect.center = (cur_pos[0], cur_pos[1] + 1)
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
459 elif self.zoom_display:
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
460 if ev.key == K_LEFT:
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
461 self._move_zoom(-1, 0)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
462 elif ev.key == K_RIGHT:
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
463 self._move_zoom(1, 0)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
464 elif ev.key == K_UP:
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
465 self._move_zoom(0, -1)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
466 elif ev.key == K_DOWN:
507
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
467 self._move_zoom(0, 1)
caec319a4ae3 Add support for moving zoomed region
Neil Muller <neil@dip.sun.ac.za>
parents: 506
diff changeset
468
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
469 if ev.key == K_o:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
470 self.toggle_trans_images(None, None)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
471 elif ev.key == K_t:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
472 self.toggle_things(None, None)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
473 elif ev.key == K_r:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
474 self.toggle_thing_rects(None, None)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
475 elif ev.key == K_i:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
476 self.toggle_images(None, None)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
477 elif ev.key == K_d:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
478 self.toggle_rects(None, None)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
479 elif ev.key == K_b:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
480 self.toggle_toolbar(None, None)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
481 elif ev.key == K_z:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
482 self.toggle_zoom(None, None)
699
8edd7b52423a Re-enable keys
Neil Muller <neil@dip.sun.ac.za>
parents: 698
diff changeset
483 elif ev.key == K_a:
664
d1c1253fcd77 Now with somewhat fewer crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 663
diff changeset
484 self.toggle_anim(None, None)
482
2bef605a0ef2 Refactor to add support for key movement of images
Neil Muller <neil@dip.sun.ac.za>
parents: 323
diff changeset
485
689
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
486 def mouse_down(self, ev, widget):
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
487 pos = self._conv_pos(ev.pos)
719
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
488 if self._parent.paused:
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
489 # Ignore this if the filechooser is active
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
490 return False
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
491 if self.mode == DELETE:
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
492 cand = None
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
493 # Images are drawn above rectangles, so search those first
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
494 for image in self.images:
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
495 if image.rect.collidepoint(pos):
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
496 cand = image
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
497 break
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
498 if cand:
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
499 self.images.remove(cand)
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
500 self.invalidate()
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
501 return
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
502 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
503 if rect.collidepoint(pos):
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
504 cand = (col, rect)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
505 break
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
506 if cand:
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
507 self.rects.remove(cand)
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
508 self.invalidate()
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
509 elif self.mode == CYCLE:
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
510 scene = self._scene
510
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
511 cand = None
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
512 for thing in scene.things.itervalues():
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
513 if thing.contains(pos):
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
514 cand = thing
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
515 break
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
516 if cand:
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
517 # Find current interacts in this thing
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
518 cur_interact = cand.current_interact
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
519 j = cand.interacts.values().index(cur_interact)
538
d1b86d5849a0 More pep8 cleanups
Neil Muller <neil@dip.sun.ac.za>
parents: 537
diff changeset
520 if j + 1 < len(cand.interacts):
d1b86d5849a0 More pep8 cleanups
Neil Muller <neil@dip.sun.ac.za>
parents: 537
diff changeset
521 next_name = cand.interacts.keys()[j + 1]
510
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
522 else:
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
523 next_name = cand.interacts.keys()[0]
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
524 if cand.interacts[next_name] != cur_interact:
780
0548894408a8 'Fix' rect_drawer
Neil Muller <neil@dip.sun.ac.za>
parents: 748
diff changeset
525 cand._set_interact(next_name)
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
526 elif self.mode == DRAW:
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
527 self.start_pos = pos
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
528 self.end_pos = pos
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
529 elif self.mode == IMAGE:
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
530 if self.current_image:
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
531 self.images.append(self.current_image)
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
532 self.current_image = None
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
533 self.old_mouse_pos = None
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
534 self.invalidate()
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
535 else:
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
536 cand = None
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
537 for image in self.images:
713
62f4f948ff01 Fix bug with zooms and images
Neil Muller <neil@dip.sun.ac.za>
parents: 712
diff changeset
538 if image.rect.collidepoint(pos):
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
539 cand = image
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
540 break
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
541 if cand:
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
542 self.images.remove(cand)
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
543 self.current_image = cand
502
f53aaba58273 Use relative motion for images to remove jumping when combining key & mouse
Neil Muller <neil@dip.sun.ac.za>
parents: 482
diff changeset
544 # We want to move relative to the current mouse pos, so
506
d54667b2c44d Partial zoom support
Neil Muller <neil@dip.sun.ac.za>
parents: 505
diff changeset
545 self.old_mouse_pos = pos
200
7bedca2376f5 Image placement
Neil Muller <neil@dip.sun.ac.za>
parents: 199
diff changeset
546 self.invalidate()
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
547
689
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
548 def mouse_up(self, ev, widget):
719
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
549 if self._parent.paused:
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
550 return False
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
551 if self.mode == DRAW:
737
69a0349dce8e Fix rect_drawer to call prepare
Neil Muller <neil@mcp.home.test>
parents: 719
diff changeset
552 if self.start_pos is None:
69a0349dce8e Fix rect_drawer to call prepare
Neil Muller <neil@mcp.home.test>
parents: 719
diff changeset
553 # We've come here not via a drawing situation, so bail
69a0349dce8e Fix rect_drawer to call prepare
Neil Muller <neil@mcp.home.test>
parents: 719
diff changeset
554 return False
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
555 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
556 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
557 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
558 rect.normalize()
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
559 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
560 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
561
689
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
562 def mouse_move(self, ev, widget):
712
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
563 # We're only interested in this if left mouse button is down or we've
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
564 # got and image
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
565 if self.mode == IMAGE and self.current_image:
712
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
566 pos = self._conv_pos(ev.pos)
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
567 if self.old_mouse_pos:
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
568 delta = (pos[0] - self.old_mouse_pos[0],
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
569 pos[1] - self.old_mouse_pos[1])
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
570 self.current_image.rect.center = (
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
571 self.current_image.rect.center[0] + delta[0],
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
572 self.current_image.rect.center[1] + delta[1])
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
573 else:
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
574 self.current_image.rect.center = pos
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
575 self.invalidate()
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
576 self.old_mouse_pos = pos
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
577 return True
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
578 elif ev.buttons[0] == 1 and self.mode == DRAW:
689
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
579 self.end_pos = self._conv_pos(ev.pos)
929b63589c96 Further fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 686
diff changeset
580 return True
712
f33dd2093f77 Hook up image drawing code again
Neil Muller <neil@dip.sun.ac.za>
parents: 708
diff changeset
581 return False
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
582
510
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
583 def animate(self):
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
584 if self.draw_anim:
715
4716709b28c1 Hook up animation in rect_drawer again
Neil Muller <neil@dip.sun.ac.za>
parents: 713
diff changeset
585 self._scene.animate()
510
d274cc414178 Add show animate & cycle interact options
Neil Muller <neil@dip.sun.ac.za>
parents: 509
diff changeset
586
509
616334ea5e8c Add mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 508
diff changeset
587
662
6daaeffb37d1 The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents: 661
diff changeset
588 class ModeLabel(LabelWidget):
509
616334ea5e8c Add mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 508
diff changeset
589
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
590 def __init__(self, pos, gd, app_image, size=None):
509
616334ea5e8c Add mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 508
diff changeset
591 self.app_image = app_image
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
592 super(ModeLabel, self).__init__(pos,
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
593 gd, _('Mode : '), fontname=constants.bold_font,
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
594 fontsize=15, color=pygame.color.Color(128, 0, 255),
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
595 size=size)
748
763ff5a9ee42 Work around multiple prepare calling bug
Neil Muller <neil@dip.sun.ac.za>
parents: 747
diff changeset
596 self.start_rect = self.rect.copy()
509
616334ea5e8c Add mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 508
diff changeset
597
698
1e54c6966666 Mode label updates again
Neil Muller <neil@dip.sun.ac.za>
parents: 697
diff changeset
598 def draw(self, surface):
737
69a0349dce8e Fix rect_drawer to call prepare
Neil Muller <neil@mcp.home.test>
parents: 719
diff changeset
599 self.do_prepare()
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
600 text = _('Mode : %s') % self.app_image.get_mode_name()
698
1e54c6966666 Mode label updates again
Neil Muller <neil@dip.sun.ac.za>
parents: 697
diff changeset
601 if self.text != text:
1e54c6966666 Mode label updates again
Neil Muller <neil@dip.sun.ac.za>
parents: 697
diff changeset
602 self.text = text
748
763ff5a9ee42 Work around multiple prepare calling bug
Neil Muller <neil@dip.sun.ac.za>
parents: 747
diff changeset
603 self.is_prepared = False
763ff5a9ee42 Work around multiple prepare calling bug
Neil Muller <neil@dip.sun.ac.za>
parents: 747
diff changeset
604 self.rect = self.start_rect.copy()
763ff5a9ee42 Work around multiple prepare calling bug
Neil Muller <neil@dip.sun.ac.za>
parents: 747
diff changeset
605 self.do_prepare()
698
1e54c6966666 Mode label updates again
Neil Muller <neil@dip.sun.ac.za>
parents: 697
diff changeset
606 super(ModeLabel, self).draw(surface)
509
616334ea5e8c Add mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 508
diff changeset
607
616334ea5e8c Add mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 508
diff changeset
608
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
609 def make_button(text, gd, action, ypos):
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
610 rect = pygame.rect.Rect(0, 0, constants.menu_width,
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
611 constants.menu_button_height)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
612 rect.move_ip(805, ypos)
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
613 button = TextButton(rect.topleft, gd, text, size=(constants.menu_width,
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
614 constants.menu_button_height),
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
615 fontname=constants.font, fontsize=12,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
616 color=pygame.color.Color(255, 255, 0), border=1, padding=3)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
617 button.add_callback('clicked', action)
197
640044d7ddda Tweak layout
Neil Muller <neil@dip.sun.ac.za>
parents: 196
diff changeset
618 return button
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
619
509
616334ea5e8c Add mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 508
diff changeset
620
648
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
621 class RectApp(Container):
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
622 """The actual rect drawer main app"""
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
623 def __init__(self, rect, gd, detail):
648
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
624 super(RectApp, self).__init__(rect, gd)
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
625
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
626 try:
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
627 state = gd.initial_state()
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
628 scene = state.scenes[gd._initial_scene]
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
629 except KeyError:
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
630 raise RectDrawerError(_('Invalid scene: %s') % gd._initial_scene)
686
48f68ae7d454 Throw out more old stuff. Fix animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 685
diff changeset
631 gd.sound.disable_sound() # No sound here
48f68ae7d454 Throw out more old stuff. Fix animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 685
diff changeset
632
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
633 if detail:
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
634 try:
697
4bf13af26d6a Fix detail loading. Clear display on state changes
Neil Muller <neil@dip.sun.ac.za>
parents: 691
diff changeset
635 scene = state.detail_views[detail]
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
636 except KeyError:
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
637 raise RectDrawerError(_('Invalid detail: %s') % detail)
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
638
719
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
639 self.paused = False
3aa6163f0775 Correctly pause rect drawer while file chooser is active (avoid spurious empty rectangle)
Neil Muller <neil@dip.sun.ac.za>
parents: 718
diff changeset
640
708
9b6d68ba627e Partially hook up file chooser code
Neil Muller <neil@dip.sun.ac.za>
parents: 703
diff changeset
641 self.image = AppImage(self, gd, state, scene, detail is not None)
662
6daaeffb37d1 The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents: 661
diff changeset
642 self.add(self.image)
809
9968778115ce Better positioning of the mode label
Neil Muller <neil@dip.sun.ac.za>
parents: 806
diff changeset
643 mode_label = ModeLabel((805, 0), self.gd, self.image, size=(200, 50))
662
6daaeffb37d1 The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents: 661
diff changeset
644 self.add(mode_label)
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
645 y = mode_label.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
646 draw = make_button(_('Draw Rect'), gd, self.image.draw_mode, y)
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
647 self.add(draw)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
648 y += draw.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
649 load_image = make_button(_("Load image"), gd, self.image.image_load, y)
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
650 self.add(load_image)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
651 y += load_image.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
652 add_image = make_button(_("Place/Move images"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
653 self.image.image_mode, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
654 add_image.enabled = False
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
655 self.add(add_image)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
656 self.image.place_image_menu = add_image
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
657 y += add_image.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
658 cycle = make_button(_("Cycle interacts"), gd, self.image.cycle_mode, y)
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
659 self.add(cycle)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
660 y += cycle.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
661 delete = make_button(_("Delete Objects"), gd, self.image.del_mode, y)
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
662 self.add(delete)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
663 y += delete.rect.height
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
664 palette = AppPalette((810, y), gd, self.image, size=(200, 0))
701
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
665 self.add(palette)
9c920deb28c2 Recreate the palette selection
Neil Muller <neil@dip.sun.ac.za>
parents: 700
diff changeset
666 y += palette.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
667 print_rects = make_button(_("Print objects"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
668 self.image.print_objs, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
669 self.add(print_rects)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
670 y += print_rects.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
671 toggle_things = make_button(_("Show Things (t)"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
672 self.image.toggle_things, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
673 self.add(toggle_things)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
674 y += toggle_things.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
675 toggle_thing_rects = make_button(_("Show Thing Rects (r)"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
676 self.image.toggle_thing_rects, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
677 self.add(toggle_thing_rects)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
678 y += toggle_thing_rects.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
679 toggle_images = make_button(_("Show Images (i)"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
680 self.image.toggle_images, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
681 self.add(toggle_images)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
682 y += toggle_images.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
683 trans_images = make_button(_("Opaque Images (o)"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
684 self.image.toggle_trans_images, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
685 self.add(trans_images)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
686 y += trans_images.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
687 toggle_rects = make_button(_("Show Drawn Rects (d)"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
688 self.image.toggle_rects, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
689 self.add(toggle_rects)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
690 y += toggle_rects.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
691 toggle_toolbar = make_button(_("Show Toolbar (b)"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
692 self.image.toggle_toolbar, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
693 self.add(toggle_toolbar)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
694 y += toggle_toolbar.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
695 toggle_anim = make_button(_("Show Animations (a)"), gd,
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
696 self.image.toggle_anim, y)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
697 self.add(toggle_anim)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
698 y += toggle_anim.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
699 toggle_zoom = make_button(_("Zoom (z)"), gd,
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
700 self.image.toggle_zoom, y)
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
701 self.add(toggle_zoom)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
702 y += toggle_zoom.rect.height
794
6b89fa491b70 Setup for translating pyntnclick tools
Neil Muller <neil@dip.sun.ac.za>
parents: 780
diff changeset
703 quit_but = make_button(_("Quit"), gd, self.quit, 570)
663
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
704 self.add(quit_but)
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
705
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
706 def quit(self, ev, widget):
b67fdd4a152d Readd buttons to rect_drawer - now with extra crashy bits
Neil Muller <neil@dip.sun.ac.za>
parents: 662
diff changeset
707 pygame.event.post(pygame.event.Event(QUIT))
662
6daaeffb37d1 The rect drawer becomes less black
Neil Muller <neil@dip.sun.ac.za>
parents: 661
diff changeset
708
686
48f68ae7d454 Throw out more old stuff. Fix animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 685
diff changeset
709 def animate(self):
48f68ae7d454 Throw out more old stuff. Fix animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 685
diff changeset
710 self.image.animate()
48f68ae7d454 Throw out more old stuff. Fix animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 685
diff changeset
711
648
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
712
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
713 class RectEngine(object):
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
714 """Engine for the rect drawer."""
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
715
691
60bf20849231 Fix detail loading in rect_drawer. Improve error reporting when loading fails
Neil Muller <neil@dip.sun.ac.za>
parents: 690
diff changeset
716 def __init__(self, gd, detail):
648
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
717 self.state = None
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
718 self._gd = gd
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
719 rect = pygame.display.get_surface().get_rect()
805
e11e092cc58e Fix rect_drawer yet again
Neil Muller <neil@dip.sun.ac.za>
parents: 798
diff changeset
720 self.app = RectApp(rect.topleft, self._gd, detail)
648
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
721
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
722 def run(self):
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
723 """App loop"""
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
724 clock = pygame.time.Clock()
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
725 while True:
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
726 events = pygame.event.get()
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
727 for ev in events:
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
728 if ev.type == QUIT:
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
729 return
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
730 else:
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
731 self.app.event(ev)
686
48f68ae7d454 Throw out more old stuff. Fix animation support
Neil Muller <neil@dip.sun.ac.za>
parents: 685
diff changeset
732 self.app.animate()
648
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
733 surface = pygame.display.get_surface()
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
734 self.app.draw(surface)
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
735 pygame.display.flip()
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
736 clock.tick(self._gd.constants.frame_rate)
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
737
b2c2b6f56291 baby steps to fixing rect_drawer - it has now progressed to being completely useless
Neil Muller <neil@dip.sun.ac.za>
parents: 636
diff changeset
738
589
ebc48b397fd5 Turn rect_drawer into a command line option
Neil Muller <neil@dip.sun.ac.za>
parents: 576
diff changeset
739 def make_rect_display():
162
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
740 pygame.display.init()
225e3a4b1e85 Start of a tool to help construct interact rectangles
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
741 pygame.font.init()
661
5dc866e1d71d Misc pep8 and pyflakes fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 648
diff changeset
742 pygame.display.set_mode((constants.screen[0]
5dc866e1d71d Misc pep8 and pyflakes fixes
Neil Muller <neil@dip.sun.ac.za>
parents: 648
diff changeset
743 + constants.menu_width, constants.screen[1]))