Skip to content

Commit

Permalink
Improve and move to dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
don4get committed Jun 21, 2020
1 parent 36389c2 commit 9db51e5
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 12 deletions.
8 changes: 8 additions & 0 deletions examples/example_calculator/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys

from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtWidgets import *

from nodedge.mdi_window import MdiWindow
Expand All @@ -13,6 +14,13 @@
app = QApplication(sys.argv)

app.setStyle("Fusion")
p = app.palette()
p.setColor(QPalette.Window, QColor(53, 53, 53))
p.setColor(QPalette.Button, QColor(53, 53, 53))
p.setColor(QPalette.Highlight, QColor(142, 45, 197))
p.setColor(QPalette.ButtonText, QColor(255, 255, 255))
p.setColor(QPalette.WindowText, QColor(255, 255, 255))
app.setPalette(p)

window = MdiWindow()

Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import glob
from os.path import basename, dirname, isfile, join

Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/add_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from nodedge.blocks.block import Block, EvaluationError
from nodedge.blocks.block_config import BLOCKS_ICONS_PATH, OP_NODE_ADD, registerNode

Expand Down
3 changes: 1 addition & 2 deletions nodedge/blocks/block_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
import os
from typing import Dict, TypeVar

from nodedge.blocks.block import Block

NODELISTWIDGET_MIMETYPE = "application/x-item"

OP_NODE_INPUT = 1
Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/divide_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from nodedge.blocks.block import Block, EvaluationError
from nodedge.blocks.block_config import BLOCKS_ICONS_PATH, OP_NODE_DIVIDE, registerNode

Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/graphics_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import os

from PyQt5.QtCore import QRectF
Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/graphics_block_content.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QLabel

from nodedge.graphics_node_content import GraphicsNodeContent
Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/graphics_input_block_content.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
Graphics input block content module containing
:class:`~nodedge.graphics_input_block_content.GraphicsInputBlockContent` class.
Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/graphics_output_block_content.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLabel

Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/input_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from nodedge.blocks.block import Block
from nodedge.blocks.block_config import BLOCKS_ICONS_PATH, OP_NODE_INPUT, registerNode
from nodedge.blocks.graphics_block import GraphicsBlock
Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/multiply_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from nodedge.blocks.block import Block, EvaluationError
from nodedge.blocks.block_config import (
BLOCKS_ICONS_PATH,
Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/output_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from nodedge.blocks.block import Block, EvaluationError
from nodedge.blocks.block_config import BLOCKS_ICONS_PATH, OP_NODE_OUTPUT, registerNode
from nodedge.blocks.graphics_block import GraphicsBlock
Expand Down
1 change: 1 addition & 0 deletions nodedge/blocks/subtract_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from nodedge.blocks.block import Block, EvaluationError
from nodedge.blocks.block_config import (
BLOCKS_ICONS_PATH,
Expand Down
79 changes: 79 additions & 0 deletions nodedge/edge_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
"""Edge validators module containing the Edge Validator functions which can be
registered as callbacks to :class:`~nodedge.edge.Edge` class.
Example of registering Edge Validator callbacks:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can register validation callbacks once for example on the bottom of node_edge.py
file or on the application start with calling this:
.. code-block:: python
from nodedge.edge_validators import *
Edge.registerEdgeValidator(edgeValidatorDebug)
Edge.registerEdgeValidator(edgeCannotConnectTwoOutputsOrTwoInputs)
Edge.registerEdgeValidator(edgeCannotConnectInputAndOutputOfSameNode)
"""

from nodedge.socket import Socket

DEBUG = False


def printError(*args):
"""Helper method which prints to console if `DEBUG` is set to `True`"""
if DEBUG:
print("Edge Validation Error:", *args)


def edgeValidatorDebug(inputSocket: Socket, outputSocket: Socket) -> bool:
"""This will consider edge always valid, however writes bunch of debug stuff into
console """
print("VALIDATING:")
print(
inputSocket,
"input" if inputSocket.isInput else "output",
"of node",
inputSocket.node,
)
for s in inputSocket.node.inputs + inputSocket.node.outputs:
print("\t", s, "input" if s.is_input else "output")
print(
outputSocket,
"input" if inputSocket.isInput else "output",
"of node",
outputSocket.node,
)
for s in outputSocket.node.inputs + outputSocket.node.outputs:
print("\t", s, "input" if s.isInput else "output")

return True


def edgeCannotConnectTwoOutputsOrTwoInputs(
inputSocket: Socket, outputSocket: Socket
) -> bool:
"""Edge is invalid if it connects 2 output sockets or 2 input sockets"""
if inputSocket.isOutput and outputSocket.isOutput:
printError("Connecting 2 outputs")
return False

if inputSocket.isInput and outputSocket.isInput:
printError("Connecting 2 inputs")
return False

return True


def edgeCannotConnectInputAndOutputOfSameNode(
inputSocket: Socket, outputSocket: Socket
) -> bool:
"""Edge is invalid if it connects the same node"""
if inputSocket.node == outputSocket.node:
printError("Connecting the same node")
return False

return True
10 changes: 5 additions & 5 deletions nodedge/graphics_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def initUI(self):

# noinspection PyAttributeOutsideInit
def initStyle(self):
"""Initialize ``QObjects`` like ``QColor``, ``QPen`` and ``QBrush``"""
self._color_background = QColor("#ffffff")
"""Initialize ``QObjects`` like ``QColor``, ``QPten`` and ``QBrush``"""
self._color_background = QColor("#DFE0DC")
self._color_light = QColor("#ffffff")
self._color_dark = QColor("#ffffff")

Expand All @@ -74,13 +74,13 @@ def initSizes(self):
self.scene_width = 64000
self.scene_height = 64000

def setScene(self, width, height):
def setScene(self, width, height) -> None:
"""
Set `width` and `height` of the graphics scene.
"""
self.setSceneRect(-width // 2, -height // 2, width, height)

def drawBackground(self, painter, rectangle):
def drawBackground(self, painter, rectangle) -> None:
"""
Draw background scene grid.
"""
Expand Down Expand Up @@ -152,7 +152,7 @@ def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None:

super().mousePressEvent(event)

def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None:
"""
Handle Qt's mouse's button release event.
Expand Down
2 changes: 1 addition & 1 deletion nodedge/mdi_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def initUI(self):
self.setWindowIcon(self.icon)

self.styleSheetFilename = os.path.join(
os.path.dirname(__file__), "qss/calculator.qss"
os.path.dirname(__file__), "qss/calculator-dark.qss"
)
loadStyleSheets(
# os.path.join(os.path.dirname(__file__), "qss/calculator-dark.qss"),
Expand Down
11 changes: 9 additions & 2 deletions nodedge/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@


class NodesAndSockets:
def __init__(self, nodes, sockets):
"""
:class:`~nodedge.node.NodesAndSockets` class
"""

def __init__(self, nodes, sockets) -> None:
"""
:param nodes: list of nodes to add to the structure
:param sockets: list of sockets to add to the structure
"""
self.nodes: List["Node"] = nodes
self.sockets: List["Socket"] = sockets

Expand Down Expand Up @@ -151,7 +159,6 @@ def initSockets(
socketType=out,
allowMultiEdges=self._outputAllowMultiEdges,
countOnThisNodeSide=len(outputs),
isInput=False,
)
self.outputSockets.append(socket)

Expand Down
2 changes: 0 additions & 2 deletions tests/socket_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
from PyQt5.QtCore import QPointF
from PyQt5.QtWidgets import QMainWindow

from nodedge.edge import Edge
from nodedge.editor_widget import EditorWidget
from nodedge.node import Node
from nodedge.scene import Scene
Expand Down

0 comments on commit 9db51e5

Please sign in to comment.