OpenGLContext.wxcontext
Context functionality under the wxPython GUI environment
Functions
Classes
Context sub-class for the wxPython GUI environment
This is one of the "supported" Context types (pygame and
glut being the other two). The base Context here is the
root of a hierarchy of wxPython-specific contexts with
most users wanting to use the wxInteractiveContext class,
which provides navigation and examination support.
__init__(
self
,
parent
,
definition
= None
,
id
= -1
,
pos
= wx.Point(-1, -1)
,
style
= 262144
,
name
= 'GLContext'
,
**
named
)
Initialize the wxContext object and window
- parent
- wx.Window parent of the context window
- id
- wxPython ID for the window, can normally be left as the default
- pos
- wxPython position object or a two-tuple of coordinates for the wxPython window that we are creating
- size
- wxPython size object, or a two-tuple of dimensions for the wxPython window that we are creating
- style
- wxPython style integer (a bit-mask) dictating the window style
- name
- string determining the wxPython window's name, which is an internal value which allows wxPython programmers to search for particular windows.
This implementation simply passes the wxPython-specific
arguments to the wxGLCanvas initializer, then calls the
context.Context initializer.
_OnInitCallback(
self
,
event
= None
)
Callback for GTK initialisation-finished event
On all platforms other than GTK, will be called
immediately by the DoInit method. On GTK, it will
be called as the EVT_WINDOW_CREATE event handler.
On GTK where this context is not being created
as a child of a new frame, this will get called
during the first OnPaint method.
DoInit(
self
)
Call the OnInit method at a time when the context is valid
This method provides a customization point where
contexts which do not completely initialize during
their __init__ method can arrange to have the OnInit
method processed after their initialization has
completed. The default implementation here simply
calls OnInit directly w/ appropriate setCurrent
and unsetCurrent calls.
Note:
The only context currently known to require
this customization is the wxPython-on-GTK context,
everything else completes context initialization
before calling Context.__init__.
getDefaultIcons(
cls
)
Get the OpenGLContext icons as a wxPython wxIconBundle
You can call frame.SetIcons( bundle ) on the bundle returned
from this function (set of 2 icons, 16x16 and 32x32)
ProcessEvent(
self
,
event
)
Dispatch events to appropriate engine based on event type
Because the method named "ProcessEvent" is used by both
wxPython and the OpenGLContext.events package, we need to
dispatch to the appropriate handler when the method is called.
XXX This method doesn't appear to get called by wxPython, and
even if it were, almost every context uses the
EventHandlerMixIn class's implementation (which isn't
aware of the wxEventPtr class) anyway.
setCurrent(
self
)
Acquire the OpenGL "focus"
Basically this just calls the GUI library SetCurrent
method after dispatching to the superclass's
implementation.
setupCallbacks(
self
)
Setup various callbacks for this context
Binds most of the wxPython event types to callbacks on this
object, which allows interactive sub-classes to easily
manage the bindings without needing any wxPython-specific
logic.
wxFlagsFromDefinition(
cls
,
definition
)
Determine the flags to pass to he initialiser (attribList)
wxOnEraseBackground(
self
,
event
)
Prevent flashing of the window by capturing and ignoring background erase events
As you might imagine, this is just a hack.
wxOnIdle(
self
,
event
)
Callback: Handle wxPython idle event notification
The major function of this callback is to virtualize
OnIdle handling, that is, to call self.OnIdle if it
actually exists.
wxOnPaint(
self
,
event
)
Callback: Called for each paint event
wxOnPaint is responsible for doing all of the processing
required to setup-for and trigger a redraw of the OpenGL
context. Because this callback can only occur in the
GUI/rendering thread, the call to triggerRedraw should
always cause an immediate rendering cycle.
Note the use of GetClientSize and Viewport, which
updates the viewport dimensions before rendering.
Note also the use of wxPaintDC. Without this
instantiation the paint handler would fail, even
though we don't actually use the dc at all.