From b4f963ad7ed51d07b46a0b4ab6e89e70feb9a381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Math=C3=AFs=20F=C3=A9d=C3=A9rico?= Date: Sun, 30 Jan 2022 05:22:54 +0100 Subject: [PATCH 1/2] :beetle: Fix some bugs when scene is None --- pyflow/blocks/executableblock.py | 12 ++++++------ pyflow/blocks/widgets/blocktitle.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pyflow/blocks/executableblock.py b/pyflow/blocks/executableblock.py index 8867098f..91e1e4c6 100644 --- a/pyflow/blocks/executableblock.py +++ b/pyflow/blocks/executableblock.py @@ -72,15 +72,15 @@ def has_output(self) -> bool: def run_code(self): """Run the code in the block.""" - # Queue the code to execute code = self.source - kernel = self.scene().kernel - kernel.execution_queue.append((self, code)) + if self.scene(): + kernel = self.scene().kernel + kernel.execution_queue.append((self, code)) - if kernel.busy is False: - kernel.run_queue() - self.has_been_run = True + if kernel.busy is False: + kernel.run_queue() + self.has_been_run = True def execution_finished(self): """Reset the text of the run buttons.""" diff --git a/pyflow/blocks/widgets/blocktitle.py b/pyflow/blocks/widgets/blocktitle.py index b964d986..5c5814c2 100644 --- a/pyflow/blocks/widgets/blocktitle.py +++ b/pyflow/blocks/widgets/blocktitle.py @@ -8,13 +8,16 @@ """ import time -from typing import OrderedDict +from typing import List, OrderedDict, TYPE_CHECKING from PyQt5.QtCore import Qt from PyQt5.QtGui import QFocusEvent, QFont, QMouseEvent from PyQt5.QtWidgets import QLineEdit, QWidget, QGraphicsItem from pyflow.core.serializable import Serializable +if TYPE_CHECKING: + from pyflow.graphics.view import View + class Title(QLineEdit, Serializable): """The title of an Block. Needs to be double clicked to interact.""" @@ -60,9 +63,11 @@ def readOnly(self, value: bool): self.setReadOnly(value) new_mode = "NOOP" if value else "EDITING" - views = self.parent_block.scene().views() - for view in views: - view.set_mode(new_mode) + scene = self.parent_block.scene() + if scene: + views: List["View"] = scene.views() + for view in views: + view.set_mode(new_mode) def mousePressEvent(self, event: QMouseEvent): """ From 6effbefea9cdd41f9b1ff195330a5adf0cd85b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Math=C3=AFs=20F=C3=A9d=C3=A9rico?= Date: Sun, 30 Jan 2022 05:46:23 +0100 Subject: [PATCH 2/2] :tada: Add folding & backed number line --- pyflow/blocks/pyeditor.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pyflow/blocks/pyeditor.py b/pyflow/blocks/pyeditor.py index 25447879..0956aefa 100644 --- a/pyflow/blocks/pyeditor.py +++ b/pyflow/blocks/pyeditor.py @@ -19,6 +19,7 @@ POINT_SIZE = 11 + class PythonEditor(Editor): """In-block python editor for Pyflow.""" @@ -31,10 +32,14 @@ def __init__(self, block: Block): """ super().__init__(block) + self.foreground_color = QColor("#dddddd") + self.background_color = QColor("#212121") self.update_theme() theme_manager().themeChanged.connect(self.update_theme) + self.fontmetrics = QFontMetrics(self.font()) + # Set caret self.setCaretForegroundColor(QColor("#D4D4D4")) @@ -49,10 +54,10 @@ def __init__(self, block: Block): self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) # # Add folding - # self.setFolding(QsciScintilla.FoldStyle.CircledTreeFoldStyle, 1) - # self.setFoldMarginColors(background_color, background_color) - # self.setMarkerForegroundColor(foreground_color, 0) - # self.setMarkerBackgroundColor(background_color, 0) + self.setFolding(QsciScintilla.FoldStyle.CircledTreeFoldStyle, 1) + self.setFoldMarginColors(self.background_color, self.background_color) + self.setMarkerForegroundColor(self.foreground_color, 1) + self.setMarkerBackgroundColor(self.background_color, 1) # Add background transparency self.setStyleSheet("background:transparent") @@ -68,14 +73,12 @@ def update_theme(self): self.setFont(font) # Margin 0 is used for line numbers - fontmetrics = QFontMetrics(font) - foreground_color = QColor("#dddddd") - background_color = QColor("#212121") + self.fontmetrics = QFontMetrics(self.font()) self.setMarginsFont(font) - self.setMarginWidth(2, fontmetrics.width("00") + 6) - self.setMarginLineNumbers(2, True) - self.setMarginsForegroundColor(foreground_color) - self.setMarginsBackgroundColor(background_color) + self.setMarginWidth(0, self.fontmetrics.width("00") + 6) + self.setMarginLineNumbers(0, True) + self.setMarginsForegroundColor(self.foreground_color) + self.setMarginsBackgroundColor(self.background_color) lexer = QsciLexerPython() theme_manager().current_theme().apply_to_lexer(lexer)