8
8
import uuid
9
9
10
10
import traitlets as trait
11
+ import ipywidgets as widgets
11
12
from matplotlib import colors
12
13
import pandas as pd
13
14
@@ -38,18 +39,27 @@ def validate(self, obj, value):
38
39
39
40
return value
40
41
41
- class IDObject (trait . HasTraits ):
42
+ class IDObject (widgets . Widget ):
42
43
""" an object with an id
43
44
44
45
"""
45
46
id = HashableType ()
46
47
groups = trait .List (trait = trait .CUnicode (),default_value = ("all" ,),
47
48
help = 'the groups that this object belongs to' )
48
- other_info = trait .CUnicode ('' ,help = 'other information about the object as HTML' )
49
+ other_info = trait .CUnicode ('' ,help = 'other information about the object as HTML' ). tag ( sync = True )
49
50
50
51
@trait .default ('id' )
51
52
def _default_id (self ):
52
53
return uuid .uuid4 ()
54
+
55
+ def get_object_trait_names (self ):
56
+ """ get trait names which are only associated with the object,
57
+ i.e. not from the ipywidgets base class
58
+ """
59
+ base_ipywidget_traits = set (widgets .Widget ().trait_names ())
60
+ all_traits = set (self .trait_names ())
61
+ return list (all_traits .difference (base_ipywidget_traits ))
62
+
53
63
54
64
def trait_series (self ):
55
65
""" create pandas.Series of objects traits
@@ -65,7 +75,7 @@ def trait_series(self):
65
75
66
76
"""
67
77
trait_dict = {}
68
- for name in self .trait_names ():
78
+ for name in self .get_object_trait_names ():
69
79
value = getattr (self , name )
70
80
# might break series if cell value is a list
71
81
value = tuple (value ) if isinstance (value , list ) else value
@@ -155,16 +165,16 @@ class GeometricObject(IDObject):
155
165
(0.0, 0.0, 0.0)
156
166
157
167
"""
158
- position = Vector3 (default_value = (0 ,0 ,0 ),help = 'cartesian coordinate of pivot' )
168
+ position = Vector3 (default_value = (0 ,0 ,0 ),help = 'cartesian coordinate of pivot' ). tag ( sync = True )
159
169
160
- visible = trait .Bool (True )
161
- color = Color ('red' )
162
- transparency = trait .CFloat (1 ,min = 0.0 ,max = 1.0 )
170
+ visible = trait .Bool (True ). tag ( sync = True )
171
+ color = Color ('red' ). tag ( sync = True )
172
+ transparency = trait .CFloat (1 ,min = 0.0 ,max = 1.0 ). tag ( sync = True )
163
173
164
- label = trait .CUnicode ('-' )
165
- label_visible = trait .Bool (False )
166
- label_color = Color ('red' )
167
- label_transparency = trait .CFloat (1 ,min = 0.0 ,max = 1.0 )
174
+ label = trait .CUnicode ('-' ). tag ( sync = True ). tag ( sync = True )
175
+ label_visible = trait .Bool (False ). tag ( sync = True )
176
+ label_color = Color ('red' ). tag ( sync = True )
177
+ label_transparency = trait .CFloat (1 ,min = 0.0 ,max = 1.0 ). tag ( sync = True )
168
178
169
179
def default_viewmap (label_height = None ):
170
180
""" a wrapper to signal that all
@@ -204,7 +214,7 @@ class Sphere(GeometricObject):
204
214
205
215
206
216
"""
207
- radius = trait .CFloat (1 ,min = 0. )
217
+ radius = trait .CFloat (1 ,min = 0. ). tag ( sync = True )
208
218
209
219
# TODO orientation of default geometries
210
220
@default_viewmap ('height' )
@@ -219,9 +229,9 @@ class Box(GeometricObject):
219
229
(0.0, 0.0, 0.0)
220
230
221
231
"""
222
- width = trait .CFloat (1 )
223
- height = trait .CFloat (1 )
224
- depth = trait .CFloat (1 )
232
+ width = trait .CFloat (1 ). tag ( sync = True )
233
+ height = trait .CFloat (1 ). tag ( sync = True )
234
+ depth = trait .CFloat (1 ). tag ( sync = True )
225
235
226
236
@default_viewmap ('radius' )
227
237
class Octahedron (GeometricObject ):
@@ -235,8 +245,8 @@ class Octahedron(GeometricObject):
235
245
(0.0, 0.0, 0.0)
236
246
237
247
"""
238
- radius = trait .CFloat (1 )
239
- detail = trait .CFloat (0 )
248
+ radius = trait .CFloat (1 ). tag ( sync = True )
249
+ detail = trait .CFloat (0 ). tag ( sync = True )
240
250
241
251
@default_viewmap ('radius' )
242
252
class Icosahedron (GeometricObject ):
@@ -250,8 +260,8 @@ class Icosahedron(GeometricObject):
250
260
(0.0, 0.0, 0.0)
251
261
252
262
"""
253
- radius = trait .CFloat (1 )
254
- detail = trait .CFloat (0 )
263
+ radius = trait .CFloat (1 ). tag ( sync = True )
264
+ detail = trait .CFloat (0 ). tag ( sync = True )
255
265
256
266
@default_viewmap ('radius' )
257
267
class Circle (GeometricObject ):
@@ -265,8 +275,8 @@ class Circle(GeometricObject):
265
275
(0.0, 0.0, 0.0)
266
276
267
277
"""
268
- radius = trait .CFloat (1 )
269
- segments = trait .CFloat (36 )
278
+ radius = trait .CFloat (1 ). tag ( sync = True )
279
+ segments = trait .CFloat (36 ). tag ( sync = True )
270
280
271
281
class Plane (GeometricObject ):
272
282
""" a plane object
@@ -279,8 +289,8 @@ class Plane(GeometricObject):
279
289
(0.0, 0.0, 0.0)
280
290
281
291
"""
282
- normal = Vector3 (default_value = (0 ,0 ,1 ),help = 'the normal vector of the plane' )
283
- width = trait .CFloat (1 ,min = 0.0 )
292
+ normal = Vector3 (default_value = (0 ,0 ,1 ),help = 'the normal vector of the plane' ). tag ( sync = True )
293
+ width = trait .CFloat (1 ,min = 0.0 ). tag ( sync = True )
284
294
285
295
@trait .validate ('normal' )
286
296
def _valid_normal (self , proposal ):
@@ -309,9 +319,9 @@ class Line(GeometricObject):
309
319
310
320
"""
311
321
312
- end = Vector3 (default_value = (1 ,1 ,1 ),help = 'cartesian coordinate of line end' )
313
- end_color = Color ('red' )
314
- linewidth = trait .CFloat (1 ,min = 0.0 )
322
+ end = Vector3 (default_value = (1 ,1 ,1 ),help = 'cartesian coordinate of line end' ). tag ( sync = True )
323
+ end_color = Color ('red' ). tag ( sync = True )
324
+ linewidth = trait .CFloat (1 ,min = 0.0 ). tag ( sync = True )
315
325
316
326
# TDOD only development version of PlainGeometry exposes face colors
317
327
class TriclinicSolid (GeometricObject ):
@@ -333,10 +343,10 @@ class TriclinicSolid(GeometricObject):
333
343
pivot must be at the centre or corner
334
344
335
345
"""
336
- a = Vector3 (default_value = (1 ,0 ,0 ),help = 'box vector a' )
337
- b = Vector3 (default_value = (0 ,1 ,0 ),help = 'box vector b' )
338
- c = Vector3 (default_value = (0 ,0 ,1 ),help = 'box vector c' )
339
- pivot = trait .CUnicode ('centre' ,help = 'pivot about centre or corner' )
346
+ a = Vector3 (default_value = (1 ,0 ,0 ),help = 'box vector a' ). tag ( sync = True )
347
+ b = Vector3 (default_value = (0 ,1 ,0 ),help = 'box vector b' ). tag ( sync = True )
348
+ c = Vector3 (default_value = (0 ,0 ,1 ),help = 'box vector c' ). tag ( sync = True )
349
+ pivot = trait .CUnicode ('centre' ,help = 'pivot about centre or corner' ). tag ( sync = True )
340
350
341
351
@trait .validate ('pivot' )
342
352
def _valid_pivot (self , proposal ):
@@ -364,7 +374,7 @@ class TriclinicWire(TriclinicSolid):
364
374
not valid
365
375
366
376
"""
367
- linewidth = trait .CFloat (1 )
377
+ linewidth = trait .CFloat (1 ). tag ( sync = True )
368
378
369
379
# TODO Gimbal: add labels at end of each vector
370
380
class Gimbal (GeometricObject ):
@@ -390,13 +400,13 @@ class Gimbal(GeometricObject):
390
400
not valid
391
401
392
402
"""
393
- a = Vector3 (default_value = (1 ,0 ,0 ),help = 'vector a' )
394
- b = Vector3 (default_value = (0 ,1 ,0 ),help = 'vector b' )
395
- c = Vector3 (default_value = (0 ,0 ,1 ),help = 'vector c' )
396
- a_color = Color ('red' )
397
- b_color = Color ('green' )
398
- c_color = Color ('orange' )
399
- linewidth = trait .CFloat (1 ,min = 0.0 )
403
+ a = Vector3 (default_value = (1 ,0 ,0 ),help = 'vector a' ). tag ( sync = True )
404
+ b = Vector3 (default_value = (0 ,1 ,0 ),help = 'vector b' ). tag ( sync = True )
405
+ c = Vector3 (default_value = (0 ,0 ,1 ),help = 'vector c' ). tag ( sync = True )
406
+ a_color = Color ('red' ). tag ( sync = True )
407
+ b_color = Color ('green' ). tag ( sync = True )
408
+ c_color = Color ('orange' ). tag ( sync = True )
409
+ linewidth = trait .CFloat (1 ,min = 0.0 ). tag ( sync = True )
400
410
401
411
402
412
0 commit comments