24
24
'event_return' , 'extrusion' , 'faces' , 'frame' , 'gcurve' , 'gdots' ,
25
25
'ghbars' , 'gobj' , 'graph' , 'gvbars' , 'helix' , 'label' ,
26
26
'local_light' , 'menu' , 'meta_canvas' , 'points' , 'pyramid' ,
27
- 'quad' , 'radio' , 'ring' , 'simple_sphere' , 'sleep' , 'slider' , 'sphere' ,
27
+ 'quad' , 'radio' , 'ring' , 'set_browser' , ' simple_sphere' , 'sleep' , 'slider' , 'sphere' ,
28
28
'standardAttributes' , 'text' , 'textures' , 'triangle' , 'vertex' ,
29
- 'wtext' , 'winput' , 'keysdown' ]
29
+ 'wtext' , 'winput' ]
30
30
31
31
__p = platform .python_version ()
32
32
_ispython3 = (__p [0 ] == '3' )
40
40
version = [__version__ , 'jupyter' ]
41
41
GSversion = [__gs_version__ , 'glowscript' ]
42
42
43
- keysdownlist = [] # list of keys currently pressed
44
-
45
43
# To print immediately, do this:
46
44
# print(.....)
47
45
# sys.stdout.flush()
97
95
'right' :'q' , 'top' :'r' , 'bottom' :'s' , '_cloneid' :'t' ,
98
96
'logx' :'u' , 'logy' :'v' , 'dot' :'w' , 'dot_radius' :'x' ,
99
97
'markers' :'y' , 'legend' :'z' , 'label' :'A' , 'delta' :'B' , 'marker_color' :'C' ,
100
- 'size_units' :'D' , 'userpan' :'E' , 'scroll' : 'F' }
98
+ 'size_units' :'D' , 'userpan' :'E' }
101
99
102
100
# methods are X in {'m': '23X....'}
103
101
# pos is normally updated as an attribute, but for interval-based trails, it is updated (multiply) as a method
@@ -524,7 +522,7 @@ class standardAttributes(baseObj):
524
522
['visible' ],
525
523
[]],
526
524
'compound' :[['pos' , 'color' , 'trail_color' ],
527
- ['axis' , 'size' , 'up' , 'origin' ],
525
+ ['axis' , 'size' , 'up' ],
528
526
['visible' , 'opacity' ,'shininess' , 'emissive' ,
529
527
'make_trail' , 'trail_type' , 'interval' , 'texture' ,
530
528
'retain' , 'trail_color' , 'trail_radius' , 'obj_idxs' , 'pickable' ],
@@ -700,7 +698,7 @@ def setup(self, args):
700
698
701
699
702
700
# set canvas
703
- if self .canvas is None : ## not specified in constructor
701
+ if self .canvas == None : ## not specified in constructor
704
702
self .canvas = canvas .get_selected ()
705
703
#cmd["attrs"].append({"attr": 'canvas', "value": self.canvas.idx})
706
704
cmd ['canvas' ] = self .canvas .idx
@@ -713,7 +711,7 @@ def setup(self, args):
713
711
if _special_clone is not None : cmd ["_cloneid" ] = _special_clone
714
712
self .appendcmd (cmd )
715
713
716
- # if ('frame' in args and args['frame'] is not None):
714
+ # if ('frame' in args and args['frame'] != None):
717
715
# frame.objects.append(self)
718
716
# frame.update_obj_list()
719
717
@@ -1001,9 +999,9 @@ def rotate(self, angle=None, axis=None, origin=None):
1001
999
saveorigin = origin
1002
1000
if angle == 0 :
1003
1001
return
1004
- if angle is None :
1002
+ if angle == None :
1005
1003
raise TypeError ('You must specify an angle through which to rotate' )
1006
- if axis is None :
1004
+ if axis == None :
1007
1005
rotaxis = self .axis
1008
1006
else :
1009
1007
rotaxis = axis
@@ -1530,34 +1528,32 @@ def size(self,value): # compound axis and size don't interact
1530
1528
if not self ._constructing :
1531
1529
self .addattr ('size' )
1532
1530
1533
- @property
1534
- def origin (self ):
1535
- return self ._origin
1536
- @origin .setter
1537
- def origin (self ,value ): # compound origin cannot be reset
1538
- if not self ._constructing :
1539
- raise AttributeError ('The compound "origin" attribute is read-only; change "pos" instead.' )
1540
- self ._origin = value
1531
+ def _world_zaxis (self ):
1532
+ axis = self ._axis
1533
+ up = norm (self ._up )
1534
+ if abs (axis .dot (up )) / sqrt (axis .mag2 ) > 0.98 :
1535
+ if abs (norm (axis ).dot (vector (- 1 ,0 ,0 ))) > 0.98 :
1536
+ z_axis = axis .cross (vector (0 ,0 ,1 )).norm ()
1537
+ else :
1538
+ z_axis = axis .cross (vector (- 1 ,0 ,0 )).norm ()
1539
+ else :
1540
+ z_axis = axis .cross (up ).norm ()
1541
+ return z_axis
1541
1542
1542
1543
def world_to_compound (self , v ):
1543
- v = v - self ._pos
1544
- x_axis = self ._axis .hat
1545
- y_axis = self ._up .hat
1546
- z_axis = x_axis .cross (y_axis )
1547
- ox = self ._size0 .x / self ._size .x # _size0 is the original size
1548
- oy = self ._size0 .y / self ._size .y
1549
- oz = self ._size0 .z / self ._size .z
1550
- return self ._origin + vector (v .dot (x_axis )* ox , v .dot (y_axis )* oy , v .dot (z_axis )* oz )
1544
+ axis = self ._axis
1545
+ z_axis = self ._world_zaxis ()
1546
+ y_axis = z_axis .cross (axis ).norm ()
1547
+ x_axis = axis .norm ()
1548
+ v = v - self ._pos
1549
+ return vector (v .dot (x_axis ), v .dot (y_axis ), v .dot (z_axis ))
1551
1550
1552
1551
def compound_to_world (self , v ):
1553
- v = v - self ._origin
1554
- x_axis = self ._axis .hat
1555
- y_axis = self ._up .hat
1556
- z_axis = x_axis .cross (y_axis )
1557
- ox = self ._size .x / self ._size0 .x # _size0 is the original size
1558
- oy = self ._size .y / self ._size0 .y
1559
- oz = self ._size .z / self ._size0 .z
1560
- return self ._pos + v .x * ox * x_axis + v .y * oy * y_axis + v .z * oz * z_axis
1552
+ axis = self ._axis
1553
+ z_axis = self ._world_zaxis ()
1554
+ y_axis = z_axis .cross (axis ).norm ()
1555
+ x_axis = axis .norm ()
1556
+ return self ._pos + (v .x * x_axis ) + (v .y * y_axis ) + (v .z * z_axis )
1561
1557
1562
1558
class vertex (standardAttributes ):
1563
1559
def __init__ (self , ** args ):
@@ -1965,7 +1961,7 @@ def __init__(self,*args1, **args):
1965
1961
1966
1962
super (curveMethods , self ).setup (args )
1967
1963
1968
- if tpos is not None :
1964
+ if tpos != None :
1969
1965
if len (args1 ) > 0 : raise AttributeError ('Malformed constructor' )
1970
1966
self .append (tpos )
1971
1967
if len (args1 ) > 0 :
@@ -1989,7 +1985,7 @@ def __init__(self,*args1, **args):
1989
1985
1990
1986
super (curveMethods , self ).setup (args )
1991
1987
1992
- if tpos is not None :
1988
+ if tpos != None :
1993
1989
if len (args1 ) > 0 : raise AttributeError ('Malformed constructor' )
1994
1990
self .append (tpos )
1995
1991
if len (args1 ) > 0 :
@@ -2282,7 +2278,6 @@ def __init__(self, **args):
2282
2278
self ._title = ""
2283
2279
self ._xtitle = ""
2284
2280
self ._ytitle = ""
2285
- self ._scroll = False
2286
2281
argsToSend = []
2287
2282
2288
2283
## override default vector attributes
@@ -2297,7 +2292,7 @@ def __init__(self, **args):
2297
2292
2298
2293
## override default scalar attributes
2299
2294
scalarAttributes = ['width' , 'height' , 'title' , 'xtitle' , 'ytitle' ,'align' ,
2300
- 'xmin' , 'xmax' , 'ymin' , 'ymax' , 'logx' , 'logy' , 'fast' , 'scroll' ]
2295
+ 'xmin' , 'xmax' , 'ymin' , 'ymax' , 'logx' , 'logy' , 'fast' ]
2301
2296
for a in scalarAttributes :
2302
2297
if a in args :
2303
2298
argsToSend .append (a )
@@ -2310,12 +2305,6 @@ def __init__(self, **args):
2310
2305
2311
2306
cmd = {"cmd" : objName , "idx" : self .idx }
2312
2307
2313
- if self ._scroll :
2314
- if not ('xmin' in argsToSend and 'xmax' in argsToSend ):
2315
- raise AttributeError ("For a scrolling graph, both xmin and xmax must be specified." )
2316
- if self ._xmax <= self ._xmin :
2317
- raise AttributeError ("For a scrolling graph, xmax must be greater than xmin." )
2318
-
2319
2308
## send only args specified in constructor
2320
2309
for a in argsToSend :
2321
2310
aval = getattr (self ,a )
@@ -2329,16 +2318,11 @@ def __init__(self, **args):
2329
2318
def fast (self ): return self ._fast
2330
2319
@fast .setter
2331
2320
def fast (self ,val ):
2321
+ # if _isnotebook and not val:
2322
+ # raise AttributeError('"fast = False" is currently not available in a Jupyter notebook.')
2332
2323
self ._fast = val
2333
2324
self .addattr ('fast' )
2334
2325
2335
- @property
2336
- def scroll (self ): return self ._scroll
2337
- @scroll .setter
2338
- def scroll (self ,val ):
2339
- self ._scroll = val
2340
- self .addattr ('scroll' )
2341
-
2342
2326
@property
2343
2327
def width (self ): return self ._width
2344
2328
@width .setter
@@ -2830,7 +2814,7 @@ def __init__(self, **args):
2830
2814
2831
2815
for a in canvasNonVecAttrs :
2832
2816
if a in args :
2833
- if args [a ] is not None :
2817
+ if args [a ] != None :
2834
2818
setattr (self , '_' + a , args [a ])
2835
2819
cmd [a ]= args [a ]
2836
2820
del args [a ]
@@ -3115,13 +3099,11 @@ def objz(self, obj, operation):
3115
3099
3116
3100
## key events conflict with notebook command mode; not permitted for now
3117
3101
def handle_event (self , evt ): ## events and scene info updates
3118
- global keysdownlist
3119
3102
ev = evt ['event' ]
3120
3103
if ev == 'pick' :
3121
3104
self .mouse .setpick ( evt )
3122
3105
self ._waitfor = True # what pick is looking for
3123
3106
elif ev == '_compound' : # compound, text, extrusion
3124
- print ('compound event return' )
3125
3107
obj = self ._compound
3126
3108
p = evt ['pos' ]
3127
3109
if obj ._objName == 'text' :
@@ -3133,7 +3115,7 @@ def handle_event(self, evt): ## events and scene info updates
3133
3115
# on_change functions that detect changes in e.g. obj.pos.y
3134
3116
obj ._pos .value = list_to_vec (p )
3135
3117
s = evt ['size' ]
3136
- obj ._size .value = obj . _size0 = list_to_vec (s )
3118
+ obj ._size .value = list_to_vec (s )
3137
3119
obj ._axis .value = obj ._size ._x * norm (obj ._axis )
3138
3120
obj ._up .value = list_to_vec (evt ['up' ])
3139
3121
self ._waitfor = True # what compound and text and extrusion are looking for in _wait()
@@ -3200,8 +3182,6 @@ def handle_event(self, evt): ## events and scene info updates
3200
3182
if 'autoscale' in evt and self .userzoom and not self ._set_autoscale :
3201
3183
self ._autoscale = evt ['autoscale' ]
3202
3184
self ._set_autoscale = False
3203
- if 'keysdown' in evt : keysdownlist = evt ['keysdown' ]
3204
-
3205
3185
3206
3186
def bind (self , eventtype , whattodo ):
3207
3187
evts = eventtype .split ()
@@ -3275,7 +3255,7 @@ def __init__(self, **args):
3275
3255
args ['_objName' ] = "local_light"
3276
3256
super (local_light , self ).setup (args )
3277
3257
3278
- if (canvas .get_selected () is not None ):
3258
+ if (canvas .get_selected () != None ):
3279
3259
canvas .get_selected ()._lights .append (self )
3280
3260
3281
3261
class distant_light (standardAttributes ):
@@ -3285,7 +3265,7 @@ def __init__(self, **args):
3285
3265
self ._direction = vector (0 ,0 ,1 )
3286
3266
super (distant_light , self ).setup (args )
3287
3267
3288
- if (canvas .get_selected () is not None ):
3268
+ if (canvas .get_selected () != None ):
3289
3269
canvas .get_selected ()._lights .append (self )
3290
3270
3291
3271
@property
@@ -4112,9 +4092,11 @@ def print_to_string(*args): # treatment of <br> vs. \n not quite right here
4112
4092
s = s [:- 1 ]
4113
4093
return (s )
4114
4094
4115
- def keysdown ():
4116
- global keysdownlist
4117
- keys = []
4118
- for k in keysdownlist : # return a copy of keysdownlist
4119
- keys .append (k )
4120
- return keys
4095
+ # global variable for type of web browser to display vpython
4096
+ _browsertype = 'default'
4097
+ def set_browser (type = 'default' ):
4098
+ global _browsertype
4099
+ if type == 'pyqt' :
4100
+ _browsertype = 'pyqt'
4101
+ else :
4102
+ _browsertype = 'default'
0 commit comments