Example #1
0
def run_application():
    W, H = 300, 300
    application = thorpy.Application(size=(W, H), caption="Real life example")

    draggable = thorpy.Draggable("Drag me")
    sx = thorpy.SliderX(length=100, limvals=(0, W), text="X:", type_=int)
    sy = thorpy.SliderX(length=100, limvals=(0, H), text="Y:", type_=int)

    background = thorpy.Background(color=(200, 255, 255),
                                   elements=[draggable, sx, sy])
    thorpy.store(background, [sx, sy])

    reaction1 = thorpy.Reaction(
        reacts_to=thorpy.constants.THORPY_EVENT,
        reac_func=refresh_drag,
        event_args={"id": thorpy.constants.EVENT_SLIDE},
        params={
            "drag": draggable,
            "sx": sx,
            "sy": sy
        },
        reac_name="my reaction to slide event")

    reaction2 = thorpy.Reaction(reacts_to=thorpy.constants.THORPY_EVENT,
                                reac_func=refresh_sliders,
                                event_args={"id": thorpy.constants.EVENT_DRAG},
                                params={
                                    "drag": draggable,
                                    "sx": sx,
                                    "sy": sy
                                },
                                reac_name="my reaction to drag event")

    background.add_reaction(reaction1)
    background.add_reaction(reaction2)

    menu = thorpy.Menu(background)  #create a menu for auto events handling
    menu.play()  #launch the menu
    application.quit()
Example #2
0
def run():
    import thorpy
    application = thorpy.Application((600, 600), "ThorPy test")

    ##thorpy.theme.set_theme("human")

    #### SIMPLE ELEMENTS ####

    ghost = thorpy.Ghost()
    ghost.finish()

    element = thorpy.Element("Element")
    element.finish()
    thorpy.makeup.add_basic_help(
        element, "Element instance:\nMost simple graphical element.")

    clickable = thorpy.Clickable("Clickable")
    clickable.finish()
    clickable.add_basic_help(
        "Clickable instance:\nCan be hovered and pressed.")

    draggable = thorpy.Draggable("Draggable")
    draggable.finish()
    thorpy.makeup.add_basic_help(draggable,
                                 "Draggable instance:\nYou can drag it.")

    #### SIMPLE Setters ####

    checker_check = thorpy.Checker("Checker")
    checker_check.finish()
    thorpy.makeup.add_basic_help(
        checker_check, "Checker instance:\nHere it is of type 'checkbox'.")

    checker_radio = thorpy.Checker("Radio", typ="radio")
    checker_radio.finish()
    thorpy.makeup.add_basic_help(
        checker_radio, "Checker instance:\nHere it is of type 'radio'.")

    browser = thorpy.Browser("../../", text="Browser")
    browser.finish()
    browser.set_prison()

    browserlauncher = thorpy.BrowserLauncher(browser,
                                             name_txt="Browser",
                                             file_txt="Nothing selected",
                                             launcher_txt="...")
    browserlauncher.finish()
    browserlauncher.scale_to_title()
    thorpy.makeup.add_basic_help(
        browserlauncher,
        "Browser instance:\nA way for user to find a file or" +
        "\na folder on the computer.")

    dropdownlist = thorpy.DropDownListLauncher(
        name_txt="DropDownListLauncher",
        file_txt="Nothing selected",
        titles=[str(i) for i in range(1, 9)])
    dropdownlist.finish()
    dropdownlist.scale_to_title()
    thorpy.makeup.add_basic_help(dropdownlist,
                                 "DropDownList:\nDisplay a list of choices.")

    slider = thorpy.SliderX(120, (5, 12),
                            "Slider: ",
                            typ=float,
                            initial_value=8.4)
    slider.finish()
    thorpy.makeup.add_basic_help(
        slider, "SliderX:\nA way for user to select a value." +
        "\nCan select any type of number (int, float, ..).")
    slider.set_center

    inserter = thorpy.Inserter(name="Inserter: ", value="Write here.")
    inserter.finish()
    thorpy.makeup.add_basic_help(
        inserter, "Inserter:\nA way for user to insert a value.")

    text_title = thorpy.make_text("Test Example", 25, (0, 0, 255))

    central_box = thorpy.Box("", [
        ghost, element, clickable, draggable, checker_check, checker_radio,
        dropdownlist, browserlauncher, slider, inserter
    ])
    central_box.finish()
    central_box.center()
    central_box.add_lift()
    central_box.set_main_color((200, 200, 255, 120))

    background = thorpy.Background(color=(200, 200, 200),
                                   elements=[text_title, central_box])
    background.finish()

    thorpy.store(background)

    menu = thorpy.Menu(background)
    menu.play()

    application.quit()
Example #3
0
import pygame, thorpy

ap = thorpy.Application((500, 400), "Shadows example")

e_img = thorpy.Draggable()  # do not use 'make' !
painter = thorpy.painters.imageframe.ImageFrame("character.png",
                                                colorkey=(255, 255, 255))
e_img.set_painter(painter)
e_img.finish()  #don't forget to finish

if thorpy.constants.CAN_SHADOWS:
    thorpy.makeup.add_static_shadow(e_img, {
        "target_altitude": 0,
        "shadow_radius": 3
    })

e_background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG,
                                 elements=[e_img])

menu = thorpy.Menu(e_background)
menu.play()

ap.quit()
Example #4
0
import thorpy

#Declaration of the application in which the menu is going to live.
application = thorpy.Application(size=(500, 500),
                                 caption='ThorPy stupid Example')

#Setting the graphical theme. By default, it is 'classic' (windows98-like).
thorpy.theme.set_theme('human')

#Declaration of some elements...
useless1 = thorpy.Element("This button is useless.\nAnd you can't click it.")

text = "This button also is useless.\nBut you can click it anyway."
useless2 = thorpy.Clickable(text)

draggable = thorpy.Draggable("Drag me!")

box1 = thorpy.make_ok_box([useless1, useless2, draggable])
options1 = thorpy.make_button("Some useless things...")
thorpy.set_launcher(options1, box1)

inserter = thorpy.Inserter(name="Tip text: ",
                           value="This is a default text.",
                           size=(150, 20))

file_browser = thorpy.Browser(path="C:/Users/", text="Please have a look.")

browser_launcher = thorpy.BrowserLauncher(browser=file_browser,
                                          const_text="Choose a file: ",
                                          var_text="")
Example #5
0
def run():
    application = thorpy.Application((800, 600), "ThorPy Overview")

    element = thorpy.Element("Element")
    thorpy.makeup.add_basic_help(element,
                                 "Element:\nMost simple graphical element.")

    clickable = thorpy.Clickable("Clickable")
    thorpy.makeup.add_basic_help(clickable,
                                 "Clickable:\nCan be hovered and pressed.")

    draggable = thorpy.Draggable("Draggable")
    thorpy.makeup.add_basic_help(draggable, "Draggable:\nYou can drag it.")

    checker_check = thorpy.Checker("Checker")

    checker_radio = thorpy.Checker("Radio", type_="radio")

    browser = thorpy.Browser("../../", text="Browser")

    browserlauncher = thorpy.BrowserLauncher.make(browser,
                                                  const_text="Choose file:",
                                                  var_text="")
    browserlauncher.max_chars = 20  #limit size of browser launcher

    dropdownlist = thorpy.DropDownListLauncher(
        const_text="Choose number:",
        var_text="",
        titles=[str(i) * i for i in range(1, 9)])
    dropdownlist.scale_to_title()
    dropdownlist.max_chars = 20  #limit size of drop down list

    slider = thorpy.SliderX(80, (5, 12),
                            "Slider: ",
                            type_=float,
                            initial_value=8.4)

    inserter = thorpy.Inserter(name="Inserter: ", value="Write here.")

    quit = thorpy.make_button("Quit", func=thorpy.functions.quit_menu_func)

    title_element = thorpy.make_text("Overview example", 22, (255, 255, 0))

    elements = [
        element, clickable, draggable, checker_check, checker_radio,
        dropdownlist, browserlauncher, slider, inserter, quit
    ]
    central_box = thorpy.Box(elements=elements)
    central_box.fit_children(margins=(30, 30))  #we want big margins
    central_box.center()  #center on screen
    central_box.add_lift()  #add a lift (useless since box fits children)
    central_box.set_main_color(
        (220, 220, 220, 180))  #set box color and opacity

    background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
                                        elements=[title_element, central_box])
    thorpy.store(background)

    menu = thorpy.Menu(background)
    menu.play()

    application.quit()
Example #6
0
import thorpy

application = thorpy.Application((800, 600), "ThorPy Overview")

text = thorpy.make_text("Some text", 12, (0, 0, 255))
line = thorpy.Line(200, "h")  #horizontal line of width = 200px

element = thorpy.Element("Element")
thorpy.makeup.add_basic_help(element,
                             "Element:\nMost simple graphical element.")

clickable = thorpy.Clickable("Clickable")
thorpy.makeup.add_basic_help(clickable,
                             "Clickable:\nCan be hovered and pressed.")

draggable = thorpy.Draggable("Draggable")
thorpy.makeup.add_basic_help(draggable, "Draggable:\nYou can drag it.")

checker_check = thorpy.Checker("Checker")

checker_radio = thorpy.Checker("Radio", type_="radio")

browser = thorpy.Browser("../../", text="Browser")

browserlauncher = thorpy.BrowserLauncher(browser,
                                         const_text="Choose file:",
                                         var_text="")
browserlauncher.max_chars = 15  #limit size of browser launcher

dropdownlist = thorpy.DropDownListLauncher(
    const_text="Choose:",
Example #7
0
import pygame, thorpy

ap = thorpy.Application((500,400), "Shadows example")

e_img = thorpy.Draggable(finish=False)
image_path = "../documentation/examples/character.png"
painter = thorpy.painters.imageframe.ImageFrame(image_path,
                                                colorkey=(255,255,255))
e_img.set_painter(painter)
e_img.finish() #don't forget to finish

if thorpy.constants.CAN_SHADOWS:
    thorpy.makeup.add_static_shadow(e_img, {"target_altitude":0,
                                            "shadow_radius":3})

e_text = thorpy.make_text("Drag the image", 20, (255,0,0))
e_text.stick_to("screen", "top", "top")

e_background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG,
                                        elements=[e_img, e_text])

menu = thorpy.Menu(e_background)
menu.play()

ap.quit()

#examples of shadow arguments:
##thorpy.makeup.add_static_shadow(e_img,
##    {"target_altitude":10, # altitude (in pixels) of the target
##     "shadow_radius":3, # the smaller, the sharper is the shadow
##     "sun_angle":60, # angle in degrees of the sun