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()
def createButton(title, index, painter): # Declare Variables button = None #Clickable(thorpy) # Create button button = thorpy.Clickable(title) button.user_func = Launcher.launchGame button.user_params = {"gameID": index} button.set_painter(painter) button.finish() button.set_font_size(23) button.set_font_color_hover((255, 255, 255)) # Return return button
def createButton(title, index, painter1, painter2): # Declare Variables button = None #Clickable(thorpy) # Create button if index != Scoreboard.displayGame: # Clickable Button button = thorpy.Clickable(title) button.user_func = Scoreboard.changeGame button.user_params = {"gameID": index} button.set_painter(painter1) button.finish() button.set_font_size(17) button.set_font_color_hover((255, 255, 255)) else: # Non-clickable Button button = thorpy.Element(title) button.set_painter(painter2) button.finish() button.set_font_size(17) # Return return button
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 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()
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="")
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, radius_int=0.4, border_color=(0, 0, 255), color=(100, 100, 255)) a_round_button.set_painter(painter) a_round_button.finish() buttons.append(a_round_button) #Another customized style #set default painter as ClassicFrame (same as used in theme 'classic') thorpy.painterstyle.DEF_PAINTER = thorpy.painters.classicframe.ClassicFrame thorpy.style.MARGINS = (50, 2) #set default margins thorpy.style.COLOR_TXT_HOVER = (255, 0, 0) button = thorpy.make_button("Another custom button")
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()
]: rect_corner.center = pos pygame.draw.rect(surface, color_corner, rect_corner) pygame.draw.rect(surface, self.c2, rect_body) #draw body #draw body border: pygame.draw.rect(surface, self.c3, rect_body.inflate((-5, -5))) #redraw corner rects if hovered if self.hovered: for pos in [ rect_body.topleft, rect_body.bottomleft, rect_body.topright, rect_body.bottomright ]: rect_corner.center = pos pygame.draw.rect(surface, color_corner, rect_corner) surface.set_clip(self.clip) #don't forget to set clip return surface my_painter = MyPainter((255, 0, 0), (0, 255, 0), (200, 200, 255)) my_button = thorpy.Clickable("My Button") #don't use 'make' ! my_button.set_painter(my_painter) my_button.finish() #don't forget to call 'finish() my_button.center() background = thorpy.Background.make((255, 255, 255), elements=[my_button]) background.finish() menu = thorpy.Menu(background) menu.play() application.quit()
return me, img, mi def refresh(): global me, mi me, img, mi = generate_map() me.screen.fill((255, 255, 255)) ei.get_elements()[0].set_image(img) for e in els: e.blit() pygame.display.flip() e = thorpy.make_button("Generate another map", refresh) me, img, mi = generate_map() ei = thorpy.Clickable(elements=[thorpy.Image(img)]) ei.fit_children() ei.user_func = thorpy.functions.quit_menu_func els = [e, ei] me.screen.fill((255, 255, 255)) pygame.display.flip() thorpy.store("screen", els) m = thorpy.Menu(els) m.play() game = Game(me) humans = Race("Coco", "human", LUNAR, me, "green", team=1) #LUNAR, STELLAR or SOLAR humans.dist_factor = 10 humans.finalize() #always call this function to finish initialize a race !!!
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:",
me.screen.fill((255, 255, 255)) img = thorpy.get_resized_image(img, (300, 300)) button_img_map.get_elements()[0].set_image(img) for button_genmap in buttons: button_genmap.blit() pygame.display.flip() W, H = 1000, 700 #screen size app = thorpy.Application((W, H)) FPS = 80 button_genmap = thorpy.make_button("Generate another map", refresh) me, img, mi = generate_map() img = thorpy.get_resized_image(img, (300, 300)) button_img_map = thorpy.Clickable(elements=[thorpy.Image(img)]) button_img_map.fit_children() button_img_map.user_func = thorpy.functions.quit_menu_func buttons = [button_genmap, button_img_map] thorpy.store("screen", buttons) me.screen.fill((255, 255, 255)) pygame.display.flip() m = thorpy.Menu(buttons) m.play() game = Game(me) #<fast> : quality a bit lower if true, loading time a bit faster. #<use_beach_tiler>: quality much better if true, loading much slower. #<load_tilers> : Very slow but needed if you don't have Numpy but still want HQ. game.build_map(mi, fast=False, use_beach_tiler=True, load_tilers=False)
buttons[7].scale_to_title() #set theme thorpy.set_theme("human") buttons += [thorpy.make_button("button" + str(i)) for i in range(8, 11)] #set default painter as ClassicFrame (same as used in theme 'classic') thorpy.painterstyle.DEF_PAINTER = thorpy.painters.classicframe.ClassicFrame thorpy.style.MARGINS = (50, 2) #set default margins buttons += [thorpy.make_button("button" + str(i)) for i in range(11, 14)] background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG, elements=buttons) thorpy.store(background) #very personalized style a_round_button = thorpy.Clickable("Round Button") painter = thorpy.painters.optionnal.human.Human(size=(100, 50), radius_ext=0.5, radius_int=0.4, border_color=(0, 0, 255)) a_round_button.set_painter(painter) a_round_button.finish() a_text_button = thorpy.make_text("Hello", font_size=20, font_color=(0, 255, 0)) a_text_button.stick_to(background, "right", "right") menu = thorpy.Menu([background, a_round_button, a_text_button]) menu.play() application.quit()