Phil's pyGame Utilities Documentation

Overview

Scripts
tileedit | leveledit | tganew | levelfancy

Reference
algo | ani | engine | fonts | high | html | layout | text | timer | vid

Tutorials
1 | 2 | 3 | 4 | 5

GUI Ref.
theme | style | widget | surface | const

Containers
container | app | table | document | area

Forms
form | group

Widgets
basic | button | input | keysym | slider | select | misc

Other
menus | dialog

Tutorials
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10

gui.widget

sections
Widget
Widget.focus
Widget.blur
Widget.open
Widget.close
Widget.resize
Widget.chsize
Widget.update
Widget.paint
Widget.repaint
Widget.repaintall
Widget.reupdate
Widget.next
Widget.previous
Widget.get_abs_rect
Widget.connect
Widget.send
Widget.event

Widget

Template object - base for all widgets.
Widget(**params)

A number of optional params may be passed to the Widget initializer.

decorate

defaults to True. If true, will call theme.decorate(self) to allow the theme a chance to decorate the widget.

style

a dict of style parameters.

x, y, width, height

position and size parameters, passed along to style

align, valign

alignment parameters, passed along to style

font, color, background

other common parameters that are passed along to style

cls

class name as used by Theme

name

name of widget as used by Form. If set, will call form.add(self,name) to add the widget to the most recently created Form.

focusable

True if this widget can receive focus via Tab, etc. Defaults to True.

disabled

True of this widget is disabled. Defaults to False.

value

initial value

Example - Creating your own Widget

This example shows which methods are template methods.

class Draw(gui.Widget):
    def paint(self,s):
        #paint the pygame.Surface
        return

    def update(self,s):
        #update the pygame.Surface and return the update rects
        return [pygame.Rect(0,0,self.rect.w,self.rect.h)]

    def event(self,e):
        #handle the pygame.Event
        return

    def resize(self,width=None,height=None):
        #return the width and height of this widget
        return 256,256

Widget.focus

Focus this Widget.
Widget.focus()

Widget.blur

Blur this Widget.
Widget.blur()

Widget.open

Open this Widget as a modal dialog.
Widget.open()

Widget.close

Close this Widget (if it is a modal dialog.)
Widget.close()

Widget.resize

Template method - return the size and width of this widget.

Responsible for also resizing all sub-widgets.

Widget.resize(width,height): return width,height
width

suggested width

height

suggested height

If not overridden, will return self.style.width, self.style.height

Widget.chsize

Change the size of this widget.

Calling this method will cause a resize on all the widgets, including this one.

Widget.chsize()

Widget.update

Template method - update the surface
Widget.update(s): return list of pygame.Rect(s)
s

pygame.Surface to update

return - a list of the updated areas as pygame.Rect(s).

Widget.paint

Template method - paint the surface
Widget.paint(s)
s

pygame.Surface to paint

Widget.repaint

Request a repaint of this Widget.
Widget.repaint()

Widget.repaintall

Request a repaint of all Widgets.
Widget.repaintall()

Widget.reupdate

Request a reupdate of this Widget
Widget.reupdate()

Widget.next

Pass focus to next Widget.

Widget order determined by the order they were added to their container.

Widget.next()

Widget.previous

Pass focus to previous Widget.

Widget order determined by the order they were added to their container.

Widget.previous()

Widget.get_abs_rect

Get the absolute rect of this widget on the App screen
Widget.get_abs_rect(): return pygame.Rect

Widget.connect

Connect a event code to a callback function.

There may only be one callback per event code.

Object.connect(code,fnc,value)
code

event type [[gui-const]]

fnc

callback function

*values

values to pass to callback. Please note that callbacks may also have "magicaly" parameters. Such as:

_event

receive the event

_code

receive the event code

_widget

receive the sending widget

Example
def onclick(value):
    print 'click',value

w = Button("PGU!")
w.connect(gui.CLICK,onclick,'PGU Button Clicked')

Widget.send

Send a code, event callback trigger.
Object.send(code,event=None)
code

event code

event

event

Widget.event

Template method - called when an event is passed to this object.

Please note that if you use an event, returning the value True will stop parent containers from also using the event. (For example, if your widget handles TABs or arrow keys, and you don't want those to also alter the focus.)

e

event


all content (c) 2006 Phil Hassey - Phil's pyGame Utilities