Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 🎨 Add persistent colors #276

Merged
merged 21 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b917251
:tada: :art: Add persitent colors
MathisFederico Feb 16, 2022
8fc2034
:hammer: Refactor ExecutableBlock.run_state using Enum
MathisFederico Feb 16, 2022
793b9fb
:hammer: Add Executable class
MathisFederico Feb 16, 2022
532b9ab
:wrench: Update mnist example
MathisFederico Feb 16, 2022
dbd1073
:art: Make the outline more visible
FabienRoger Feb 17, 2022
cad6fa2
:beetle: Don't mark blocks as executed after execution was canceled
FabienRoger Feb 17, 2022
2665ce2
:sparkles: Correct typing
FabienRoger Feb 17, 2022
51d8c6d
:sparkles: Remove useless import
FabienRoger Feb 17, 2022
e404261
:beetle: Fix multiple execution bug
FabienRoger Feb 18, 2022
4d01d8d
:sparkles: Remove unused variable
FabienRoger Feb 18, 2022
ceee345
:art: Changed selection and running/pending colors
MathisFederico Feb 19, 2022
63beaf0
:beetle: Run right now relauch next blocks even if they were done
MathisFederico Feb 19, 2022
f145bd0
:memo: Add executable docstrings
MathisFederico Feb 19, 2022
56ddc56
:sparkles: Fix pylint issues
MathisFederico Feb 19, 2022
746c450
:wrench: Refactor custom_bfs
MathisFederico Feb 19, 2022
3fbfc68
:wrench: Refactor right_traversal
MathisFederico Feb 19, 2022
c6dfbf2
Merge remote-tracking branch 'origin/dev' into feature/persistent_colors
MathisFederico Feb 19, 2022
0d58e55
:memo: Add missing docstrings
MathisFederico Feb 19, 2022
25a5c05
:sparkles: Fix some pylint issues
MathisFederico Feb 19, 2022
0d78e96
:art: Make the pending outline more visible
FabienRoger Feb 19, 2022
a2824b4
Merge remote-tracking branch 'origin/feature/persistent_colors' into …
FabienRoger Feb 19, 2022
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
126 changes: 35 additions & 91 deletions examples/mnist.ipyg

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions pyflow/blocks/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def __init__(
self.sockets_in: List[Socket] = []
self.sockets_out: List[Socket] = []

self._pen_outline = QPen(QColor("#7F000000"))
self.pen_width = 3
self._pen_outline = QPen(QColor("#00000000"))
self._pen_outline.setWidth(self.pen_width)
self._pen_outline_selected = QPen(QColor("#FFFFA637"))
self._pen_outline_selected.setWidth(self.pen_width)
self._brush_background = QBrush(BACKGROUND_COLOR)

self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable)
Expand Down Expand Up @@ -138,12 +141,26 @@ def paint(
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_outline
)
painter.setPen(self.pen_outline)
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawPath(path_outline.simplified())

# selection inner outline
if self.isSelected():
path_in_outline = QPainterPath()
outline_width = self.pen_outline.widthF()
path_in_outline.addRoundedRect(
-2 * outline_width,
-2 * outline_width,
self.width + 4 * outline_width,
self.height + 4 * outline_width,
self.edge_size + 2 * outline_width,
self.edge_size + 2 * outline_width,
)
painter.setPen(self._pen_outline_selected)
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawPath(path_in_outline.simplified())

def add_socket(self, socket: Socket):
"""Add a socket to the block."""
if socket.socket_type == "input":
Expand Down
33 changes: 21 additions & 12 deletions pyflow/blocks/codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pyflow.blocks.block import Block
from pyflow.core.edge import Edge
from pyflow.blocks.executableblock import ExecutableBlock
from pyflow.blocks.executableblock import ExecutableBlock, ExecutableState
from pyflow.blocks.pyeditor import PythonEditor
from pyflow.core.add_button import AddEdgeButton, AddNewBlockButton

Expand Down Expand Up @@ -62,14 +62,17 @@ 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_outlines = [
QPen(QColor("#7F000000")), # Idle
QPen(QColor("#FF0000")), # Running
QPen(QColor("#00ff00")), # Transmitting
]
self._pen_outlines = {
ExecutableState.IDLE: QPen(QColor("#00000000")), # No outline
ExecutableState.RUNNING: QPen(QColor("#fffc6107")), # Dark orange
ExecutableState.PENDING: QPen(QColor("#90fc6107")), # Transparent orange
ExecutableState.DONE: QPen(QColor("#158000")), # Dark green
ExecutableState.CRASHED: QPen(QColor("#ff0000")), # Red: Crashed
}
for pen in self._pen_outlines.values():
pen.setWidth(self.pen_width)

self.output_panel_background_color = "#1E1E1E"

Expand Down Expand Up @@ -133,14 +136,14 @@ def init_add_newblock_button(self):

def handle_run_right(self):
"""Called when the button for "Run All" was pressed."""
if self.run_state != 0:
if self.run_state in (ExecutableState.PENDING, ExecutableState.RUNNING):
self._interrupt_execution()
else:
self.run_right()

def handle_run_left(self):
"""Called when the button for "Run Left" was pressed."""
if self.run_state != 0:
if self.run_state in (ExecutableState.PENDING, ExecutableState.RUNNING):
self._interrupt_execution()
else:
self.run_left()
Expand Down Expand Up @@ -170,10 +173,17 @@ def run_code(self):
super().run_code() # actually run the code

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

def execution_canceled(self):
"""Reset the text of the run buttons after it was canceled."""
super().execution_canceled()
self.run_button.setText(">")
self.run_all_button.setText(">>")

def link(self, block: "ExecutableBlock"):
"""Link a block to the current one."""
# Add sockets to the new block and the current one
Expand Down Expand Up @@ -259,9 +269,8 @@ def source(self, value: str):
if value != self._source:
# If text has changed, set self and all output blocks to not run
output_blocks, _ = self.custom_bfs(self, reverse=True)
for block in output_blocks:
block.has_been_run = False
self.has_been_run = False
for block in output_blocks + [self]:
block.run_state = ExecutableState.IDLE
self.source_editor.setText(value)
self._source = value

Expand Down
Loading