<s> import wx <EOL> import pyglet <EOL> from pyglet . gl import * <EOL> import sys <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> from pyglet . window . win32 import _user32 <EOL> from pyglet . gl import wgl <EOL> elif sys . platform == '<STR_LIT>' : <EOL> from pyglet . image . codecs . gdkpixbuf2 import gdk <EOL> from pyglet . gl import glx <EOL> class AbstractCanvas ( pyglet . event . EventDispatcher ) : <EOL> def __init__ ( self , context , config ) : <EOL> if not config : <EOL> platform = pyglet . window . get_platform ( ) <EOL> display = platform . get_default_display ( ) <EOL> screen = display . get_screens ( ) [ <NUM_LIT:0> ] <EOL> for template_config in [ <EOL> pyglet . gl . Config ( double_buffer = True , depth_size = <NUM_LIT> ) , <EOL> pyglet . gl . Config ( double_buffer = True , depth_size = <NUM_LIT:16> ) ] : <EOL> try : <EOL> config = screen . get_best_config ( template_config ) <EOL> break <EOL> except pyglet . window . NoSuchConfigException : <EOL> pass <EOL> if not config : <EOL> raise pyglet . window . NoSuchConfigException ( <EOL> '<STR_LIT>' ) <EOL> if not config . is_complete ( ) : <EOL> config = screen . get_best_config ( config ) <EOL> if not context : <EOL> context = config . create_context ( pyglet . gl . current_context ) <EOL> self . _display = display <EOL> self . _screen = screen <EOL> self . _config = config <EOL> self . _context = context <EOL> def on_resize ( self , width , height ) : <EOL> self . switch_to ( ) <EOL> glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> glMatrixMode ( GL_PROJECTION ) <EOL> glLoadIdentity ( ) <EOL> glOrtho ( <NUM_LIT:0> , width , <NUM_LIT:0> , height , - <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> def switch_to ( self ) : <EOL> self . _switch_to_impl ( ) <EOL> self . _context . set_current ( ) <EOL> pyglet . gl . gl_info . set_active_context ( ) <EOL> pyglet . gl . glu_info . set_active_context ( ) <EOL> def _switch_to_impl ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def flip ( self ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> AbstractCanvas . register_event_type ( '<STR_LIT>' ) <EOL> AbstractCanvas . register_event_type ( '<STR_LIT>' ) <EOL> class AbstractWxCanvas ( wx . Panel , AbstractCanvas ) : <EOL> def __init__ ( self , parent , id = - <NUM_LIT:1> , config = None , context = None ) : <EOL> wx . Window . __init__ ( self , parent , id , style = wx . FULL_REPAINT_ON_RESIZE ) <EOL> AbstractCanvas . __init__ ( self , config , context ) <EOL> self . Bind ( wx . EVT_PAINT , self . _OnPaint ) <EOL> self . Bind ( wx . EVT_SIZE , self . _OnSize ) <EOL> self . Bind ( wx . EVT_ERASE_BACKGROUND , self . _OnEraseBackground ) <EOL> def _OnPaint ( self , event ) : <EOL> wx . PaintDC ( self ) <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> self . flip ( ) <EOL> def _OnEraseBackground ( self , event ) : <EOL> pass <EOL> def _OnSize ( self , event ) : <EOL> width , height = self . GetClientSize ( ) <EOL> self . dispatch_event ( '<STR_LIT>' , width , height ) <EOL> class Win32WxCanvas ( AbstractWxCanvas ) : <EOL> def __init__ ( self , parent , id = - <NUM_LIT:1> , config = None , context = None ) : <EOL> super ( Win32WxCanvas , self ) . __init__ ( parent , id , config , context ) <EOL> self . _hwnd = self . GetHandle ( ) <EOL> self . _dc = _user32 . GetDC ( self . _hwnd ) <EOL> self . _context . _set_window ( self ) <EOL> self . _wgl_context = self . _context . _context <EOL> self . switch_to ( ) <EOL> def _switch_to_impl ( self ) : <EOL> wgl . wglMakeCurrent ( self . _dc , self . _wgl_context ) <EOL> def flip ( self ) : <EOL> wgl . wglSwapLayerBuffers ( self . _dc , wgl . WGL_SWAP_MAIN_PLANE ) <EOL> class GTKWxCanvas ( AbstractWxCanvas ) : <EOL> _window = None <EOL> def __init__ ( self , parent , id = - <NUM_LIT:1> , config = None , context = None ) : <EOL> super ( GTKWxCanvas , self ) . __init__ ( parent , id , config , context ) <EOL> self . _glx_context = self . _context . _context <EOL> self . _x_display = self . _config . _display <EOL> self . _x_screen_id = self . _screen . _x_screen_id <EOL> self . _glx_1_3 = False <EOL> def _OnPaint ( self , event ) : <EOL> if not self . _window : <EOL> self . _window = self . GetHandle ( ) <EOL> gdk_window = gdk . gdk_window_lookup ( self . _window ) <EOL> if self . _glx_1_3 : <EOL> self . _glx_window = glx . glXCreateWindow ( self . _x_display , <EOL> self . _config . _fbconfig , self . _window , None ) <EOL> self . switch_to ( ) <EOL> super ( GTKWxCanvas , self ) . _OnPaint ( event ) <EOL> def _switch_to_impl ( self ) : <EOL> if not self . _window : <EOL> return <EOL> if self . _glx_1_3 : <EOL> glx . glXMakeContextCurrent ( self . _x_display , <EOL> self . _glx_window , self . _glx_window , self . _glx_context ) <EOL> else : <EOL> glx . glXMakeCurrent ( self . _x_display , self . _window , self . _glx_context ) <EOL> def flip ( self ) : <EOL> if not self . _window : <EOL> return <EOL> if self . _glx_1_3 : <EOL> glx . glXSwapBuffers ( self . _x_display , self . _glx_window ) <EOL> else : <EOL> glx . glXSwapBuffers ( self . _x_display , self . _window ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> WxCanvas = Win32WxCanvas <EOL> elif sys . platform == '<STR_LIT>' : <EOL> WxCanvas = GTKWxCanvas <EOL> else : <EOL> assert False <EOL> class TestCanvas ( WxCanvas ) : <EOL> label = pyglet . text . Label ( '<STR_LIT>' , font_size = <NUM_LIT> , <EOL> anchor_x = '<STR_LIT>' , anchor_y = '<STR_LIT>' ) <EOL> def on_draw ( self ) : <EOL> width , height = self . GetClientSize ( ) <EOL> glClear ( GL_COLOR_BUFFER_BIT ) <EOL> self . label . text = '<STR_LIT>' % pyglet . gl . gl_info . get_version ( ) <EOL> self . label . x = width // <NUM_LIT:2> <EOL> self . label . y = height // <NUM_LIT:2> <EOL> self . label . draw ( ) <EOL> class TestFrame ( wx . Frame ) : <EOL> def __init__ ( self , parent , title ) : <EOL> wx . Frame . __init__ ( self , parent , - <NUM_LIT:1> , title , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> canvas = TestCanvas ( self ) <EOL> class TestApp ( wx . App ) : <EOL> def OnInit ( self ) : <EOL> frame = TestFrame ( None , '<STR_LIT>' ) <EOL> self . SetTopWindow ( frame ) <EOL> frame . Show ( True ) <EOL> return True <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> TestApp ( redirect = False ) . MainLoop ( ) </s>
