def __init__(self, parent=None): super(PyFlow, self).__init__(parent=parent) self.setupUi(self) self.listViewUndoStack = QUndoView(self.dockWidgetContents_3) self.listViewUndoStack.setObjectName("listViewUndoStack") self.gridLayout_6.addWidget(self.listViewUndoStack, 0, 0, 1, 1) self.styleSheetEditor = StyleSheetEditor() self.G = GraphWidget('root', self) self.nodeBox2 = NodesBox(None, self.G) self.SceneLayout.addWidget(self.G) self.gridLayout_7.addWidget(self.nodeBox2) self.actionVariables.triggered.connect(self.toggleVariables) self.actionPlot_graph.triggered.connect(self.G.plot) self.actionDelete.triggered.connect(self.on_delete) self.actionPropertyView.triggered.connect(self.togglePropertyView) self.actionScreenshot.triggered.connect(self.G.screenShot) self.actionShortcuts.triggered.connect(self.shortcuts_info) self.actionSave.triggered.connect(self.G.save) self.actionLoad.triggered.connect(self.G.load) self.actionSave_as.triggered.connect(self.G.save_as) self.actionAlignLeft.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Left)) self.actionAlignUp.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Up)) self.actionAlignBottom.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Down)) self.actionAlignRight.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Right)) self.actionNew_Node.triggered.connect( lambda: self.newPlugin(PluginType.pNode)) self.actionNew_Command.triggered.connect( lambda: self.newPlugin(PluginType.pCommand)) self.actionFunction_Library.triggered.connect( lambda: self.newPlugin(PluginType.pFunctionLibrary)) self.actionNew_pin.triggered.connect( lambda: self.newPlugin(PluginType.pPin)) self.actionHistory.triggered.connect(self.toggleHistory) self.actionNew.triggered.connect(self.G.new_file) self.actionEdit_Theme.triggered.connect(self.editTheme) self.dockWidgetUndoStack.setVisible(False) self.setMouseTracking(True) self.variablesWidget = VariablesWidget(self, self.G) self.leftDockGridLayout.addWidget(self.variablesWidget) self._lastClock = 0.0 self.fps = EDITOR_TARGET_FPS self.tick_timer = QtCore.QTimer() self.tick_timer.timeout.connect(self.mainLoop) self.styleSheetEditor.Updated.connect(self.updateStyle) self.setStyleSheet(self.styleSheetEditor.getStyleSheet())
class PyFlow(QMainWindow, GraphEditor_ui.Ui_MainWindow): def __init__(self, parent=None): super(PyFlow, self).__init__(parent=parent) self.setupUi(self) self.listViewUndoStack = QUndoView(self.dockWidgetContents_3) self.listViewUndoStack.setObjectName("listViewUndoStack") self.gridLayout_6.addWidget(self.listViewUndoStack, 0, 0, 1, 1) self.G = GraphWidget('root', self) self.SceneLayout.addWidget(self.G) self.actionVariables.triggered.connect(self.toggleVariables) self.actionPlot_graph.triggered.connect(self.G.plot) self.actionDelete.triggered.connect(self.on_delete) self.actionPropertyView.triggered.connect(self.togglePropertyView) self.actionScreenshot.triggered.connect(self.G.screenShot) self.actionShortcuts.triggered.connect(self.shortcuts_info) self.actionSave.triggered.connect(self.G.save) self.actionLoad.triggered.connect(self.G.load) self.actionSave_as.triggered.connect(self.G.save_as) self.actionAlignLeft.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Left)) self.actionAlignUp.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Up)) self.actionAlignBottom.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Down)) self.actionAlignRight.triggered.connect( lambda: self.G.alignSelectedNodes(Direction.Right)) self.actionNew_Node.triggered.connect( lambda: self.newPlugin(PluginType.pNode)) self.actionNew_Command.triggered.connect( lambda: self.newPlugin(PluginType.pCommand)) self.actionFunction_Library.triggered.connect( lambda: self.newPlugin(PluginType.pFunctionLibrary)) self.actionNew_pin.triggered.connect( lambda: self.newPlugin(PluginType.pPin)) self.actionHistory.triggered.connect(self.toggleHistory) self.actionNew.triggered.connect(self.G.new_file) self.dockWidgetUndoStack.setVisible(False) self.setMouseTracking(True) self.variablesWidget = VariablesWidget(self, self.G) self.leftDockGridLayout.addWidget(self.variablesWidget) self._lastClock = 0.0 self.fps = EDITOR_TARGET_FPS self.tick_timer = QtCore.QTimer() self.tick_timer.timeout.connect(self.mainLoop) def startMainLoop(self): self.tick_timer.start(1000 / EDITOR_TARGET_FPS) def mainLoop(self): deltaTime = clock() - self._lastClock ds = (deltaTime * 1000.0) if ds > 0: self.fps = int(1000.0 / ds) self.G.Tick(deltaTime) self._lastClock = clock() def createPopupMenu(self): pass def toggleHistory(self): self.dockWidgetUndoStack.setVisible( not self.dockWidgetUndoStack.isVisible()) def newPlugin(self, pluginType): name, result = QInputDialog.getText(self, 'Plugin name', 'Enter plugin name') if result: _implementPlugin(name, pluginType) def closeEvent(self, event): self.tick_timer.stop() self.tick_timer.timeout.disconnect() self.G.shoutDown() # save editor config settings = QtCore.QSettings(SETTINGS_PATH, QtCore.QSettings.IniFormat, self) settings.beginGroup('Editor') settings.setValue("geometry", self.saveGeometry()) settings.setValue("windowState", self.saveState()) settings.endGroup() QMainWindow.closeEvent(self, event) def applySettings(self, settings): self.restoreGeometry(settings.value('Editor/geometry')) self.restoreState(settings.value('Editor/windowState')) def togglePropertyView(self): if self.dockWidgetNodeView.isVisible(): self.dockWidgetNodeView.setVisible(False) else: self.dockWidgetNodeView.setVisible(True) def toggleVariables(self): if self.dockWidgetVariables.isVisible(): self.dockWidgetVariables.hide() else: self.dockWidgetVariables.show() def shortcuts_info(self): data = "Ctrl+Shift+N - togle node box\n" data += "Ctrl+N - new file\n" data += "Ctrl+S - save\n" data += "Ctrl+Shift+S - save as\n" data += "Ctrl+O - open file\n" data += "Ctrl+F - frame\n" data += "C - comment selected nodes\n" data += "Delete - kill selected nodes\n" data += "Ctrl+Shift+ArrowLeft - Align left\n" data += "Ctrl+Shift+ArrowUp - Align Up\n" data += "Ctrl+Shift+ArrowRight - Align right\n" data += "Ctrl+Shift+ArrowBottom - Align Bottom\n" QMessageBox.information(self, "Shortcuts", data) def on_delete(self): self.G.killSelectedNodes() @staticmethod def instance(parent=None): settings = QtCore.QSettings(SETTINGS_PATH, QtCore.QSettings.IniFormat) instance = PyFlow(parent) instance.applySettings(settings) instance.startMainLoop() return instance @staticmethod def hotReload(): reload(Pins) reload(FunctionLibraries) reload(Nodes) Nodes._getClasses() FunctionLibraries._getFunctions()