@@ -33,22 +33,26 @@ def connectionLost(self, reason):
33
33
d .trigger (e = "connectionLost" , model = None , params = None )
34
34
35
35
def lineReceived (self , string ):
36
- model , method , params = json .loads (string )
37
- if method == 'set-mp-time' :
36
+ obj = json .loads (string )
37
+ if obj [ ' method' ] == 'set-mp-time' :
38
38
if self .factory .clock :
39
39
self .factory .clock .setTime (float (params [0 ]))
40
- elif method == 'disconnect' :
40
+ elif obj [ ' method' ] == 'disconnect' :
41
41
self .factory .p .transport .loseConnection ()
42
42
else :
43
- if method == 'reset' :
43
+ if obj [ ' method' ] == 'reset' :
44
44
if self .factory .clock :
45
45
self .factory .clock .setTime (0.0 )
46
46
for d in self .factory .dispatchers :
47
- d .trigger (e = method , model = model , params = params )
48
- self .sendLine (json .dumps ([model , "sync" , None ]))
47
+ d .trigger (e = obj ['method' ],
48
+ model = obj ['model' ],
49
+ params = obj ['params' ])
50
+ self .sendCommand (obj ['model' ], "sync" )
49
51
50
- def sendCommand (self , model , method , * params ):
51
- self .sendLine (json .dumps ([model , method , params ]))
52
+ def sendCommand (self , model , method , ** params ):
53
+ self .sendLine (json .dumps ({"model" : model ,
54
+ "method" : method ,
55
+ "params" : params }))
52
56
53
57
class JNI_Server (Factory ):
54
58
@@ -70,31 +74,31 @@ def buildProtocol(self, addr):
70
74
def update_display (self , chunks , clear = False ):
71
75
visual_locations = [chunk .get_visual_location () for chunk in chunks ]
72
76
visual_objects = [chunk .get_visual_object () for chunk in chunks ]
73
- self .p .sendCommand (self .model , "update-display" , [visual_locations , visual_objects ], clear )
77
+ self .p .sendCommand (self .model , "update-display" , chunks = [visual_locations , visual_objects ], clear = clear )
74
78
75
79
def set_cursor_location (self , loc ):
76
- self .p .sendCommand (self .model , "set-cursor-loc" , loc )
80
+ self .p .sendCommand (self .model , "set-cursor-loc" , loc = loc )
77
81
78
82
def digit_sound (self , digit ):
79
- self .p .sendCommand (self .model , "new-digit-sound" , digit )
83
+ self .p .sendCommand (self .model , "new-digit-sound" , digit = digit )
80
84
81
85
def tone_sound (self , freq , duration ):
82
- self .p .sendCommand (self .model , "new-tone-sound" , freq , duration )
86
+ self .p .sendCommand (self .model , "new-tone-sound" , frequency = freq , duration = duration )
83
87
84
- def word_sound (self , word ):
85
- self .p .sendCommand (self .model , "new-word-sound" , word )
88
+ def word_sound (self , words ):
89
+ self .p .sendCommand (self .model , "new-word-sound" , words = words )
86
90
87
- def other_sound (self , content , duration , delay , recode ):
88
- self .p .sendCommand (self .model , "new-other-sound" , content , duration , delay , recode )
91
+ def other_sound (self , content , onset , delay , recode ):
92
+ self .p .sendCommand (self .model , "new-other-sound" , content = content , onset = onset , delay = delay , recode = recode )
89
93
90
94
def trigger_reward (self , reward ):
91
- self .p .sendCommand (self .model , "trigger-reward" , reward )
92
-
93
- def set_visual_center_pint (self , (x , y )):
94
- self .p .sendCommand (self .model , "set-visual-center-point" , x , y )
95
+ self .p .sendCommand (self .model , "trigger-reward" , reward = reward )
95
96
96
97
def disconnect (self ):
97
98
self .p .sendCommand (self .model , "disconnect" )
98
99
99
100
def setup (self , width , height ):
100
- self .p .sendCommand (self .model , "setup" , width , height )
101
+ self .p .sendCommand (self .model , "setup" , width = width , height = height )
102
+
103
+ def trigger_event (self , event , * args ):
104
+ self .p .sendCommand (self .model , "trigger-event" , event = event , args = args )
0 commit comments