Skip to content

Commit

Permalink
Merge pull request #117 from Bycelium/Add-ipynb-conversion-draft
Browse files Browse the repository at this point in the history
☔ Add unit tests to ipynb conversion
  • Loading branch information
MathisFederico authored Dec 19, 2021
2 parents c91586c + 58db48f commit 3f28dec
Show file tree
Hide file tree
Showing 6 changed files with 1,279 additions and 5 deletions.
4 changes: 2 additions & 2 deletions opencodeblocks/graphics/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def createNewMdiChild(self, filename: str = None):
ocb_widget = OCBWidget()
if filename is not None:
ocb_widget.scene.load(filename)
ocb_widget.savepath = filename
if filename.split(".")[-1] == "ipyg":
ocb_widget.savepath = filename
return self.mdiArea.addSubWindow(ocb_widget)

def onFileNew(self):
Expand Down Expand Up @@ -374,7 +375,6 @@ def oneFileSaveAsJupyter(self) -> bool:
)
if filename == "":
return False
current_window.savepath = filename
current_window.saveAsJupyter()
self.statusbar.showMessage(
f"Successfully saved ipygraph as jupter notebook at {current_window.savepath}",
Expand Down
12 changes: 9 additions & 3 deletions opencodeblocks/scene/from_ipynb_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:

next_block_x_pos: float = 0
next_block_y_pos: float = 0
next_block_id = 0

for cell in data["cells"]:
if "cell_type" not in cell or cell["cell_type"] not in ["code", "markdown"]:
Expand All @@ -62,7 +63,7 @@ def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:
block_height: float = text_height + MARGIN_Y

block_data = {
"id": len(blocks_data),
"id": next_block_id,
"block_type": BLOCK_TYPE_TO_NAME[block_type],
"width": block_width,
"height": block_height,
Expand Down Expand Up @@ -93,6 +94,7 @@ def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:
next_block_y_pos += block_height + MARGIN_BETWEEN_BLOCKS_Y

blocks_data.append(block_data)
next_block_id += 1

adujst_markdown_blocks_width(blocks_data)

Expand Down Expand Up @@ -144,9 +146,13 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict:
]
edges_data: List[OrderedDict] = []

greatest_block_id: int = 0
if len(blocks_data) > 0:
greatest_block_id = blocks_data[-1]["id"]

for i in range(1, len(code_blocks)):
socket_id_out = len(blocks_data) + 2 * i
socket_id_in = len(blocks_data) + 2 * i + 1
socket_id_out = greatest_block_id + 2 * i + 2
socket_id_in = greatest_block_id + 2 * i + 1
code_blocks[i - 1]["sockets"].append(
get_output_socket_data(socket_id_out, code_blocks[i - 1]["width"])
)
Expand Down
Loading

0 comments on commit 3f28dec

Please sign in to comment.