Skip to content

Commit

Permalink
🪲 Fix for #94 as well as *ExecutingBlock* serialization issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyle committed Dec 11, 2021
1 parent 17fef8a commit 2e4b402
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion opencodeblocks/blocks/codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def serialize(self):
base_dict = super().serialize()
base_dict["source"] = self.source
base_dict["stdout"] = self.stdout

return base_dict

def deserialize(
Expand Down
4 changes: 3 additions & 1 deletion opencodeblocks/blocks/drawingblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def serialize(self):

def valueChanged(self):
"""Called when the content of the drawing block changes."""
self.run_right()
# Make sure that the slider is initialized before trying to run it.
if self.scene() is not None:
self.run_right()

@property
def source(self):
Expand Down
8 changes: 2 additions & 6 deletions opencodeblocks/blocks/executableblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def run_right(self):
edges = bfs_edges(graph, self)
blocks_to_run: List["OCBExecutableBlock"] = [self] + [v for _, v in edges]
for block in blocks_to_run[::-1]:
block.run_left(in_run_right=True)
block.run_left()

def reset_has_been_run(self):
"""Called when the output is an error"""
Expand All @@ -145,14 +145,10 @@ def handle_image(self, image: str):

def serialize(self):
"""Return a serialized version of this block"""
base_dict = super().serialize()
base_dict["source"] = self.source
return base_dict
return super().serialize()

def deserialize(
self, data: OrderedDict, hashmap: dict = None, restore_id: bool = True
):
"""Restore a codeblock from it's serialized state"""
if "source" in data:
setattr(self, "source", data["source"])
super().deserialize(data, hashmap, restore_id)
7 changes: 5 additions & 2 deletions opencodeblocks/blocks/sliderblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, **kwargs):
self.layout = QVBoxLayout(self.root)

self.slider = QSlider(Qt.Horizontal)
self.slider.valueChanged.connect(self.valueChanged)

self.variable_layout = QHBoxLayout()
self.variable_text = QLineEdit("slider_value")
Expand All @@ -40,12 +39,16 @@ def __init__(self, **kwargs):
self.layout.addWidget(self.slider)
self.layout.addLayout(self.variable_layout)

self.slider.valueChanged.connect(self.valueChanged)

self.holder.setWidget(self.root)

def valueChanged(self):
""" This is called when the value of the slider changes """
self.variable_value.setText(f"{self.value}")
self.run_right()
# Make sure that the slider is initialized before trying to run it.
if self.scene() is not None:
self.run_right()

@property
def source(self):
Expand Down
6 changes: 6 additions & 0 deletions opencodeblocks/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import math
import json
from os import path
from types import FunctionType, ModuleType
from typing import List, OrderedDict, Union

Expand Down Expand Up @@ -154,6 +155,11 @@ def load(self, filepath: str):
self.history.checkpoint("Loaded scene")
self.has_been_modified = False

# Add filepath to kernel path
dir_path = repr(path.abspath(path.dirname(filepath)))
setup_path_code = f"__import__(\"sys\").path[0] = {dir_path}"
self.kernel.execute(setup_path_code)

def load_from_ipyg(self, filepath: str):
""" Load an interactive python graph (.ipyg) into the scene.
Expand Down

0 comments on commit 2e4b402

Please sign in to comment.