def test_deck(): green = glooey.Placeholder(50, 50, 'green') deck.add_state('a', green) yield "Add state 'a'; show a green placeholder" orange = glooey.Placeholder(50, 50, 'orange') deck.add_state('b', orange) yield "Add state 'b'; keep showing state 'a'" deck.state = 'b' yield "Change to state 'b'; show an orange placeholder" purple = glooey.Placeholder(50, 50, 'purple') deck.add_state('b', purple) yield "Replace state 'b'; show a purple placeholder." deck.reset_states(a=orange, c=green) yield "Reset the deck with states 'a' and 'c'; don't show anything." deck.state = 'c' yield "Change to state 'c'; show a green placeholder" deck.remove_state('c') yield "Remove state 'c'; don't show anything." deck.state = 'a' yield "Change to state 'a'; show an orange placeholder" deck.clear() yield "Clear the deck; don't show anything."
def __init__(self, interface): super().__init__() self.interface = interface self.vbox = glooey.VBox() self.vbox.add(LabelWhite("Hello world")) self.vbox.add(glooey.Placeholder()) self.vbox.add(glooey.Placeholder()) self._attach_child(self.vbox)
def __init__(self): super().__init__() for i in range(5): for j in range(5): self.add(i, j, glooey.Placeholder(150, 150)) self.add(2, 2, glooey.EventLogger(150, 150, 'orange'))
def test_layers(): purple = glooey.Placeholder(48, 50, 'purple') board.move(widget, center_left=(175, 150), layer=1) board.add(purple, center_left=(175, 150), layer=2) yield "The purple widget on top." board.move(widget, center_left=(175, 150), layer=2) board.move(purple, center_left=(175, 150), layer=1) yield "The orange widget on top." board.remove(purple) yield "Remove the purple widget"
def test_size_hint(): # Test setting and change the size hints. w = glooey.Placeholder(50, 50) w.alignment = 'center' gui.clear() gui.add(w) yield "A 50x50 placeholder." w.width_hint = 200 yield "A 200x50 placeholder." w.width_hint = 0 w.height_hint = 100 yield "A 50x100 placeholder." w.height_hint = 0 w.size_hint = 200, 100 yield "A 200x100 placeholder." w.size_hint = 0, 0 # Test setting class-wide custom size hints. class Widget200x0(glooey.Placeholder): # custom_alignment = 'center' custom_width_hint = 200 gui.clear() gui.add(Widget200x0(50, 50)) yield "A custom 200x50 placeholder." class Widget0x100(glooey.Placeholder): # custom_alignment = 'center' custom_height_hint = 100 gui.clear() gui.add(Widget0x100(50, 50)) yield "A custom 50x100 placeholder." class Widget200x100(glooey.Placeholder): # custom_alignment = 'center' custom_size_hint = 200, 100 gui.clear() gui.add(Widget200x100(50, 50)) yield "A custom 200x100 placeholder."
def test_checkbox(): yield "Green button with orange over and purple down states." button.disable() yield "Grey inactive button (no rollover)." button.enable() gui.clear() hbox = glooey.HBox() proxy = glooey.Placeholder(100, 10) hbox.pack(button) hbox.pack(proxy) hbox.alignment = 'center' hbox.padding = 10 gui.add(hbox) button.add_proxy(proxy) yield "Rollover or click the placeholder to control the button." gui.clear() hbox.remove(button) gui.add(button)
def test_padding(): yield "Show both widgets." first.hide() yield "Hide the first widget." first.unhide() second.hide() yield "Hide the second widget." hbox.hide() yield "Hide the hbox." third = glooey.Placeholder() hbox.add(third) yield "Add a third widget to the hbox, but don't show it." hbox.unhide() yield "Unhide the hbox, keep hiding the second widget." hbox.remove(third) yield "Remove the third widget from the hbox." second.unhide()
Forward = MyButton Backward = MyButton Grip = MyButton class MyForm(glooey.Form): class Base(glooey.Background): custom_outline = 'green' class Focused(glooey.Background): custom_outline = 'orange' hbox = MyHBox() text = MyForm() scroll = MyScrollBox() content = glooey.Placeholder(200, 300) hbox.add(text, 'expand') hbox.add(scroll, 'expand') scroll.add(content) window = pyglet.window.Window(width=450, height=200) gui = glooey.Gui(window) gui.add(hbox) @run_demos.on_space(gui) def test_40(): yield "Focus on the form (left), then drag the scroll grip." pyglet.app.run()
class Decoration(glooey.Background): custom_center = pyglet.resource.texture('center.png') custom_top = pyglet.resource.texture('top.png') custom_bottom = pyglet.resource.texture('bottom.png') custom_left = pyglet.resource.texture('left.png') custom_right = pyglet.resource.texture('right.png') custom_top_left = pyglet.resource.image('top_left.png') custom_top_right = pyglet.resource.image('top_right.png') custom_bottom_left = pyglet.resource.image('bottom_left.png') custom_bottom_right = pyglet.resource.image('bottom_right.png') class Box(glooey.Bin): # These paddings are asymmetric because the border images have a # 3px shadow on the bottom left side, although you can't see it # on a black background. custom_right_padding = 14 custom_top_padding = 14 custom_left_padding = 17 custom_bottom_padding = 17 window = pyglet.window.Window() gui = glooey.Gui(window) frame = WesnothFrame() frame.add(glooey.Placeholder(300, 200)) gui.add(frame) pyglet.app.run()
#!/usr/bin/env python3 import glooey import pyglet window = pyglet.window.Window() gui = glooey.Gui(window) hbox = glooey.HBox() hbox.add(glooey.Placeholder()) hbox.add(glooey.Placeholder()) gui.add(hbox) pyglet.app.run()
#!/usr/bin/env python3 import glooey import pyglet win = pyglet.window.Window(800, 600) gui = glooey.Gui(win) box = glooey.Placeholder(50, 50) box.padding = 100 box.alignment = "fill right" gui.add(box) #p = glooey.Placeholder(50, 50) #box.add(p) box.debug_placement_problems() pyglet.app.run()
return right - left, top - bottom def do_resize_children(self): for child, offset in self._yield_offsets(): rect = child.claimed_rect.copy() rect.center = self.rect.center + offset child._resize(rect) def _yield_offsets(self): N = len(self._children) for i, child in enumerate(self._children): offset = self.radius * Vector.from_degrees(360 * i / N) yield child, offset window = pyglet.window.Window() gui = glooey.Gui(window) ring = Ring(radius=150) for i in range(10): green = glooey.Placeholder(50, 50) ring.add(green) for i in range(0, 10, 2): orange = glooey.Placeholder(50, 50, 'orange') ring.replace(ring.children[i], orange) gui.add(ring) pyglet.app.run()
#!/usr/bin/env python3 import pyglet import glooey import run_demos window = pyglet.window.Window() gui = glooey.Gui(window) bin = glooey.Bin() widget = glooey.Placeholder(100, 100) bin.add(widget) gui.add(bin) @run_demos.on_space(gui) def test_bin(): bin.add(widget) yield "Put a widget in the bin." bin.clear() yield "Clear the bin." pyglet.app.run()
#!/usr/bin/env python3 import pyglet import glooey import run_demos window = pyglet.window.Window() gui = glooey.Gui(window) hbox = glooey.HBox() hbox.padding = 30 first = glooey.Placeholder() second = glooey.Placeholder() hbox.add(first) hbox.add(second) gui.add(hbox) @run_demos.on_space(gui) # def test_padding(): yield "Show both widgets." first.hide() yield "Hide the first widget." first.unhide() second.hide() yield "Hide the second widget." hbox.hide() yield "Hide the hbox."
custom_top_right = pyglet.resource.image('top_right.png') custom_bottom_left = pyglet.resource.image('bottom_left.png') custom_bottom_right = pyglet.resource.image('bottom_right.png') class Box(glooey.Grid): custom_right_padding = 14 custom_top_padding = 14 custom_left_padding = 17 custom_bottom_padding = 17 custom_cell_padding = 9 class Buttons(glooey.HBox): custom_cell_padding = 3 custom_alignment = 'right' class YesButton(WesnothButton): custom_text = 'Ok' class NoButton(WesnothButton): custom_text = 'Cancel' window = pyglet.window.Window() gui = glooey.Gui(window) dialog = WesnothDialog() dialog.add(glooey.Placeholder(300, 200)) dialog.open(gui) pyglet.app.run()
#!/usr/bin/env python3 import glooey import pyglet window = pyglet.window.Window() gui = glooey.Gui(window) widget = glooey.Placeholder() widget.alignment = 'top left' gui.add(widget) widget.debug_drawing_problems() pyglet.app.run()
class TestVScrollBar(TestHVScrollBar, glooey.VScrollBar): pass window = pyglet.window.Window() gui = glooey.Gui(window) grid = glooey.Grid(2, 2) frame = glooey.Frame() pane = TestScrollPane() hbar = TestHScrollBar(pane) vbar = TestVScrollBar(pane) big_content = TestScrollContent() small_content = glooey.Placeholder(100, 100) grid.size_hint = 200, 200 grid.padding = 10 grid.set_row_height(1, 0) grid.set_col_width(1, 0) grid.alignment = 'center' frame.alignment = 'fill' frame.decoration.outline = 'green' pane.add(big_content) frame.add(pane) grid.add(0, 0, frame) grid.add(0, 1, vbar) grid.add(1, 0, hbar) gui.add(grid)
#!/usr/bin/env python3 import pyglet import glooey window = pyglet.window.Window() gui = glooey.Gui(window) hbox = glooey.HBox() hbox.padding = 10 left = glooey.Placeholder() right = glooey.Placeholder() hbox.add(left) hbox.add(right) gui.add(hbox) pyglet.app.run()
#!/usr/bin/env python3 import glooey import pyglet window = pyglet.window.Window() gui = glooey.Gui(window) grid = glooey.Grid(2, 2) grid.padding = 10 grid.add(0, 0, glooey.Placeholder()) grid.add(0, 1, glooey.Placeholder()) grid.add(1, 0, glooey.Placeholder()) grid.add(1, 1, glooey.Placeholder()) gui.add(grid) pyglet.app.run()