widgets Package

widgets Package

This module contains all widgets used to construct the screens of the GUI

box Module

Some Box widgets as base for the GUI classes

class usf.widgets.box.Container(orientation, border=False)[source]

Bases: usf.widgets.widget.Widget

This widget is never used directly, it is used to be a base for the HBox and VBox widget.

add(widget, **kwargs)[source]

This function is used to add a widget in the container

draw()[source]

This method draw all widgets surfaces in a surface and return it

focusable = True
handle_keys(event)[source]

This function is used for keyboard events.

handle_mouse(event)[source]

This function is used for mouse events.

update_pos()[source]

updating the position of all widgets in the container

update_size()[source]

This function is used to update the container size after adding a widget.

class usf.widgets.box.HBox[source]

Bases: usf.widgets.box.Container

A widget which is able to contain others widgets and align them horizontally.

class usf.widgets.box.VBox[source]

Bases: usf.widgets.box.Container

A widget which is able to contain others widgets and align them vertically.

button Module

A button widget, with a label.

class usf.widgets.button.Button(text)[source]

Bases: usf.widgets.label.Label

A simple button. It returns a callback when we click on it.

handle_keys(event)[source]
handle_mouse(event)[source]

This function handles mouse event. It returns a callback when we click on it.

hover()[source]
out()[source]
set_size((w, h))[source]

Set the size of the widget. This function is usually called by the container, HBox or VBox.

checkbox Module

This module provide a simple checkbox widget.

class usf.widgets.checkbox.CheckBox[source]

Bases: usf.widgets.widget.Widget

A checkbox widget.

get_value()[source]

Get the value of the checkbox, it returns a boolean. (true of checked and false if unchecked)

handle_mouse(event)[source]
set_size((w, h))[source]

Set the size of the widget.

set_value(value)[source]

Set the value of the checkbox, it must be a boolean.

checkbox_text Module

This module provide a checkbox with a label beside it.

class usf.widgets.checkbox_text.TextCheckBox(text)[source]

Bases: usf.widgets.box.HBox

A checkbox widget.

get_value()[source]

Get the value of the checkbox, it returns a boolean. (true of checked and false if unchecked)

handle_keys(event)[source]
handle_mouse(event)[source]
set_size((w, h))[source]

Set the size of the widget.

set_value(value)[source]

Set the value of the checkbox, it must be a boolean.

update_image()[source]

coverflow Module

A nice coverflow effect for images

class usf.widgets.coverflow.Coverflow(values)[source]

Bases: usf.widgets.widget.Widget

The coverflow widget is used to display many image and choose one of the them. It should be big, about 800 * 275. This widget is animated and requires a lot of CPU.

animation()[source]

update the animation

animation_speed = True
draw()[source]

Draw the widget, the surface will be redrawed if the widget is animated. You can force redrawing by set need_update to True.

draw_left()[source]

Draw three small image at left.

draw_main()[source]

Draw the selected image, it is bigger than the other and in the center

draw_right()[source]

Draw three small image at right.

get_value()[source]

return the currently selected value

handle_keys(event)[source]

manage keyboard input events

handle_mouse(event)[source]

This function handle all mouse events which are on the widget.

launch_anim(direction)[source]

start a translation animation in the direction

load_main_frame()[source]

#FIXME get xapantu to document a little! :P

next()[source]

Select the next item.

previous()[source]

Select the previous item.

sizex(x)[source]

This method is used to get the real size of an element. All size in the code above are for a widget size = 800*275. So, if the size is different, this function modify it. This function is used for the x axis. Use sizey for y axis.

sizey(y)[source]

Same as sizex, but for the y axis.

usf.widgets.coverflow.get_text_transparent(name)[source]

image Module

class usf.widgets.image.Image(image)[source]

Bases: usf.widgets.widget.Widget

An image widget which can be used as a base for others widgets like buttons.

setImage(path)[source]

With this method, you can change the image. ‘CONFIG.system_path’ will be added to ‘path’

set_size((w, h))[source]

Set the size of the image. /!The width and the height have to be the real value (not the value only for 800x480)

imagebutton Module

A Button widget with an image inside, instead of a text.

class usf.widgets.imagebutton.ImageButton(image, image_hover)[source]

Bases: usf.widgets.image.Image

draw()[source]

Return the widget surface. This fonction is often overrided.

handle_mouse(event)[source]
set_size((w, h))[source]

label Module

A label widget, to place text.

class usf.widgets.label.Label(text, **kwargs)[source]

Bases: usf.widgets.widget.Widget

A simple label widget

get_text()[source]

Get the current text of the widget.

set_size((w, h))[source]

Set the size of the widget. This function is usually called by the container, HBox or VBox.

set_text(text)[source]

update the text surface

paragraph Module

class usf.widgets.paragraph.Paragraph(path)[source]

Bases: usf.widgets.widget.Widget

A simple paragraph widget. It reads a text which is in the data/text directory. It include a scroll bar but doesn’t support (yet) auto word wrap.

animation()[source]

This function is used for auto scroll. It is called by the start_anim method which is in the Widget class.

animation_speed = 0.03333333333333333
draw()[source]
handle_mouse(event)[source]
update_defil()[source]

Update the position of the scroll bar.

slider Module

A slider widget to configure values in a range.

class usf.widgets.slider.Slider(text)[source]

Bases: usf.widgets.widget.Widget

draw()[source]
get_value()[source]
handle_keys(event)[source]
handle_mouse(event)[source]
set_value(value)[source]

special Module

Provide a widget to construct the Keyboard Configuration Interface.

class usf.widgets.special.KeyboardWidget(value)[source]

Bases: usf.widgets.widget.Widget

actually it should be KeyWidget, if i get it correctly

draw()[source]
get_value()[source]
handle_keys(event)[source]
handle_mouse(event)[source]
set_size((w, h))[source]
update()[source]

spinner Module

class usf.widgets.spinner.Spinner(values, width=100)[source]

Bases: usf.widgets.box.HBox

A spinner widget. (which could be called “select” too) It looks like this: <- text ->

It can be used to select an option (like a character, a game mode, etc...).

get_index()[source]

Get the index (the range of the current value).

get_value()[source]

Get the current value of the spinner.

handle_keys(event)[source]
handle_mouse(event)[source]
set_index(index)[source]

Set the index (the range of the current value) of the spinner.

set_value(value)[source]

Set the value of the spinner. The value must be in the array that was passed in the __init__ function.

tab Module

class usf.widgets.tab.Tab[source]

Bases: usf.widgets.box.VBox

/!This widget isn’t finished at all TODO

add_tab(tab, box)[source]
handle_mouse(event)[source]
class usf.widgets.tab.TabBar[source]

Bases: usf.widgets.box.HBox

Used in the Tab widget

handle_mouse(event)[source]

text_entry Module

This module provides a widget for UI, allowing to display and edit a line of text, it can be used to edit settings like an IP address for a network game, or a player name.

class usf.widgets.text_entry.TextEntry(text, *args, **kwargs)[source]

Bases: usf.widgets.button.Button

A widget allowing to enter some text

animation()[source]
animation_speed = 0.1
draw()[source]
get_text()[source]

Get the current text of the widget.

handle_keys(event)[source]

manage keyboard input events

handle_mouse(event)[source]

set focus if the click was on the text entry, so we can type in it

move_cursor(x)[source]

place the cursor at the position nearest of x in the widget

widget Module

The base widget object. Probably not tu use directly, but used as base for all other widgets.

class usf.widgets.widget.Widget[source]

Bases: object

This class is the base of all other widget.

animation()[source]
animation_speed = 1.0
draw()[source]

Return the widget surface. This fonction is often overrided.

focusable = False
get_id()[source]
handle_keys(event)[source]
handle_mouse(event)[source]

This function is used for mouse events.

height = 0
last_animation = 0.0
margin = 0
margin_left = 0
parentpos = (0, 0)
properties = {}
set_align(align)[source]
set_id(value)[source]
set_size((w, h))[source]

This function is used to resize a widget.

start_anim()[source]
text = ''
update_pos()[source]
update_size()[source]
widget_id = ''
width = 0
x = 0
y = 0
usf.widgets.widget.get_scale(surface)[source]
usf.widgets.widget.optimize_size(size)[source]