pygo/sgc/widgets/boxes.py
2012-04-14 18:38:47 -04:00

75 lines
2.2 KiB
Python

#!/usr/bin/env python
# Copyright (C) 2011-2012 Sam Bull
"""
Boxes are container widgets with automatic positioning/padding of widgets.
"""
from container import Container
class VBox(Container):
"""
VBox is a container widget which sorts widgets into a vertical
structure.
If ``surf`` is not given, container will be the right size to fit all
widgets.
"""
_settings_default = {"border": 5, "spacing": 5, "col": 0, "widgets": None}
def _config(self, **kwargs):
"""
widgets: ``list`` Contains widgets to pack into box.
The order of widgets in the list denotes order they are packed.
border: ``int`` Number of pixels to space around edges when ``surf``
is not given.
col: ``tuple`` (r,g,b) Colour for background, 0 is transparent.
spacing: ``int`` Number of pixels to space between widgets.
"""
if "spacing" in kwargs:
self._settings["spacing"] = kwargs["spacing"]
if "widgets" in kwargs:
pos = 0
for w in kwargs["widgets"]:
w.pos = (0, pos)
pos += w.rect.h + self._settings["spacing"]
Container._config(self, **kwargs)
class HBox(Container):
"""
HBox is a container widget which sorts widgets into a horizontal
structure.
If ``surf`` is not given, container will be the right size to fit all
widgets.
"""
_settings_default = {"border": 5, "spacing": 5, "col": 0, "widgets": None}
def _config(self, **kwargs):
"""
widgets: ``list`` Contains widgets to pack into box.
The order of widgets in the list denotes order they are packed.
border: ``int`` Number of pixels to space around edges when ``surf``
is not given.
col: ``tuple`` (r,g,b) Colour for background, 0 is transparent.
spacing: ``int`` Number of pixels to space between widgets.
"""
if "spacing" in kwargs:
self._settings["spacing"] = kwargs["spacing"]
if "widgets" in kwargs:
pos = 0
for w in kwargs["widgets"]:
w.pos = (pos, 0)
pos += w.rect.w + self._settings["spacing"]
Container._config(self, **kwargs)