ALBOW
A Little Bit of Widgetry for PyGame
This is a very basic, no-frills widget set for creating a GUI using
PyGame. It was developed to serve the needs of one particular game (my
PyWeek 3 competition entry, Sneak) and so far has not been extensively
tested outside that environment. I am documenting and releasing it as a
separate package so that others may benefit from it, and so that it
will be permissible for use in future PyGame entries.
Contents
Usage
Typical usage of the widget system is as follows:
- Initialize the PyGame display surface.
- Create an instance of RootWidget or subclass thereof (such as Shell), passing it the display surface.
- Create additional widgets if needed and add them as subwidgets of
the root widget. If using Shell, create the screens you will be using
and display your main screen.
- Start the frame timer if you will be using it (see RootWidget.set_timer()).
- Call the run() method of the root widget.
Events
Mouse events are classified into mouse_down, mouse_drag, mouse_up and mouse_move,
and are delivered by calling the corresponding method of the relevant
widget. Mouse-down events are delivered to the widget in which the
event occurs. Mouse-drag and mouse-up events are delivered to the
widget that received the last mouse-down event. Mouse-move events (with
no mouse button pressed) are delivered to the widget in which they
occur.
In addition to the usual PyGame event attributes, mouse events have the following extra attributes:
- local
- Position of the mouse in the local coordinate system of the widget to which it is delivered.
Keyboard events are delivered by calling the key_down or key_up methods of the widget having the current keyboard focus. A widget is given the keyboard focus by calling its focus()
method. If the focus widget does not handle a key-down event, it is
passed up the widget hierarchy until a handler is found. (This does not
currently apply to key-up events.)
In addition to the usual PyGame event attributes, key events have the following extra attributes:
- cmd
- True if the Control, Meta or (on a Mac) Command key modifier is present.
---