XPWidgetDefs¶
To use:
import xp
A widget is a call-back driven screen entity like a push-button, window, text entry field, etc.
Use the widget API to create widgets of various classes. You can nest them into trees of widgets to create complex user interfaces.
Constants¶
XPWidgetPropertyID¶
Properties are values attached to instances of your widgets. A property is
identified by a 32-bit ID, and may be accessed using setWidgetProperty()
and getWidgetProperty()
.
Each widget instance may have a property or not have it. When you set a property on a widget for the first time, the property is added to the widget; it then stays there for the life of the widget.
Some property IDs are predefined by the widget package; you can make up your own property IDs as well.
|
A window’s refcon is an opaque value used by client code to find other data based on it. Official SDK xpProperty_Refcon |
|
These properties are used by the utilities to implement dragging. Official SDK xpProperty_Dragging Official SDK xpProperty_DragXOff Official SDK xpProperty_DragYOff |
|
Is the widget hilited? (For widgets that support this kind of thing.) Official SDK xpProperty_Hilited |
|
Is there a C++ object attached to this widget? Official SDK xpProperty_Object |
|
If this property is 1, the widget package will use OpenGL to restrict drawing to the Wiget’s exposed rectangle. Official SDK xpProperty_Clip |
|
Is this widget enabled (for those that have a disabled state too)? Official SDK xpProperty_Enabled |
|
Minimum value for a user-defined property Official SDK xpProperty_UserStart |
Note
Property IDs 1 - 999 are reserved for the widget’s library.
Note
Property IDs 1000 - 9999 are allocated to the standard widget classes provided with the library Properties 1000 - 1099 are for widget class 0, 1100 - 1199 for widget class 1, etc.
If you create your own property, make sure it’s value is greater than Property_UserStart
.
Such properties will use Python object for storage rather than a simple int or float.
XPDispatchMode¶
The dispatching modes describe how the widgets library sends out messages.
- Mode_Direct = 0¶
The message will only be sent to the target widget.
Official SDK xpMode_Direct
- Mode_UpChain = 1¶
The message is sent to the target widget, then up the chain of parents until the message is handled or a parentless widget is reached.
Official SDK xpMode_UpChain
- Mode_Recursive = 2¶
The message is sent to the target widget and then all of its children recursively depth-first.
Official SDK xpMode_Recursive
- Mode_DirectAllCallbacks = 3¶
The message is sent just to the target, but goes to every callback, even if it is handled.
Official SDK xpMode_DirectAllCallbacks
- Mode_Once = 4¶
The message is only sent to the very first handler even if it is not accepted. (This is really only useful for some internal Widget Lib functions.
Official SDK xpMode_Once
XPWidgetClass¶
Widget classes define predefined widget types. A widget class basically specifies from a library the widget function to be used for the widget. Most widgets can be made right from classes.
- WidgetClass_None = 0¶
Official SDK xpWidgetClass_None
Note
Additional widget classes are defined in XPStandardWidgets
.
XPWidgetMessage¶
Widgets receive 32-bit messages indicating what action is to be taken or notifications of events. The list of messages may be expanded.
You can intercept widget messages by adding a callback (addWidgetCallback()
)
to the widget, or one of its parents.
Note
Additional widget messages are defined in
XPStandardWidgets
.
- Msg_None = 0¶
No message, should not be sent.
Official SDK xpMsg_None
- Msg_Create = 1¶
The create message is sent once per widget that is created with your widget function and once for any widget that has your widget function attached.
Dispatching
Param1
Param2
Direct
1= you are being added as a subclass, 0 if the widget is first being created.
N/A
Official SDK xpMsg_Create
- Msg_Destroy = 2¶
The destroy message is sent once for each message that is destroyed that has your widget function.
Dispatching
Param1
Param2
Direct for
1= you are being deleted by
N/A
all
a recursive delete to the parent, 0 for explicit deletion.
Official SDK xpMsg_Destroy
- Msg_Paint = 3¶
The paint message is sent to your widget to draw itself. The paint message is the bare-bones message; in response you must draw yourself, draw your children, set up clipping and culling, check for visibility, etc. If you don’t want to do all of this, ignore the paint message and a
Msg_Paint
(see below) will be sent to you.
Dispatching
Param1
Param2
Direct
N/A
N/A
Official SDK xpMsg_Paint
- Msg_Draw = 4¶
The draw message is sent to your widget when it is time to draw yourself. OpenGL will be set up to draw in 2-d global screen coordinates, but you should use the XPLM to set up OpenGL state.
Dispatching
Param1
Param2
Direct
N/A
N/A
Official SDK xpMsg_Draw
- Msg_KeyPress = 5¶
The key press message is sent once per key that is pressed. The first parameter is the type of key code (integer or char) and the second is the code itself.
Note
Handling this message ‘consumes’ the keystroke; not handling it passes it to your parent widget.
Dispatching
Param1
Param2
Up Chain
XPKeyState_t tuple
key code
Official SDK xpMsg_KeyPress
- Msg_KeyTakeFocus = 6¶
Keyboard focus is being given to you.
Note
Handling this message accepts focus; not handling refuses focus.
Dispatching
Param1
Param2
Direct
1= a child of yours gave up focus to you. 0= someone set focus to you explicitly.
N/A
Official SDK xpMsg_KeyTakeFocus
- Msg_KeyLoseFocus = 7¶
Keyboard focus is being taken away from you. The first parameter will be one if you are losing focus because another widget is taking it, or 0 if someone called the API to make you lose focus explicitly.
Dispatching
Param1
Param2
Direct
1= if focus is being taken by another widget. 0= code requested to remove focus.
N/A
Official SDK xpMsg_KeyLoseFocus
- Msg_MouseDown = 8¶
You receive one mousedown event per click with a mouse-state structure pointed to by parameter 1, by accepting this you eat the click, otherwise your parent gets it. You will not receive drag and mouse up messages if you do not accept the down message.
Note
Handling this message consumes the mouse click, not handling it passes it to the next widget. You can act ‘transparent’ as a window by never handling moues clicks to certain areas.
Dispatching: Up chain BUT: Technically this is direct dispatched, but the widgets library will shop it to each widget until one consumes the click, making it effectively “up chain”.
Dispatching
Param1
Param2
Up chain
XPMouseState_t tuple.
N/A
Official SDK xpMsg_MouseDown
- Msg_MouseDrag = 9¶
You receive a series of mouse drag messages (typically one per frame in the sim) as the mouse is moved once you have accepted a mouse down message. Parameter one points to a mouse-state structure describing the mouse location. You will continue to receive these until the mouse button is released. You may receive multiple mouse state messages with the same mouse position. You will receive mouse drag events even if the mouse is dragged out of your current or original bounds at the time of the mouse down.
Dispatching
Param1
Param2
Direct
XPMouseState_t tuple.
N/A
Official SDK xpMsg_MouseDrag
- Msg_MouseUp = 10¶
The mouseup event is sent once when the mouse button is released after a drag or click. You only receive this message if you accept the mouseDown message. Parameter one points to a mouse state structure.
Dispatching
Param1
Param2
Direct
XPMouseState_t tuple.
N/A
Official SDK xpMsg_MouseUp
- Msg_Reshape = 11¶
Your geometry or a child’s geometry is being changed.
Dispatching
Param1
Param2
Up-chain
WidgetID of original reshaped target.
XPWidgetGeometryChange_t tuple.
Official SDK xpMsg_Reshape
- Msg_ExposedChanged = 12¶
Your exposed area has changed.
Dispatching
Param1
Param2
Direct
N/A
N/A
Official SDK xpMsg_ExposedChanged
- Msg_AcceptChild = 13¶
A child has been added to you. The child’s ID is passed in parameter one.
Dispatching
Param1
Param2
Direct
Widget ID of child being added.
N/A
Official SDK xpMsg_AcceptChild
- Msg_LoseChild = 14¶
A child has been removed from to you. The child’s ID is passed in parameter one.
Dispatching
Param1
Param2
Direct
Widget ID of child being removed.
N/A
Official SDK xpMsg_LoseChild
- Msg_AcceptParent = 15¶
You now have a new parent, or have no parent. The parent’s ID is passed in, or 0 for no parent.
Dispatching
Param1
Param2
Direct
Widget ID of your parent, 0 if no parent.
N/A
Official SDK xpMsg_AcceptParent
- Msg_Shown = 16¶
You or a child has been shown. Note that this does not include you being shown because your parent was shown, you were put in a new parent, your root was shown, etc.
Dispatching: Up chain
Param 1: The widget ID of the shown widget.
Dispatching
Param1
Param2
Up-chain
WidgetID of shown widget.
N/A
Official SDK xpMsg_Shown
- Msg_Hidden = 17¶
You have been hidden. See limitations as with
Msg_Shown
above.
Dispatching
Param1
Param2
Up-chain
WidgetID of hidden widget.
N/A
Official SDK xpMsg_Hidden
- Msg_DescriptorChanged = 18¶
Your descriptor has changed.
Dispatching
Param1
Param2
Direct
N/A
N/A
Official SDK xpMsg_DescriptorChanged
- Msg_PropertyChanged = 19¶
A property has changed. Param 1 contains the property ID.
Dispatching
Param1
Param2
Direct
XPWidgetPropertyID being changed.
New property value.
Official SDK xpMsg_PropertyChanged
- Msg_MouseWheel = 20¶
The mouse wheel has moved.
Note
Handling this message ‘consumes’ the wheel event; not handling it passes it to your parent widget.
Dispatching
Param1
Param2
Up-chain
XPMouseState_t tuple.
N/A
Official SDK xpMsg_MouseWheel
- Msg_CursorAdjust = 21¶
The cursor is over your widget. If you consume this message, change the XPLMCursorStatus value to indicate the desired result, with the same rules as in with
XPLMDisplay.XPLMHandleCursor_f()
callback used with windows.Note
Handling this message ‘consumes’ the message.
Dispatching
Param1
Param2
Up-chain
XPMouseState_t tuple.
CursorStatus Set this to cursor result you desire.
Official SDK xpMsg_CursorAdjust
- Msg_UserStart = 1000¶
Dispatching
Param1
Param2
User Provided
User Provided
User Provided
Official SDK xpMsg_UserStart
Tuples¶
The C-API packed some returns in a structure, requiring you to manipulate it to extract out the values. XPPython3 extracts the values for you, and returns a tuple instead for these items:
XPMouseState_t¶
XPMouseState_t is a four integer tuple which contains information about the current state of the mouse. It is provided with messages when the mouse is is clicked or dragged:
mouseState = (x, # (x, y) position of the mouse
y,
button, # mouse button, left = 0 (right button not supported yet)
delta # scroll wheel delta (button, in this case would be the wheel axis number)
)
XPKeyState_t¶
XPKeyState_t is a three integer tuple which contains information about the key. It is provided with messages when a key is pressed:
keyState = (key, # The ASCII key pressed. WARNING: this may be 0 for some non-ASCII
flags, # XPLMKeyFlags int
vkey # Virtual key code
)
flags
is a bitfield or’d values XPLMKeyFlags to indicate state of Shift, Ctrl, Alt and whether the key is up or down.vkey
is the virtual key, one of Virtual Key Codes
XPWidgetGeometryChange_t¶
XPWidgetGeometryChange_t is a four integer tuple which contains deltas for your widget’s geometry when it changes:
geometryChange = (dx, # (dx, dy) change in position +Y = the widget moved up.
dy,
dwidth, # (dwidth, dheight) change in size
dheight
)