def init_ui(screen): slider = thorpy.SliderX(100, (5, 15), "Simulation speed") slider.user_func = slider_reaction button_stop = thorpy.make_button("Quit", func=stop_execution) button_pause = thorpy.make_button("Pause", func=pause_execution) button_play = thorpy.make_button("Play", func=start_execution) timer = thorpy.OneLineText("Seconds passed") button_load = thorpy.make_button(text="Load a file", func=open_file) box = thorpy.Box(elements=[ slider, button_pause, button_stop, button_play, button_load, timer ]) reaction1 = thorpy.Reaction( reacts_to=thorpy.constants.THORPY_EVENT, reac_func=slider_reaction, event_args={"id": thorpy.constants.EVENT_SLIDE}, params={}, reac_name="slider reaction") box.add_reaction(reaction1) menu = thorpy.Menu(box) for element in menu.get_population(): element.surface = screen box.set_topleft((0, 0)) box.blit() box.update() return menu, box, timer
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()
def show_options(self): e_life_size = thorpy.SliderX(100, (6, 20), "Life font size", type_=int, initial_value=self.life_font_size) ## e_life_color = thorpy.ColorSetter(text="Life font color", ## value=self.life_font_color) e_title = thorpy.make_text("Units life") e_box = thorpy.make_ok_cancel_box([e_title, e_life_size]) e_box.center() result = thorpy.launch_blocking(e_box) if result.how_exited == "done": self.life_font_size = e_life_size.get_value() ## self.life_font_color = e_life_color.get_value() self.refresh_graphics_options() self.me.draw() self.menu.blit() pygame.display.flip()
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()
def make_thorpy_interface(): TE = gui_properties['THORPY_ELEMENTS'] DOUBLE_CLICK_TIME, TOOLBOX_COLOR, TOOLBOX_HEIGHT, TOOLBOX_WIDTH, COLOR_BOX_COLORS, COLOR_BOX_RECT_TUPLES = gui_properties[ 'DOUBLE_CLICK_TIME'], gui_properties['TOOLBOX_COLOR'], gui_properties[ 'TOOLBOX_HEIGHT'], gui_properties['TOOLBOX_WIDTH'], gui_properties[ 'COLOR_BOX_COLORS'], gui_properties['COLOR_BOX_RECT_TUPLES'] SELECTED_COLOR_INDEX_SINGLE_CLICK, SELECTED_COLOR_INDEX_DOUBLE_CLICK, SELECTED_COLOR, SMOKE_COLOR = gui_properties[ 'SELECTED_COLOR_INDEX_SINGLE_CLICK'], gui_properties[ 'SELECTED_COLOR_INDEX_DOUBLE_CLICK'], gui_properties[ 'SELECTED_COLOR'], gui_properties['SMOKE_COLOR'] PYGAME_ELEMENTS, COLOR_BOX_EVENT = gui_properties[ 'PYGAME_ELEMENTS'], gui_properties['COLOR_BOX_EVENT'] TE['clear_clickable'] = thorpy.make_button("Clear", func=clear_data) TE['exit_clickable'] = thorpy.make_button("Exit", func=thorpy.functions.quit_func) TE['vel_clickable'] = thorpy.make_button("Show Velocity", func=None) if webbrowser_available: TE['help_clickable'] = thorpy.make_button("Help", func=None) TE['help_clickable'].set_size((TOOLBOX_WIDTH - 10, 40)) TE['viscosity_slider'] = thorpy.SliderX(length=123, limvals=(0, 999), text="Visc:", type_=int) TE['force_slider'] = thorpy.SliderX(length=120, limvals=(0, 999), text="Force:", type_=int) TE['buoyancy_text'] = thorpy.OneLineText(text="Buoyant Force:", elements=None) TE['buoyancy_text'].set_font_size(16) TE['red_buoyancy_slider'] = thorpy.SliderX(length=126, limvals=(-300, 300), text="Red:", type_=int) TE['green_buoyancy_slider'] = thorpy.SliderX(length=116, limvals=(-300, 300), text="Green:", type_=int) TE['blue_buoyancy_slider'] = thorpy.SliderX(length=125, limvals=(-300, 300), text="Blue:", type_=int) TE['dissipation_text'] = thorpy.OneLineText(text="Dissipation:", elements=None) TE['dissipation_text'].set_font_size(16) TE['red_dissipation_slider'] = thorpy.SliderX(length=127, limvals=(0, 1.5), text="Red:", type_=float) TE['green_dissipation_slider'] = thorpy.SliderX(length=120, limvals=(0, 1.5), text="Green:", type_=float) TE['blue_dissipation_slider'] = thorpy.SliderX(length=127, limvals=(0, 1.5), text="Blue:", type_=float) TE['force_slider'].set_value(simulation_properties['force'] * 50) TE['viscosity_slider'].set_value(gui_properties['VISC_SLIDER_VALUE']) TE['red_buoyancy_slider'].set_value( simulation_properties['temp_source_red']) TE['green_buoyancy_slider'].set_value( simulation_properties['temp_source_green']) TE['blue_buoyancy_slider'].set_value( simulation_properties['temp_source_blue']) TE['red_dissipation_slider'].set_value( simulation_properties['smoke_diff_away_red']) TE['green_dissipation_slider'].set_value( simulation_properties['smoke_diff_away_green']) TE['blue_dissipation_slider'].set_value( simulation_properties['smoke_diff_away_blue']) TE['cs'] = thorpy.ColorSetter( "Choose a color", value=COLOR_BOX_COLORS[SELECTED_COLOR_INDEX_DOUBLE_CLICK]) TE['cs'].set_size((TOOLBOX_WIDTH - 10, 135)) TE['clear_clickable'].set_size((TOOLBOX_WIDTH - 10, 40)) TE['exit_clickable'].set_size((TOOLBOX_WIDTH - 10, 40)) TE['vel_clickable'].set_size((TOOLBOX_WIDTH - 10, 40)) TE['cs_clickable'] = thorpy.make_button("Set Color") TE['cs_clickable'].set_size((TOOLBOX_WIDTH - 10, 40)) elements = [ TE['cs'], TE['cs_clickable'], TE['vel_clickable'], TE['viscosity_slider'], TE['force_slider'], TE['buoyancy_text'], TE['red_buoyancy_slider'], TE['green_buoyancy_slider'], TE['blue_buoyancy_slider'], TE['dissipation_text'], TE['red_dissipation_slider'], TE['green_dissipation_slider'], TE['blue_dissipation_slider'], TE['clear_clickable'], TE['exit_clickable'], TE['help_clickable'] ] TE['central_box'] = thorpy.Box(elements=elements) central_box_color = tuple(list(TOOLBOX_COLOR) + [255]) #need to add an alpha value TE['central_box'].set_main_color( central_box_color) #set box color and opacity TE['menu'] = thorpy.Menu(TE['central_box']) for element in TE['menu'].get_population(): element.surface = gui_properties['SCREEN'] TE['central_box'].set_topleft((0, 53)) TE['central_box'].set_size((TOOLBOX_WIDTH, TOOLBOX_HEIGHT + 70)) TE['central_box'].blit() TE['central_box'].update()
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()
#Main game: pygame.init() screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT]) #screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) pygame.display.set_caption('Ball Game') balls = pygame.sprite.Group() clock = pygame.time.Clock() maxMass = 75 minMass = 10 massSlider = thorpy.SliderX(maxMass - minMass, [minMass, maxMass], 'Mass slider ', type_=int) massSlider.set_font_size(14) quitButton = thorpy.make_button('Quit', func=thorpy.functions.quit_func) quitButton.set_font_size(14) box = thorpy.Box(elements=[massSlider, quitButton]) box.set_main_color([255, 255, 255]) box_xsize = 100 box_ysize = 5 box.enlarge([box_xsize, box_ysize]) menu = thorpy.Menu(box) for element in menu.get_population(): element.surface = screen
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:", var_text="", titles=[str(i) * i for i in range(1, 9)]) dropdownlist.scale_to_title() dropdownlist.max_chars = 12 #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.") title_element = thorpy.make_text("Overview example", 22, (255, 0, 0)) elements = [ text, line, element, clickable, draggable, checker_check, checker_radio, dropdownlist, browserlauncher, slider, inserter ] 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
v = 340 wavelength = v / f color = (255, 255, 255) t = 1 FPS = 90 A = height / 10 toChange = False screen = pygame.display.set_mode((width, height)) clock = pygame.time.Clock() snd = pygame.font.init() buttonAir = thorpy.make_button("powietrze, v = 340 m/s", airFunction) buttonWater = thorpy.make_button("woda, v = 1500 m/s", waterFunction) buttonIce = thorpy.make_button("lód, v = 3400 m/s", iceFunction) slider = thorpy.SliderX(int(width / 6), (1, 10), "f[HZ]") slider2 = thorpy.SliderX(int(width / 6), (1, height / 5), "A") box = thorpy.Box(elements=[slider, slider2, buttonAir, buttonWater, buttonIce]) menu = thorpy.Menu(box) for element in menu.get_population(): element.surface = screen box.set_topleft((0, 0)) box.center() box.blit() box.update() APP_ON = True
import pygame, thorpy pygame.init() pygame.key.set_repeat(300, 30) screen = pygame.display.set_mode((400, 400)) screen.fill((255, 255, 255)) rect = pygame.Rect((0, 0, 50, 50)) rect.center = screen.get_rect().center clock = pygame.time.Clock() pygame.draw.rect(screen, (255, 0, 0), rect) pygame.display.flip() slider = thorpy.SliderX(100, (12, 35), "My Slider") button = thorpy.make_button("Quit", func=thorpy.functions.quit_func) box = thorpy.Box(elements=[slider, button]) menu = thorpy.Menu(box) for element in menu.get_population(): element.surface = screen box.set_topleft((100, 100)) box.blit() box.update() playing_game = True while playing_game: clock.tick(45) for event in pygame.event.get(): if event.type == pygame.QUIT:
import math import pygame import thorpy pygame.init() clock = pygame.time.Clock() width = 700 height = 700 crashed = False pygame.key.set_repeat(300, 30) Display = pygame.display.set_mode((width, height)) slider1 = thorpy.SliderX(100, (5, 45), "m1", type_=int, initial_value=20) slider2 = thorpy.SliderX(100, (5, 45), "m2", type_=int, initial_value=20) slider3 = thorpy.SliderX(100, (50, 500), "r1", type_=int, initial_value=100) slider4 = thorpy.SliderX(100, (50, 500), "r2", type_=int, initial_value=100) slider5 = thorpy.SliderX(100, (0, 360), "a1", type_=int, initial_value=0) slider6 = thorpy.SliderX(100, (0, 360), "a2", type_=int, initial_value=0) r1 = slider3.get_value() r2 = slider4.get_value() m1 = slider1.get_value() m2 = slider2.get_value() a1 = math.pi / 2 a2 = math.pi / 2 g = 1 a1_v = 0 a2_v = 0 a1_a = 1 a2_a = 1 x2 = 0
import thorpy clock = pygame.time.Clock() pygame.init() pygame.font.init() myfont = pygame.font.SysFont('Arial', 15) width = 800 height = 500 Display = pygame.display.set_mode((width, height)) animate = False crashed = False points = [] inserter = thorpy.Inserter(name="Factor: ", value="2") slider2 = thorpy.SliderX(150, (1, 200), "# of points", type_=int, initial_value=200) factor = int(inserter.get_value()) n = slider2.get_value() radius = 250 box = thorpy.Box(elements=[inserter, slider2]) menu = thorpy.Menu(box) for element in menu.get_population(): element.surface = Display box.set_topleft((500, 300)) textsurface = myfont.render('Toggle animation by pressing the spacebar', False, (0, 0, 0))
UI_TITLE_FONT, (0, 0, 0)) STATS_PADDING = 30 sus_def_text = 'Susceptible: ' inf_def_text = 'Infected: ' rem_def_text = 'Removed: ' susceptible_text = STATS_FONT.render(sus_def_text, True, (0, 0, 0)) infected_text = STATS_FONT.render(inf_def_text, True, (0, 0, 0)) removed_text = STATS_FONT.render(rem_def_text, True, (0, 0, 0)) author_line = BYLINE_FONT.render( 'ViruSim, Alex Christoforides and Chris Dicovskiy', True, (0, 0, 0)) # Setup simulation parameter UI elements infection_chance_slider = thorpy.SliderX( 100, (0.0, max_infection_chance), 'Infection Chance', initial_value=infection_chance_default_value) infection_radius_slider = thorpy.SliderX( 100, (0, max_infection_radius), 'Infection Radius', type_=int, initial_value=infection_radius_default_value) population_density_slider = thorpy.SliderX( 100, (0.0, max_population_density), 'Population Density %', initial_value=population_density_default_value) recovery_chance_slider = thorpy.SliderX( 100, (0.0, max_recovery_chance), 'Recovery Chance %', initial_value=recovery_chance_default_value) starting_infected_textbox = thorpy.Inserter(