comparison pyntnclick/gamescreen.py @ 726:efa58c92b304 pyntnclick

Move prepare out of __init__ and into everywhere else
author Neil Muller <neil@dip.sun.ac.za>
date Tue, 15 Jan 2013 22:44:50 +0200
parents 38f537b0ee82
children ef4bda7d623d
comparison
equal deleted inserted replaced
725:65e9b5c40233 726:efa58c92b304
11 from pyntnclick.engine import Screen 11 from pyntnclick.engine import Screen
12 from pyntnclick.widgets.base import ( 12 from pyntnclick.widgets.base import (
13 Container, ModalStackContainer, ModalWrapper) 13 Container, ModalStackContainer, ModalWrapper)
14 from pyntnclick.widgets.text import TextButton, WrappedTextLabel 14 from pyntnclick.widgets.text import TextButton, WrappedTextLabel
15 from pyntnclick.widgets.imagebutton import ImageButtonWidget 15 from pyntnclick.widgets.imagebutton import ImageButtonWidget
16
17 16
18 17
19 class InventorySlot(ImageButtonWidget): 18 class InventorySlot(ImageButtonWidget):
20 SELECTED_COLOR = Color("yellow") 19 SELECTED_COLOR = Color("yellow")
21 SELECTED_WIDTH = 2 20 SELECTED_WIDTH = 2
146 self.add_callback(MOUSEBUTTONDOWN, self.mouse_down) 145 self.add_callback(MOUSEBUTTONDOWN, self.mouse_down)
147 self.add_callback(MOUSEMOTION, self.mouse_move) 146 self.add_callback(MOUSEMOTION, self.mouse_move)
148 self.is_detail = is_detail 147 self.is_detail = is_detail
149 if is_detail: 148 if is_detail:
150 self.close_button = TextButton((0, 0), self.gd, "Close") 149 self.close_button = TextButton((0, 0), self.gd, "Close")
150 self.close_button.do_prepare()
151 self.close_button.rect.midbottom = self.rect.midbottom 151 self.close_button.rect.midbottom = self.rect.midbottom
152 self.close_button.add_callback('clicked', self.close) 152 self.close_button.add_callback('clicked', self.close)
153 self.add(self.close_button) 153 self.add(self.close_button)
154 154
155 def draw(self, surface): 155 def draw(self, surface):
220 rect = (self.left, self.rect.top) 220 rect = (self.left, self.rect.top)
221 if width is not None: 221 if width is not None:
222 rect = Rect(rect, (width, self.rect.height)) 222 rect = Rect(rect, (width, self.rect.height))
223 tool = cls(rect, *args, **kw) 223 tool = cls(rect, *args, **kw)
224 self.add(tool) 224 self.add(tool)
225 tool.do_prepare()
225 self.left += tool.rect.width 226 self.left += tool.rect.width
226 return tool 227 return tool
227 228
228 def draw(self, surface): 229 def draw(self, surface):
229 bg = Surface(self.rect.size) 230 bg = Surface(self.rect.size)
337 338
338 def show_message(self, message): 339 def show_message(self, message):
339 rect = Rect((0, 0), (1, 1)) 340 rect = Rect((0, 0), (1, 1))
340 max_width = self.gd.constants.screen[0] - 100 341 max_width = self.gd.constants.screen[0] - 100
341 widget = WrappedTextLabel(rect, self.gd, message, max_width=max_width) 342 widget = WrappedTextLabel(rect, self.gd, message, max_width=max_width)
343 widget.do_prepare()
342 widget.rect.center = self.container.rect.center 344 widget.rect.center = self.container.rect.center
343 self.queue_widget(widget) 345 self.queue_widget(widget)
344 346
345 def handle_result(self, resultset): 347 def handle_result(self, resultset):
346 """Handle dealing with result or result sequences""" 348 """Handle dealing with result or result sequences"""