def clear(self): for item in self.items: item.on_destruction() Renderer.del_widget(item) WidgetHandler.del_widget(item) self.items.clear() self.h = 0
def __init__(self, x, y, texto, action=None): self.f = font.SysFont('Verdana', 16) imagen = self.crear(texto) rect = imagen.get_rect(topleft=(x, y)) super().__init__(imagen, rect) Renderer.add_widget(self, 1) WidgetHandler.add_widget(self, 1) self.action = action
def __init__(self, name, text, x, y): self.x, self.y = x, y self.name = name self.f = font.SysFont('Verdana', 16) render = self.f.render(text, 1, (0, 0, 0)) rect = render.get_rect(topleft=(x, y)) EventHandler.register(self.show, 'show_text') super().__init__(render, rect) Renderer.add_widget(self, 1) WidgetHandler.add_widget(self, 1)
def __init__(self, x, y): self.f = font.SysFont('Verdana', 16) self.empty_f = font.SysFont('Verdana', 16, italic=True) self.w, self.h = 310, 23 image = Surface((self.w, self.h)) image.fill(self.color_fondo, (1, 1, self.w - 2, self.h - 2)) rect = image.get_rect(topleft=(x, y)) super().__init__(image, rect) Renderer.add_widget(self, 1) WidgetHandler.add_widget(self, 1) self.input = []
def __init__(self, x, y): self.f = font.SysFont('Verdana', 16) self.empty_f = font.SysFont('Verdana', 16, italic=True) self.w, self.h = 310, 23 self.image = Surface((self.w, self.h)) self.image.fill(self.color_fondo, (1, 1, self.w - 2, self.h - 2)) self.rect = self.image.get_rect(topleft=(x, y)) super().__init__() Renderer.add_widget(self) WidgetHandler.add_widget(self) WidgetHandler.set_active(self) EventHandler.register(self.update_status, 'check') self.input = []
def __init__(self, text, x, y, w=0, size=16, just=0): self.f = font.SysFont('Verdana', size) if w == 0: w = self.f.size(text)[0] + 1 self.x, self.y, self.w, = x, y, w self.image = render_textrect(text, self.f, w, COLOR_TEXTO, COLOR_FONDO, justification=just) self.w, self.h = self.image.get_size() self.rect = self.image.get_rect(topleft=(x, y)) super().__init__() Renderer.add_widget(self, 1) WidgetHandler.add_widget(self, 1)
def __init__(self, parent, text, y, h): super().__init__(parent, text, y, h) self.item = Item(text) self.name = self.item.name + '.Label' self.fuente = font.SysFont('Courier', h) self.altura_del_texto = self.fuente.get_height() texto = self.compress() self.img_sel = render_textrect(texto, self.fuente, parent.w, [255, 255, 255], COLOR_FONDO) self.img_uns = render_textrect(texto, self.fuente, parent.w, [0, 0, 0], COLOR_FONDO) self.image = self.img_uns self.w, self.h = self.image.get_size() self.x, self.y = parent.x, y self.rect = self.image.get_rect(topleft=(self.x, self.y)) Renderer.add_widget(self) WidgetHandler.add_widget(self)
def __init__(self, parent, text, y, h): self.item = Item(text) self.name = self.item.name + '.Label' self.fuente = font.SysFont('Verdana', h) texto = self.item.shelf(precio='precio' in text, isbn='ISBN' in text) self.altura_del_texto = self.fuente.get_height() self.img_sel = render_textrect(texto, self.fuente, parent.w, [255, 255, 255], COLOR_FONDO) self.img_uns = render_textrect(texto, self.fuente, parent.w, [0, 0, 0], COLOR_FONDO) self.image = self.img_uns self.w, self.h = self.image.get_size() self.x, self.y = parent.x, y self.rect = self.image.get_rect(topleft=(self.x, self.y)) super().__init__(parent) Renderer.add_widget(self) WidgetHandler.add_widget(self)
def __init__(self, x, y, name, initial_state=False): super().__init__() self.x, self.y = x, y self.nombre = name self.img_true = self._crear(True) self.img_false = self._crear(False) self.state = initial_state if self.state: self.image = self.img_true else: self.image = self.img_false self.rect = self.image.get_rect(center=(self.x, self.y)) Renderer.add_widget(self) WidgetHandler.add_widget(self) EventHandler.trigger('check', self, { 'name': self.nombre, 'status': self.state })
def hide(self): Renderer.del_widget(self) WidgetHandler.del_widget(self)
def show(self): Renderer.add_widget(self) WidgetHandler.add_widget(self)
from pygame import init from frontend import Renderer, EventManager, Block init() Renderer.init() EventManager.init() for pos in [(10, 10), (20+32, 10)]: b = Block(*pos) Renderer.add_block(b) EventManager.add_object(b) while True: EventManager.update() Renderer.update()
def clear(self): for item in self.items: Renderer.del_widget(item) WidgetHandler.del_widget(item) self.items.clear() self.h = 0
def on_destruction(self): Renderer.del_widget(self.sell_button) WidgetHandler.del_widget(self.sell_button)