-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.py
689 lines (621 loc) · 28.3 KB
/
layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
__author__ = 'Jan Bogaerts'
__copyright__ = "Copyright 2015, AllThingsTalk"
__credits__ = []
__maintainer__ = "Jan Bogaerts"
__email__ = "jb@allthingstalk.com"
__status__ = "Prototype" # "Development", or "Production"
import json
from kivy.properties import BooleanProperty, NumericProperty, StringProperty
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.label import Label
from kivy.uix.slider import Slider
from kivy.uix.textinput import TextInput
from kivy.uix.progressbar import ProgressBar
from kivy.event import EventDispatcher
from kivy.uix.checkbox import CheckBox
from kivy.uix.gridlayout import GridLayout
from kivy.uix.spinner import Spinner
import attiotuserclient as IOT
import styleManager as sm
from knob import Knob
from gauge import Gauge
import os
from errors import *
from genericwidgets import SliderExt
class BaseIO(EventDispatcher):
def __init__(self, asset, type, **kwargs):
self.asset = asset
self.uiEl = None # the ui element that represents this switch, so we can change it's state.
self._updatingValue = False # when mqtt updates the value, the ui control is updated. We need to prevent that this then triggers sending a new message to the server
self.controlType = type
super(BaseIO, self).__init__(**kwargs)
def prepareUiElement(self):
"""common code, applied to all or most ui elements"""
if self.uiEl.size: # if a custom size was specified, don't allow the control to stretch. if the user did not specify a custom size, then allow the control to stretch.
self.uiEl.size_hint = (None, None)
self.uiEl.pos_hint = {"center_x": 0.5}
def getPropertyEditors(self, skin):
return []
class SwitchInput(BaseIO):
value = BooleanProperty(False)
def __init__(self, value, asset, **kwargs):
self.value = value
super(SwitchInput, self).__init__(asset, 'switch', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
if self.uiEl:
if value:
self.uiEl.state = "down"
else:
self.uiEl.state = "normal"
finally:
self._updatingValue = False
def getUI(self):
result = ToggleButton()
if self.value:
result.state = 'down'
skin = sm.getSkin('switch', self.asset)
result.background_normal = os.path.join(skin['path'], skin["normal"])
result.background_down = os.path.join(skin['path'], skin["down"])
result.size = sm.getControlSize(skin, self.asset)
result.border = 0,0,0,0
self.uiEl = result
self.prepareUiElement()
result.bind(state=self.state_changed)
return result
def state_changed(self, instance, value):
if self._updatingValue == False: # don't send to cloud if cloud just updated the ui element.
retryCount = 0
isSent = False
while not isSent and retryCount < 5: # we retry a couply of times, could be that the user was really quick and the connection was not setup yet (on mobile after turning dev on when app was open)
try:
IOT.send(self.asset.id, value == "down")
isSent = True
except Exception as e:
if retryCount < 5:
retryCount += 1
else:
if e.message:
showError(e)
else:
showErrorMsg("There was a communication problem, please try again")
class draggableInput(BaseIO):
"""base class for inputs that work with drag moves, like the knob and slider.
Adds properties to show the label, markers and when the change events are triggered"""
def getPropertyEditors(self, skin):
"""
get all the controls for editing the extra properties of this control.
The list of controls that is returned, our bound to this object (changes will be stored in the skin object)
:param skin: json object
:return: a list of kivy controls that can be used for editing the properties for the skin.
"""
items = []
grd = GridLayout(cols=2)
grd.bind(minimum_height = grd.setter('height'))
grd.size_hint = (1, None)
chk = CheckBox(active=sm.getVar(skin, self.asset, "show_label", False), height='28dp', size_hint=(1, None))
chk.bind(active=self.on_show_labelChanged)
lbl = Label(text='show label', height='28dp', size_hint=(1, None), halign='right')
lbl.bind(size = lbl.setter('text_size'))
grd.add_widget(lbl)
grd.add_widget(chk)
chk = CheckBox(active=sm.getVar(skin, self.asset, "show_marker", False), height='28dp', size_hint=(1, None))
chk.bind(active=self.on_show_markerChanged)
lbl = Label(text='show marker', height='28dp', size_hint=(1, None), halign='right')
lbl.bind(size = lbl.setter('text_size'))
grd.add_widget(lbl)
grd.add_widget(chk)
chk = CheckBox(active=sm.getVar(skin, self.asset, "send_on_release", False), height='28dp', size_hint=(1, None))
chk.bind(active=self.on_send_on_release_Changed)
lbl = Label(text='send on release', height='28dp', size_hint=(1, None), halign='right')
lbl.bind(size = lbl.setter('text_size'))
grd.add_widget(lbl)
grd.add_widget(chk)
items.append(grd)
return items
def on_show_labelChanged(self, checkbox, value):
if not self.asset.skin:
self.asset.skin = {'show_label': value}
else:
self.asset.skin['show_label'] = value
def on_send_on_release_Changed(self, checkbox, value):
if not self.asset.skin:
self.asset.skin = {'send_on_release': value}
else:
self.asset.skin['send_on_release'] = value
def on_show_markerChanged(self, checkbox, value):
if not self.asset.skin:
self.asset.skin = {'show_marker': value}
else:
self.asset.skin['show_marker'] = value
class sliderInput(draggableInput):
value = NumericProperty()
def __init__(self, value, typeInfo, asset, **kwargs):
self.value = value
self._typeInfo = typeInfo
super(sliderInput, self).__init__(asset, 'slider', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
if self.uiEl:
if self.uiEl.max < value:
self.uiEl.max = value
if self.uiEl.min > value:
self.uiEl.min = value
self.uiEl.value = value
finally:
self._updatingValue = False
def getUI(self):
"""get the ui element"""
result = Slider() #SliderExt()
if self.value:
result.value = self.value
skin = sm.getSkin('slider', self.asset)
result.size = sm.getControlSize(skin, self.asset)
result.orientation = sm.getVar(skin, self.asset, "orientation")
result.min = sm.getMinimum('slider', self.value, self._typeInfo)
result.max = sm.getMaximum('slider', self.value, self._typeInfo)
result.step = sm.getStep('slider', self._typeInfo)
result.show_label = sm.getVar(skin, self.asset, "show_label")
result.show_marker = sm.getVar(skin, self.asset, "show_marker")
self.uiEl = result
self.prepareUiElement()
if sm.getVar(skin, self.asset, "send_on_release", False):
result.on_dragEnded = self.value_changed # set the callback for when drag ends (self made, so no binding)
else:
result.bind(value=self.value_changed)
return result
def value_changed(self, instance, value):
retryCount = 0
isSent = False
if self._updatingValue == False: # don't send to cloud if cloud just updated the ui element.
while not isSent and retryCount < 5: # we retry a couply of times, could be that the user was really quick and the connection was not setup yet (on mobile after turning dev on when app was open)
try:
min = sm.getMinimum('slider', self.value, self._typeInfo) # snap to borders, so it's easy to set min and max values.
max = sm.getMaximum('slider', self.value, self._typeInfo)
if value < min + 5:
value = min
elif value > max - 5:
value = max
if self._typeInfo['type'] == 'number':
IOT.send(self.asset.id, value)
else:
IOT.send(self.asset.id, int(value)) # if the cloud expects ints, we can't send something like 1.0
isSent = True
except Exception as e:
if retryCount < 5:
retryCount += 1
else:
if e.message:
showError(e)
else:
showErrorMsg("There was a communication problem, please try again")
class knobInput(draggableInput):
value = NumericProperty()
def __init__(self, value, typeInfo, asset, **kwargs):
self.value = value
self._typeInfo = typeInfo
super(knobInput, self).__init__(asset, 'knob', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
if self.uiEl:
if self.uiEl.max < value:
self.uiEl.max = value
if self.uiEl.min > value:
self.uiEl.min = value
self.uiEl.value = value
finally:
self._updatingValue = False
def getUI(self):
"""get the ui element"""
result = Knob()
if self.value:
result.value = self.value
skin = sm.getSkin('knob', self.asset)
result.size = sm.getControlSize(skin, self.asset)
result.knobimg_source = os.path.join(skin['path'], skin["knob"])
result.marker_img = os.path.join(skin['path'], skin['marker'])
result.min = sm.getMinimum('knob', self.value, self._typeInfo)
result.max = sm.getMaximum('knob', self.value, self._typeInfo)
result.step = sm.getStep('knob', self._typeInfo)
result.show_label = sm.getVar(skin, self.asset, "show_label", False)
result.show_marker = sm.getVar(skin, self.asset, "show_marker", False)
self.uiEl = result
self.prepareUiElement()
if sm.getVar(skin, self.asset, "send_on_release", False):
result.on_dragEnded = self.value_changed # set the callback for when drag ends (self made, so no binding)
else:
result.bind(value=self.value_changed)
return result
def value_changed(self, instance, value):
retryCount = 0
isSent = False
if self._updatingValue == False: # don't send to cloud if cloud just updated the ui element.
while not isSent and retryCount < 5: # we retry a couply of times, could be that the user was really quick and the connection was not setup yet (on mobile after turning dev on when app was open)
try:
if self._typeInfo['type'] == 'number':
IOT.send(self.asset.id, value)
else:
IOT.send(self.asset.id, int(value)) # if the cloud expects ints, we can't send something like 1.0
isSent = True
except Exception as e:
if retryCount < 5:
retryCount += 1
else:
if e.message:
showError(e)
else:
showErrorMsg("There was a communication problem, please try again")
class LedOutput(BaseIO):
value = BooleanProperty(False)
def __init__(self, value, asset, **kwargs):
self.value = value
super(LedOutput, self).__init__(asset, 'led', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
if self.uiEl:
if value:
self.uiEl.state = "down"
else:
self.uiEl.state = "normal"
finally:
self._updatingValue = False
def getUI(self):
result = ToggleButton()
if self.value:
result.state = 'down'
skin = sm.getSkin('led', self.asset)
result.background_normal = os.path.join(skin['path'], skin['normal'])
result.background_down = os.path.join(skin['path'], skin['down'])
result.size = sm.getControlSize(skin, self.asset)
result.border = [0, 0, 0, 0]
self.uiEl = result
self.prepareUiElement()
return result
class GaugeOutput(BaseIO):
value = NumericProperty()
def __init__(self, value, typeInfo, asset, **kwargs):
self.value = value
self._typeInfo = typeInfo
super(GaugeOutput, self).__init__(asset, 'gauge', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
if self.uiEl:
if self.max < value:
self.max = value
if self.min > value:
self.min = value
self.uiEl.value = (value / (self.max - self.min)) * 100 # need to convert into % cause the gauge can only process from 0 to 100
finally:
self._updatingValue = False
def getUI(self):
"""get the ui element"""
result = Gauge()
skin = sm.getSkin('gauge', self.asset)
result.size = sm.getControlSize(skin, self.asset)
result.file_gauge = os.path.join(skin['path'], skin['gauge'])
result.file_needle = os.path.join(skin['path'], skin['needle'])
#self.min = sm.getMinimum('gauge', self.value, self._typeInfo)
#self.max = sm.getMaximum('gauge', self.value, self._typeInfo)
self.min = 0 #temp fix, gauge needs to be updated so it can handle values better
self.max = 100
if self.value:
result.value = (self.value / (self.max - self.min)) * 100 # need to convert into % cause the gauge can only process from 0 to 100
self.uiEl = result
self.prepareUiElement()
return result
class MeterOutput(BaseIO):
value = NumericProperty()
def __init__(self, value, typeInfo, asset, **kwargs):
self.value = value
self._typeInfo = typeInfo
super(MeterOutput, self).__init__(asset, 'meter', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
if self.uiEl:
if self.max < value:
self.max = value
if self.min > value:
self.min = value
self.uiEl.value = (value / (self.max - self.min)) * 100 # need to convert into % cause the gauge can only process from 0 to 100
finally:
self._updatingValue = False
def getUI(self):
"""get the ui element"""
result = ProgressBar()
skin = sm.getSkin('meter', self.asset)
result.size = sm.getControlSize(skin, self.asset)
result.min = sm.getMinimum('meter', self.value, self._typeInfo)
result.max = sm.getMaximum('meter', self.value, self._typeInfo)
if self.value:
result.value = self.value
self.uiEl = result
self.prepareUiElement()
return result
class TextboxInput(BaseIO):
#if 'enum' in datatype:
value = StringProperty()
def __init__(self, value, typeInfo, asset, **kwargs):
self.value = str(value) # in case not a string type
self._typeInfo = typeInfo
super(TextboxInput, self).__init__(asset, 'text', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
self.uiEl.text = str(value)
finally:
self._updatingValue = False
def getUI(self):
"""get the ui element"""
if 'enum' in self._typeInfo:
result = Spinner()
result.values = self._typeInfo['enum']
elif self._typeInfo['type'].lower() == 'boolean':
result = Spinner()
result.values = ['true', 'false']
else:
result = TextInput()
if self.value:
result.text = self.value.lower()
skin = sm.getSkin('text', self.asset)
result.size = sm.getControlSize(skin, self.asset)
self.uiEl = result
self.prepareUiElement()
result.bind(text=self.value_changed)
return result
def value_changed(self, instance, value):
retryCount = 0
isSent = False
if self._updatingValue == False: # don't send to cloud if cloud just updated the ui element.
while not isSent and retryCount < 5: # we retry a couply of times, could be that the user was really quick and the connection was not setup yet (on mobile after turning dev on when app was open)
try:
IOT.send(self.asset.id, value)
isSent = True
except Exception as e:
if retryCount < 5:
retryCount += 1
else:
if e.message:
showError(e)
else:
showErrorMsg("There was a communication problem, please try again")
class TextOutput(BaseIO):
value = StringProperty()
def __init__(self, value, typeInfo, asset, **kwargs):
self.value = value
self._typeInfo = typeInfo
super(TextOutput, self).__init__(asset, 'label', **kwargs)
def on_value(self, instance, value):
self._updatingValue = True
try:
if self.uiEl:
self.uiEl.text = value
finally:
self._updatingValue = False
def getUI(self):
"""get the ui element"""
result = Label()
skin = sm.getSkin('label', self.asset)
result.text_size = sm.getControlSize(skin, self.asset)
result.bind(texture_size=self.setter('size'))
if self.value:
result.text = self.value
self.uiEl = result
self.prepareUiElement()
return result
class Asset:
def __init__(self, parent, id):
self.parent = parent
self.isLoaded = False
self.id = id
self.title = ""
self.control = None
self.skin = None
def load(self, subscribe = True):
"""load all the data for the asset. At this point, we also register with the broker
returns the asset object that was retrieved from the platform"""
data = IOT.getAsset(self.id)
if data:
if self.skin and 'title' in self.skin: # if user overwote the title, use that value, otherwise use the default value from the cloud
self.title = self.skin['title']
else:
self.title = data["title"]
self.assetType = str(data['is']) # unicode shit
self.dataType = data['profile']
if self.skin and 'control' in self.skin:
self.control = self.getControl(self.skin['control'], data['state'])
else:
self.control = self.getControlFromCloud(data['control'], data['state'])
self.isLoaded = True
if subscribe:
IOT.subscribe(self.id, self._valueChanged)
return data
def unload(self):
self.isLoaded = False
self.control = None
self.skin = None
self.title = ''
def loadSecure(self, subscribe = True):
"""load all the data for the asset. At this point, we also register with the broker
returns the asset object that was retrieved from the platform"""
try:
return self.load(subscribe)
except Exception as e:
showError(e)
def getGenericActuatorControl(self, datatype, value):
type = str(datatype['type'])
if type == 'boolean':
self.control = SwitchInput(value['value'], self)
return
elif type == 'number' or type == 'integer':
self.control = sliderInput(value['value'], datatype, self)
return
self.control = TextboxInput(str(value['value']), datatype, self)
def getGenericSensorControl(self, datatype, value):
type = datatype['type']
if type == 'boolean':
self.control = LedOutput(value['value'], self)
return
elif type == 'number' or type == 'integer':
self.control = GaugeOutput(value['value'], datatype, self)
return
self.control = TextOutput(str(value['value']), datatype, self)
def getSupportedControls(self):
"""list the controls supported by this asset and return them"""
type = str(self.dataType['type'])
if self.assetType == 'actuator':
if type == 'boolean':
return ['switch', 'led', 'text', 'label']
elif type == 'number' or type == 'integer':
return ['slider', 'knob', 'text', 'label']
return ['text', 'label']
elif self.assetType == 'sensor':
if type == 'boolean':
return ['led', 'label']
elif type == 'number' or type == 'integer':
return ['meter', 'gauge', 'text', 'label']
return ['text', 'label']
def getControl(self, controlName, value):
if controlName == 'switch':
return SwitchInput(value['value'], self)
if controlName == 'led':
return LedOutput(value['value'], self)
if controlName == 'text':
return TextboxInput(value['value'],self.dataType, self)
if controlName == 'label':
return TextOutput(value['value'], self.dataType, self)
if controlName == 'slider':
return sliderInput(value['value'], self)
if controlName == 'knob':
return knobInput(value['value'], self)
if controlName == 'meter':
return MeterOutput(value['value'], self)
if controlName == 'gauge':
return GaugeOutput(value['value'], self)
raise Exception("can't build widget because there was an unknown control in layout definition (" + controlName + ')')
def getControlFromCloud(self, requested, value):
"""build the name of the data object that should be used in the display"""
if not self.control:
if self.assetType == 'actuator':
if not requested['name']:
self.getGenericActuatorControl(self.dataType, value)
elif requested['name'] in ['slider', 'line-progress']:
if self.dataType['type'] in ['integer', 'number']: # can only handle numbers in a slider at the moment
self.control = sliderInput(value['value'], self.dataType, self)
return self.control
elif requested['name'] == 'knob':
if self.dataType['type'] in ['integer', 'number']:
self.control = knobInput(value['value'], self.dataType, self)
return self.control
elif requested['name'] == 'toggle':
if type == 'boolean':
self.control = SwitchInput(value['value'], self)
return self.control
self.getGenericActuatorControl(self.dataType, value)
elif self.assetType == 'sensor':
if not requested['name']:
self.getGenericSensorControl(self.dataType, value)
elif requested['name'] in ['slider', 'line-progress']:
if self.dataType['type'] in ['integer', 'number']:
self.control = GaugeOutput(value['value'], self.dataType, self)
return self.control
elif requested['name'] == 'onoff':
if type == 'boolean':
self.control = LedOutput(value['value'], self)
return self.control
self.getGenericSensorControl(self.dataType, value)
return self.control
def _valueChanged(self, value):
"""called when the cloud has reported a value change for this asset"""
if self.control:
if 'value' in value:
self.control.value = value['value']
elif 'Value' in value:
self.control.value = value['Value']
def delete(self):
self.parent.assets.remove(self)
class Section:
def __init__(self, parent):
self.parent = parent
self.title = ''
self.isExpanded = True
self.assets = []
def delete(self):
self.parent.sections.remove(self)
class Group(EventDispatcher):
title = StringProperty('')
icon = StringProperty('')
def __init__(self, parent, **kwargs):
""""ceate object"""
self.parent = parent
self.sections = []
self.isSelected = False
super(Group, self).__init__(**kwargs)
def delete(self):
self.parent.groups.remove(self)
class Layout:
def __init__(self):
"""create object"""
self.groups = []
self.userName = ""
self.password = ''
self.server = ''
self.broker = ''
self.title = ''
def load(self, filename):
""""load the config from file"""
self.title = os.path.splitext(os.path.basename(filename))[0]
with open(filename) as data_file:
data = json.load(data_file)
if data["version"] == 1.0:
credentials = data["credentials"]
self.userName = credentials["username"]
self.password = credentials["password"]
self.server = credentials["server"]
self.broker = credentials["broker"]
for group in data["layout"]:
grp = Group(self)
self.groups.append(grp)
grp.title = group["group"]
grp.icon = group["icon"]
if 'isSelected' in group:
grp.isSelected = group["isSelected"]
else:
grp.isSelected = False
for section in group["sections"]:
sctn = Section(grp)
grp.sections.append(sctn)
sctn.title = section["section"]
sctn.isExpanded = section["isExpanded"]
for rec in section["assets"]:
asset = Asset(sctn, rec["id"])
if "skin" in rec:
asset.skin = rec["skin"]
sctn.assets.append(asset)
else:
raise Exception("The layout you are trying to load is of an unsupported version.")
def save(self, filename):
"""save the layout to specified file"""
with open(filename, 'w') as f:
f.write('{{"version":1.0, "credentials":{{"username": "{}", "password": "{}", "server":"{}", "broker": "{}"}}, "layout":['
.format(self.userName, self.password, self.server, self.broker))
for grp in self.groups:
if grp != self.groups[0]: f.write(', ')
f.write('{{ "group": "{}", "icon": "{}", "isSelected": {}, "sections":['.format(grp.title, grp.icon, str(grp.isSelected).lower()) )
for sctn in grp.sections:
if sctn != grp.sections[0]: f.write(', ')
f.write('{{"section": "{}", "isExpanded": {}, "assets":[ '.format(sctn.title, str(sctn.isExpanded).lower()))
for asset in sctn.assets:
if asset != sctn.assets[0]: f.write(', ')
f.write('{{"id": "{}"'.format(asset.id))
if asset.skin:
f.write(', "skin": ' + json.dumps(asset.skin))
f.write('}')
f.write(']}')
f.write(']}')
f.write(']}')