Skip to content

Commit 0327be5

Browse files
committed
lots of updates
1 parent eefbd65 commit 0327be5

9 files changed

+41
-32
lines changed

examples/python/environment.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env python
22

3+
4+
import sys,os
5+
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../lib/python"))
6+
37
# For general environment
48
from twisted.internet import reactor
59
from twisted.internet.task import LoopingCall, Cooperator
@@ -18,7 +22,7 @@
1822

1923
class Letter(object):
2024

21-
colors = {'blue':(0, 0, 255), 'red':(255, 0, 0)}
25+
colors = {':blue':(0, 0, 255), ':red':(255, 0, 0)}
2226

2327
def __init__(self, letter, quad, start, colors, max_font_size):
2428
self.letter = letter
@@ -51,7 +55,7 @@ class Environment(object):
5155
STATE_SEARCH = 3
5256
STATE_DONE = 4
5357

54-
colors = {'white':(255, 255, 255), 'black':(0, 0, 0)}
58+
colors = {':white':(255, 255, 255), ':black':(0, 0, 0)}
5559

5660
def __init__(self, actr=False):
5761

@@ -101,14 +105,14 @@ def reset(self):
101105
while not self.screen_rect.contains(self.intro_xs) or self.intro_ts.colliderect(self.intro_xs):
102106
self.intro_xs.center = (randint(0, self.screen_rect.width), randint(0, self.screen_rect.height))
103107
self.start = sample([1, 0, 0, 0], 4)
104-
colors = sample(["red", "blue"], 2)
108+
colors = sample([":red", ":blue"], 2)
105109
self.letters = sample(string.ascii_uppercase, 4)
106110
self.objects = [Letter(self.letters[i], i + 1, self.start[i], colors, self.max_font_size) for i in range(0, len(self.letters))]
107111
self.clockwise = choice([True, False])
108112
if self.clockwise:
109-
self.bgcolorname = 'black'
113+
self.bgcolorname = ':black'
110114
else:
111-
self.bgcolorname = 'white'
115+
self.bgcolorname = ':white'
112116
self.bgcolor = self.colors[self.bgcolorname]
113117
start = self.start.index(True)
114118
if self.clockwise:
@@ -250,6 +254,7 @@ def setDefaultClock(self):
250254
@d.listen('connectionMade')
251255
def ACTR6_JNI_Event(self, model, params):
252256
self.state = self.STATE_WAIT_MODEL
257+
self.actr.setup(self.screen_rect.width, self.screen_rect.height)
253258

254259
@d.listen('connectionLost')
255260
def ACTR6_JNI_Event(self, model, params):
@@ -258,15 +263,15 @@ def ACTR6_JNI_Event(self, model, params):
258263

259264
@d.listen('reset')
260265
def ACTR6_JNI_Event(self, model, params):
261-
self.actr_time_lock = params[0]
266+
self.actr_time_lock = params['time-lock']
262267
self.setDefaultClock()
263268
self.state = self.STATE_WAIT_MODEL
264269

265270
@d.listen('model-run')
266271
def ACTR6_JNI_Event(self, model, params):
267-
if not params[0]:
272+
if not params['resume']:
268273
self.state = self.STATE_INTRO
269-
X = VisualChunk(None, "letterobj", self.intro_xs.centerx, self.intro_xs.centery, color="red")
274+
X = VisualChunk(None, "letterobj", self.intro_xs.centerx, self.intro_xs.centery, color=":red")
270275
self.actr.update_display([X], clear=True)
271276
self.actr_running = True
272277
if self.actr_time_lock:
@@ -280,13 +285,13 @@ def ACTR6_JNI_Event(self, model, params):
280285

281286
@d.listen('keypress')
282287
def ACTR6_JNI_Event(self, model, params):
283-
self.handle_key_press(params[0], chr(params[0]))
288+
self.handle_key_press(params['keycode'], chr(params['keycode']))
284289

285290
@d.listen('mousemotion')
286291
def ACTR6_JNI_Event(self, model, params):
287292
# Store "ACT-R" cursor in variable since we are
288293
# not going to move the real mouse
289-
self.fake_cursor = params[0]
294+
self.fake_cursor = params['loc']
290295

291296
@d.listen('mouseclick')
292297
def ACTR6_JNI_Event(self, model, params):

json-network-interface.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
(send-command instance "set-mp-time" (jsown:new-js ("time" (mp-time))) :sync t)))
142142

143143
(defmethod device-handle-keypress ((instance json-interface-module) key)
144-
(send-command instance "keypress" (jsown:new-js ("keycode" char-code) ("unicode" key))
144+
(send-command instance "keypress" (jsown:new-js ("keycode" (char-code key)))
145145
:sync (not (numberp (jni-sync instance)))))
146146

147147
(defmethod device-move-cursor-to ((instance json-interface-module) loc)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/Python/actr6_jni/server.py lib/python/actr6_jni/server.py

+25-21
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,26 @@ def connectionLost(self, reason):
3333
d.trigger(e="connectionLost", model=None, params=None)
3434

3535
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':
3838
if self.factory.clock:
3939
self.factory.clock.setTime(float(params[0]))
40-
elif method == 'disconnect':
40+
elif obj['method'] == 'disconnect':
4141
self.factory.p.transport.loseConnection()
4242
else:
43-
if method == 'reset':
43+
if obj['method'] == 'reset':
4444
if self.factory.clock:
4545
self.factory.clock.setTime(0.0)
4646
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")
4951

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}))
5256

5357
class JNI_Server(Factory):
5458

@@ -70,31 +74,31 @@ def buildProtocol(self, addr):
7074
def update_display(self, chunks, clear=False):
7175
visual_locations = [chunk.get_visual_location() for chunk in chunks]
7276
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)
7478

7579
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)
7781

7882
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)
8084

8185
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)
8387

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)
8690

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)
8993

9094
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)
9596

9697
def disconnect(self):
9798
self.p.sendCommand(self.model, "disconnect")
9899

99100
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)
File renamed without changes.

0 commit comments

Comments
 (0)