list_box

ListBoxes make use of a ListBoxRenderer. The default ListBoxRenderer simply displays an item’s string representation. To make your own ListBoxRenderer create a class that has a render_item() method that accepts the item to be rendered and returns a widget to render.

Here is an simple example of using the ListBox widget:

class MySys(bgui.System):
        def lb_click(self, lb):
                print(lb.selected)

        def __init__(self):
                bgui.System.__init__(self)

                items = ["One", "Two", 4, 4.6]
                self.frame = bgui.Frame(self, 'window', border=2, size=[0.5, 0.5],
                        options=bgui.BGUI_DEFAULT|bgui.BGUI_CENTERED)
                self.lb = bgui.ListBox(self.frame, "lb", items=items, padding=0.05, size=[0.9, 0.9], pos=[0.05, 0.05])
                self.lb.on_click = self.lb_click

                # ... rest of __init__
class bgui.list_box.ListBox(parent, name, items=[], padding=0, aspect=None, size=[1, 1], pos=[0, 0], sub_theme='', options=12)

Widget for displaying a list of data

Parameters:
  • parent – the widget’s parent
  • name – the name of the widget
  • items – the items to fill the list with (can also be changed via ListBox.items)
  • padding – the amount of extra spacing to put between items (can also be changed via ListBox.padding)
  • aspect – constrain the widget size to a specified aspect ratio
  • size – a tuple containing the width and height
  • pos – a tuple containing the x and y position
  • sub_theme – name of a sub_theme defined in the theme file (similar to CSS classes)
  • options – various other options
add_animation(animation)

Add the animation to the list of currently running animations

Parameters:animation – The animation
children

The widget’s children

frozen

Whether or not the widget should accept events

items

The list of items to display in the ListBox

move(position, time, callback=None)

Move a widget to a new position over a number of frames

Parameters:
  • positon – The new position
  • time – The time in milliseconds to take doing the move
  • callback – An optional callback that is called when he animation is complete
name

The widget’s name

on_active

The widget’s on_active callback

on_click

The widget’s on_click callback

on_hover

The widget’s on_hover callback

on_mouse_enter

The widget’s on_mouse_enter callback

on_mouse_exit

The widget’s on_mouse_exit callback

on_release

The widget’s on_release callback

padding

The amount of extra spacing to put between items

parent

The widget’s parent

position

The widget’s position

renderer

The ListBoxRenderer to use to display items

size

The widget’s size

system

A reference to the system object

visible

Whether or not the widget is visible

z_index

The widget’s z-index. Widget’s with a higher z-index are drawn over those that have a lower z-index

class bgui.list_box.ListBoxRenderer(listbox)

Base class for rendering an item in a ListBox

Parameters:listbox – the listbox the renderer will be used with (used for parenting)
render_item(item)

Creates and returns a bgui.label.Label representation of the supplied item

Parameters:item – the item to be rendered
Return type:bgui.label.Label

Previous topic

label

Next topic

progress_bar

This Page