本文整理汇总了Python中pyglet_gui.manager.Manager类的典型用法代码示例。如果您正苦于以下问题:Python Manager类的具体用法?Python Manager怎么用?Python Manager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UIResourceList
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()
示例2: EventLogController
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()
示例3: __init__
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)
]
示例4: VerticalHUD
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()
示例5: GUI
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()
示例6: __init__
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)
示例7: TestContainer
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()
示例8: test_new_manager_without_window
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)
示例9: GenericButtonTest
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)
示例10: build_building_gui
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
示例11: setUp
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)
示例12: setUp
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)
示例13: __init__
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
示例14: TestButton
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)
示例15: TestSpacer
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()