Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
class EventLogController(pygsty.controllers.BaseController):
    def __init__(self):
        super().__init__()
        self.hud_batch = pyglet.graphics.Batch()
        self.doc = Document(self.last_message, width=800, height=100, is_fixed_size=True)
        self.frame = Frame(self.doc)
        self.manager = Manager(self.frame, window=pygsty.engine(), batch=self.hud_batch, theme=config.ui_theme)
        self.manager.set_position(0, 0)
        self._latest_event = None
        self._log = self.last_message

    def draw_hud(self):
        self.hud_batch.draw()

    @property
    def last_message(self):
        last_event = models.event_log.last_event()
        if last_event:
            return last_event.formatted_message()
        else:
            return ""

    def update(self, dt):
        if not models.event_log.last_event() is self._latest_event:
            self._log = self.last_message + self._log
            self.doc.set_text(self._log)
            self._latest_event = models.event_log.last_event()
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
    def setUp(self):
        super(TestHorizontalContainer, self).setUp()

        self.container = HorizontalContainer([Viewer(width=50, height=50),
                                           Viewer(width=50, height=50)])

        self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
    def __init__(self,
                 ability1=None,
                 ability2=None,
                 ability3=None,
                 ability4=None):

        self.a1 = ability1
        self.a2 = ability2
        self.a3 = ability3
        self.a4 = ability4
        #self.abilityCont=[]
        abilityButtons = []
        for i in xrange(4):
            abilityButtons.append(
                Graphic(width=100, height=100, path='abilityoutline'))
        self.abilityCont = HorizontalContainer(content=abilityButtons,
                                               align=VALIGN_BOTTOM)

        Manager.__init__(self,
                         self.abilityCont,
                         window=g.screen,
                         batch=g.guiBatch,
                         is_movable=False,
                         anchor=ANCHOR_BOTTOM,
                         offset=(0, 0),
                         theme=g.theme)
        self.constructAbilityButtons()
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
    def __init__(self, client, 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(ContainerItem(name, title, icon, self.client, dam, hit,
                                    arm, gold),
                      is_expandable=True))

        self.container_inventory_list = Scrollable(height=256,
                                                   width=512,
                                                   is_fixed_size=True,
                                                   content=VerticalContainer(
                                                       invitems,
                                                       align=HALIGN_LEFT))

        self.exit_button = OneTimeButton(label='Close', on_release=self.close)
        self.inventory_container = HorizontalContainer(
            [self.container_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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
class UIResourceList(object):
    def __init__(self, window, batch):
        self.window = window
        self.batch = batch
        self._resource_menu = None

    def render(self):
        self.remove()

        content = Frame(
            Scrollable(
                VerticalContainer(
                    [
                        SectionHeader("Resources"),
                        UIResourceSection("Primary Resources", "primary", is_open=True),
                        UIResourceSection("Processed Material", "processed_material", is_open=False),
                        UIResourceSection("Raw Material", "raw_material", is_open=False),
                        OneTimeButton("Close", self.remove),
                    ],
                    align=HALIGN_LEFT,
                ),
                height=400,
            )
        )

        self._resource_menu = Manager(
            content, window=self.window, batch=self.batch, anchor=ANCHOR_TOP_LEFT, theme=resource_menu_theme
        )

    def remove(self, *args):
        if self._resource_menu:
            self._resource_menu.delete()
Ejemplo n.º 13
0
 def __init__(self,name,text,a=0):
     if text[0]=='>':
         color=g.greentextColor
     else:
         color=g.postColor
     if a>0:
         if a==ADMIN_MODERATOR:
             nameColor=g.modColor
             appendix='#Mod#'
         elif a==ADMIN_ADMIN:
             nameColor=g.adminColor
             appendix='#Admin#'
         else:
             nameColor=g.adminColor
             appendix='#Owner#'
     else:
         nameColor=g.nameColor
         appendix=''
     if appendix:
         horz=HorizontalContainer(content=[Label(name,bold=True,color=nameColor),Label(appendix+':',color=nameColor),Label(text,color=color)])
     else:
         horz=HorizontalContainer(content=[Label(name+':',bold=True,color=nameColor),Label(text,color=color)])
     Manager.__init__(self,
         Frame(horz),
         window=g.screen,
         batch=g.chatBubbleBatch,
         anchor=ANCHOR_BOTTOM_LEFT,
         is_movable=False,
         offset=(0,0),
         theme=g.chatTheme)
Ejemplo n.º 14
0
    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 setUp(self):
     TestPygletGUI.setUp(self)
     self.input = TextInput(text="test")
     self.manager = Manager(self.input,
                            window=self.window,
                            batch=self.batch,
                            theme=self.theme)
Ejemplo n.º 16
0
    def __init__(self, window, controls, bodies):
        self.window = window
        self.controls = controls
        self.bodies = bodies

        self.fps_counter = FPSCounter(window, self.fps_update)

        # Setup HUD elements
        self.label_fps = Label("", bold=True, font_name="Arial", font_size=12, color=(127, 127, 127, 127))
        self.label_time = Label("", bold=True, font_name="Arial", font_size=18, color=(127, 127, 127, 127))
        self.label_help = BetterLabel(load_string('help.txt'), bold=False, font_name="Arial", font_size=18, color=(170, 170, 170, 255), multiline=True, lblwidth=600)
        self.label_planet_info = BetterLabel("", bold=False, font_name="Arial", font_size=12, color=(170, 170, 170, 255), multiline=True, lblwidth=400, lblalign='right')
        self.managers = [
            Manager(self.label_fps, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_TOP_LEFT),
            Manager(self.label_time, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_BOTTOM_LEFT)
        ]
        self.label_help_manager = Manager(self.label_help, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_TOP_LEFT, offset=(0, -17))
        self.label_planet_info_manager = Manager(self.label_planet_info, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_BOTTOM_RIGHT, offset=(-180, 36))

        body_buttons = []
        for body in self.bodies:
            body_buttons.append(BodyButton(self, body).button)

        self.managers_when_not_locked = [
            Manager(VerticalContainer(body_buttons, align=HALIGN_RIGHT), window=window, theme=ThemeFromPath("theme/bodybutton"), is_movable=False, anchor=ANCHOR_TOP_RIGHT)
        ]
Ejemplo n.º 17
0
class VerticalHUD():
    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
        # Currently disabled
        #self.init_effects(space, level)

    def init_effects(self, space, level):
        pos = (self.inventory_frame.x,
               self.inventory_frame.y + self.inventory_frame.height / 2 - 50)
        self.inventory_effect = Effects.Inventory(space, pos, "Inventory",
                self.inventory_frame.width, self.inventory_frame.height + 100,
                ["H2O(l)", "CH4(g)", "NaCl(s)"], gui_container = self.inventory_container)

    def get_effects(self):
        return []
        #currently disabled
        #return [self.inventory_effect]

    def on_draw(self):
        self.tick += 1
        if self.tick > 30:
            return
        self.tick = 0
        self.update_status()

    def update_status(self):
        level_time = self.window.level.get_time()
        points = self.window.level.get_points()
        status_text = '''
Time: %d sec
Points: %d points
FPS: %.2f FPS
''' % (level_time, points, pyglet.clock.get_fps())
        self.status_doc.set_text(status_text)

    def delete(self):
        self.window.remove_handlers(on_draw = self.on_draw)
        self.manager.delete()
Ejemplo n.º 18
0
class GUI:
    """
    Controls the GUI (HUD) of this application
    """

    def __init__(self, window, controls, bodies):
        self.window = window
        self.controls = controls
        self.bodies = bodies

        self.fps_counter = FPSCounter(window, self.fps_update)

        # Setup HUD elements
        self.label_fps = Label("", bold=True, font_name="Arial", font_size=12, color=(127, 127, 127, 127))
        self.label_time = Label("", bold=True, font_name="Arial", font_size=18, color=(127, 127, 127, 127))
        self.label_help = BetterLabel(load_string('help.txt'), bold=False, font_name="Arial", font_size=18, color=(170, 170, 170, 255), multiline=True, lblwidth=600)
        self.label_planet_info = BetterLabel("", bold=False, font_name="Arial", font_size=12, color=(170, 170, 170, 255), multiline=True, lblwidth=400, lblalign='right')
        self.managers = [
            Manager(self.label_fps, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_TOP_LEFT),
            Manager(self.label_time, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_BOTTOM_LEFT)
        ]
        self.label_help_manager = Manager(self.label_help, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_TOP_LEFT, offset=(0, -17))
        self.label_planet_info_manager = Manager(self.label_planet_info, window=window, theme=empty_theme, is_movable=False, anchor=ANCHOR_BOTTOM_RIGHT, offset=(-180, 36))

        body_buttons = []
        for body in self.bodies:
            body_buttons.append(BodyButton(self, body).button)

        self.managers_when_not_locked = [
            Manager(VerticalContainer(body_buttons, align=HALIGN_RIGHT), window=window, theme=ThemeFromPath("theme/bodybutton"), is_movable=False, anchor=ANCHOR_TOP_RIGHT)
        ]

    def fps_update(self, fps):
        self.label_fps.set_text(str(fps) + "fps")

    def update_time(self, timestep, solarsystem_time):
        self.label_time.set_text("1 second = " + str(floor(timestep / 60 / 60)) + "hours. Current Date: " + str(J2000 + datetime.timedelta(seconds=solarsystem_time)))

    def draw(self):
        if self.controls.draw_help_label:
            self.label_help_manager.draw()

        if self.controls.selected_body:
            body = self.controls.selected_body
            text = ""
            text += "Name: " + body.name + "\n"
            text += "Position: " + str(round(body.xyz.x, 2)) + " " + str(round(body.xyz.y, 2)) + " " + str(round(body.xyz.z, 2)) + "\n"
            text += "Rotation Period: " + str(round(body.sidereal_rotation_period / 60 / 60 / 24, 2)) + "days\n"
            self.label_planet_info.set_text(text)
            self.label_planet_info_manager.draw()

        for manager in self.managers:
            manager.draw()

        if not self.controls.mouse_locked:
            for manager in self.managers_when_not_locked:
                manager.draw()
 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 __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)
Ejemplo n.º 21
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):
     self.coinsText = Label("Coins: 0")
     Manager.__init__(self,
         self.coinsText,
         window=g.gameEngine.window,
         batch=g.guiBatch,
         theme=g.theme,
         is_movable=False,
         anchor=ANCHOR_TOP,
         offset=(0,-25))
class TestContainer(TestPygletGUI):
    """
    This test case tests basic functionality of
    a container. We use an empty widgets for this.
    """
    def setUp(self):
        super(TestContainer, self).setUp()

        self.container = Container(
            [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_set_manager(self):
        """
        Tests that the manager is set for every children.
        """
        # manager size is correct
        for item in self.container.content:
            self.assertTrue(item.has_manager())

    def test_deletion(self):
        self.manager.delete()

        # confirm that widget is also deleted
        for item in self.container.content:
            self.assertFalse(item.has_manager())

    def test_add(self):
        """
        Tests that we can add a new item.
        """
        item = Viewer(width=50, height=50)
        self.container.add(item)

        self.assertEqual(item.has_manager(), True)

    def test_remove(self):
        """
        Tests that we can remove a new item.
        """
        item = self.container.content[0]
        self.container.remove(item)

        self.assertEqual(item.has_manager(), False)

    def tearDown(self):
        self.manager.delete()
        super(TestContainer, self).tearDown()
Ejemplo n.º 24
0
    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)
Ejemplo n.º 25
0
    def __init__(self, text="", window=None, batch=None, group=None,
                 theme=None, on_escape=None, have_focus=False):
        def on_ok(_):
            if on_escape is not None:
                on_escape(self)
            self.delete()

        button = FocusButton("Ok", on_press=on_ok)
        Manager.__init__(self, content=Frame(VerticalContainer(
                         [Label(text), button])),
                         window=window, batch=batch, group=group,
                         theme=theme, is_movable=True)
        Manager.set_next_focus(self, 1)
Ejemplo n.º 26
0
    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)
Ejemplo n.º 27
0
    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)
Ejemplo n.º 28
0
 def __init__(self):
     gameSettingsButton = HighlightedButton(label="Game Settings",on_release=self.gameSettings,width=120,height=30)
     settingsButton = HighlightedButton(label="Video Settings",on_release=self.settings,width=120,height=30)
     keybindingsButton = HighlightedButton(label="Keybindings",on_release=self.keybindings,width=120,height=30)
     helpButton = HighlightedButton(label="Help",on_release=self.help,width=120,height=30)
     disconnectButton = HighlightedButton(label="Disconnect",on_release=self.disconnect,width=120,height=30)
     closeButton = HighlightedButton(label="Close",on_release=self.delete,width=120,height=30)
     quitButton = HighlightedButton(label="Quit",on_release=self.onQuit,width=120,height=30)
     Manager.__init__(self,
         Frame(VerticalContainer(content=[gameSettingsButton,settingsButton,keybindingsButton,helpButton,disconnectButton,quitButton,Spacer(0,20),closeButton])),
         window=g.screen,
         batch=g.guiBatch,
         is_movable=False,
         theme=g.theme)
Ejemplo n.º 29
0
class TestContainer(TestPygletGUI):
    """
    This test case tests basic functionality of
    a container. We use an empty widgets for this.
    """

    def setUp(self):
        super().setUp()

        self.container = Container([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_set_manager(self):
        """
        Tests that the manager is set for every children.
        """
        # manager size is correct
        for item in self.container.content:
            self.assertTrue(item.has_manager())

    def test_deletion(self):
        self.manager.delete()

        # confirm that widget is also deleted
        for item in self.container.content:
            self.assertFalse(item.has_manager())

    def test_add(self):
        """
        Tests that we can add a new item.
        """
        item = Viewer(width=50, height=50)
        self.container.add(item)

        self.assertEqual(item.has_manager(), True)

    def test_remove(self):
        """
        Tests that we can remove a new item.
        """
        item = self.container.content[0]
        self.container.remove(item)

        self.assertEqual(item.has_manager(), False)

    def tearDown(self):
        self.manager.delete()
        super().tearDown()
Ejemplo n.º 30
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)
Ejemplo n.º 31
0
 def __init__(self, content, x, y):
     self.frame = Frame(content, path='frame_alternative')
     #print content.__dict__
     #print "CONTENTHEIGHT",content.height
     #print content.__dict__
     #frame.expand(content.width,content.label.content_height)
     #print content.__dict__
     Manager.__init__(self,
                      self.frame,
                      window=g.screen,
                      batch=g.guiBatch,
                      is_movable=False,
                      offset=(x, y),
                      theme=g.theme,
                      anchor=ANCHOR_BOTTOM_LEFT)
Ejemplo n.º 32
0
    def test_new_manager_without_window(self):
        other_manager = Manager(Viewer(width=50, height=50), batch=self.batch, theme=self.theme)

        # confirm that a new manager without window starts
        # with no size
        self.assertTrue(other_manager.width, 0)

        # change the manager's window
        other_manager.window = self.window

        # confirm it has a size.
        self.assertEqual(self.manager.width, 50)

        # confirm it is in the correct position
        self.assertEqual(self.manager.x, self.window.width / 2 - self.manager.width / 2)
Ejemplo n.º 33
0
class TestSpacer(TestPygletGUI):
    """
    Tests that the spacer is working correctly
    inside containers.
    """
    def setUp(self):
        TestPygletGUI.setUp(self)

        self.widgets = []
        for i in range(2):
            self.widgets.append(Viewer(width=100, height=50))
        for i in range(2):
            self.widgets.append(Viewer(width=20, height=50))

        self.container = VerticalContainer([
            HorizontalContainer([self.widgets[0], self.widgets[1]], padding=0),
            HorizontalContainer([
                Spacer(), self.widgets[2],
                Spacer(), self.widgets[3],
                Spacer()
            ],
                                padding=0)
        ],
                                           padding=0)

        self.manager = Manager(self.container,
                               window=self.window,
                               batch=self.batch,
                               theme=self.theme)

    def test_initial(self):
        self.assertEqual(self.container.width, 200)

        # space left for the spacers occupy:
        width_left = 200 - 40

        # expected spacer size
        spacer_size = int(width_left / 3.)

        # Spacers should occupy same space
        self.assertEqual(self.widgets[2].x, self.container.x + spacer_size)
        self.assertEqual(
            self.widgets[3].x,
            self.widgets[2].x + self.widgets[2].width + spacer_size)

    def tearDown(self):
        self.manager.delete()
        super(TestSpacer, self).tearDown()
Ejemplo n.º 34
0
    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))
Ejemplo n.º 35
0
class GenericButtonTest(object):
    def setUp(self):
        self.manager = Manager(self.button, window=self.window, batch=self.batch, theme=self.theme)

    def test_creation(self):
        self.assertNotEqual(self.button.width, 0)
        self.assertNotEqual(self.button.height, 0)
        self.assertEqual(self.button.is_loaded, True)

    def test_press(self):
        self.button.on_mouse_press(0, 0, None, None)
        self.assertEqual(self.button.is_pressed, True)

    def test_delete(self):
        self.manager.delete()
        self.assertEqual(self.button.is_loaded, False)
Ejemplo n.º 36
0
    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)
Ejemplo n.º 37
0
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)
Ejemplo n.º 38
0
    def load_elem(self, elem):
        Manager(elem.viewer(),
                window=self,
                batch=self.batch,
                **elem.manager_settings())

        self.all_elements[elem.__class__.__name__] = elem
Ejemplo n.º 39
0
class GenericButtonTest(object):
    def setUp(self):
        self.manager = Manager(self.button, window=self.window, batch=self.batch, theme=self.theme)

    def test_creation(self):
        self.assertNotEqual(self.button.width, 0)
        self.assertNotEqual(self.button.height, 0)
        self.assertEqual(self.button.is_loaded, True)

    def test_press(self):
        self.button.on_mouse_press(0, 0, None, None)
        self.assertEqual(self.button.is_pressed, True)

    def test_delete(self):
        self.manager.delete()
        self.assertEqual(self.button.is_loaded, False)
Ejemplo n.º 40
0
    def setUp(self):
        super().setUp()

        self.container = GridContainer([[Viewer(width=50, height=50), Viewer(width=50, height=50)],
                                     [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 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)
Ejemplo n.º 42
0
	def build_building_gui(self, selected_building):
		building = selected_building
		produce_content = [Label(text='Produce')]
		for resource in building.producable_resources:
			produce_button = GroupButton(
				group_id='action-gui-buttons',
				label=resource.name,
				on_press=lambda x: self.handle_building_click(x, produce_button, building, Produce(building, resource, selected_building.container.remaining_capacity(resource))),
				)
			produce_content.append(produce_button)
		produce_container = HorizontalContainer(produce_content)

		action_container = VerticalContainer([
			produce_container,
			])
		self.action_gui_batch = pyglet.graphics.Batch()
		self.action_gui_manager = Manager(
			action_container,
			window=self.window,
			theme=self.theme,
			batch=self.action_gui_batch,
			)
		self.action_gui_manager.set_position(
			#it's on the right as a hack to fix the Manager bug
			self.window.width - action_container.width - 30,
			self.window.height - action_container.height - 10,
			)
		self.action_gui_manager.is_movable = False
Ejemplo n.º 43
0
 def __init__(self):
     super().__init__()
     self.hud_batch = pyglet.graphics.Batch()
     self.doc = Document(self.last_message, width=800, height=100, is_fixed_size=True)
     self.frame = Frame(self.doc)
     self.manager = Manager(self.frame, window=pygsty.engine(), batch=self.hud_batch, theme=config.ui_theme)
     self.manager.set_position(0, 0)
     self._latest_event = None
     self._log = self.last_message
Ejemplo n.º 44
0
class TestButton(TestPygletGUI):

    def setUp(self):
        TestPygletGUI.setUp(self)
        self.button = Button(label="test")
        self.manager = Manager(self.button, window=self.window, batch=self.batch, theme=self.theme)

    def test_creation(self):
        self.assertNotEqual(self.button.width, 0)
        self.assertNotEqual(self.button.height, 0)
        self.assertEqual(self.button.is_loaded, True)

    def test_press(self):
        self.button.on_mouse_press(0, 0, None, None)
        self.assertEqual(self.button.is_pressed, True)

    def test_delete(self):
        self.manager.delete()

        self.assertEqual(self.button.is_loaded, False)
Ejemplo n.º 45
0
    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)
Ejemplo n.º 46
0
class TestSpacer(TestPygletGUI):
    """
    Tests that the spacer is working correctly
    inside containers.
    """
    def setUp(self):
        TestPygletGUI.setUp(self)

        self.widgets = []
        for i in range(2):
            self.widgets.append(Viewer(width=100, height=50))
        for i in range(2):
            self.widgets.append(Viewer(width=20, height=50))

        self.container = VerticalContainer([HorizontalContainer([self.widgets[0],
                                                           self.widgets[1]], padding=0),
                                         HorizontalContainer([Spacer(),
                                                           self.widgets[2],
                                                           Spacer(),
                                                           self.widgets[3],
                                                           Spacer()], padding=0)], padding=0)

        self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)

    def test_initial(self):
        self.assertEqual(self.container.width, 200)

        # space left for the spacers occupy:
        width_left = 200 - 40

        # expected spacer size
        spacer_size = int(width_left/3.)

        # Spacers should occupy same space
        self.assertEqual(self.widgets[2].x, self.container.x + spacer_size)
        self.assertEqual(self.widgets[3].x, self.widgets[2].x + self.widgets[2].width + spacer_size)

    def tearDown(self):
        self.manager.delete()
        super(TestSpacer, self).tearDown()
Ejemplo n.º 47
0
class TestSlider(TestPygletGUI):

    def setUp(self):
        TestPygletGUI.setUp(self)
        self.slider = HorizontalSlider(min_value=0, max_value=10)
        self.manager = Manager(self.slider, window=self.window, batch=self.batch, theme=self.theme)

    def test_set_value(self):
        self.slider.set_knob_pos(0.5)
        self.assertEqual(self.slider.value, 5)

    def test_mouse_slide(self):

        # push the slider to the minimum
        self.slider.on_mouse_press(0, 0, None, None)
        self.assertEqual(self.slider.value, 0)

        # push the slider to the maximum
        self.slider.on_mouse_press(10000, 0, None, None)
        self.assertEqual(self.slider.value, 10)

    def tearDown(self):
        self.manager.delete()
        super(TestSlider, self).tearDown()
Ejemplo n.º 48
0
class TestInput(TestPygletGUI):

    def setUp(self):
        TestPygletGUI.setUp(self)
        self.input = TextInput(text="test")
        self.manager = Manager(self.input, window=self.window, batch=self.batch, theme=self.theme)

    def test_focus(self):
        self.input.on_gain_focus()

        self.assertEqual(self.input.is_focus(), True)

        self.input.on_lose_focus()
        self.assertEqual(self.input.is_focus(), False)

    def test_input(self):
        self.assertEqual(self.input.get_text(), "test")
        self.input.on_gain_focus()
        self.input.on_text("text")
        self.assertEqual(self.input.get_text(), "text")  # it starts with all text selected, so 'test' is erased.
        self.input.on_text(" text")
        self.assertEqual(self.input.get_text(), "text text")

    def test_motion(self):
        self.input.on_gain_focus()

        self.input.on_text_motion(pyglet.window.key.MOTION_RIGHT)
        # 'test|' where | is the carret.
        self.assertEqual(self.input.get_text(), "test")

        self.input.on_text_motion(pyglet.window.key.MOTION_BACKSPACE)
        # 'tes|'
        self.assertEqual(self.input.get_text(), "tes")

        self.input.on_text_motion(pyglet.window.key.MOTION_LEFT)
        # 't|es'
        self.input.on_text_motion(pyglet.window.key.MOTION_LEFT)

        self.input.on_text_motion(pyglet.window.key.MOTION_DELETE)
        # 't|s'
        self.assertEqual(self.input.get_text(), "ts")

    def test_delete(self):
        self.manager.delete()

    def test_delete_without_focus(self):
        self.input.on_gain_focus()
        self.input.on_lose_focus()
        self.manager.delete()

    def test_delete_with_focus(self):
        self.input.on_gain_focus()
        self.manager.delete()
Ejemplo n.º 49
0
    def setUp(self):
        TestPygletGUI.setUp(self)

        self.widgets = []
        for i in range(2):
            self.widgets.append(Viewer(width=100, height=50))
        for i in range(2):
            self.widgets.append(Viewer(width=20, height=50))

        self.container = VerticalContainer([HorizontalContainer([self.widgets[0],
                                                           self.widgets[1]], padding=0),
                                         HorizontalContainer([Spacer(),
                                                           self.widgets[2],
                                                           Spacer(),
                                                           self.widgets[3],
                                                           Spacer()], padding=0)], padding=0)

        self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
Ejemplo n.º 50
0
	def build_status_gui(self):
		self.status_box = Document(
			pyglet.text.document.UnformattedDocument(),
			width=self.window.width*0.9,
			height=self.window.height/4,
			is_fixed_size=True,
			)
		status_frame = Frame(self.status_box)
		self.status_gui_batch = pyglet.graphics.Batch()
		self.status_gui_manager = Manager(
			status_frame,
			window=self.window,
			theme=self.theme,
			batch=self.status_gui_batch,
			)
		self.status_gui_manager.set_position(
			(self.window.width - status_frame.width)/2,
			10,
			)
		self.status_gui_manager.is_movable = False
Ejemplo n.º 51
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)
Ejemplo n.º 52
0
    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
Ejemplo n.º 53
0
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()
Ejemplo n.º 54
0
 def setUp(self):
     TestPygletGUI.setUp(self)
     self.button = Button(label="test")
     self.manager = Manager(self.button, window=self.window, batch=self.batch, theme=self.theme)
Ejemplo n.º 55
0
class TestDialog(TestPygletGUI):
    """
    This test case tests basic functionality of
    widget+manager. We use an empty widget for this.
    """

    def setUp(self):
        super(TestDialog, self).setUp()

        self.widget = Viewer(width=50, height=50)
        self.manager = Manager(self.widget, window=self.window, batch=self.batch, theme=self.theme)

    def test_top_down_draw(self):
        """
        Tests that the manager's size was set
        according to the child size.
        """
        # manager size is correct
        self.assertEqual(self.manager.width, 50)
        self.assertEqual(self.manager.height, 50)

        # widget is centered in the window
        self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2)
        self.assertEqual(self.widget.y, self.window.height/2 - self.widget.height/2)

    def test_bottom_up_draw(self):
        """
        Tests that the manager's size is modified
        if we set a new size to the widget.
        """
        self.widget.width = 60
        self.widget.parent.reset_size()

        # manager size was reset
        self.assertEqual(self.manager.width, self.widget.width)

        # widget and manager were re-centered in the window
        self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2)
        self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2)

    def test_substitute_widget(self):
        """
        Tests substitution of manager's content
        by other widget.
        """
        self.new_widget = Viewer(width=60, height=50)

        self.manager.content = self.new_widget

        self.assertTrue(not self.widget.has_manager())
        self.assertFalse(self.widget.is_loaded)

        self.assertTrue(self.new_widget.has_manager())
        self.assertTrue(self.new_widget.is_loaded)

        # manager size was reset, new widget position is correct
        self.assertEqual(self.manager.width, self.new_widget.width)
        self.assertEqual(self.new_widget.x, self.window.width/2 - self.new_widget.width/2)

    def test_window_resize(self):
        self.window.width = 100
        self.manager.on_resize(self.window.width, self.window.height)

        # manager size didn't changed.
        self.assertEqual(self.manager.width, 50)

        # manager is still centered.
        self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2)

    def test_change_offset(self):
        self.manager.offset = (10, 0)

        # manager is centered with an offset.
        self.assertEqual(self.manager.x - 10, self.window.width/2 - self.manager.width/2)

    def test_change_anchor(self):
        self.manager.anchor = pyglet_gui.constants.ANCHOR_TOP_LEFT

        # manager is in correct position.
        self.assertEqual(self.manager.x, 0)

    def test_new_manager_is_on_top(self):
        other_manager = Manager(Viewer(width=50, height=50), window=self.window,
                              batch=self.batch,
                              theme=self.theme)

        # confirm that a new manager starts always on top
        self.assertTrue(other_manager.root_group.is_on_top())

    def test_new_manager_without_window(self):
        other_manager = Manager(Viewer(width=50, height=50),
                              batch=self.batch,
                              theme=self.theme)

        # confirm that a new manager without window starts
        # with no size
        self.assertTrue(other_manager.width, 0)

        # change the manager's window
        other_manager.window = self.window

        # confirm it has a size.
        self.assertEqual(self.manager.width, 50)

        # confirm it is in the correct position
        self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2)

    def test_deletion(self):
        self.manager.delete()

        # confirm that widget is also deleted
        self.assertTrue(not self.widget.has_manager())

    def tearDown(self):
        self.manager.delete()
        super(TestDialog, self).tearDown()
Ejemplo n.º 56
0
    def setUp(self):
        super(TestDialog, self).setUp()

        self.widget = Viewer(width=50, height=50)
        self.manager = Manager(self.widget, window=self.window, batch=self.batch, theme=self.theme)
class TestHorizontalContainer(TestPygletGUI):
    """
    This test case tests basic functionality of
    an horizontal container.
    """

    def setUp(self):
        super().setUp()

        self.container = HorizontalContainer([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 x is the left x (container.x)
        self.assertEqual(self.container.content[0].x,
                         self.container.x)

        # second widget x is the left x (container.x + container.content[0].width)
        # plus the padding (self.container.padding)
        self.assertEqual(self.container.content[1].x,
                         self.container.x + self.container.content[0].width
                         + self.container.padding)

    def test_top_down_draw(self):
        """
        Tests that the manager's size was set according to the child size.
        """
        # manager size is correct
        self.assertEqual(self.manager.width, 100 + self.container.padding)
        self.assertEqual(self.manager.height, 50)

        # 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()

        # manager width was set
        self.assertEqual(self.manager.width, 110 + self.container.padding)
        # container height was set
        self.assertEqual(self.container.height, 60)

        # container and manager were re-centered in the window
        self.assertEqual(self.container.x, self.window.width/2 - self.container.width/2)
        self.assertEqual(self.manager.y, self.window.height/2 - self.manager.height/2)

        self._test_content_position()

    def test_add_widget(self):
        self.container.add(Viewer(width=50, height=50))

        self.assertEqual(self.manager.width, 150 + 2*self.container.padding)
        self.assertEqual(self.manager.height, 50)

        self._test_content_position()

    def test_remove_widget(self):
        self.container.remove(self.container.content[0])

        self.assertEqual(self.manager.width, 50 + self.container.padding)
        self.assertEqual(self.manager.height, 50)

    def tearDown(self):
        self.manager.delete()
        super().tearDown()
Ejemplo n.º 58
0
 def setUp(self):
     self.manager = Manager(self.button, window=self.window, batch=self.batch, theme=self.theme)
Ejemplo n.º 59
0
class TestGridContainer(TestPygletGUI):
    """
    This test case tests basic functionality of
    a grid container.
    """

    def setUp(self):
        super().setUp()

        self.container = GridContainer([[Viewer(width=50, height=50), Viewer(width=50, height=50)],
                                     [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_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, 100 + self.container.padding)
        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)

    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][0].width = 60
        self.container.content[0][0].height = 60
        self.container.content[0][0].parent.reset_size()

        # container width was set
        self.assertEqual(self.container.width, 110 + self.container.padding)
        # 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)

    def test_add_row(self):
        """
        Tests that if we add a row with 3 columns,
        we have the correct sizes.
        """
        self.container.add_row([Viewer(width=50, height=50),
                                Viewer(width=50, height=50),
                                Viewer(width=50, height=50)])

        self.assertEqual(self.container.width, 150 + 2 * self.container.padding)
        self.assertEqual(self.container.height, 150 + 2 * self.container.padding)

    def test_add_column(self):
        """
        Tests that if we add a column with 3 rows,
        we have the correct sizes.
        """
        self.container.add_column([Viewer(width=50, height=50),
                                   Viewer(width=50, height=50),
                                   Viewer(width=50, height=50)])

        self.assertEqual(self.container.width, 150 + 2 * self.container.padding)
        self.assertEqual(self.container.height, 150 + 2 * self.container.padding)

    def test_substitute_element(self):
        self.container.set(1, 1, Viewer(width=100, height=50))

        self.assertEqual(self.container.width, 150 + self.container.padding)
        self.assertEqual(self.container.height, 100 + self.container.padding)

    def tearDown(self):
        self.manager.delete()
        super().tearDown()
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()