Code: Select all
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# exercice 1 version 1
# ---------------------
# grey rectangle item symbolize things very deep or very high at different scale.
# you can place it in red or green area (boxes) thanks to OK or X button
# you can come back to centralbox thanks to ^ button
# version 1 : + and - are not working yet, it aims at ordering items vertically in a their current box / depth.
# you can hover an element to get depth value
# Modify button is not working yet, it aims at modify element's title and/or corpus.
# RESET button works partially, it does not clean at one shot.
# GETLIST button is for experimental and comprehension purposes
# on your right hand gives "LIFT Y" which breaks while using element movements
import pygame
import thorpy
""" uncomment to get full screen, you have to install mss first , try: sudo pip3 install mss
from mss import mss
screen = mss().monitors[1]
print(screen)
WIDTH = screen['width']
HEIGHT = screen['height']
"""
WIDTH = 800
HEIGHT = 600
douz_W = int(WIDTH/12)
douz_H = int(HEIGHT/12)
application = thorpy.Application((WIDTH, HEIGHT), " TEST")
title_element = thorpy.make_text("Thorpy exercice 1", 45, (250,200,0))
class Mission():
mission_list = []
@classmethod
def build_example_deck(cls):
foo_bar_dict = {"ISS":"408 km","ground":"0 m","Eiffel tower":"324 m","Le Triomphant":"- 400 m","Atlantide":"- 2410 m","Mariannes":"- 10994 m","Everest":"8848 m"}
for k, v in foo_bar_dict.items():
Mission(k,v)
#yield Mission(k,v)
print("@classmethod build_example_deck() just called !")
print(Mission.mission_list)
for mission in Mission.mission_list:
print("\n",mission.title," : ",mission.corpus)
def __init__(self, title = None,corpus = None):
self.title = title
self.corpus = corpus
Mission.mission_list.append(self)
def print_self(self):
print(self.__dict__)
Mission.build_example_deck()
print("coucou")
def text_input(title, value=""):
ins = thorpy.Inserter.make(title,value=value)
box = thorpy.make_ok_box([ins])
thorpy.auto_ok(box)
box.center()
thorpy.launch_blocking(box)
return ins.get_value()
def pass_func():
pass
def helium_move():
pass_func()
def lead_move():
pass_func()
def perf_injector(tit,cor):
new_elem = thorpy.Element.make(tit)
thorpy.makeup.add_basic_help(new_elem,cor)
#new_elem.finish()
new_validator = thorpy.make_button("ok", move_to_box)
thorpy.makeup.add_basic_help(new_validator,"click here to accept")
new_validator.set_main_color((0,255,0,170))
new_xannihilator = thorpy.make_button("X", move_to_box)
thorpy.makeup.add_basic_help(new_xannihilator,"click here to reject")
new_xannihilator.set_main_color((255,0,0,150))
new_go_up = thorpy.make_button("^", easy_move)
thorpy.makeup.add_basic_help(new_go_up,"click here to teleport")
new_go_up.set_main_color((180,180,180, 200))
new_helium = thorpy.make_button("+", helium_move)
thorpy.makeup.add_basic_help(new_helium,"click here to move toper in current box")
new_helium.set_main_color((50,50,50, 70))
new_lead = thorpy.make_button("-", lead_move)
thorpy.makeup.add_basic_help(new_lead,"click here to move lower in current box")
new_lead.set_main_color((220,220,220, 100))
new_kill = thorpy.make_button("KILL", kill_fn)
thorpy.makeup.add_basic_help(new_kill,"click here to remove this line")
new_kill.set_main_color((0,0,0, 250))
new_activline = [new_elem,new_validator,new_xannihilator, new_go_up, new_helium, new_lead, new_kill]
new_activgroup = thorpy.make_group(new_activline, "h")
central_box.add_elements([new_activgroup])
new_validator.user_params = {"element":new_activgroup, "from_box":central_box, "to_box":succes_box}
new_xannihilator.user_params = {"element":new_activgroup, "from_box":central_box, "to_box":failed_box}
new_go_up.user_params = {"element":new_activgroup,"to_box":central_box}
new_kill.user_params = {"element":new_activgroup}
new_activgroup.finish()
thorpy.functions.refresh_current_menu()
central_box.store()
central_box.unblit_and_reblit()
def autoload():
for mission in Mission.mission_list:
perf_injector(mission.title,mission.corpus)
def newtask_fn():
tit = text_input("Title: ")
print(type(tit))
#x = Mission(tit,cor,them,creationdate = arrow.utcnow())
cor = text_input("Corpus: ")
x = Mission(tit,cor)
print("\n create_mission")
x.print_self()
perf_injector(tit,cor)
background.unblit_and_reblit()
def getlist_fn():
print("\n\n ____ getlist_fn ___")
for element in central_box.get_elements():
for inside in element.get_elements():
print("\n\n")
print("inside : ",inside," type : ",type(inside))
if type(inside) == thorpy.elements.element.Element:
print(inside.__dict__)
print("inside.normal_params : ",inside.normal_params)
print("\n ",inside.normal_params.__dict__)
#print("inside.current_state : ",inside.current_state)
#print("\n ",inside.current_state.__dict__)
def reset_fn():
resetbox = central_box
for element in resetbox.get_elements():
print(element)
print(type(element))
resetbox.remove_elements([element])
resetbox.store()
thorpy.functions.refresh_current_menu()
resetbox.unblit_and_reblit()
def pass_func():
pass
newtask = thorpy.make_button("NEWTASK", func = newtask_fn)
modify = thorpy.make_button("MODIFY", func = pass_func )
reset = thorpy.make_button("RESET", func = reset_fn )
getlist = thorpy.make_button("GETLIST", func = getlist_fn)
#-----------------------------------------------------
barbuttonlist = [newtask,modify,reset,getlist]
barbuttonlist[0].set_main_color((0,0,255))
barbuttonlist[1].set_main_color((255,145,0))
barbuttonlist[2].set_main_color((125,125,125))
barbuttonlist[3].set_main_color((180,0,125))
#barbuttonlist[4].set_main_color((170,0,200))
#barbuttonlist[5].set_main_color((50,150,0))
clicksgroup = thorpy.make_group(barbuttonlist, "h")
def move_to_box(element, from_box, to_box):
if element in central_box.get_elements():
print("\n.......................................................")
for e in element.get_elements():
print("\n")
e.force_unjailed()
from_box.remove_elements([element])
from_box.store()
from_box.unblit_and_reblit()
to_box.add_elements([element])
thorpy.functions.refresh_current_menu()
to_box.store()
to_box.unblit_and_reblit()
else:
print("element not source box box")
def easy_move(element, to_box):
for e in element.get_elements():
print(e.get_ancesters()[1])
e.force_unjailed()
current_box = e.get_ancesters()[1]
current_box.remove_elements([element])
current_box.store()
current_box.unblit_and_reblit()
to_box.add_elements([element])
thorpy.functions.refresh_current_menu()
to_box.store()
to_box.unblit_and_reblit()
def kill_fn(element):
for e in element.get_elements():
print(e.get_ancesters()[1])
e.force_unjailed()
current_box = e.get_ancesters()[1]
current_box.remove_elements([element])
current_box.store()
current_box.unblit_and_reblit()
thorpy.functions.refresh_current_menu()
central_box = thorpy.Box.make(elements=None,
size=(9*douz_W,5*douz_H))
failed_box = thorpy.Box.make(elements=None,
size=(9*douz_W,2*douz_H))
succes_box = thorpy.Box.make(elements=None,
size=(9*douz_W,2*douz_H))
central_box.center()
central_box.add_lift()
central_box.set_main_color((220,220,220,70))
failed_box.add_lift()
failed_box.set_main_color((255,0,0,90))
succes_box.add_lift()
succes_box.set_main_color((0,255,0,70))
autoload()
background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
elements=[title_element, clicksgroup, central_box, failed_box, succes_box])
thorpy.store(background)
menu = thorpy.Menu(background)
menu.play()
application.quit()