class Component
Component is an abstract base class representing a visual component of
the graphical user interface. A Component owns a rectangular region
of screen space defined by its bounds property. It may be contained
within another component, in which case it is clipped to the boundaries of
its container.
Geometry Properties
The geometry properties control the position and size of the component
within its container. There are several overlapping sets of geometry properties,
corresponding to different ways of defining the component's bounding rectangle.
The properties within each set are orthogonal, meaning that any one of
them may be changed without affecting the others.
- bounds
- A rectangle (left, top, right, bottom) in the container's
coordinate system.
- left
- top
- right
- bottom
- Each of these properties corresponds to one element of the bounds
rectangle. Changing one of these properties changes the position of one
edge of the component without affecting any of the others (and will consequently
change the width or height).
- x
- y
- width
- height
- The x and y properties are the coordinates of the
top left corner of the component in its container's coordinate system.
Assigning to x or y will change the position of the component
within its container, but not its size.
- position
- size
- The position property is equivalent to the tuple (x,
y). The size property is equivalent to the tuple (width, height).
Other Properties
- container
- The Frame which contains this Component, if any. Setting this property
has the effect of removing the Component from the previous container and
adding it to the new container.
- visible
- True if the component is to be (potentially) visible within its container.
Setting this to false will hide the component.
- border
- Setting this to true requests that the component be given a border.
The width and style of the border (or whether it even exists at all) is platform-dependent.
When the border is present, it is positioned around the outside of the component's
bounds rectangle, and is not included in the component's size.
Resizing Attributes
These attributes determine what happens to the container's position and
size when the size of its container changes as a result of the user resizing
the containing window, or a containing component's resize method
being called. These attributes are typically not set directly, but are established
by the container's place method when the component is added to
the container.
- hmove
- If true, a change to the width of the container causes this component
to move horizontally by the same amount.
- vmove
- If true, a change to the height of the container causes this component
to move vertically by the same amount.
- hstretch
- If true, a change to the width of the container causes the width
of this component to change by the same amount.
- vstretch
- If true, a change to the height of the container causes the height
of this component to change by the same amount.
Methods
- hide()
- Makes the component invisible. Equivalent to setting the visible
property to false.
- show()
- Makes the component visible. Equivalent to setting the visible
property to true. Some components may also do other things in response to
this method (e.g. see Window).
- become_target()
- Arranges for this component to have the first chance to handle
keystrokes, menu commands and other messages dispatched to the containing
window. If the component is not contained in a window, the effect is undefined.
- is_target()
- Returns true if this component is the current message target
within its containing window. If the component is not contained in a window,
the result is undefined.
- current_target()
- Returns the component which is the current message target within
the containing window. If there is no current target, the window itself is
returned. If the component is not contained in a window, the result is undefined.
- resize(geometry_property = value,
...)
- Changes the specified geometry properties, and if this causes the
component's size to change, updates the geometries of its subcomponents according
to their resizing attributes. (Assigning directly to the geometry properties
does not cause subcomponents to be moved or resized.)
Callbacks
- targeted(state)
- Called whenever this object becomes or ceases to be the current message
target. The state argument is true if the object has become the
target, false if it has ceased to be the target.
Destructor
- destroy()
- Destroys the component and removes it from the screen. It should not
be used again.