fixup Flowchart for PyQt6
This commit is contained in:
parent
d0c062d7e5
commit
eec411a3c6
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from ..Qt import QtCore, QtGui
|
from ..Qt import QtCore, QtGui, QtWidgets
|
||||||
from ..graphicsItems.GraphicsObject import GraphicsObject
|
from ..graphicsItems.GraphicsObject import GraphicsObject
|
||||||
from .. import functions as fn
|
from .. import functions as fn
|
||||||
from .Terminal import *
|
from .Terminal import *
|
||||||
@ -436,6 +436,24 @@ class Node(QtCore.QObject):
|
|||||||
t.disconnectAll()
|
t.disconnectAll()
|
||||||
|
|
||||||
|
|
||||||
|
class TextItem(QtWidgets.QGraphicsTextItem):
|
||||||
|
def __init__(self, text, parent, on_update):
|
||||||
|
super().__init__(text, parent)
|
||||||
|
self.on_update = on_update
|
||||||
|
|
||||||
|
def focusOutEvent(self, ev):
|
||||||
|
super().focusOutEvent(ev)
|
||||||
|
if self.on_update is not None:
|
||||||
|
self.on_update()
|
||||||
|
|
||||||
|
def keyPressEvent(self, ev):
|
||||||
|
if ev.key() == QtCore.Qt.Key_Enter or ev.key() == QtCore.Qt.Key_Return:
|
||||||
|
if self.on_update is not None:
|
||||||
|
self.on_update()
|
||||||
|
return
|
||||||
|
super().keyPressEvent(ev)
|
||||||
|
|
||||||
|
|
||||||
#class NodeGraphicsItem(QtGui.QGraphicsItem):
|
#class NodeGraphicsItem(QtGui.QGraphicsItem):
|
||||||
class NodeGraphicsItem(GraphicsObject):
|
class NodeGraphicsItem(GraphicsObject):
|
||||||
def __init__(self, node):
|
def __init__(self, node):
|
||||||
@ -461,16 +479,13 @@ class NodeGraphicsItem(GraphicsObject):
|
|||||||
|
|
||||||
self.setFlags(flags)
|
self.setFlags(flags)
|
||||||
self.bounds = QtCore.QRectF(0, 0, 100, 100)
|
self.bounds = QtCore.QRectF(0, 0, 100, 100)
|
||||||
self.nameItem = QtGui.QGraphicsTextItem(self.node.name(), self)
|
self.nameItem = TextItem(self.node.name(), self, self.labelChanged)
|
||||||
self.nameItem.setDefaultTextColor(QtGui.QColor(50, 50, 50))
|
self.nameItem.setDefaultTextColor(QtGui.QColor(50, 50, 50))
|
||||||
self.nameItem.moveBy(self.bounds.width()/2. - self.nameItem.boundingRect().width()/2., 0)
|
self.nameItem.moveBy(self.bounds.width()/2. - self.nameItem.boundingRect().width()/2., 0)
|
||||||
self.nameItem.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
|
self.nameItem.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
|
||||||
self.updateTerminals()
|
self.updateTerminals()
|
||||||
#self.setZValue(10)
|
#self.setZValue(10)
|
||||||
|
|
||||||
self.nameItem.focusOutEvent = self.labelFocusOut
|
|
||||||
self.nameItem.keyPressEvent = self.labelKeyPress
|
|
||||||
|
|
||||||
self.menu = None
|
self.menu = None
|
||||||
self.buildMenu()
|
self.buildMenu()
|
||||||
|
|
||||||
@ -481,16 +496,6 @@ class NodeGraphicsItem(GraphicsObject):
|
|||||||
#item.setZValue(z+1)
|
#item.setZValue(z+1)
|
||||||
#GraphicsObject.setZValue(self, z)
|
#GraphicsObject.setZValue(self, z)
|
||||||
|
|
||||||
def labelFocusOut(self, ev):
|
|
||||||
QtGui.QGraphicsTextItem.focusOutEvent(self.nameItem, ev)
|
|
||||||
self.labelChanged()
|
|
||||||
|
|
||||||
def labelKeyPress(self, ev):
|
|
||||||
if ev.key() == QtCore.Qt.Key_Enter or ev.key() == QtCore.Qt.Key_Return:
|
|
||||||
self.labelChanged()
|
|
||||||
else:
|
|
||||||
QtGui.QGraphicsTextItem.keyPressEvent(self.nameItem, ev)
|
|
||||||
|
|
||||||
def labelChanged(self):
|
def labelChanged(self):
|
||||||
newName = str(self.nameItem.toPlainText())
|
newName = str(self.nameItem.toPlainText())
|
||||||
if newName != self.node.name():
|
if newName != self.node.name():
|
||||||
@ -574,7 +579,7 @@ class NodeGraphicsItem(GraphicsObject):
|
|||||||
|
|
||||||
def mouseClickEvent(self, ev):
|
def mouseClickEvent(self, ev):
|
||||||
#print "Node.mouseClickEvent called."
|
#print "Node.mouseClickEvent called."
|
||||||
if int(ev.button()) == int(QtCore.Qt.LeftButton):
|
if ev.button() == QtCore.Qt.LeftButton:
|
||||||
ev.accept()
|
ev.accept()
|
||||||
#print " ev.button: left"
|
#print " ev.button: left"
|
||||||
sel = self.isSelected()
|
sel = self.isSelected()
|
||||||
@ -587,7 +592,7 @@ class NodeGraphicsItem(GraphicsObject):
|
|||||||
self.update()
|
self.update()
|
||||||
#return ret
|
#return ret
|
||||||
|
|
||||||
elif int(ev.button()) == int(QtCore.Qt.RightButton):
|
elif ev.button() == QtCore.Qt.RightButton:
|
||||||
#print " ev.button: right"
|
#print " ev.button: right"
|
||||||
ev.accept()
|
ev.accept()
|
||||||
#pos = ev.screenPos()
|
#pos = ev.screenPos()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from ..Qt import QtCore, QtGui
|
from ..Qt import QtCore, QtGui, QtWidgets
|
||||||
import weakref
|
import weakref
|
||||||
from ..graphicsItems.GraphicsObject import GraphicsObject
|
from ..graphicsItems.GraphicsObject import GraphicsObject
|
||||||
from .. import functions as fn
|
from .. import functions as fn
|
||||||
@ -273,6 +273,25 @@ class Terminal(object):
|
|||||||
"""
|
"""
|
||||||
return self._name < other._name
|
return self._name < other._name
|
||||||
|
|
||||||
|
|
||||||
|
class TextItem(QtWidgets.QGraphicsTextItem):
|
||||||
|
def __init__(self, text, parent, on_update):
|
||||||
|
super().__init__(text, parent)
|
||||||
|
self.on_update = on_update
|
||||||
|
|
||||||
|
def focusOutEvent(self, ev):
|
||||||
|
super().focusOutEvent(ev)
|
||||||
|
if self.on_update is not None:
|
||||||
|
self.on_update()
|
||||||
|
|
||||||
|
def keyPressEvent(self, ev):
|
||||||
|
if ev.key() == QtCore.Qt.Key_Enter or ev.key() == QtCore.Qt.Key_Return:
|
||||||
|
if self.on_update is not None:
|
||||||
|
self.on_update()
|
||||||
|
return
|
||||||
|
super().keyPressEvent(ev)
|
||||||
|
|
||||||
|
|
||||||
class TerminalGraphicsItem(GraphicsObject):
|
class TerminalGraphicsItem(GraphicsObject):
|
||||||
|
|
||||||
def __init__(self, term, parent=None):
|
def __init__(self, term, parent=None):
|
||||||
@ -280,27 +299,16 @@ class TerminalGraphicsItem(GraphicsObject):
|
|||||||
GraphicsObject.__init__(self, parent)
|
GraphicsObject.__init__(self, parent)
|
||||||
self.brush = fn.mkBrush(0,0,0)
|
self.brush = fn.mkBrush(0,0,0)
|
||||||
self.box = QtGui.QGraphicsRectItem(0, 0, 10, 10, self)
|
self.box = QtGui.QGraphicsRectItem(0, 0, 10, 10, self)
|
||||||
self.label = QtGui.QGraphicsTextItem(self.term.name(), self)
|
on_update = self.labelChanged if self.term.isRenamable() else None
|
||||||
|
self.label = TextItem(self.term.name(), self, on_update)
|
||||||
self.label.scale(0.7, 0.7)
|
self.label.scale(0.7, 0.7)
|
||||||
self.newConnection = None
|
self.newConnection = None
|
||||||
self.setFiltersChildEvents(True) ## to pick up mouse events on the rectitem
|
self.setFiltersChildEvents(True) ## to pick up mouse events on the rectitem
|
||||||
if self.term.isRenamable():
|
if self.term.isRenamable():
|
||||||
self.label.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
|
self.label.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
|
||||||
self.label.focusOutEvent = self.labelFocusOut
|
|
||||||
self.label.keyPressEvent = self.labelKeyPress
|
|
||||||
self.setZValue(1)
|
self.setZValue(1)
|
||||||
self.menu = None
|
self.menu = None
|
||||||
|
|
||||||
def labelFocusOut(self, ev):
|
|
||||||
QtGui.QGraphicsTextItem.focusOutEvent(self.label, ev)
|
|
||||||
self.labelChanged()
|
|
||||||
|
|
||||||
def labelKeyPress(self, ev):
|
|
||||||
if ev.key() == QtCore.Qt.Key_Enter or ev.key() == QtCore.Qt.Key_Return:
|
|
||||||
self.labelChanged()
|
|
||||||
else:
|
|
||||||
QtGui.QGraphicsTextItem.keyPressEvent(self.label, ev)
|
|
||||||
|
|
||||||
def labelChanged(self):
|
def labelChanged(self):
|
||||||
newName = str(self.label.toPlainText())
|
newName = str(self.label.toPlainText())
|
||||||
if newName != self.term.name():
|
if newName != self.term.name():
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from ..Node import Node
|
from ..Node import Node
|
||||||
from ...Qt import QtGui, QtCore
|
from ...Qt import QtGui, QtCore, QtWidgets
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import sys
|
import sys
|
||||||
from .common import *
|
from .common import *
|
||||||
@ -173,6 +173,20 @@ class RegionSelectNode(CtrlNode):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
|
class TextEdit(QtWidgets.QTextEdit):
|
||||||
|
def __init__(self, on_update):
|
||||||
|
super().__init__()
|
||||||
|
self.on_update = on_update
|
||||||
|
self.lastText = None
|
||||||
|
|
||||||
|
def focusOutEvent(self, ev):
|
||||||
|
text = str(self.toPlainText())
|
||||||
|
if text != self.lastText:
|
||||||
|
self.lastText = text
|
||||||
|
self.on_update()
|
||||||
|
super().focusOutEvent(ev)
|
||||||
|
|
||||||
|
|
||||||
class EvalNode(Node):
|
class EvalNode(Node):
|
||||||
"""Return the output of a string evaluated/executed by the python interpreter.
|
"""Return the output of a string evaluated/executed by the python interpreter.
|
||||||
The string may be either an expression or a python script, and inputs are accessed as the name of the terminal.
|
The string may be either an expression or a python script, and inputs are accessed as the name of the terminal.
|
||||||
@ -190,15 +204,12 @@ class EvalNode(Node):
|
|||||||
|
|
||||||
self.ui = QtGui.QWidget()
|
self.ui = QtGui.QWidget()
|
||||||
self.layout = QtGui.QGridLayout()
|
self.layout = QtGui.QGridLayout()
|
||||||
self.text = QtGui.QTextEdit()
|
self.text = TextEdit(self.update)
|
||||||
self.text.setTabStopWidth(30)
|
self.text.setTabStopWidth(30)
|
||||||
self.text.setPlainText("# Access inputs as args['input_name']\nreturn {'output': None} ## one key per output terminal")
|
self.text.setPlainText("# Access inputs as args['input_name']\nreturn {'output': None} ## one key per output terminal")
|
||||||
self.layout.addWidget(self.text, 1, 0, 1, 2)
|
self.layout.addWidget(self.text, 1, 0, 1, 2)
|
||||||
self.ui.setLayout(self.layout)
|
self.ui.setLayout(self.layout)
|
||||||
|
|
||||||
self.text.focusOutEvent = self.focusOutEvent
|
|
||||||
self.lastText = None
|
|
||||||
|
|
||||||
def ctrlWidget(self):
|
def ctrlWidget(self):
|
||||||
return self.ui
|
return self.ui
|
||||||
|
|
||||||
@ -221,13 +232,6 @@ class EvalNode(Node):
|
|||||||
def code(self):
|
def code(self):
|
||||||
return self.text.toPlainText()
|
return self.text.toPlainText()
|
||||||
|
|
||||||
def focusOutEvent(self, ev):
|
|
||||||
text = str(self.text.toPlainText())
|
|
||||||
if text != self.lastText:
|
|
||||||
self.lastText = text
|
|
||||||
self.update()
|
|
||||||
return QtGui.QTextEdit.focusOutEvent(self.text, ev)
|
|
||||||
|
|
||||||
def process(self, display=True, **args):
|
def process(self, display=True, **args):
|
||||||
l = locals()
|
l = locals()
|
||||||
l.update(args)
|
l.update(args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user