Skip to content

Commit 46b8ec6

Browse files
committed
Some speedup in generating large numbers of compounds
1 parent 7bbbe1c commit 46b8ec6

File tree

3 files changed

+19
-45
lines changed

3 files changed

+19
-45
lines changed

vpython/vpython.py

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@
2828
'standardAttributes', 'text', 'textures', 'triangle', 'vertex',
2929
'wtext', 'winput', 'keysdown']
3030

31-
__p = platform.python_version()
32-
_ispython3 = (__p[0] == '3')
33-
34-
if _ispython3:
35-
from inspect import signature # Python 3; needed to allow zero arguments in a bound function
36-
else:
37-
from inspect import getargspec # Python 2; needed to allow zero arguments in a bound function
31+
from inspect import signature # needed to allow zero arguments in a bound function
3832

3933
# __version__ is the version number of the Jupyter VPython installer, generated in building the installer.
4034
version = [__version__, 'jupyter']
@@ -175,10 +169,6 @@ def _encode_attr(D, ismethods): # ismethods is True if a list of method operatio
175169
out.append(s)
176170
return out
177171

178-
if sys.version > '3':
179-
long = int
180-
181-
182172
def list_to_vec(L):
183173
return vector(L[0], L[1], L[2])
184174

@@ -385,14 +375,9 @@ def handle_msg(self, msg):
385375
obj._text = evt['text']
386376
obj._number = evt['value']
387377
# inspect the bound function and see what it's expecting
388-
if _ispython3: # Python 3
389-
a = signature(obj._bind)
390-
if str(a) != '()': obj._bind( obj )
391-
else: obj._bind()
392-
else: # Python 2
393-
a = getargspec(obj._bind)
394-
if len(a.args) > 0: obj._bind( obj )
395-
else: obj._bind()
378+
a = signature(obj._bind)
379+
if str(a) != '()': obj._bind( obj )
380+
else: obj._bind()
396381
else: ## a canvas event
397382
if 'trigger' not in evt:
398383
cvs = baseObj.object_registry[evt['canvas']]
@@ -1446,11 +1431,6 @@ def __init__(self, objList, **args):
14461431
savesize = args['size']
14471432
del args['size']
14481433

1449-
baseObj.sent = False
1450-
while not baseObj.sent: # wait for compounding objects to exist
1451-
if _isnotebook: rate(1000)
1452-
else: time.sleep(0.001)
1453-
14541434
self.compound_idx += 1
14551435
args['_objName'] = 'compound'+str(self.compound_idx)
14561436
super(compound, self).setup(args)
@@ -3117,14 +3097,9 @@ def handle_event(self, evt): ## events and scene info updates
31173097
del evt['height']
31183098
for fct in self._binds['resize']:
31193099
# inspect the bound function and see what it's expecting
3120-
if _ispython3: # Python 3
3121-
a = signature(fct)
3122-
if str(a) != '()': fct( evt )
3123-
else: fct()
3124-
else: # Python 2
3125-
a = getargspec(fct)
3126-
if len(a.args) > 0: fct( evt )
3127-
else: fct()
3100+
a = signature(fct)
3101+
if str(a) != '()': fct( evt )
3102+
else: fct()
31283103
else: # pause/waitfor, update_canvas
31293104
if 'pos' in evt:
31303105
pos = evt['pos']
@@ -3144,14 +3119,9 @@ def handle_event(self, evt): ## events and scene info updates
31443119
evt1 = event_return(evt) ## turn it into an object
31453120
for fct in self._binds[ev]:
31463121
# inspect the bound function and see what it's expecting
3147-
if _ispython3: # Python 3
3148-
a = signature(fct)
3149-
if str(a) != '()': fct( evt1 )
3150-
else: fct()
3151-
else: # Python 2
3152-
a = getargspec(fct)
3153-
if len(a.args) > 0: fct( evt1 )
3154-
else: fct()
3122+
a = signature(fct)
3123+
if str(a) != '()': fct( evt1 )
3124+
else: fct()
31553125
self._waitfor = evt1 # what pause and waitfor are looking for
31563126
else: ## user can change forward (spin), range/autoscale (zoom), up (touch), center (pan)
31573127
if 'forward' in evt and self.userspin and not self._set_forward:
@@ -4111,4 +4081,4 @@ def set_browser(type='default'):
41114081
if type=='pyqt':
41124082
_browsertype='pyqt'
41134083
else:
4114-
_browsertype='default'
4084+
_browsertype='default'

vpython/vpython_libraries/glowcomm.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
}
7676
var t2 = msclock()
7777
var dt = Math.floor(t1+interval-t2) // attempt to keep the time between renders constant
78-
if (dt < 15) dt = 0 // becaause setTimeout is inaccurate for small dt's
78+
if (dt < 15) dt = 0 // because setTimeout is inaccurate for small dt's
7979
timer = setTimeout(send, dt)
8080
}
8181

@@ -256,11 +256,13 @@
256256
events.push(evt)
257257
}
258258

259-
function send_compound(cvs, pos, size, up) {
259+
function send_compound(cvs, pos, size, up) { // compound, extrusion, 3D text
260260
"use strict";
261261
var evt = {event: '_compound', 'canvas': cvs, 'pos': [pos.x, pos.y, pos.z],
262262
'size': [size.x, size.y, size.z], 'up': [up.x, up.y, up.z]}
263263
events.push(evt)
264+
clearTimeout(timer) // Don't wait for next transmission to Python
265+
send()
264266
}
265267

266268
var waitfor_canvas = null

vpython/vpython_libraries/glowcomm.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,13 @@ function send_pick(cvs, p, seg) {
306306
events.push(evt)
307307
}
308308

309-
function send_compound(cvs, pos, size, up) {
310-
"use strict";
309+
function send_compound(cvs, pos, size, up) { // compound, extrusion, 3D text
310+
"use strict";
311311
var evt = {event: '_compound', 'canvas': cvs, 'pos': [pos.x, pos.y, pos.z],
312312
'size': [size.x, size.y, size.z], 'up': [up.x, up.y, up.z]}
313313
events.push(evt)
314+
clearTimeout(timer) // Don't wait for next transmission to Python
315+
send()
314316
}
315317

316318
var waitfor_canvas = null

0 commit comments

Comments
 (0)