<s> from framework . latentmodule import LatentModule <EOL> import threading <EOL> import rpyc , rpyc . core , rpyc . utils . classic , rpyc . utils . server <EOL> from pandac . PandaModules import * <EOL> from direct . task import Task <EOL> import pygame , time <EOL> import framework . ui_elements . ScrollPresenter , framework . ui_elements . TextPresenter , framework . ui_elements . ImagePresenter , framework . ui_elements . AudioPresenter , framework . ui_elements . WorldspaceGizmos <EOL> import direct . gui . OnscreenImage <EOL> try : <EOL> import framework . speech_io . speech <EOL> except Exception as e : <EOL> print "<STR_LIT>" , e <EOL> client_version = '<STR_LIT>' <EOL> class Main ( LatentModule ) : <EOL> def __init__ ( self ) : <EOL> LatentModule . __init__ ( self ) <EOL> self . client_port = <NUM_LIT> <EOL> self . client_id = <NUM_LIT:0> <EOL> self . keydown_mastercallback = None <EOL> self . keyup_mastercallback = None <EOL> self . joymove_mastercallback = None <EOL> self . speech_mastercallback = None <EOL> self . callbacks_connected = False <EOL> self . localtesting = False <EOL> self . allow_speech = ( self . client_id == <NUM_LIT:0> ) if self . localtesting else True <EOL> self . joystick = None <EOL> self . last_x = <NUM_LIT:0> <EOL> self . last_y = <NUM_LIT:0> <EOL> self . last_u = <NUM_LIT:0> <EOL> self . last_v = <NUM_LIT:0> <EOL> self . last_buttons = ( ) <EOL> def run ( self ) : <EOL> moduleself = self <EOL> class MainService ( rpyc . core . SlaveService ) : <EOL> """<STR_LIT>""" <EOL> def exposed_mastercallbacks ( self , keydown_cbf , keyup_cbf , joymove_cbf , speech_cbf ) : <EOL> moduleself . keydown_mastercallback = rpyc . async ( keydown_cbf ) <EOL> moduleself . keyup_mastercallback = rpyc . async ( keyup_cbf ) <EOL> moduleself . joymove_mastercallback = rpyc . async ( joymove_cbf ) <EOL> moduleself . speech_mastercallback = rpyc . async ( speech_cbf ) <EOL> moduleself . callbacks_connected = True <EOL> def exposed_stimpresenter ( self ) : <EOL> return moduleself <EOL> winprops = WindowProperties ( ) <EOL> winprops . setTitle ( '<STR_LIT>' + client_version + '<STR_LIT>' + str ( self . client_port ) ) <EOL> base . win . requestProperties ( winprops ) <EOL> base . buttonThrowers [ <NUM_LIT:0> ] . node ( ) . setButtonDownEvent ( '<STR_LIT>' ) <EOL> base . buttonThrowers [ <NUM_LIT:0> ] . node ( ) . setButtonUpEvent ( '<STR_LIT>' ) <EOL> self . accept ( '<STR_LIT>' , self . on_keydown ) <EOL> self . accept ( '<STR_LIT>' , self . on_keyup ) <EOL> pygame . init ( ) <EOL> try : <EOL> self . joystick = pygame . joystick . Joystick ( self . client_id if self . localtesting else <NUM_LIT:0> ) <EOL> self . joystick . init ( ) <EOL> taskMgr . add ( self . update_joystick , '<STR_LIT>' ) <EOL> print "<STR_LIT>" <EOL> except : <EOL> print "<STR_LIT>" <EOL> if self . allow_speech : <EOL> try : <EOL> framework . speech_io . speech . listenfor ( [ '<STR_LIT:yes>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:left>' , '<STR_LIT:right>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , self . on_speech ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> self . remote_server = rpyc . utils . server . ThreadedServer ( MainService , port = self . client_port ) <EOL> self . remote_thread = threading . Thread ( target = self . remote_server . start ) <EOL> self . remote_thread . setDaemon ( True ) <EOL> self . remote_thread . start ( ) <EOL> self . sleep ( <NUM_LIT> ) <EOL> def on_tick ( self , dt ) : <EOL> time . sleep ( <NUM_LIT> ) <EOL> def on_keydown ( self , keyname ) : <EOL> if self . callbacks_connected : <EOL> self . keydown_mastercallback ( keyname ) <EOL> def on_keyup ( self , keyname ) : <EOL> if self . callbacks_connected : <EOL> self . keyup_mastercallback ( keyname ) <EOL> def on_speech ( self , phrase , listener ) : <EOL> self . speech_mastercallback ( phrase ) <EOL> def update_joystick ( self , task ) : <EOL> if self . callbacks_connected and self . joystick is not None : <EOL> for e in pygame . event . get ( ) : pass <EOL> x = self . joystick . get_axis ( <NUM_LIT:1> ) <EOL> y = self . joystick . get_axis ( <NUM_LIT:0> ) <EOL> if self . joystick . get_numaxes ( ) >= <NUM_LIT:5> : <EOL> u = self . joystick . get_axis ( <NUM_LIT:3> ) <EOL> v = self . joystick . get_axis ( <NUM_LIT:4> ) <EOL> else : <EOL> u = <NUM_LIT:0> <EOL> v = <NUM_LIT:0> <EOL> buttons = ( self . joystick . get_button ( <NUM_LIT:0> ) , self . joystick . get_button ( <NUM_LIT:1> ) , self . joystick . get_button ( <NUM_LIT:2> ) , self . joystick . get_button ( <NUM_LIT:3> ) ) <EOL> if not ( self . last_x == x and self . last_y == y and self . last_u == u and self . last_v == v and self . last_buttons == buttons ) : <EOL> self . joymove_mastercallback ( x , y , u , v , buttons ) <EOL> self . last_x = x <EOL> self . last_y = y <EOL> self . last_u = u <EOL> self . last_v = v <EOL> self . last_buttons = buttons <EOL> return Task . cont </s>
