Skip to content

Commit

Permalink
Merge pull request #232 from Bycelium/feature/editor_folder_and_numbers
Browse files Browse the repository at this point in the history
🎉 🎨 Improve pyeditor
  • Loading branch information
AlexandreSajus authored Jan 30, 2022
2 parents 4255e28 + 6effbef commit 7461912
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
12 changes: 6 additions & 6 deletions pyflow/blocks/executableblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
25 changes: 14 additions & 11 deletions pyflow/blocks/pyeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

POINT_SIZE = 11


class PythonEditor(Editor):

"""In-block python editor for Pyflow."""
Expand All @@ -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"))

Expand All @@ -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")
Expand All @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions pyflow/blocks/widgets/blocktitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 7461912

Please sign in to comment.