Skip to content

Commit

Permalink
Merge pull request #102 from MathisFederico/bug/html-display
Browse files Browse the repository at this point in the history
🪲 adds html output support
  • Loading branch information
MathisFederico authored Dec 8, 2021
2 parents aecac6b + cc1055a commit 5747a48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions opencodeblocks/blocks/codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ def init_run_button(self):
"""Initialize the run button"""
run_button = QPushButton(">", self.root)
run_button.move(int(self.edge_size), int(self.edge_size / 2))
run_button.setFixedSize(int(3 * self.edge_size), int(3 * self.edge_size))
run_button.setFixedSize(int(3 * self.edge_size),
int(3 * self.edge_size))
run_button.clicked.connect(self.run_left)
return run_button

def init_run_all_button(self):
"""Initialize the run all button"""
run_all_button = QPushButton(">>", self.root)
run_all_button.setFixedSize(int(3 * self.edge_size), int(3 * self.edge_size))
run_all_button.setFixedSize(
int(3 * self.edge_size), int(3 * self.edge_size))
run_all_button.clicked.connect(self.run_right)
run_all_button.raise_()

Expand Down Expand Up @@ -228,6 +230,8 @@ def stdout(self, value: str):
if hasattr(self, "output_panel"):
if value.startswith("<img>"):
display_text = self.b64_to_html(value[5:])
elif value.startswith("<div>"):
display_text = value
else:
display_text = self.str_to_html(value)
self.output_panel.setText(display_text)
Expand Down
4 changes: 4 additions & 0 deletions opencodeblocks/graphics/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def message_to_output(self, message: dict) -> Tuple[str, str]:
message_type = 'image'
# output an image (from plt.plot or plt.imshow)
out = message['data']['image/png']
elif 'text/html' in message['data']:
message_type = 'text'
# output some html text (like a pandas dataframe)
out = message['data']['text/html']
else:
message_type = 'text'
# output data as str (for example if code="a=10\na")
Expand Down

0 comments on commit 5747a48

Please sign in to comment.