Skip to content

Commit

Permalink
Add base ideas for code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
don4get committed Jul 19, 2020
1 parent d401a27 commit 607ee7e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nodedge/blocks/add_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ def evalImplementation(self):
self.value = result

return self.value


# TODO: make evalImplementation generic with respect to number of inputs
# TODO: Find a way to extract exceptions from evalImplementation
# TODO: Create a script to generate blocks from a dictionary (JSON / CSV / whatever)
# TODO: Create a script to generate tests for blocks: list of Inputs and list of expected Outputs
3 changes: 3 additions & 0 deletions nodedge/blocks/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def eval(self, index=0):

try:
self.checkInputsValidity()
# TODO: Implement evalInputs and checkInputsConsistency methods
# self.evalInputs()
# self.checkInputsConsistency()
self.value = self.evalImplementation()
self.isDirty = False
self.isInvalid = False
Expand Down
22 changes: 22 additions & 0 deletions nodedge/code_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
"""
Code generator module containing :class:`~nodedge.code_generator.CodeGenerator` class.
"""


class CodeGenerator:
"""
:class:`~nodedge.code_generator.CodeGenerator` class .
"""

# noinspection PyUnresolvedReferences
def __init__(self, scene: "Scene") -> None: # type: ignore
self.scene = scene

def generateCode(self):
for node in self.scene.nodes:
node.code()


# TODO: Find a way to generate beautiful code
# TODO: Find inputs blocks, assign them to a variable,
9 changes: 9 additions & 0 deletions nodedge/editor_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ def createActions(self) -> None:
self.fitInViewAct.setStatusTip("Fit content in view")
self.fitInViewAct.triggered.connect(self.onFitInView)

self.generateCodeAct = QAction("Generate code", self)
self.generateCodeAct.setShortcut(QKeySequence("Ctrl+G"))
self.generateCodeAct.setStatusTip("Generate python code")
self.generateCodeAct.triggered.connect(self.onGenerateCode)

# noinspection PyArgumentList, PyAttributeOutsideInit, DuplicatedCode
def createMenus(self) -> None:
"""
Expand Down Expand Up @@ -542,3 +547,7 @@ def beforeSaveFileAs(
def onFitInView(self):
if self.currentEditorWidget is not None:
self.currentEditorWidget.graphicsView.graphicsScene.fitInView()

def onGenerateCode(self):
if self.currentEditorWidget is not None:
self.currentEditorWidget.graphicsView.graphicsScene.fitInView()
2 changes: 2 additions & 0 deletions nodedge/mdi_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def initUI(self) -> None:
self.styleSheetFilename
)

# self.setWindowFlag(Qt.FramelessWindowHint)

self.timer = QTimer()
self.timer.setTimerType(Qt.PreciseTimer)
self.timer.setInterval(500)
Expand Down
2 changes: 1 addition & 1 deletion nodedge/qss/calculator-dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ color:#eeeeee;
QDockWidget{
color:#dddddd;
font-weight:bold;
titlebar-close-icon:url(":icons/docktitle-close-btn-light.png");
titlebar-close-icon:url("../../nodedge/resources/iconsModified/close_window_100.png");
titlebar-normal-icon:url(":icons/docktitle-normal-btn-light.png");
}

Expand Down
2 changes: 2 additions & 0 deletions nodedge/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from PySide2.QtGui import QDragEnterEvent, QDropEvent
from PySide2.QtWidgets import QGraphicsItem

from nodedge.code_generator import CodeGenerator
from nodedge.edge import Edge
from nodedge.graphics_scene import GraphicsScene
from nodedge.graphics_view import GraphicsView
Expand Down Expand Up @@ -49,6 +50,7 @@ def __init__(self) -> None:

self.history: SceneHistory = SceneHistory(self)
self.clipboard: SceneClipboard = SceneClipboard(self)
self.codeGenerator: CodeGenerator = CodeGenerator(self)

self._isModified: bool = False
self.isModified: bool = False
Expand Down

0 comments on commit 607ee7e

Please sign in to comment.