ThorPy

A GUI library for pygame

User Guide - Cheat Sheet

List of ThorPy elements - List of ThorPy events - List of style methods

List of ThorPy elements

Here are summarized the available built-in elements in ThorPy. We give some examples pointing out specificities of the elements that can be given during initialization. This however does not embrace all the parameters of the different elements. but not all the arguments that can be passed to the constructor. Please note that if you instanciate elements by using class constructors (i.e you do not use make method), you must finish (my_element.finish()) all elements once you have stipulated their design. Refer to this important note. Finally, many composite elements are available (alerts, dialog and choice boxes, image buttons, etc..) : you can find them on the examples page.

Background : define a background for another element or menu.
Example : Background.make(image="/my_data/my_image.png", elements=some_elements), Background(color=(255,255,255))
Full prototype : make(color=None, image=None, elements=None, mode="scale to screen")

Box : box containing other elements
Example : Box.make(elements=some_elements)
Full prototype : make(elements, size=None)

Browser : file and folder browser
Example : Browser.make(path="/my/path/"), Browser.make"./", folders=False, file_types=(".txt", ".png"))
Full prototype : make(path="./", ddl_size=None, folders=True, files=True, file_types=None, text="")

BrowserLauncher : button for launching a file browser
Example : BrowserLauncher.make(a_browser, "Choose a file")
Full prototype : make(browser, const_text="", var_text="", show_select=True, click_cancel=False, text_ok="Ok", text_cancel="Cancel", size=style.MAKE_SIZE)

BrowserLight : file and folder browser for a given directory
Example : BrowserLight.make(path="/my/path/"), BrowserLight.make("./", folders=False, file_types=(".txt", ".png"))
Full prototype : make(path="./", ddl_size=None, folders=True, files=True, file_types=None, text="")

Checker : check or radio box
Example : Checker.make("Do you like potatoes?", value=True), Checker.make("my radio", typ="radio")
Full prototype : make(text="", value=False, type_="checkbox")

Clickable : pressable and hoverable element
Example : Clickable.make("hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

ClickDraggable : togglable clickable that can be dragged/dropped according to its state pressed/unpressed
Example : ClickDraggable.make("hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

ColorSetter : box in which three sliders and a visualization square provide a way to define a color
Example : ColorSetter.make("Choose a color", value=(255, 0, 0))
Full prototype : make(text="", elements=None, size=None, color_size=(50, 50), value=(255, 0, 0))

ColorSetterLauncher : button for launching a ColorSetter instance
Example : ColorSetterLauncher.make(aColorSetter, text="Choose color", show_select=True, click_cancel=False)
Full prototype : make(colorsetter, text="", show_select=True, click_cancel=False)

Draggable : clickable that can be dragged/dropped
Example : Draggable.make("hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

DropDownList : vertical list of multiple texts that can be selected
Example : DropDownList.make(titles=["proposition1", "prop2", "prop3"])
Full prototype : make(titles, size="auto", heavy=False, folders=None, margins=None, x=None)

DropDownListLauncher : button for launching a drop down list
Example : DropDownListLauncher.make(const_text="Choose", titles=list_of_titles)
Full prototype : make(const_text="", var_text="", titles=None, ddlf_size="auto", show_select=True, click_cancel=True, size=style.MAKE_SIZE)

DynamicShadow : shadow that changes when linked element changes
Shadows are highly parametrizable. They do not provide a make initializer (thus you must call finish method!). Please refer to this simple example.
Example : DynamicShadow(target=an_element)

Element : most simple graphical element
Example : Element.make(text="hello"), Element.make("hello", elements=some_children)
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

Ghost : non-graphical element
Example : Ghost.make(), Ghost.make(elements=some_children)
Full prototype : make(elements=None)

Hoverable : hoverable element (reacts on mouse hover)
Example : Hoverable.make("hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

HoverZone : ghost element that can post hover events
Example : HoverZone.make(pygame.Rect(100,50,200,200)), HoverZone.make(some_element.get_rect())
Full prototype : make(zone=None, elements=None)

Image : image element
Example : Image.make(path="path/to/an/image")
Full prototype : make(path=None, color=None)

Inserter : element for text insertion
Example : Inserter.make(name="Write here:", value="just here")
Full prototype : make(name="", elements=None, value="", size=(None, None))

KeyPressable : element that is pressed when a key is pressed
Example : KeyPressable.make(key=pygame.K_t, text="hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

KeyTogglable : element that toggles according to a key press
Example : KeyTogglable.make(key=pygame.K_t, text="hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

Line : separation line
Example : Line.make(size=100, type_="horizontal")
Full prototype : make(size, type_, color=None, pressed=True)

MultilineText : pure text on multiple lines (of course can be only 1 line)
Example : MultilineText.make(text="1st line!\n2nd line...", size=(100,100))
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

OneLineText : pure text on only one line
Example : OneLineText.make("hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

ParamSetter : Put automatically defined elements in a box, in order to set variables.
Example : ParamSetter.make(varsets=a_varset)(see game examples)
Full prototype : make(varsets, elements=None, size=None)

ParamSetterLauncher : Button that launch a ParamSetter.
Example : ParamSetterLauncher.make(varsets=varset_list_or_paramsetter)(see game examples)
Full prototype : (params, text="", title=None, click_cancel=False, text_ok="Ok", text_cancel="Cancel", paramsetter_elements=None, size=style.MAKE_SIZE)

Pressable : element that can be pressed/unpressed (with mouse by default)
Example : Pressable.make("hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

SliderX : slider for choosing a value
Example : SliderX.make(length=100, limvals=(4, 12), text="hello", initial_value=10, typ=float)
Full prototype : make(length, limvals=None, text="", type_=float, initial_value=None)

StaticShadow : shadow that follows its target element
Shadows are highly parametrizable. They do not provide a make initializer (thus you must call finish method!). Please refer to this simple example.
Example : StaticShadow(target_element=an_element)

Togglable : element that can be toggled by mouse
Example : Togglable.make("hello")
Full prototype : make(text="", elements=None, size=style.MAKE_SIZE)

List of ThorPy events

Here are summarized the id attribute of events automatically posted by built-in ThorPy elements. They are all stored in thorpy.constants module. They are all regrouped under the pygame event whose type is thorpy.constants.THORPY_EVENT (see this important note on thorpy events). We summarize below the thorpy events avalaible, giving for each of them the constant name corresponding to their id attribute. With each event are listed its other attributes.

Id Description Attributes
EVENT_CANCEL Posted when a cancel button from a box has been clicked el : element canceled
EVENT_CHANGE_STATE Posted when the state of an element has been changed el : concerned element
EVENT_DDL Posted when a string has been selected in a Drop Down List. Can be posted by a DropDownList or a DropDownListLauncher. el : DropDownList element; value : selected text
EVENT_DONE Posted when a button for validating something has been clicked el : concerned element
EVENT_DRAG Posted each time an element is dragged el : dragged element
EVENT_HOVER Posted when an hoverable element is hovered el : hovered element
EVENT_INSERT Posted when a text has been inserted (and validated) el : inserter element; value : inserted text
EVENT_LAUNCH Posted when an element has been dynamically launched in a menu el : launched element
EVENT_PRESS Posted when an element has been pressed (i.e it enters the state 'pressed') el : pressed element
EVENT_SLIDE Posted when a slider's dragger has been slided el : slider element
EVENT_TIME Posted by the menu, except if it is a thorpy.BasicMenu instance. The menu tries to post this event at each frame (so if your menu has attribute fps = 60, you can expect this event to occur 60 times per second tick : the number of milliseconds passed between the previous two frames of the menu
EVENT_UNPRESS Posted when an element has been unpressed el : unpressed element
EVENT_UNLAUNCH Posted when an element has been dynamically removed from a menu el : concerned element
EVENT_WHEEL Posted when mousewheel has been used on an element that handles it el : concerned element

List of ThorPy basic styling methods

The following methods can be used on all graphical elements for basic styling changes. Also, consider using thorpy.set_theme function if you plan to change the style of a whole group of elements (example : thorpy.set_theme('human')). Moreover, you are free to redefine all the graphical default values contained into thorpy.style (example : thorpy.style.MARGINS = (20,10) will change the default x-y margins for all the next elements initialized). Finally, the tutorial section contains a tutorial about defining your own design template.

set_size(new_size) : resize the element. The new size is a tuple whose elements can be None : in this case, the resizing doesn't occur on the corresponding axis.

scale_to_title() : resize the element so that it fits its textual content. You can optionally pass a tuple as argument, indicating the margins (otherwise the default margins are used).

set_main_color(new_color) : change the element's main color. The color can be in the format (R,G,B) or (R,G,B,A). The element's painter determines how this influe the appearance.

set_font(new_font) : change the font of the element's text. If the font cannot be found in your system, then this instruction is ignored.

set_font_color(color) : change the color of the font.

set_font_size(size): change the font size. The size is a integer corresponding to the size of the font in pts (typical value : 12)

set_font_color_hover(color) : change the color of the font when hovered, for hoverable elements.