Example #1
0
def main():
    pygame.init()  # Iniciamos pygame.
    infoObject = pygame.display.Info()
    icon = pygame.image.load('images/ant.png')

    preferredSize = int(infoObject.current_h *
                        0.88)  # Obtenemos la altura de la pantalla.
    application = thorpy.Application((preferredSize, preferredSize),
                                     "Langton's Ant", "pygame")

    # Verifica si el tamaño ingresado es válido y si lo es, inicia la simulación.
    def start():
        if tamaño.get_value().isdigit() and iteraciones.get_value().isdigit():
            tam = int(tamaño.get_value())
            it = int(iteraciones.get_value())
            if tam > 0 and it > 0:
                if tam > int(0.65 * (preferredSize // 2)):
                    thorpy.launch_blocking_alert(
                        title="¡Tamaño no soportado!",
                        text=
                        "El tamaño actual generaría una grilla con celdas de tamaño cero.",
                        parent=background)
                    tamaño.set_value("")
                else:
                    simulation.simulate(tam, it, preferredSize)
            else:
                thorpy.launch_blocking_alert(title="¡Tamaño no soportado!",
                                             text="El tamaño no es válido.",
                                             parent=background)
        else:
            thorpy.launch_blocking_alert(
                title="¡Valores incorrectos!",
                text="Los valores introducidos no son válidos.",
                parent=background)
            tamaño.set_value("")
            iteraciones.set_value("")

    iteraciones = thorpy.Inserter(name="Iteraciones: ",
                                  value="1")  # Campo de número de iteraciones.
    tamaño = thorpy.Inserter(name="Tamaño: ", value="10")  # Campo de tamaño.
    boton = thorpy.make_button("Aceptar", start)  # Botón aceptar.

    title_element = thorpy.make_text("Configurar simulación", 22,
                                     (255, 255, 255))

    central_box = thorpy.Box(elements=[iteraciones, tamaño,
                                       boton])  # Contenedor central.
    central_box.fit_children(margins=(30, 30))
    central_box.center()  # center on screen
    central_box.set_main_color((220, 220, 220, 180))

    background = thorpy.Background((0, 0, 0),
                                   elements=[title_element, central_box])
    thorpy.store(background)

    menu = thorpy.Menu(background)
    menu.play()  # Lanzamos el menú.

    application.quit()
Example #2
0
    def displayLauncher():

        # Declare Variables
        index = None  #int
        game = None  #String
        application = None  #Application(thorpy)
        buttons = [None, None, None]  #Clickable(thorpy) Array
        scoreboardButton = None  #Clickable(thorpy)
        quitButton = None  #Clickable(thorpy)
        buttonGroup = None  #Group(thorpy)
        menu = None  #Menu(thorpy)
        background = None  #Background(thorpy)
        painter = None  #Painters(thorpy)
        title = None  #Text(thorpy)

        # Create GUI and set theme
        application = thorpy.Application(size=(1280, 800),
                                         caption="Mini-Arcade")
        thorpy.theme.set_theme("human")

        # Create title
        title = thorpy.make_text("Mini-Arcade\n", 35, (0, 0, 0))

        # Create buttons
        painter = thorpy.painters.roundrect.RoundRect(size=(150, 75),
                                                      color=(102, 204, 255),
                                                      radius=0.3)
        for index, game in enumerate(Launcher.gameTitle):
            buttons[index] = Launcher.createButton(game, index, painter)
        scoreboardButton = thorpy.Clickable("Scoreboard")
        scoreboardButton.user_func = Launcher.launchScoreboard
        scoreboardButton.set_painter(painter)
        scoreboardButton.finish()
        scoreboardButton.set_font_size(23)
        scoreboardButton.set_font_color_hover((255, 255, 255))
        quitButton = thorpy.Clickable("Exit")
        quitButton.user_func = thorpy.functions.quit_menu_func
        quitButton.set_painter(painter)
        quitButton.finish()
        quitButton.set_font_size(23)
        quitButton.set_font_color_hover((255, 255, 255))

        # Format the buttons
        buttonGroup = thorpy.make_group(buttons)

        # Set background
        background = thorpy.Background(
            color=(255, 255, 255),
            elements=[title, buttonGroup, scoreboardButton, quitButton])
        thorpy.store(background)

        # Create menu and display
        menu = thorpy.Menu(background)
        menu.play()

        # Exiting
        application.quit()
Example #3
0
def main_menu(width, height, func_run, func_menu):
    def func_about():
        about_text = thorpy.make_text(
            'Game of the Hyenas \n '
            'by \n\n '
            'AnDreWerDnA'
            ' \n 700y \n Pk \n\n '
            '-  Python Code Jam 5 -', 25)

        normal_about, hover_about = 'assets/back-on.png',\
                                    'assets/back-off.png',

        back_button = thorpy.make_image_button(img_normal=normal_about,
                                               img_hover=hover_about,
                                               colorkey=(0, 0, 0))
        back_button.user_func = func_menu
        about_background = thorpy.Background(
            image='map_objects/menu_bg.jpg',
            elements=[about_text, back_button])
        thorpy.store(about_background)
        about_menu = thorpy.Menu(about_background)
        about_menu.play()

    application = thorpy.Application((width, height),
                                     "Code Jam",
                                     icon='pyGame')

    normal, hover = 'assets/play-on.png', 'assets/play-off.png'
    normal_quit, hover_quit = 'assets/quit-on.png', 'assets/quit-off.png'
    normal_about, hover_about = 'assets/about-on.png', 'assets/about-off.png'

    play_button = thorpy.make_image_button(img_normal=normal,
                                           img_hover=hover,
                                           colorkey=(0, 0, 0))

    about_button = thorpy.make_image_button(img_normal=normal_about,
                                            img_hover=hover_about,
                                            colorkey=(0, 0, 0))

    quit_button = thorpy.make_image_button(img_normal=normal_quit,
                                           img_hover=hover_quit,
                                           colorkey=(0, 0, 0))

    background = thorpy.Background(
        image='map_objects/menu_bg.jpg',
        elements=[play_button, about_button, quit_button])
    # Set functions for the buttons
    play_button.user_func = func_run
    quit_button.set_as_exiter()
    about_button.user_func = func_about
    thorpy.store(background)
    menu = thorpy.Menu(background)
    menu.play()

    application.quit()
Example #4
0
def check_gui(module_name):
    try:
        __import__(module_name)
    except ImportError:
        text = get_msg(module_name, GAME_NAME)
        print(text)
        import thorpy
        ap = thorpy.Application((800,600))
        thorpy.launch_blocking_alert("Missing module", text)
        ap.quit()
        exit()
Example #5
0
def drawSplash():
    # readFile()
    # 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...
    global board
    useless1 = thorpy.make_button("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.make(text)

    draggable = thorpy.Draggable.make("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.make(name="Tip text: ",
                                    value="This is a default text.",
                                    size=(150, 20))

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

    browser_launcher = thorpy.BrowserLauncher.make(browser=file_browser,
                                                   const_text="Choose a file: ",
                                                   var_text="")

    color_setter = thorpy.ColorSetter.make()
    color_launcher = thorpy.ColorSetterLauncher.make(color_setter,
                                                     "Launch color setter")

    options2 = thorpy.make_button("Useful things")
    box2 = thorpy.make_ok_box([inserter, color_launcher, browser_launcher])
    thorpy.set_launcher(options2, box2)

    quit_button = thorpy.make_button("Quit")
    quit_button.set_as_exiter()

    central_box = thorpy.Box.make([options1, options2, quit_button])
    central_box.set_main_color((200, 200, 200, 120))
    central_box.center()

    # Declaration of a background element - include your own path!
    background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
                                        elements=[central_box])

    menu = thorpy.Menu(elements=background, fps=45)
    menu.play()
def check_gui(module_name):
    try:
        __import__(module_name)
    except ImportError:
        text = "Could not load "+module_name+". Module "+module_name+\
            " is needed to run "+game_name+".\n\nTry running 'pip install "+\
            module_name+"' in a console to install this dependency."
        print(text)
        import thorpy
        ap = thorpy.Application((800, 600))
        thorpy.launch_blocking_alert("Missing module", text)
        ap.quit()
        exit()
Example #7
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 #8
0
from capture import takePicture
from crop import main as cropMain
import thorpy
import pygame
from controller import startGenerate

pygame.display.init()

application = thorpy.Application(size=(300, 300),
                                 caption="Realtime Website Generator")
title = thorpy.make_text("Realtime Website Generator", 20, (0, 153, 255))

takepicbutt = thorpy.make_button("Take Picture", func=takePicture)
croppicbutt = thorpy.make_button("Crop Picture", func=cropMain)

genwebbutt = thorpy.make_button("Generate Website", func=startGenerate)

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

background = thorpy.Background.make(
    color=(200, 200, 255),
    elements=[title, takepicbutt, croppicbutt, genwebbutt, quit_button])

thorpy.store(background)

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

application.quit()
#!/usr/bin/python
import thorpy
import subprocess


commit = subprocess.check_output(['git', 'show', '--oneline', '-s']).split(" ")[0]

application = thorpy.Application((320, 415), "Badge Programmer")


vfile = open('fwver.txt','r')
fwver = vfile.read()

fwver = thorpy.OneLineText.make("Firmware Version   :  %s" % (fwver)) 
swver = thorpy.OneLineText.make("Provisioner Version:  %s" % (commit)) 

def launch(command):
  command = "xterm -fn fixed -fullscreen -e %s" % command
  process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
  process.wait()

def getNewFW():
  launch("python get_latest_firmware.py")
  exit(0)
  pass


def getNewProv():
  launch("python update_provisioner.py")
  exit(0)
  pass
Example #10
0
    print("reaction 2 launched")


def my_func_reaction1(el, reac_1):
    new_reaction = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN,
                                           reac_func=my_func_reaction2)
    el.remove_reaction(reac_1)
    el.add_reaction(new_reaction)
    thorpy.functions.refresh_current_menu()  #tell menu to refresh reactions!
    info_text.set_text("Reaction 1 will never be launched again")
    info_text.center()
    background.unblit_and_reblit()
    print("reaction 1 launched - replacing reac 1 by reac 2")


application = thorpy.Application(size=(300, 300), caption="Reaction tuto")

info_text = thorpy.make_text("No reaction launched")
info_text.center()

background = thorpy.Background(elements=[info_text], color=(255, 255, 255))

reac_1 = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN,
                                 reac_func=my_func_reaction1,
                                 params={
                                     "el": background,
                                     "reac_1": None
                                 })
reac_1.params["reac_1"] = reac_1
background.add_reaction(reac_1)
Example #11
0
#ThorPy storage tutorial : manual placing
import thorpy, random

application = thorpy.Application(size=(400, 400), caption="Storage")

elements = [thorpy.make_button("button" + str(i)) for i in range(13)]
for e in elements:
    w, h = e.get_rect().size
    w, h = w * (1 + random.random() / 2.), h * (1 + random.random() / 2.)
    e.set_size((w, h))
elements[6] = thorpy.Element(text="")
elements[6].set_size((100, 100))

elements[0].set_topleft((10, 300))
elements[1].set_topleft(elements[0].get_rect().bottomright)
elements[2].set_center((100, 200))
elements[3].stick_to(elements[2], target_side="bottom", self_side="top")
elements[4].stick_to(elements[2], target_side="right", self_side="left")

background = thorpy.Background(color=(200, 200, 255), elements=elements)
thorpy.store(background, elements[6:12], x=380, align="right")
elements[5].center(element=elements[6])
elements[5].rank = elements[6].rank + 0.1  #be sure number 5 is blitted after 6
background.sort_children_by_rank()  #tell background to sort its children
elements[12].set_location((0.1, 0.2))  #relative placing of number 12

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

application.quit()
Example #12
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 #13
0
import pygame
import thorpy #for GUI and other graphics - see www.thorpy.org

import maps.maps as maps
import gui.gui as gui
from logic.races import Race, LUNAR, STELLAR, SOLAR
from logic.game import Game, get_sprite_frames
import gui.theme as theme
from logic.player import Player
################################################################################

theme.set_theme("human")

W,H = 1200, 700 #screen size
FPS = 30
app = thorpy.Application((W,H))

map_initializer = maps.map1 #go in mymaps.py and PLAY with PARAMS !!!
maps.map1.world_size = (32,32)
maps.map1.chunk = (1322, 43944)
maps.map1.max_number_of_roads = 5 #5
maps.map1.max_number_of_rivers = 5 #5
maps.map1.village_homogeneity = 0.1
maps.map1.seed_static_objects = 15
maps.map1.zoom_cell_sizes = [32]


##for map_initializer in [maps.map1, maps.map0, maps.map2, maps.map3]:
##    me = map_initializer.configure_map_editor(FPS) #me = "Map Editor"
##    app.get_screen().fill((0,0,0))
####    me.show_hmap()
Example #14
0

def make_debris():
    angle = random.randint(0, 360)  #pick random angle
    spread = 15  #spread of debris directions
    debrisgen.generate(
        V2(pygame.mouse.get_pos()),  #position
        n=20,  #number of debris
        v_range=(10, 50),  #translational velocity range
        omega_range=(5, 25),  #rotational velocity range
        angle_range=(angle - spread, angle + spread))


# ##############################################################################

app = thorpy.Application((400, 400), "Effects")

smokegen1 = thorpy.fx.get_smokegen(n=50, color=(200, 200, 255), grow=0.6)
smokegen2 = thorpy.fx.get_fire_smokegen(n=50, color=(200, 255, 155), grow=0.4)
debrisgen = thorpy.fx.get_debris_generator(
    duration=200,  #nb. frames before die
    color=(100, 100, 100),
    max_size=10)

e_ship = thorpy.Image("../documentation/examples/boat_example.png",
                      colorkey=(255, 255, 255))
if thorpy.constants.CAN_SHADOWS:  #set shadow
    thorpy.makeup.add_static_shadow(
        e_ship, {
            "target_altitude": 5,
            "shadow_radius": 3,
Example #15
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()
import thorpy

application = thorpy.Application((700, 700), "Style examples")

buttons = [thorpy.make_button("button" + str(i)) for i in range(8)]

buttons[0].set_main_color(
    (0, 255, 0))  #slow method, to be used outside of a loop
buttons[1].set_main_color((0, 255, 0, 100))  #with alpha value this time
buttons[2].set_font_color(
    (255, 255, 0))  #slow method, to be used outside of a loop
buttons[3].set_font_color_hover((0, 255, 0))  #...
buttons[4].set_font("century")  #may not work on your computer
buttons[5].set_font_size(18)
buttons[5].scale_to_title()
buttons[6].set_size((100, 100))
buttons[7].set_text("First line\nSecond line")
buttons[7].scale_to_title()

#use predefined theme
for theme_name in ["classic", "round", "human", "simple", "windows10"]:
    thorpy.set_theme(theme_name)
    button = thorpy.make_button("Theme name : " + theme_name)
    button.scale_to_title()
    buttons.append(button)
    thorpy.theme.set_default_theme_as_current()

#A customized style
a_round_button = thorpy.Clickable("Custom round Button")
painter = thorpy.painters.optionnal.human.Human(size=(200, 30),
                                                radius_ext=0.5,
Example #17
0
    thorpy.launch_nonblocking_choices("This is a non-blocking choices box!\n",
                                      choices)
    print("Proof that it is non-blocking : this sentence is printing!")


def my_choices_2():
    choices = [("I like blue", set_blue), ("No! red", set_red),
               ("cancel", None)]
    thorpy.launch_blocking_choices("Blocking choices box!\n",
                                   choices,
                                   parent=background)  #for auto unblit
    print("This sentence will print only after you clicked ok")


signal.signal(signal.SIGINT, ctrlC)

application = thorpy.Application((320, 480), "OctoPy")
pygame.mouse.set_visible(False)

#button1 = thorpy.make_button("Non-blocking version", func=my_choices_1)
#button2 = thorpy.make_button("Blocking version", func=my_choices_2)

title = thorpy.make_text("Status:", (5, 5), (0, 0, 0))

background = thorpy.Background.make(elements=[title])
thorpy.store(background)

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

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

application = thorpy.Application((300, 300))


class MyPainter(thorpy.painters.painter.Painter):
    def __init__(
        self,
        c1,
        c2,
        c3,
        size=None,
        clip=None,
        pressed=False,
        hovered=False,
    ):
        super(MyPainter, self).__init__(size, clip, pressed, hovered)
        self.c1 = c1
        self.c2 = c2
        self.c3 = c3

    def get_surface(self):
        #transparent surface so that all that is not drawn is invisible
        surface = pygame.Surface(self.size,
                                 flags=pygame.SRCALPHA).convert_alpha()
        rect_corner = pygame.Rect(0, 0, self.size[0] // 6, self.size[1] // 6)
        rect_body = surface.get_rect().inflate((-5, -5))
        color_corner = self.c1  #this color will change accordin to the state
        if self.pressed:
            color_corner = self.c3
        #draw the four corners:
Example #19
0
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=512)
##SEED = 18
##SEED = 10131425
##SEED = int(save["cam"]["seed"])
##SEED = 800
SEED = 66
##SEED = 0

S = terrain.S
parameters.set_S(S)


METADATA_PATH = "./metadata" #create a file for storing data on application
mdm = thorpy.MetaDataManager()
mdm.read_data(METADATA_PATH)
app = thorpy.Application((S,S))
mdm.load_font_data(METADATA_PATH)
gui.show_loading()
gui.playing() #set key delay
thorpy.set_theme("human")
screen = thorpy.get_screen()
e_bckgr = thorpy.Ghost.make()
sound.play_random_music()
terrain.cache()

savefile=gui.launch_main_menu() #xxx
climate = terrain.Climate(0)

if savefile:
    gui.show_loading()
    sm = savemanager.SaveManager(savefile)
Example #20
0
import pygame
import thorpy
import boardGUI



application = thorpy.Application(size=(600, 800), caption="SUDOKU")
thorpy.theme.set_theme('human')

title = thorpy.make_text("SUDOKU", 80, (255,255,255))
title.set_topleft((200,200))

#Picture for menu
normal = "sudoku.png"
pic_button = thorpy.make_image_button(normal,
                                    alpha=255,
                                    colorkey=(100,200,100))

#Start Button
start = thorpy.make_button("START")
start.set_font("Bahnschrift SemiBold")
start.set_main_color((0,148,0))
start.set_font_color((255,255,255))
start.set_font_size(40)
start.set_size((200,100))
start.center()




#Quit button
Example #21
0
import thorpy

from snake import main

application = thorpy.Application(size=(500, 500),
                                 caption='ThorPy stupid Example')
thorpy.theme.set_theme('classic')

start_single = thorpy.make_button("Single game", func=main)
create_host = thorpy.make_button("Create server")
connect = thorpy.make_button("Connect to game")
settings = thorpy.make_button("Settings")
quit_button = thorpy.make_button("Quit")
quit_button.set_as_exiter()

central_box = thorpy.Box.make(
    [start_single, create_host, connect, settings, quit_button])
central_box.set_main_color((200, 200, 200, 120))
central_box.center()

# background = thorpy.Background(elements=[central_box])

menu = thorpy.Menu(elements=central_box, fps=45)
menu.play()

application.quit()
Example #22
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 #23
0
import thorpy

application = thorpy.Application(size=(300, 300), caption="Hello Test")

my_button = thorpy.make_button("hello there")
my_button.center()

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

application.quit()
Example #24
0

def parar_gv():
    print("Modo Gravacao Desativado")
    GPIO.output(in1, GPIO.LOW)
    GPIO.output(in2, GPIO.LOW)
    GPIO.output(in3, GPIO.LOW)
    GPIO.output(in4, GPIO.LOW)


def sair():
    GPIO.cleanup()
    exit()


application = thorpy.Application(size=(800, 600), caption='Dollynho')

titulo = thorpy.make_text("Dollynho", 30, (40, 40, 40))

subtitulo = thorpy.make_text("Escolha um modo de funcionamento:", 20,
                             (40, 40, 40))

#Botoes invisiveis para espacamento
inv1 = thorpy.make_button("")
inv1.set_size((50, 50))
inv1.set_main_color((0, 0, 0, 0))
inv2 = thorpy.make_button("")
inv2.set_size((20, 20))
inv2.set_main_color((0, 0, 0, 0))
inv3 = thorpy.make_button("")
inv3.set_size((15, 15))
Example #25
0
            sgn = 1
        elif c1_loose:  #j1 win ==> up
            sgn = -1
        elif j1_main:  #j1 win ==> up
            sgn = -1
        else:
            sgn = 1
        for i in range(30):
            c1.move((0, sgn * 10))
            c2.move((0, sgn * 10))
            b.unblit_and_reblit()
            pygame.display.flip()
            pygame.time.wait(20)


app = thorpy.Application((800, 600), "Pomme d'API")

simg = 30
img = thorpy.load_image("./coeur.png", colorkey=(255, 255, 255))
img_coeur = thorpy.get_resized_image(img, (simg, simg))
img = thorpy.load_image("./trefle.png", colorkey=(255, 255, 255))
img_trefle = thorpy.get_resized_image(img, (simg, simg))
img = thorpy.load_image("./pique.png", colorkey=(255, 255, 255))
img_pique = thorpy.get_resized_image(img, (simg, simg))
img = thorpy.load_image("./carreau.png", colorkey=(255, 255, 255))
img_carreau = thorpy.get_resized_image(img, (simg, simg))
img_nothing = img_carreau.copy()
img_nothing.fill((50, 50, 50))

couleur2img = couleur2texte = {
    "c": img_coeur,
Example #26
0
"""Example from www.thorpy.org/examples.html"""
import thorpy, pygame

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

bar = thorpy.LifeBar(
    "Remaining time",
    color=(255, 165, 0),
    text_color=(0, 0, 0),
    size=(200, 30),
    font_size=None,  #keep default one
    type_="h")  #h or v
bar.center()

counter = 0


def event_time():
    global counter
    if counter % 4 == 0:
        life = min(1., counter / 500.)
        bar.set_life(life)
        bar.set_text(str(counter))
        bar.unblit_and_reblit()
    if counter < 500:
        counter += 1


bar.add_reaction(
    thorpy.ConstantReaction(thorpy.THORPY_EVENT, event_time,
                            {"id": thorpy.constants.EVENT_TIME}))
Example #27
0
#!/usr/bin/python
import thorpy
import pygame
import subprocess
import os
from results import *

application = thorpy.Application((480, 730), "Badge Programmer")

#vfile = open('fwver.txt','r')
#fwver = vfile.read()

rfile = open('result.txt', 'r')
try:
    res = int(rfile.read())
except ValueError:
    res = 100

fwver = thorpy.OneLineText.make("Firmware Version   :  %s" % (res))
swver = thorpy.OneLineText.make("Provisioner Version:  %s" % (" "))

icon = thorpy.Image("none.png")

if res == results.PASS:
    icon = thorpy.Image("pass.png")
elif res == results.FAIL_BOOT:
    icon = thorpy.Image("fail.png")
elif res == results.FAIL_RESET:
    icon = thorpy.Image("fail.png")
elif res == results.FAIL_CPY:
    icon = thorpy.Image("fail.png")
"""Example from www.thorpy.org/examples.html"""
import thorpy

application = thorpy.Application((800, 600), "Example of animated gif")

gif_element = thorpy.AnimatedGif("../documentation/examples/myGif.gif")
gif_element.center()

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

application.quit()

"""
Other parameters to pass to the constructor of AnimatedGif:
        <path>: the path to the image.
        <color>: if path is None, use this color instead of image.
        <low>: increase this parameter to lower the gif speed.
        <nread>: number of times the gif is played
"""
Example #29
0
    def drawBoard():

        # Declare variables
        application = None  #Application(thorpy)
        title = None  #Text(thorpy)
        content = None  #Text(thorpy)
        buttons = [None, None, None]  #Clickable/Element(thorpy) Array
        quitButton = None  #Clickable(thorpy)
        painter1 = None  #Painters(thorpy)
        painter2 = None  #Painters(thorpy)
        buttonGroup = None  #Group(thorpy)
        menu = None  #Menu(thorpy)
        background = None  #Background(thorpy)
        contentString = None  #String

        # Create GUI and set theme
        application = thorpy.Application(size=(1280, 800),
                                         caption="Mini-Arcade")
        thorpy.theme.set_theme("human")

        # Create title
        title = thorpy.make_text("Scoreboard\n", 35, (0, 0, 0))

        # Create buttons
        painter1 = thorpy.painters.roundrect.RoundRect(size=(100, 50),
                                                       color=(102, 204, 255),
                                                       radius=0.3)
        painter2 = thorpy.painters.roundrect.RoundRect(size=(100, 50),
                                                       color=(57, 197, 187),
                                                       radius=0.3)
        for index, game in enumerate(Scoreboard.gameTitle):
            buttons[index] = Scoreboard.createButton(game, index, painter1,
                                                     painter2)
        quitButton = thorpy.Clickable("Return")
        quitButton.user_func = Scoreboard.exitScoreboard
        quitButton.set_painter(painter1)
        quitButton.finish()
        quitButton.set_font_size(17)
        quitButton.set_font_color_hover((255, 255, 255))

        # Create texts
        contentString = ""
        for index, score in enumerate(
                Scoreboard.scores[Scoreboard.displayGame]):
            contentString = contentString + str(index +
                                                1) + ": " + str(score) + "\n"
        contentString += "\n\n"
        content = thorpy.make_text(contentString, 20, (0, 0, 0))

        # Format the buttons and texts
        buttonGroup = thorpy.make_group(buttons)

        # Set background
        background = thorpy.Background(
            color=(255, 255, 255),
            elements=[title, buttonGroup, content, quitButton])
        thorpy.store(background)

        # Create menu and display
        menu = thorpy.Menu(background)
        menu.play()

        # Exiting
        application.quit()

def my_choices_1():
    choices = [("I like blue", set_blue), ("No! red", set_red),
               ("cancel", None)]
    thorpy.launch_nonblocking_choices("This is a non-blocking choices box!\n",
                                      choices)
    print("Proof that it is non-blocking : this sentence is printing!")


def my_choices_2():
    choices = [("I like blue", set_blue), ("No! red", set_red),
               ("cancel", None)]
    thorpy.launch_blocking_choices("Blocking choices box!\n",
                                   choices,
                                   parent=background)  #for auto unblit
    print("This sentence will print only after you clicked ok")


application = thorpy.Application((500, 500), "Launching alerts")

button1 = thorpy.make_button("Non-blocking version", func=my_choices_1)
button2 = thorpy.make_button("Blocking version", func=my_choices_2)

background = thorpy.Background(elements=[button1, button2])
thorpy.store(background)

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

application.quit()