def __init__(self, closeButton=True): g.selectMeneWindowOpened = True self.currentMeneID = g.currMeneID self.selectMeneID = None self.meneCont = [] self.meneButtons = [] self.closeButton = closeButton self.constructMeneButtons() selectButton = HighlightedButton("Select Mene", on_release=self.selectMene, width=150, height=30) if closeButton: closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') cont = VerticalContainer(content=[ HorizontalContainer(content=[Spacer(0, 0), closeBtn]), HorizontalContainer(content=self.meneCont), Spacer(0, 10), selectButton ]) else: cont = VerticalContainer(content=[ HorizontalContainer(content=self.meneCont), Spacer(0, 10), selectButton ]) Manager.__init__(self, Frame(cont), window=g.screen, batch=g.guiBatch, is_movable=False, offset=(0, 0), theme=g.theme)
def __init__(self, client, inventory): self.client = client invitems = [] for name, value in inventory.items(): title = value['title'] equipped = value['equipped'] icon = value['icon'] hit = value['hit'] dam = value['dam'] arm = value['arm'] invitems.append( Frame(InventoryItem(name, title, equipped, icon, self.client, hit, dam, arm), is_expandable=True)) self.close_button = OneTimeButton(label='Close', on_release=self.close) self.inventory_list = Scrollable(height=256, width=512, is_fixed_size=True, content=VerticalContainer( invitems, align=HALIGN_LEFT)) self.inventory_container = VerticalContainer( [self.inventory_list, self.close_button]) Manager.__init__(self, Frame(self.inventory_container, is_expandable=True), window=self.client.window, theme=UI_THEME, is_movable=True, anchor=ANCHOR_BOTTOM_RIGHT)
def __init__(self, window, batch, space, level, height, width): self.space = space self.level = level status_text = pyglet.text.decode_attributed(''' Time: 0 sec \n Points: 0 points \n FPS: 00.00 FPS ''') self.status_doc = Document(status_text, height=height, width=width) status_frame = Frame(self.status_doc) inv_text = pyglet.text.decode_html("<h4>Inventory</h4>") inventory_header = Document(inv_text, width=width) self.inventory_container = VerticalContainer([]) container = VerticalContainer( [inventory_header, self.inventory_container]) self.inventory_frame = Frame(container) container = VerticalContainer([status_frame, self.inventory_frame]) self.manager = Manager(container, window=window, batch=batch, group=RenderingOrder.hud, anchor=ANCHOR_TOP_RIGHT, theme=theme, is_movable=False) self.window = window self.window.push_handlers(on_draw=self.on_draw) self.tick = 0
def __init__(self, window, batch, space, level, height, width): self.space = space self.level = level self.height = height self.width = width progress_text = "Progress: ..." self.progress_doc = Document(progress_text, width=width / 2) objective_doc = Document(level.objective, width=width / 2) left_frame = Frame(VerticalContainer( [objective_doc, None, self.progress_doc]), is_expandable=True) self.left_container = VerticalContainer([left_frame]) victory_formula = level.victory_condition[0] info_frame = self.create_info_frame(victory_formula) self.info_container = VerticalContainer([info_frame]) container = HorizontalContainer( [self.left_container, self.info_container]) self.manager = Manager(container, window=window, batch=batch, group=RenderingOrder.hud, anchor=ANCHOR_BOTTOM_LEFT, theme=theme, is_movable=False) self.window = window self.window.push_handlers(on_draw=self.on_draw) self.tick = 0 self.init_effects(space, level)
def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Controller.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalContainer([Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalContainer([ self.book, Label(title, path=["section"]), ]), path=["section", "center"]), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(self.folding_content) VerticalContainer.__init__(self, content=layout, align=align)
def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Controller.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalContainer([ Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalContainer([ self.book, Label(title, path=["section"]), ]), path=["section", "center"]), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(self.folding_content) VerticalContainer.__init__(self, content=layout, align=align)
def __init__(self, title, content): VerticalContainer.__init__(self, content=[ HorizontalContainer([Graphic(path=["titlebar", "left"], is_expandable=True), Frame(Label(title, path=["titlebar"]), path=["titlebar", "center"]), Graphic(path=["titlebar", "right"], is_expandable=True), ], align=VALIGN_BOTTOM, padding=0), Frame(content, path=["titlebar", "frame"], is_expandable=True), ], padding=0)
def __init__(self): g.postWindowOpened = True label1 = Label("Notifications", bold=True, color=g.loginFontColor) closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') self.postCont = [] #self.menes = [{"name":"Hitler","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'americanbear'},{"name":"Stalin","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'lorslara'},{"name":"Ebin","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'squadlider'},{"name":"Mao","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'mongolbear'},{"name":"Uusi mene","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'mongol'},{"name":"Hintti","hp":50,"level":15,"power":60,"defense":50,"speed":70,'sprite':'uusimene'}] #self.selectedMene=self.menes[0]["name"] for c in g.mails: label = Label(c["s"], bold=True, color=g.guiNameColor, font_size=g.theme["font_size"] + 2) label1 = Label(c["t"][:16] + '...', color=g.whiteColor) deleteBtn = HighlightedButton("", on_release=self.deletemail, width=14, height=14, path='delete_alt', argument=c["id"]) openBtn = HighlightedButton("", on_release=self.openmail, width=20, height=21, path='mailopen', argument=c["id"]) self.postCont.append( VerticalContainer(content=[ HorizontalContainer(content=[openBtn, label, deleteBtn]), label1 ], align=HALIGN_LEFT)) self.vertCont = VerticalContainer(self.postCont, align=VALIGN_TOP) self.report = Document("", is_fixed_size=True, height=g.SCREEN_HEIGHT / 2, width=g.SCREEN_WIDTH / 5) self.scrollable = Scrollable(content=self.vertCont, height=g.SCREEN_HEIGHT / 2, width=g.SCREEN_WIDTH / 5) total = HorizontalContainer( content=[self.scrollable, self.report, closeBtn], align=VALIGN_TOP) Manager.__init__( self, Frame(total), window=g.screen, batch=g.guiBatch, is_movable=False, anchor=ANCHOR_LEFT, offset=(40, int(g.SCREEN_HEIGHT * g.WINDOW_POSY_RELATIVE)), theme=g.theme) if len(self.postCont) > 0: self.openmail(self.postCont[0]._content[0]._content[0].arg)
def __init__(self, options, labels=None, align=HALIGN_CENTER, padding=4, on_select=None): Selector.__init__(self, options, labels, on_select) VerticalContainer.__init__(self, list(self._options.values()), align=align, padding=padding)
def __init__(self, client, inventory=[], player_inventory=[]): self.client = client invitems = [] for name, value in inventory.items(): title = value['title'] icon = value['icon'] dam = value['dam'] hit = value['hit'] arm = value['arm'] gold = value['value'] invitems.append( Frame(ShopItem(name, title, icon, self.client, dam, hit, arm, gold), is_expandable=True)) self.shop_inventory_list = Scrollable(height=256, width=512, is_fixed_size=True, content=VerticalContainer( invitems, align=HALIGN_LEFT)) player_invitems = [] for name, value in player_inventory.items(): title = value['title'] icon = value['icon'] dam = value['dam'] hit = value['hit'] arm = value['arm'] player_invitems.append( Frame(PlayerShopItem(name, title, icon, self.client, dam, hit, arm), is_expandable=True)) self.player_inventory_list = Scrollable(height=256, width=512, is_fixed_size=True, content=VerticalContainer( player_invitems, align=HALIGN_LEFT)) self.exit_button = OneTimeButton(label='Close', on_release=self.close) self.inventory_container = HorizontalContainer([ self.shop_inventory_list, self.player_inventory_list, self.exit_button ]) Manager.__init__(self, Frame(self.inventory_container, is_expandable=True), window=self.client.window, theme=UI_THEME, is_movable=True)
def __init__(self): g.ignoreWindowOpened = True label1 = Label("Ignore List", bold=True, color=g.loginFontColor) closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') title = [label1, None, closeBtn] ignores = [] for c in ignoreList: ignores.append(c) ignores.sort() ignoreCont = [] for c in ignores: label = HighlightedButton(c, width=150, height=24, path='baroutline_btn', on_release=self.constructSelect, argument=c, align=HALIGN_LEFT, font_color=g.guiNameColor) ignoreCont.append(label) #label=Label(c,bold=True,color=g.nameColorLighter) #removeBtn = HighlightedButton("",on_release=self.removeIgnore,width=24,height=24,path='ignoreremove',argument=c) #ignoreCont.append(HorizontalContainer(content=[label,removeBtn])) addBtn = HighlightedButton("Ignore Player", on_release=addIgnorePopup, width=100, height=24) horzCont = HorizontalContainer(content=title) frame = Frame( VerticalContainer(content=[ horzCont, Scrollable(height=400, width=400, content=VerticalContainer(content=ignoreCont, align=HALIGN_LEFT, padding=0)), addBtn ])) Manager.__init__( self, frame, window=g.screen, batch=g.guiBatch, is_movable=False, anchor=ANCHOR_LEFT, offset=(40, int(g.SCREEN_HEIGHT * g.WINDOW_POSY_RELATIVE)), theme=g.theme)
def __init__(self, title, content=None, x=0, y=0, type=0): g.selectedWindowOpened = True cont = [] self.type = type cont.append(Label(title, color=g.loginFontColor)) for c in content: cont.append( HighlightedButton(c["text"], on_release=c["function"], width=120, height=24, path='empty', argument=c["argument"], align=HALIGN_LEFT)) frame = Frame(VerticalContainer(content=cont, padding=0, align=HALIGN_LEFT), path='frame_alternative') Manager.__init__(self, frame, window=g.screen, batch=g.selectWindowBatch, is_movable=False, offset=(0, 0), theme=g.theme) self.set_position(x, y - self.height)
def create_folding_description(window, batch, heading, description, chapters=list()): """ window - window batch - batch heading - heading of the widget description - description for the widget chapters - list of tuples (heading,text) """ description_doc = pyglet.text.decode_attributed(description) layout = list() layout.append(SectionHeader(heading)) layout.append(Document(description_doc, width=300)) for chapter in chapters: heading, text = chapter text_doc = pyglet.text.decode_attributed(text) layout.append(FoldingSection(heading, Document(text_doc, width=300), is_open=False)) content = Frame(Scrollable(VerticalContainer(layout, align=HALIGN_LEFT),height=400)) Manager(content, window=window, batch=batch, group=RenderingOrder.gui, anchor=ANCHOR_BOTTOM_RIGHT, theme=theme, is_movable=False)
def init_menu_state(self): self.batch = pyglet.graphics.Batch() label = pyglet.text.Label('AsTeRoIdS', font_name='Times New Roman', font_size=36, x=window.width // 2, y=3 * window.height // 4, anchor_x='center', anchor_y='center', batch=self.batch, group=self.foreground) def callback1(is_pressed): self.init_game_state() self.state = 'PLAYING' button1 = Button('Start Game', on_press=callback1) def callback2(is_pressed): exit() button2 = Button('Quit', on_press=callback2) Manager(VerticalContainer([button1, button2]), window=window, theme=theme, batch=self.batch) self.asteroids = self.gen_asteroids(num_ast)
def __init__(self, text="", ok="Ok", cancel="Cancel", window=None, batch=None, group=None, theme=None, on_ok=None, on_cancel=None): def on_ok_click(_): if on_ok is not None: on_ok(self) self.delete() def on_cancel_click(_): if on_cancel is not None: on_cancel(self) self.delete() Manager.__init__(self, content=Frame( VerticalContainer([ Label(text), HorizontalContainer([ Button(ok, on_press=on_ok_click), None, Button(cancel, on_press=on_cancel_click) ]) ])), window=window, batch=batch, group=group, theme=theme, is_movable=True)
def on_mouse_press(self, x, y, button, modifiers): if not self._is_loaded or not self._options or len(self._options) == 0: return """ A mouse press is going to create a manager with the options. """ # if it's already opened, we just close it. if self._pulldown_menu is not None: self._delete_pulldown_menu() return # the function we pass to the manager. def on_escape(_): self._delete_pulldown_menu() width, height = self._manager.window.get_size() x = self.x y = -(height - self.y - 1) + self.height # we set the manager self._pulldown_menu = Manager(Frame(Scrollable(VerticalContainer( list(self._options.values())), height=self.max_height), path=['dropdown', 'pulldown']), window=self._manager.window, batch=self._manager.batch, group=self._manager.root_group.parent, theme=self._manager.theme, is_movable=False, anchor=ANCHOR_TOP_LEFT, offset=(x, y))
def setUp(self): super(TestVerticalContainer, self).setUp() self.container = VerticalContainer([Viewer(width=50, height=50), Viewer(width=50, height=50)]) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
def constructMeneButtons(self): for mene in meneList: if mene.hp <= 0: disabled = True else: disabled = False if g.gameEngine.fightScreen.myMene.ID == mene.ID: ispressed = True self.selectMeneID = mene.ID else: ispressed = False button = Button("", on_press=self.updateWindow, disabled=disabled, width=TILESIZE * 2, height=TILESIZE * 2, argument=mene.ID, texture=g.gameEngine.resManager.meneSprites[ mene.spriteName]["portraitlarge"], is_pressed=ispressed, outline='menewindowbutton') nameLabel = Label(mene.name, bold=True, color=g.npcColor) lvlLabel = Label("Lvl: %s" % mene.level) hpBar = HpBar(height=20, width=64 * 2, maxhp=mene.maxhp, currenthp=mene.hp) self.meneCont.append( VerticalContainer(content=[button, nameLabel, lvlLabel, hpBar], padding=0)) self.meneButtons.append(button)
def __init__(self, name, level, hp, maxhp): self.nameLabel = Label(name, color=g.whiteColor, font_size=g.theme["font_size"] + 2, bold=True) self.levelLabel = Label('Lvl: ' + str(level), color=g.whiteColor, font_size=g.theme["font_size"] + 2, bold=True) self.hpBar = HpBar() Manager.__init__( self, VerticalContainer(content=[ HorizontalContainer( content=[self.nameLabel, None, self.levelLabel]), self.hpBar ], align=HALIGN_LEFT), window=g.screen, batch=g.guiBatch, is_movable=False, anchor=ANCHOR_BOTTOM_LEFT, offset=(0, 0), theme=g.theme) self.hpBar.setHP(hp, maxhp)
def __init__(self): g.partyWindowOpened = True #label1=Label("Friends List",bold=True,color=g.loginFontColor) #closeBtn =HighlightedButton("",on_release=self.delete,width=19,height=19,path='delete') party = [] for member in g.partyMembers: leader = None if member.access: leader = 'partyleader' party.append( PartyMemberButton(on_press=self.constructSelect, label=member.name, width=64, height=64, argument=member.name, texture=member.texture, outline='partymember', font_valign=VALIGN_BOTTOM, font=g.defaultFont.name, font_color=g.partyColor, font_size=10, leader=leader)) test = VerticalContainer(content=party) Manager.__init__(self, test, window=g.screen, batch=g.guiBatch, is_movable=False, anchor=ANCHOR_LEFT, offset=(g.SCREEN_WIDTH * 0.05, int(g.SCREEN_HEIGHT * g.WINDOW_POSY_RELATIVE * 1.3)), theme=g.theme)
def bagHoverTemplate(money, es): moneyTmp = money / 100.0 moneyCont = HorizontalContainer( content=[Label("%.2f" % moneyTmp), Graphic("euro")]) esCont = HorizontalContainer( content=[Label("%s" % es), Graphic('es_icon')]) return VerticalContainer(content=[esCont, moneyCont], align=HALIGN_RIGHT)
class ChatWindowManager(Manager): def __init__(self, client): self.client = client self.message_container = VerticalContainer(content=[], align=HALIGN_LEFT) self.messages = Scrollable(height=100, width=300, is_fixed_size=True, content=self.message_container) self.text_input = TextInput("", length=20, max_length=256) self.send_button = OneTimeButton("Send", on_release=self.submit_message) self.enter_field = HorizontalContainer( [self.text_input, self.send_button]) self.chat_window = VerticalContainer([self.messages, self.enter_field]) Manager.__init__(self, Frame(self.chat_window, path='chatFrame'), window=self.client.window, theme=UI_THEME, is_movable=True, anchor=ANCHOR_BOTTOM_LEFT) def add_message(self, message): step = 40 for i in range(0, len(message), step): self.message_container.add( Label("> " + message[i:step], font_name='Lucida Grande')) step += 40 self.text_input.set_text("") def submit_message(self, state): message = self.text_input.get_text() self.text_input.set_text("") if message[0] == "/": self.message_container.add( Label("> " + message, font_name='Lucida Grande', color=[200, 200, 255, 255])) self.client.command(message[1:].split(' ')) else: self.client.chat(message)
def __init__(self): newgameButton=Button(label="New Game", on_press=self.newGame) quitButton=Button(label="Quit Game", on_press=self.quitGame) Manager.__init__(self, VerticalContainer(content=[newgameButton,Spacer(0,20),quitButton]), window=g.gameEngine.window, batch=g.guiBatch, theme=g.theme, is_movable=False)
def __init__(self): quitButton = Button(label="Exit Game",on_press=self.quitGame) closeButton = Button(label="Return",on_press=self.close) Manager.__init__(self, Frame(VerticalContainer(content=[quitButton,closeButton])), window=g.gameEngine.window, batch=g.guiBatch, theme=g.theme, is_movable=False)
def initManager(self): self.mode = MODE_CONNECTING self.guiBatch = pyglet.graphics.Batch() self.statusText = Label("Connecting", color=(255, 255, 255, 255)) self.downloadText = Label("", color=(255, 255, 255, 255)) self.manager = Manager(VerticalContainer( [self.statusText, self.downloadText]), window=self.screen, batch=self.guiBatch, theme=theme)
def __init__(self, client): self.client = client self.message_container = VerticalContainer(content=[], align=HALIGN_LEFT) self.messages = Scrollable(height=100, width=300, is_fixed_size=True, content=self.message_container) self.text_input = TextInput("", length=20, max_length=256) self.send_button = OneTimeButton("Send", on_release=self.submit_message) self.enter_field = HorizontalContainer( [self.text_input, self.send_button]) self.chat_window = VerticalContainer([self.messages, self.enter_field]) Manager.__init__(self, Frame(self.chat_window, path='chatFrame'), window=self.client.window, theme=UI_THEME, is_movable=True, anchor=ANCHOR_BOTTOM_LEFT)
def __init__(self, client): self.client = client self.login_button = OneTimeButton(label="Login", on_release=self.login) self.username_field = TextInput("") self.password_field = TextInput("") self.login_container = VerticalContainer( [self.login_button, self.username_field, self.password_field]) Manager.__init__(self, Frame(self.login_container), window=self.client.window, theme=UI_THEME)
def __init__(self, client, name, title, dialog): self.client = client self.name = name title = Label(title, font_size=12) dialog = pyglet.text.decode_text(dialog) document = Document(dialog, width=300, height=100) accept_button = OneTimeButton(label="Ok, I'll do it!", on_release=self.accept) reject_button = OneTimeButton(label="No, Thanks.", on_release=self.reject) text_container = VerticalContainer([title, document]) button_container = HorizontalContainer([accept_button, reject_button]) quest_container = VerticalContainer([text_container, button_container]) Manager.__init__(self, Frame(quest_container, is_expandable=True), window=self.client.window, theme=UI_THEME, is_movable=True)
def abilityHoverTemplate(args): cont = [] if 'name' in args: cont.append( Label(args['name'], bold=True, font_size=g.theme['font_size'] + 1)) if 'type' in args: cont.append(Label(args['type'])) if 'info' in args: cont.append( Label(args['info'].format(*args['args']), width=TILESIZE * 4, multiline=True, color=g.loginFontColor)) return VerticalContainer(cont, align=HALIGN_LEFT, padding=0)
def __init__(self, text="", window=None, textcolor=None,batch=None, group=None, width=None, theme=None, on_escape=None, have_focus=False,font_size=None): def on_ok(_): if on_escape is not None: on_escape(self) self.delete() #button = FocusButton("Ok", on_press=on_ok) button=HighlightedButton("Ok",on_release=on_ok,height=35,width=80) Manager.__init__(self, content=Frame(VerticalContainer( [Label(text,color=textcolor,font_size=font_size,width=width,multiline=True), Spacer(min_height=5),button])), window=window, batch=batch, group=group, theme=theme, is_movable=True) Manager.set_next_focus(self, 1)
def __init__(self, client): self.client = client self.connect_button = OneTimeButton(label="Connect", on_release=self.connect) self.server_field = TextInput("localhost") self.port_field = TextInput("10000") self.connect_container = VerticalContainer( [self.connect_button, self.server_field, self.port_field]) Manager.__init__(self, Frame(self.connect_container, path='connectFrame'), window=self.client.window, theme=UI_THEME)
def __init__(self, client, quests): self.client = client quest_list = [] for quest in quests: quest_title = Label(quest['title']) quest_container = HorizontalContainer([quest_title]) quest_list.append(quest_container) close_button = OneTimeButton(label="Close", on_release=self.close) quest_container = VerticalContainer(quest_list) button_container = HorizontalContainer([close_button]) questlog_container = VerticalContainer( [quest_container, button_container]) Manager.__init__(self, Frame(questlog_container, is_expandable=True), window=self.client.window, theme=UI_THEME, is_movable=True)
def __init__(self, window, batch, space, level, height, width): self.space = space self.level = level self.height = height self.width = width progress_text = "Progress: ..." self.progress_doc = Document(progress_text, width = width/2) objective_doc = Document(level.objective, width = width/2) left_frame = Frame(VerticalContainer([objective_doc, None, self.progress_doc]), is_expandable = True) self.left_container = VerticalContainer([left_frame]) victory_formula = level.victory_condition[0] info_frame = self.create_info_frame(victory_formula) self.info_container = VerticalContainer([info_frame]) container = HorizontalContainer([self.left_container, self.info_container]) self.manager = Manager(container, window=window, batch=batch, group=RenderingOrder.hud, anchor=ANCHOR_BOTTOM_LEFT, theme=theme, is_movable=False) self.window = window self.window.push_handlers(on_draw=self.on_draw) self.tick = 0 self.init_effects(space, level)
def delete(self): if not self.is_open: self.folding_content.delete() self.folding_content = None VerticalContainer.delete(self)
class HorizontalHUD: def __init__(self, window, batch, space, level, height, width): self.space = space self.level = level self.height = height self.width = width progress_text = "Progress: ..." self.progress_doc = Document(progress_text, width = width/2) objective_doc = Document(level.objective, width = width/2) left_frame = Frame(VerticalContainer([objective_doc, None, self.progress_doc]), is_expandable = True) self.left_container = VerticalContainer([left_frame]) victory_formula = level.victory_condition[0] info_frame = self.create_info_frame(victory_formula) self.info_container = VerticalContainer([info_frame]) container = HorizontalContainer([self.left_container, self.info_container]) self.manager = Manager(container, window=window, batch=batch, group=RenderingOrder.hud, anchor=ANCHOR_BOTTOM_LEFT, theme=theme, is_movable=False) self.window = window self.window.push_handlers(on_draw=self.on_draw) self.tick = 0 self.init_effects(space, level) def init_effects(self, space, level): pos = (self.left_container.x + self.left_container.width / 2, self.left_container.y + self.left_container.height / 2 - 50) self.victory = Effects.VictoryInventory(space, pos, "Victory Inventory", self.left_container.width, self.left_container.height + 100, level.victory_condition) def get_effects(self): return [self.victory] def update_info_text(self, formula): info_frame = self.create_info_frame(formula) for content in self.info_container.content: self.info_container.remove(content) self.info_container.add(info_frame) def create_info_frame(self, formula): cml = CachedCml.getMolecule(formula) info_text = pyglet.text.decode_html("<b>%s</b><br> %s" % ( cml.property.get("Name", "Undefined"), cml.property.get("Description", "No Description Available") )) info_doc = Document(info_text, height=self.height, width=self.width/2, is_fixed_size = True) info_frame = Frame(info_doc) return info_frame def on_draw(self): self.tick += 1 if self.tick > 30: return self.tick = 0 self.update_progress() def update_progress(self): progress_text = self.victory.progress_text() self.progress_doc.set_text("Progress: " + progress_text) def delete(self): self.window.remove_handlers(on_draw = self.on_draw) self.manager.delete()
class TestVerticalContainer(TestPygletGUI): """ This test case tests basic functionality of a vertical container. """ def setUp(self): super(TestVerticalContainer, self).setUp() self.container = VerticalContainer([Viewer(width=50, height=50), Viewer(width=50, height=50)]) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme) def _test_content_position(self): """ Tests the position of the two widgets within the container. """ # first widget y is the top y (container.y + container.height) minus its size (container.content[0].height) self.assertEqual(self.container.content[0].y, self.container.y + self.container.height - self.container.content[0].height) # second widget y is the top y (container.y + container.height - container.content[0].height) minus its size # (container.content[1].height) minus the padding (self.container.padding) self.assertEqual(self.container.content[1].y, self.container.y + self.container.height - self.container.content[0].height - self.container.content[1].height - self.container.padding) def test_top_down_draw(self): """ Tests that the container's size was set correctly and the positions of its content is correct. """ # manager size is correct self.assertEqual(self.container.width, 50) self.assertEqual(self.container.height, 100 + self.container.padding) # widget is centered in the window self.assertEqual(self.container.x, self.window.width // 2 - self.container.width // 2) self.assertEqual(self.container.y, self.window.height // 2 - self.container.height // 2) self._test_content_position() def test_bottom_up_draw(self): """ Tests that the manager's size is modified if we set a new size to the widget. """ self.container.content[0].width = 60 self.container.content[0].height = 60 self.container.content[0].parent.reset_size() # container width was set self.assertEqual(self.container.width, 60) # container height was set self.assertEqual(self.container.height, 110 + self.container.padding) # container was re-centered in the window self.assertEqual(self.container.x, self.window.width // 2 - self.container.width // 2) self.assertEqual(self.container.y, self.window.height // 2 - self.container.height // 2) self._test_content_position() def test_add_widget(self): self.container.add(Viewer(width=50, height=50)) self.assertEqual(self.manager.width, 50) self.assertEqual(self.manager.height, 150 + 2 * self.container.padding) self._test_content_position() def test_remove_widget(self): self.container.remove(self.container.content[0]) self.assertEqual(self.manager.width, 50) self.assertEqual(self.manager.height, 50 + self.container.padding) def tearDown(self): self.manager.delete() super(TestVerticalContainer, self).tearDown()