-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.py
36 lines (30 loc) · 1004 Bytes
/
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
import json
from extensions.OobaCoder.block import Block, InputBlock, OutputBlock, BlockType
blocks_json_defaults = {
'x' : 0,
'y' : 0
}
class Layout:
def __init__(self):
self.blocks = []
self.new_block_params = {}
self.new_block_label = ""
self.new_block_type_name = ""
def to_html(self):
html_string = """<div class="layout">"""
for block in self.blocks:
html_string += block.to_html()
html_string += "</div>"
return html_string
def new_block(self, blocks_json):
blocks_dict = json.loads(blocks_json)
print(self.new_block_type_name)
if self.new_block_type_name == "INPUT":
block = InputBlock()
elif self.new_block_type_name == "OUTPUT":
block = OutputBlock()
else:
return blocks_json
self.blocks.append(block)
blocks_dict[block.id] = blocks_json_defaults.copy()
return json.dumps(blocks_dict)