Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
60b1cac
:tada: highlights running blocks
AlexandreSajus Dec 8, 2021
e089743
Merge branch 'master' into feature/visual_flow
AlexandreSajus Dec 9, 2021
8b2e96b
:beetle: adds reset_buttons
AlexandreSajus Dec 9, 2021
61c1a72
:hammer: black instead of autopep8
AlexandreSajus Dec 9, 2021
d96d70f
:tada: easier coloring of objects
AlexandreSajus Dec 9, 2021
3cf3326
:wrench: easier coloring ob blocks/edges
AlexandreSajus Dec 11, 2021
e2d7689
:tada: prototype of visual flow
AlexandreSajus Dec 11, 2021
93b13c5
:tada: fully functional visual flow
AlexandreSajus Dec 12, 2021
ee4af35
:hammer: Huge refactor
AlexandreSajus Dec 12, 2021
d5affa2
:wrench: adjusted animation duration
AlexandreSajus Dec 12, 2021
e21e9d6
:wrench: modified animation behavior
AlexandreSajus Dec 12, 2021
06d29d8
Merge branch 'master' into feature/visual_flow
AlexandreSajus Dec 20, 2021
bc1a1ae
Merge branch 'master' into feature/visual_flow
AlexandreSajus Dec 20, 2021
dcc1252
:beetle: fixes interrupt execution
AlexandreSajus Dec 20, 2021
042b491
:hammer: modified animation behavior
AlexandreSajus Dec 20, 2021
7dbd793
:wrench: moves from code to executableblock
AlexandreSajus Dec 21, 2021
a1a1f46
:wrench: reduced testing time
AlexandreSajus Dec 21, 2021
3732f3d
:beetle: changes is_running attribute
AlexandreSajus Dec 21, 2021
2542aa6
:beetle: fixes run_code test
AlexandreSajus Dec 21, 2021
d6150cd
:wrench: moves from code to executable
AlexandreSajus Dec 21, 2021
d8debf1
Merge branch 'feature/visual_flow' of https://github.com/Bycelium/PyF…
AlexandreSajus Dec 21, 2021
868c209
:wrench: refactor for clarity
AlexandreSajus Dec 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 67 additions & 10 deletions opencodeblocks/blocks/codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@

""" Module for the base OCB Code Block. """

from typing import OrderedDict
from PyQt5.QtWidgets import QPushButton, QTextEdit
from typing import OrderedDict, Optional
from PyQt5.QtWidgets import (
QApplication,
QPushButton,
QTextEdit,
QWidget,
QStyleOptionGraphicsItem,
)
from PyQt5.QtCore import QTimer, Qt
from PyQt5.QtGui import QPen, QColor, QPainter, QPainterPath

from ansi2html import Ansi2HTMLConverter

from opencodeblocks.blocks.block import OCBBlock

from opencodeblocks.blocks.executableblock import OCBExecutableBlock
Expand Down Expand Up @@ -54,6 +63,18 @@ def __init__(self, source: str = "", **kwargs):

self.output_closed = True
self._splitter_size = [1, 1]
self._cached_stdout = ""
self.has_been_run = False
self.blocks_to_run = []

self._pen_outline = QPen(QColor("#7F000000"))
self._pen_outline_running = QPen(QColor("#FF0000"))
self._pen_outline_transmitting = QPen(QColor("#00ff00"))
self._pen_outlines = [
self._pen_outline,
self._pen_outline_running,
self._pen_outline_transmitting,
]

# Add output pannel
self.output_panel = self.init_output_panel()
Expand Down Expand Up @@ -97,20 +118,21 @@ def init_run_all_button(self):

def handle_run_right(self):
"""Called when the button for "Run All" was pressed"""
if self.is_running:
if self.run_color != 0:
self._interrupt_execution()
else:
self.run_right()

def handle_run_left(self):
"""Called when the button for "Run Left" was pressed"""
if self.is_running:
if self.run_color != 0:
self._interrupt_execution()
else:
self.run_left()

def run_code(self):
"""Run the code in the block"""

# Reset stdout
self._cached_stdout = ""

Expand All @@ -120,12 +142,6 @@ def run_code(self):

super().run_code() # actually run the code

def execution_finished(self):
"""Reset the text of the run buttons"""
super().execution_finished()
self.run_button.setText(">")
self.run_all_button.setText(">>")

def update_title(self):
"""Change the geometry of the title widget"""
self.title_widget.setGeometry(
Expand Down Expand Up @@ -156,6 +172,35 @@ def update_all(self):
self.update_output_panel()
self.update_run_all_button()

def paint(
self,
painter: QPainter,
option: QStyleOptionGraphicsItem,
widget: Optional[QWidget] = None,
):
"""Paint the code block"""
path_content = QPainterPath()
path_content.setFillRule(Qt.FillRule.WindingFill)
path_content.addRoundedRect(
0, 0, self.width, self.height, self.edge_size, self.edge_size
)
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(self._brush_background)
painter.drawPath(path_content.simplified())

# outline
path_outline = QPainterPath()
path_outline.addRoundedRect(
0, 0, self.width, self.height, self.edge_size, self.edge_size
)
painter.setPen(
self._pen_outline_selected
if self.isSelected()
else self._pen_outlines[self.run_color]
)
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawPath(path_outline.simplified())

@property
def source(self) -> str:
"""Source code"""
Expand All @@ -168,6 +213,17 @@ def source(self, value: str):
self.source_editor.setText(value)
self._source = value

@property
def run_color(self) -> int:
"""Run color"""
return self._run_color

@run_color.setter
def run_color(self, value: int):
self._run_color = value
# Update to force repaint
self.update()

@property
def stdout(self) -> str:
"""Access the content of the output panel of the block"""
Expand Down Expand Up @@ -231,6 +287,7 @@ def handle_image(self, image: str):
self.stdout = "<img>" + image

def serialize(self):
"""Serialize the code block"""
base_dict = super().serialize()
base_dict["source"] = self.source
base_dict["stdout"] = self.stdout
Expand Down
Loading