The ihWidget module provides a low-level interface to the
browser's graphical user interface. The classes that comprise
this module may
be grouped into two major functionalities,
Container
class) and
Widget
class).
Containment classes are the structural glue, used to group together other classes. They define the application's instance hierarchy, and through this and their own layout algorithms determine how the display real-estate will divided up amongst all of the GUI classes in the application. Thus the primary responsibility of a containment class is that of deciding the size and position of the classes that it holds.
Interaction classes are the pieces that define the capabilities
and expression of the application's user interface. Interaction
classes are primarily interested in
In addition, this module defined various low-level types for handling the actual drawing of graphics, colors, and other services often needed in a graphical environment.
There are no global values defined by this module.
WidgetParentError
This exception is raised when a
Container
, or one
of its sub-classes, is instantiated without a parent.
There are no global functions defined by this module.
Pixmap
The Pixmap is a on- or off-screen buffer that can
be drawn into. A new Pixmap can be created with
Container.MakePixmap()
.
BackPen()
BackPen(color)
Color
to use
as the new background pen; if not supplied, the
background pen is not changed.
Color
being used as the background pen.
Color
now being used
for drawing.
ClearRectangle(x, y, w, h)
integer
representing the left edge of the rectangle.
integer
representing the top edge of the rectangle.
integer
representing the width of the rectangle.
integer
representing the height of the rectangle.
Dimensions()
tuple
of the form
( x,
y,
w,
h )
, where:
integer
representing the current left edge, relative to its
display area, of the Pixmap
.
(This is usually zero).
integer
representing the current top edge, relative to its
display area, of the Pixmap
.
(This is usually zero).
integer
representing the total pixel width of the
Pixmap
.
integer
representing the total pixel height of the
Pixmap
.
Pixmap
.
DrawArc(x, y, w, h, a1, a2)
integer
representing the left edge of the arc.
integer
representing the top edge of the arc.
integer
representing the width of the arc.
integer
representing the height of the arc.
float
representing the angle (in degrees) at which to start the
arc. If not supplied, 0.0 is assumed.
float
representing the angle (in degrees) at which to end the
arc. If not supplied, 360.0 is assumed.
DrawLine(x1, y1, x2, y2)
integer
representing the x coordinate of the first
pixel in the line.
integer
representing the y coordinate of the first
pixel in the line.
integer
representing the x coordinate of the last
pixel in the line.
integer
representing the y coordinate of the last
pixel in the line.
DrawRectangle(x, y, w, h)
integer
representing the left edge of the rectangle.
integer
representing the top edge of the rectangle.
integer
representing the width of the rectangle.
integer
representing the height of the rectangle.
DrawText(x, base,
text, just)
integer
representing the pixel location at which to
render; its relationship to the text position depends on
the justification flag, as described below.
integer
representing the pixel location at which the text's
baseline is rendered.
string
representing the actual text to render.
integer
representing the justification of the text. Possible
values are:
FillArc(x, y, w, h, a1, a2)
integer
representing the left edge of the arc.
integer
representing the top edge of the arc.
integer
representing the width of the arc.
integer
representing the height of the arc.
float
representing the angle (in degrees) at which to start the
arc. If not supplied, 0.0 is assumed.
float
representing the angle (in degrees) at which to end the
arc. If not supplied, 360.0 is assumed.
FillRectangle(x, y, w, h)
integer
representing the left edge of the rectangle.
integer
representing the top edge of the rectangle.
integer
representing the width of the rectangle.
integer
representing the height of the rectangle.
ForePen()
ForePen(color)
Color
to use
as the new foreground pen; if not supplied, the
foreground pen is not changed.
Color
being used as the foreground pen.
Color
now being used
for drawing.
Paste(x, y, src,
xsrc, ysrc, w, h)
Pixmap
into
the on-screen display.
integer
representing the left edge at which to place
src.
integer
representing the top edge at which to place
src.
Pixmap
that
is to be copied.
integer
representing the left-most edge in
src that is to be copied. If
not supplied, it defaults to the 0, the extreme left.
integer
representing the top-most edge in
src that is to be copied. If
not supplied, it defaults to 0, the extreme right.
integer
representing the number of horizontal pixels in
src that are to be copied. If
not supplied, it defaults to the the total width minus
xsrc.
integer
representing the number of vertical pixels in
src that are to be copied. If
not supplied, it defaults to the the total height minus
ysrc.
TextExtent(text)
string
representing the text to measure.
tuple
of the form
( w,
h,
asc,
desc )
, where:
integer
representing the total pixel width of the string.
integer
representing the total pixel height of the string.
integer
representing the pixel distance from the text's baseline
to top edge, for this string.
integer
representing the pixel distance from the text's baseline
to bottom edge, for this string.
No member variables are defined by this type.
A Pixmap
is a graphics
buffer into which a program can render. When created by the
program with
Container.MakePixmap()
its dimensions must be
specified, and can not change for the life of the object. It
includes various methods needed for drawing and copying images
within and between Pixmap
s.
FutureCall
The FutureCall
is an object that encapsulates a
call to a function, which will happen at some later date.
A new FutureCall
can be created with
Container.FutureCall()
.
Stop()
Widget
Widget
(or
Container
's
closest parent Widget
) that created the
object.
Function
FutureCall
goes off.
Arguments
tuple
of arguments
to pass to the above function.
Keywords
dictionary
of
keyword arguments to pass to the above function.
A FutureCall
object is a
handle on an event that is to happen at some time in the future.
It encapsulates all of the information needed to perform any
arbitrary Python function call, and sets up a timer to occur at the
appointed time. When created by the program with
Container.FutureCall()
, it is initialized with the
time to make the call, and the called function, standard
parameters, and keyword parameters. The returned object can be
used to examine or change all but the first value, or to force the
call to abort prior to it executing.
Color
A palette color that can be used to draw with.
A new Color
can be created with
Container.MakeColor()
.
No methods are defined by this type.
No member variables are defined by this type.
This is a handle on an allocated palette color, to
be used in calls to
Pixmap.ForePen()
,
Pixmap.BackPen()
, and
Container.Background()
. It can not be manipulated
or examined, but can be compared with other
Color
object to see if they are the same.
When created by the program with
Container.MakeColor()
, a new palette color is
allocated from the operating system and associated with the new
object; this color is deallocated when the
Color
object has no more references on it
and is released.
Container
This is the base-class of all other GUI classes.
Its only responsibility is to hold and organize a list of child
Container
classes (or subclasses).
Widget
.
__init__(self, parent, ...)
Container
.
Application
class.
WidgetParentError
Background(self)
Background(self, color)
Color
to use
as the new background color; if not supplied, the
background color is not changed.
Color
being used as the background color.
BackPen(self)
BackPen(self, color)
Pixmap.BackPen()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
Destroy(self)
Application
class.
Dimensions(self)
tuple
of the form
( x,
y,
w,
h )
, where:
integer
representing the current left edge, relative to its
parent, of the Container
.
integer
representing the current top edge, relative to its
parent, of the Container
.
integer
representing the current total pixel width of the
Container
.
integer
representing the current total pixel height of the
Container
.
Container
.
DoResize(self, x, y, w, h)
integer
representing the new left edge of the
Container
, or
None
to leave it the same.
integer
representing the new top edge of the
Container
, or
None
to leave it the same.
integer
representing the new width of the
Container
, or
None
to leave it the same.
integer
representing the new height of the
Container
, or
None
to leave it the same.
Resize
event being sent to it.
Note that calling this method will note
automatically call the parent container's
Layout
method; you must manually do this
if you would like the parent to update its layout.
DrawArc(self, x, y, w, h, a1, a2)
Pixmap.DrawArc()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
DrawLine(self, x1, y1, x2, y2)
Pixmap.DrawLine()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
DrawRectangle(self, x, y, w, h)
Pixmap.DrawRectangle()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
DrawText(self, x, base,
text, just)
Pixmap.DrawText()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
FillArc(self, x, y, w, h, a1, a2)
Pixmap.FillArc()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
FillRectangle(self, x, y, w, h)
Pixmap.FillRectangle()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
Flush(self)
DrawLine()
,
FillArc()
, etc.) to complete. It
should be called when you would like to ensure that the
display is in a stable state, or prior to accessing
(e.g., using Paste()
) a Pixmap that
you have just drawn into.
FutureCall(self, time, func,
args, keys)
float
indicating the number of seconds in the future at which
the call is to be made.
tuple
of
arguments to supply to the function, as in the second
parameter of Python's apply()
operation. If
not given, no arguments are supplied.
dictionary
of
keyword arguments to supply to the function, as in the
third parameter of Python's apply()
operation. If not given, no keyword arguments are
supplied.
FutureCall
.
FutureCall
object, which encapsulates
the context for a function call that will happen at some
later date.
ForePen(self)
ForePen(self, color)
Pixmap.ForePen()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
KeyState(self)
integer
whose
bits represent the state of individual keys -- see
ihEvent.Event.KeyState
for details on the
meaning of this value.
Layout(self)
MakeColor(self, r, g, b)
float
representing the red component of the color, ranging from
0 (black) to 1 (most intense).
float
representing the green component of the color, ranging from
0 (black) to 1 (most intense).
float
representing the blue component of the color, ranging from
0 (black) to 1 (most intense).
Color
that can be used to set
rendering pens, etc.
MakePixmap(self, w, h)
integer
representing the number of horizontal pixels in the
buffer.
integer
representing the number of vertical pixels in the
buffer.
Pixmap
, that can be drawn into.
MaxDimensions(self, maxw, maxh)
Container
.
integer
supplying the desired maximum width of the container, or
None
if there is no limit.
integer
supplying the desired maximum height of the container, or
None
if there is no limit.
tuple
of the form
( w,
h )
, where:
integer
representing the maximum pixel width that the
Container
can be.
integer
representing the maximum pixel height that the
Container
can be.
MinDimensions()
,
PrefDimensions()
.
Container
--
this is the amount of space needed to display all of its
data, at which point any extra space will go unused.
Note that the object should always be prepared to
grow larger than this size; it is just an advisory for the
parent, so that it can make more intelligent use of its
layout area, if it chooses to do so.
The two optional parameters can be used to apply constraints on the return dimensions. For example, a window may apply a horizontal constraint when laying out out a menu bar. If these are set, the object should try to return maximum dimensions that still allow it to fit within the constraints; doing so may mean bringing the limited dimension down into its "minimum" size range.
MinDimensions(self, maxw, maxh)
Container
.
integer
supplying the desired maximum width of the container, or
None
if there is no limit.
integer
supplying the desired maximum height of the container, or
None
if there is no limit.
tuple
of the form
( w,
h )
, where:
integer
representing the minimum pixel width that the
Container
can be.
integer
representing the minimum pixel height that the
Container
can be.
PrefDimensions()
,
MaxDimensions()
.
Container
can be
made -- this is the size to which it can be reduced while
still being usable, but with all unneeded space removed.
While the parent should never make the
Component
smaller than these
dimensions, be sure that it won't crash if it does
happen to end up smaller!
The two optional parameters can be used to apply constraints on the return dimensions. For example, a window may apply a horizontal constraint when laying out out a menu bar. If these are set, the object should try to return minimum dimensions that will allow it to fit within the constraints.
MousePosition(self)
tuple
of the form
( x,
y )
, where:
integer
representing the mouse pointer's current x pixel location
in the container.
integer
representing the mouse pointer's current y pixel location
in the container.
MouseState(self)
integer
whose
bits represent the state the individual mouse buttons -- see
ihEvent.Event.MouseState
for details on
the meaning of this value.
OnRedraw(self, x, y, w, h)
integer
representing the left edge of the area that needs to be
redrawn.
integer
representing the top edge of the area that needs to be
redrawn.
integer
representing the width of the area that needs to be
redrawn.
integer
representing the height of the area that needs to be
redrawn.
integer
-- if
true (non-zero), the event was handled; if false (zero), it
continues through the higher-level event handlers.
Redraw
event; it may be sent
directly to the object if this is a
Widget
, or if this is a simple
Container
directly called by its
parent object.
Note that ev may be
None
, and if you override this class
you must be sure to call the superclass's method.
OnResize(self, x, y, w, h)
integer
representing the left edge of the new dimensions.
integer
representing the top edge of the new dimensions.
integer
representing the width of the new dimensions.
integer
representing the height of the new dimensions.
integer
-- if
true (non-zero), the event was handled; if false (zero), it
continues through the higher-level event handlers.
Resize
event; it may be sent
directly to the object if this is a
Application
, but more typically is
called as a result of a DoResize()
request.
Note that ev may be
None
.
Paste(self, x, y, src,
xsrc, ysrc, w, h)
Pixmap.Paste()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
PrefDimensions(self, maxw, maxh)
Container
.
integer
supplying the desired maximum width of the container, or
None
if there is no limit.
integer
supplying the desired maximum height of the container, or
None
if there is no limit.
tuple
of the form
( w,
h )
, where:
integer
representing the preferred pixel width that the
Container
can be.
integer
representing the preferred pixel height that the
Container
can be.
MinDimensions()
,
MaxDimensions()
.
Container
--
this is the size that it would like to be for a comfortable
display. Note that this is not, for example in the
case of a text editing field, the size needed to display all
of its data, but simply the size needed to make the graphics
as readable as possible while displaying a reasonable amount
of information; in the case of the text field, this may be
something like 1/4 of the total amount of editable text.
The two optional parameters can be used to apply constraints on the return dimensions. For example, a window may apply a horizontal constraint when laying out out a menu bar. If these are set, the object should try to return preferred dimensions that will allow it to fit within the constraints; doing so may mean bringing the limited dimension down into its "minimum" size range.
TextExtent(self, text)
Pixmap.TextExtent()
. If this object is not a
Widget
, this
method operates in the closest parent
Widget
's context.
_Document_
Document
class, representing the document this
container is on.
Children
array
of the
Container
s that are direct children of
this one in the instance hierarchy. Subclasses of this class
will typically use this array to position their children in their
Layout
method.
Height
Container
.
Width
Container
.
X
Container
within its parent.
XOffset
Container
relative to its closest parent
Widget
. If the
object is an actual Widget, XOffset
is
always set to zero. Otherwise, this value must be added to all
X locations when drawing.
Y
Container
within its parent.
YOffset
Container
relative to its closest parent
Widget
. If the
object is an actual Widget, YOffset
is
always set to zero. Otherwise, this value must be added to all
Y locations when drawing.
The Container
encapsulates the basic functionality needed to organize and layout
a Widget
instance
hierarchy. Its primary responsibilities are to keep track of its
immediate children in the instance hierarchy -- allowing them to be
added, removed, and retrieved -- and to provide the layout
mechanisms used to logically position and dimension the
hierarchy.
This class does note directly supply any drawing or event
handling functions. For the former, it depends on the closest
Widget
above it in
the instance hierarchy. All drawing operations are done in that
object's context. The most important implication of this is that
the drawing operations are performed in the other object's
coordinate system: all positions must have the values
XOffset
and
YOffset
added to them, and the clipping rectangle in use is also that of
the other object.
In addition, the Container
does not
normally receive any user interface events except for
Resize
and Redraw
, making it
unsuitable for user interface components unless special attention
is made to send events to it; instead, this class is most often
used for creating layout managers and other components that do not
directly interact with the user.
Widget
A
Container
that has its own display context and event
handling.
Container
.
ihApp.Application
.
__init__(self, parent, ...)
Widget
.
Container
;
a top-level Widget
's parent is
the
Application
class.
WidgetParentError
Widget
adds a new container to its
parents instance hierarchy that has its own graphics context
and event handling.
See
Container.__init__
for more details.
OnEnter(self, ev)
Widget
.
Event
object corresponding to the user-interface event.
integer
-- if
true (non-zero), the event was handled; if false (zero), it
continues through the higher-level event handlers.
Enter
events. It is called when the
Widget
receives this event,
indicating that the mouse pointer has just entered its
display area.
OnEvent(self, ev)
Event
object corresponding to the user-interface event.
integer
-- if
true (non-zero), the event was handled; if false (zero), it
continues through the higher-level event handlers.
OnKey(self, ev, key, state)
OnKeyPress(self, ev, key, state)
OnKeyRelease(self, ev, key, state)
Event
object corresponding to the user-interface event.
integer
representing the ASCII value of the key.
integer
representing the current state of the key modifiers, as
per the Event
class's
KeyState
member.
integer
-- if
true (non-zero), the event was handled; if false (zero), it
continues through the higher-level event handlers.
OnKeyPress()
and
OnKeyRelease()
correspond to the
specific events KeyPress
and
KeyRelease
,
respectively; OnKey()
is called
when one of the specific handlers is not available for an
event.
OnLeave(self, ev)
Widget
.
Event
object corresponding to the user-interface event.
integer
-- if
true (non-zero), the event was handled; if false (zero), it
continues through the higher-level event handlers.
Leave
events. It is called when the
Widget
receives this event,
indicating that the mouse pointer has just left its
display area.
OnMouse(self, ev, x, y,
state, button)
OnMouseMove(self, ev, x, y,
state, button)
OnMousePress(self, ev, x, y,
state, button)
OnMouseRelease(self, ev, x, y,
state, button)
Event
object corresponding to the user-interface event.
integer
representing the mouse pointer's current horizontal
position with respect to the widget.
integer
representing the mouse pointer's current vertical
position with respect to the widget.
integer
representing the current state of the mouse buttons, as
per the Event
class's
MouseState
member.
integer
representing the button that changed, as
per the Event
class's
MouseButton
member.
integer
-- if
true (non-zero), the event was handled; if false (zero), it
continues through the higher-level event handlers.
OnMouseMove()
,
OnMousePress()
, and
OnMouseRelease()
correspond to the
specific events MouseMove
,
MousePress
, and MouseRelease
,
respectively; OnMouse()
is called
when one of the specific handlers is not available for an
event.
No new member variables are defined by the class.
The Widget
is a subclass
of the Container
:
to the latter's instance hierarchy and layout functionality, it
adds its own drawing environment and event handling mechanisms.
This class's coordinate system is always arranged so that (0,0) is
the top-left corner of the Widget
, and
drawing operations are clipped at its boundaries. This means that
its XOffset
and
YOffset
members are always zero, and thus
do not be taken into account when computing screen locations.
In addition, all drawing is clipped to the
Widget
's boundaries.
Dianne Kyra Hackborn <hackbod@angryredplanet.com> | Last modified: Thu Oct 17 21:49:09 PDT 1996 |