示例#1
0
def test_hbox():

    # Test adding and removing widgets.
    for i in range(2):
        hbox.add(glooey.EventLogger(50, 50))
    yield "Make an HBox with 2 cells."

    left = glooey.EventLogger(50, 50, 'orange')
    hbox.add_left(left)
    yield "Add a orange widget on the left."

    right = glooey.EventLogger(50, 50, 'orange')
    hbox.add_right(right)
    yield "Add a orange widget on the right."

    middle = glooey.EventLogger(50, 50, 'orange')
    hbox.insert(middle, 2)
    yield "Insert a orange widget in the middle."

    hbox.replace(middle, glooey.EventLogger(50, 50, 'green'))
    yield "Replace the orange widget in the middle with a green one."

    hbox.remove(left)
    yield "Remove the widget on the left."

    hbox.remove(right)
    yield "Remove the widget on the right."

    # Test padding.
    hbox.padding = 10
    yield "Pad the widgets by 10px."
    hbox.padding = 0

    hbox.cell_padding = 10
    yield "Only pad between the widgets."
    hbox.cell_padding = 0

    # Test alignment.
    hbox.alignment = 'center'
    yield "Center-align the whole HBox."
    hbox.alignment = 'fill'

    hbox.cell_alignment = 'center'
    yield "Center-align the widgets."
    hbox.cell_alignment = 'fill'

    # Get ready to restart the tests (and make sure clear() works).
    hbox.clear()
    yield "Clear the HBox."
示例#2
0
def test_vbox():

    # Test adding and removing widgets.
    for i in range(2):
        vbox.add(glooey.EventLogger(50, 50))
    yield "Make an VBox with 2 cells."

    top = glooey.EventLogger(50, 50, 'orange')
    vbox.add_top(top)
    yield "Add a orange widget on the top."

    bottom = glooey.EventLogger(50, 50, 'orange')
    vbox.add_bottom(bottom)
    yield "Add a orange widget on the bottom."

    middle = glooey.EventLogger(50, 50, 'orange')
    vbox.insert(middle, 2)
    yield "Insert a orange widget in the middle."

    vbox.replace(middle, glooey.EventLogger(50, 50, 'green'))
    yield "Replace the orange widget in the middle with a green one."

    vbox.remove(top)
    yield "Remove the widget on the top."

    vbox.remove(bottom)
    yield "Remove the widget on the bottom."

    # Test padding.
    vbox.padding = 10
    yield "Pad the widgets by 10px."
    vbox.padding = 0

    vbox.cell_padding = 10
    yield "Only pad between the widgets."
    vbox.cell_padding = 0

    # Test alignment.
    vbox.alignment = 'center'
    yield "Center-align the whole VBox."
    vbox.alignment = 'fill'

    vbox.cell_alignment = 'center'
    yield "Center-align the widgets."
    vbox.cell_alignment = 'fill'

    # Get ready to restart the tests (and make sure clear() works).
    vbox.clear()
    yield "Clear the VBox."
示例#3
0
    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'))
示例#4
0
def test_gui():
    gui.set_cursor(pyglet.image.load('assets/misc/cursor_flipped.png'),
                   (13, 0))
    yield "Use a cursor with a bottom-right hotspot."
    gui.set_cursor(pyglet.image.load('assets/misc/cursor.png'), (0, 18))

    popup = glooey.EventLogger(0.2 * w,
                               0.2 * h,
                               color='orange',
                               align='center')
    gui.add(popup)
    yield "Mouse events should preferentially go to the pop-up."
    gui.remove(popup)
示例#5
0
#!/usr/bin/env python3

import pyglet
import glooey
import run_demos

window = pyglet.window.Window()
gui = glooey.Gui(window)
grid = glooey.Grid()
widgets = { #
        (0,0): glooey.EventLogger(50, 50),
        (0,1): glooey.EventLogger(50, 50),
        (1,0): glooey.EventLogger(50, 50),
        (1,1): glooey.EventLogger(50, 50),
}
gui.add(grid)


@run_demos.on_space(gui)  #
def test_grid():
    # Test adding and removing cells.
    for row, col in widgets:
        grid.add(row, col, widgets[row, col])
    assert grid.num_rows == 2
    assert grid.num_cols == 2
    yield "Make a 2x2 grid."

    grid.remove(1, 1)
    assert grid.num_rows == 2
    assert grid.num_cols == 2
    yield "Remove the bottom right cell."
示例#6
0
 def layer(size, color='green'):  #
     size = size * (window.height - 20)
     return glooey.EventLogger(size, size, color, align='center')
示例#7
0
def interactive_mover_tests():
    unpadded = glooey.EventLogger(50, 50, 'orange')
    padded = glooey.EventLogger(10, 10, 'purple')
    padded.padding = 20

    for widget in unpadded, padded:
        widget.alignment = 'top right'
        mover.add(widget)
        yield f"Add the {'padded' if widget is padded else 'unpadded'} widget to the top right corner of the mover."

        # Test panning by distance.

        mover.pan(-25, 0)
        yield "Pan left 25 px."

        mover.pan(-1000, 0)
        yield "Pan past the left edge."

        mover.pan(0, -25)
        yield "Pan down 25 px."

        mover.pan(0, -1000)
        yield "Pan past the bottom edge."

        mover.pan(25, 0)
        yield "Pan right 25 px."

        mover.pan(1000, 0)
        yield "Pan past the right edge."

        mover.pan(0, 25)
        yield "Pan up 25 px."

        mover.pan(0, 1000)
        yield "Pan past the top edge."

        # Test panning by percent.

        mover.pan_percent(-0.5, 0)
        yield "Pan 50% to the left."

        mover.pan_percent(-1.0, 0)
        yield "Pan past the left edge."

        mover.pan_percent(0, -0.5)
        yield "Pan 50% to the bottom."

        mover.pan_percent(0, -1.0)
        yield "Pan past the bottom edge."

        mover.pan_percent(0.5, 0)
        yield "Pan 50% to the right."

        mover.pan_percent(10.0, 0)
        yield "Pan past the right edge."

        mover.pan_percent(0, 0.5)
        yield "Pan 50% to the top."

        mover.pan_percent(0, 1.0)
        yield "Pan past the top edge."

        # Test jumping by distance.

        mover.jump(75, 75)
        yield "Jump to the center."

        mover.jump(10, 10)
        yield "Jump 10 px from the bottom-left corner."

        mover.jump(-1000, -1000)
        yield "Jump past the bottom-left corner."

        mover.jump(140, 140)
        yield "Jump 10 px from the top-right corner."

        mover.jump(1000, 1000)
        yield "Jump past the top-right corner."

        mover.jump(140, 10)
        yield "Jump 10 px from the bottom-right corner."

        mover.jump(1000, -1000)
        yield "Jump past the bottom-right corner."

        mover.jump(10, 140)
        yield "Jump 10 px from the top-left corner."

        mover.jump(-1000, 1000)
        yield "Jump past the top-left corner."

        # Test jumping by percent.

        mover.jump_percent(0.5, 0.5)
        yield "Jump to the center."

        mover.jump_percent(0.9, 0.5)
        yield "Jump 90% of the way to the right edge."

        mover.jump_percent(10.0, 0.5)
        yield "Jump past the right edge."

        mover.jump_percent(0.1, 0.5)
        yield "Jump 90% of the way to the left edge."

        mover.jump_percent(-10.0, 0.5)
        yield "Jump past the left edge."

        mover.jump_percent(0.5, 0.9)
        yield "Jump 90% of the way to the top edge."

        mover.jump_percent(0.5, 10.0)
        yield "Jump past the top edge."

        mover.jump_percent(0.5, 0.1)
        yield "Jump 90% of the way to the bottom edge."

        mover.jump_percent(0.5, -10.0)
        yield "Jump past the bottom edge."
示例#8
0
#!/usr/bin/env python3

import pyglet
import glooey
import run_demos

window = pyglet.window.Window()
w, h = window.width, window.height
gui = glooey.Gui(window)
logger = glooey.EventLogger(0.8 * w, 0.8 * h, align='center')
gui.add(logger)


@run_demos.on_space(gui)  #
def test_gui():
    gui.set_cursor(pyglet.image.load('assets/misc/cursor_flipped.png'),
                   (13, 0))
    yield "Use a cursor with a bottom-right hotspot."
    gui.set_cursor(pyglet.image.load('assets/misc/cursor.png'), (0, 18))

    popup = glooey.EventLogger(0.2 * w,
                               0.2 * h,
                               color='orange',
                               align='center')
    gui.add(popup)
    yield "Mouse events should preferentially go to the pop-up."
    gui.remove(popup)


pyglet.app.run()
示例#9
0
    custom_alignment = 'center'
    custom_color = 'green'

    def __init__(self, logger):
        super().__init__(str(logger))


window = pyglet.window.Window()
gui = glooey.Gui(window)
grid = glooey.Grid(2, 2)
grid.padding = 50
grid.cell_padding = 50
grid.set_row_height(0, 0)

loggers = [  #
    glooey.EventLogger(),
    glooey.EventLogger(),
]

grid[0, 0] = EventLoggerLabel(loggers[0])
grid[1, 0] = loggers[0]
grid[0, 1] = EventLoggerLabel(loggers[1])
grid[1, 1] = loggers[1]

gui.add(grid)


@run_demos.on_space(gui)  #
def test_mouse_events():
    yield "Move the mouse and make sure the correct events are printed."
示例#10
0
#!/usr/bin/env python3

import pyglet
import glooey

window = pyglet.window.Window()
gui = glooey.Gui(window)
gui.padding = 50
widget = glooey.EventLogger()
gui.add(widget)

pyglet.app.run()

示例#11
0
    def __init__(self):
        super().__init__()

        for i in range(2):
            for j in range(2):
                self.add(i, j, glooey.EventLogger(150, 150, 'orange'))
示例#12
0
pane = glooey.ScrollPane()
pane.size_hint = 300, 300
pane.horz_scrolling = True
pane.vert_scrolling = True

# Test widgets that are both bigger and smaller than the pane: See #32.  Note
# however that the pane is really only meant to be used with widgets larger
# than itself.  When scrolling and jumping the smaller widget, the widget seems
# to move in the wrong direction, but this is how the *visible part* of the
# widget *would* move correctly if the widget was larger than the pane.

big_content = glooey.Grid(2, 2)  # 450×450
big_content.padding = 50
for i in range(2):
    for j in range(2):
        big_content.add(i, j, glooey.EventLogger(150, 150, 'orange'))

small_content = glooey.Grid(2, 2)  # 90x90
small_content.padding = 10
for i in range(2):
    for j in range(2):
        small_content.add(i, j, glooey.EventLogger(30, 30, 'purple'))

frame.add(pane)
gui.add(frame)


@run_demos.on_space(gui)  #
def test_widget():
    for content in (big_content, small_content):
        pane.add(content)
示例#13
0
#!/usr/bin/env python3

import pyglet
import glooey
import run_demos
from vecrec import Vector, Rect

window = pyglet.window.Window()
gui = glooey.Gui(window)
frame = glooey.Frame()
frame.decoration.outline = 'green'
board = glooey.Board()
widget = glooey.EventLogger(50, 50, 'orange')

frame.add(board)
gui.add(frame)


def test_scalar_position_arguments():
    board.move(widget, left=0, bottom=0)
    yield "Put the widget in the bottom left corner."

    board.move(widget, right=400, top=300)
    yield "Put the widget in the top right corner."

    board.move(widget, center_x=200, center_y=150)
    yield "Put the widget in the center."


def test_vector_position_arguments():
    board.move(widget, bottom_left=(0, 0))