Skip to content

Commit

Permalink
🎨 Highlight the add edge button on block hover (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisFederico authored Feb 11, 2022
2 parents 9fa1502 + dbddeb2 commit b747cbd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
17 changes: 16 additions & 1 deletion pyflow/blocks/codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

from typing import OrderedDict, Tuple
from typing import TYPE_CHECKING, OrderedDict, Tuple

from ansi2html import Ansi2HTMLConverter
from PyQt5.QtGui import QColor, QPen
Expand All @@ -16,6 +16,9 @@

ansi2html_converter = Ansi2HTMLConverter()

if TYPE_CHECKING:
from PyQt5.QtWidgets import QGraphicsSceneHoverEvent


class CodeBlock(ExecutableBlock):

Expand Down Expand Up @@ -84,6 +87,8 @@ def __init__(self, source: str = "", **kwargs):
# Build root widget into holder
self.holder.setWidget(self.root)

self.setAcceptHoverEvents(True)

self.update_all() # Set the geometry of display and source_editor

def init_output_panel(self):
Expand Down Expand Up @@ -133,6 +138,16 @@ def handle_run_left(self):
else:
self.run_left()

def hoverEnterEvent(self, event: "QGraphicsSceneHoverEvent") -> None:
"""Handle the event when the mouse enters the block."""
self.add_edge_button.set_highlight(True)
return super().hoverEnterEvent(event)

def hoverLeaveEvent(self, event: "QGraphicsSceneHoverEvent") -> None:
"""Handle the event when the mouse leaves the block."""
self.add_edge_button.set_highlight(False)
return super().hoverLeaveEvent(event)

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

Expand Down
13 changes: 10 additions & 3 deletions pyflow/core/add_edge_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ def __init__(

self.edges: List["Edge"] = []

self.radius = 10
self.radius = 12
self._pen = QPen(QColor("#44000000"))
self._pen.setWidth(int(1))

self._normal_brush = QBrush(QColor("#4455FFF0"))
self._hover_brush = QBrush(QColor("#AA55FFF0"))
self._normal_brush = QBrush(QColor("#1155FFF0"))
self._hover_brush = QBrush(QColor("#FF23E9D8"))
self._block_hover_brush = QBrush(QColor("#8855FFF0"))
self._brush = self._normal_brush

self.setAcceptHoverEvents(True)

def set_highlight(self, value: bool) -> None:
if value:
self._brush = self._block_hover_brush
else:
self._brush = self._normal_brush

def hoverEnterEvent(self, event: "QGraphicsSceneHoverEvent") -> None:
"""Handle the event when the mouse enters the button."""
self._brush = self._hover_brush
Expand Down
2 changes: 1 addition & 1 deletion pyflow/graphics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def drag_edge(self, event: QMouseEvent, action="press"):
LOGGER.debug("Start draging edge from existing socket.")
return
# If it is the add edge button, create a new socket and a new edge from it.
elif (
if (
isinstance(item_at_click, AddEdgeButton)
and self.mode != self.MODE_EDGE_DRAG
):
Expand Down
2 changes: 1 addition & 1 deletion pyflow/scene/ipynb_conversion_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict

MARGIN_Y: float = 120
MARGIN_BETWEEN_BLOCKS_Y: float = 40
MARGIN_BETWEEN_BLOCKS_Y: float = 60
BLOCK_WIDTH: float = 600
TITLE_MAX_LENGTH: int = 60

Expand Down

0 comments on commit b747cbd

Please sign in to comment.