<s> '''<STR_LIT>''' <EOL> __docformat__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> import pyglet <EOL> class Rectangle ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , x1 , y1 , x2 , y2 , batch ) : <EOL> self . vertex_list = batch . add ( <NUM_LIT:4> , pyglet . gl . GL_QUADS , None , <EOL> ( '<STR_LIT>' , [ x1 , y1 , x2 , y1 , x2 , y2 , x1 , y2 ] ) , <EOL> ( '<STR_LIT>' , [ <NUM_LIT:200> , <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT:255> ] * <NUM_LIT:4> ) <EOL> ) <EOL> class TextWidget ( object ) : <EOL> def __init__ ( self , text , x , y , width , batch ) : <EOL> self . document = pyglet . text . document . UnformattedDocument ( text ) <EOL> self . document . set_style ( <NUM_LIT:0> , len ( self . document . text ) , <EOL> dict ( color = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) ) <EOL> ) <EOL> font = self . document . get_font ( ) <EOL> height = font . ascent - font . descent <EOL> self . layout = pyglet . text . layout . IncrementalTextLayout ( <EOL> self . document , width , height , multiline = False , batch = batch ) <EOL> self . caret = pyglet . text . caret . Caret ( self . layout ) <EOL> self . layout . x = x <EOL> self . layout . y = y <EOL> pad = <NUM_LIT:2> <EOL> self . rectangle = Rectangle ( x - pad , y - pad , <EOL> x + width + pad , y + height + pad , batch ) <EOL> def hit_test ( self , x , y ) : <EOL> return ( <NUM_LIT:0> < x - self . layout . x < self . layout . width and <EOL> <NUM_LIT:0> < y - self . layout . y < self . layout . height ) <EOL> class Window ( pyglet . window . Window ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Window , self ) . __init__ ( <NUM_LIT> , <NUM_LIT> , caption = '<STR_LIT>' ) <EOL> self . batch = pyglet . graphics . Batch ( ) <EOL> self . labels = [ <EOL> pyglet . text . Label ( '<STR_LIT:Name>' , x = <NUM_LIT:10> , y = <NUM_LIT:100> , anchor_y = '<STR_LIT>' , <EOL> color = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) , batch = self . batch ) , <EOL> pyglet . text . Label ( '<STR_LIT>' , x = <NUM_LIT:10> , y = <NUM_LIT> , anchor_y = '<STR_LIT>' , <EOL> color = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) , batch = self . batch ) , <EOL> pyglet . text . Label ( '<STR_LIT>' , x = <NUM_LIT:10> , y = <NUM_LIT:20> , <EOL> anchor_y = '<STR_LIT>' , color = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) , <EOL> batch = self . batch ) <EOL> ] <EOL> self . widgets = [ <EOL> TextWidget ( '<STR_LIT>' , <NUM_LIT:200> , <NUM_LIT:100> , self . width - <NUM_LIT> , self . batch ) , <EOL> TextWidget ( '<STR_LIT>' , <NUM_LIT:200> , <NUM_LIT> , self . width - <NUM_LIT> , self . batch ) , <EOL> TextWidget ( '<STR_LIT>' , <NUM_LIT:200> , <NUM_LIT:20> , self . width - <NUM_LIT> , self . batch ) <EOL> ] <EOL> self . text_cursor = self . get_system_mouse_cursor ( '<STR_LIT:text>' ) <EOL> self . focus = None <EOL> self . set_focus ( self . widgets [ <NUM_LIT:0> ] ) <EOL> def on_resize ( self , width , height ) : <EOL> super ( Window , self ) . on_resize ( width , height ) <EOL> for widget in self . widgets : <EOL> widget . width = width - <NUM_LIT> <EOL> def on_draw ( self ) : <EOL> pyglet . gl . glClearColor ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . clear ( ) <EOL> self . batch . draw ( ) <EOL> def on_mouse_motion ( self , x , y , dx , dy ) : <EOL> for widget in self . widgets : <EOL> if widget . hit_test ( x , y ) : <EOL> self . set_mouse_cursor ( self . text_cursor ) <EOL> break <EOL> else : <EOL> self . set_mouse_cursor ( None ) <EOL> def on_mouse_press ( self , x , y , button , modifiers ) : <EOL> for widget in self . widgets : <EOL> if widget . hit_test ( x , y ) : <EOL> self . set_focus ( widget ) <EOL> break <EOL> else : <EOL> self . set_focus ( None ) <EOL> if self . focus : <EOL> self . focus . caret . on_mouse_press ( x , y , button , modifiers ) <EOL> def on_mouse_drag ( self , x , y , dx , dy , buttons , modifiers ) : <EOL> if self . focus : <EOL> self . focus . caret . on_mouse_drag ( x , y , dx , dy , buttons , modifiers ) <EOL> def on_text ( self , text ) : <EOL> if self . focus : <EOL> self . focus . caret . on_text ( text ) <EOL> def on_text_motion ( self , motion ) : <EOL> if self . focus : <EOL> self . focus . caret . on_text_motion ( motion ) <EOL> def on_text_motion_select ( self , motion ) : <EOL> if self . focus : <EOL> self . focus . caret . on_text_motion_select ( motion ) <EOL> def on_key_press ( self , symbol , modifiers ) : <EOL> if symbol == pyglet . window . key . TAB : <EOL> if modifiers & pyglet . window . key . MOD_SHIFT : <EOL> dir = - <NUM_LIT:1> <EOL> else : <EOL> dir = <NUM_LIT:1> <EOL> if self . focus in self . widgets : <EOL> i = self . widgets . index ( self . focus ) <EOL> else : <EOL> i = <NUM_LIT:0> <EOL> dir = <NUM_LIT:0> <EOL> self . set_focus ( self . widgets [ ( i + dir ) % len ( self . widgets ) ] ) <EOL> elif symbol == pyglet . window . key . ESCAPE : <EOL> pyglet . app . exit ( ) <EOL> def set_focus ( self , focus ) : <EOL> if self . focus : <EOL> self . focus . caret . visible = False <EOL> self . focus . caret . mark = self . focus . caret . position = <NUM_LIT:0> <EOL> self . focus = focus <EOL> if self . focus : <EOL> self . focus . caret . visible = True <EOL> self . focus . caret . mark = <NUM_LIT:0> <EOL> self . focus . caret . position = len ( self . focus . document . text ) <EOL> window = Window ( resizable = True ) <EOL> pyglet . app . run ( ) </s>
