From 1f26f42096e887f3f121c7213495abe4dbce3866 Mon Sep 17 00:00:00 2001 From: ilgarlunin Date: Mon, 5 Aug 2019 12:10:40 +0300 Subject: [PATCH] cli wip --- PyFlow/Scripts/__init__.py | 35 ++++++++++++----- PyFlow/UI/Canvas/UINodeBase.py | 1 - PyFlow/UI/Canvas/UIPinBase.py | 1 - PyFlow/UI/Tool/__init__.py | 1 - PyFlow/UI/Widgets/InputWidgets.py | 1 - graphUiParser.py => PyFlow/graphUiParser.py | 43 +++++++++++---------- pyflow_run.py | 20 ++++++++++ 7 files changed, 68 insertions(+), 34 deletions(-) rename graphUiParser.py => PyFlow/graphUiParser.py (79%) create mode 100644 pyflow_run.py diff --git a/PyFlow/Scripts/__init__.py b/PyFlow/Scripts/__init__.py index 199caa738..88467c00f 100644 --- a/PyFlow/Scripts/__init__.py +++ b/PyFlow/Scripts/__init__.py @@ -13,20 +13,37 @@ ## limitations under the License. +import argparse import sys from PyFlow.App import PyFlow +from PyFlow import graphUiParser from Qt.QtWidgets import QApplication def main(): - app = QApplication(sys.argv) + parser = argparse.ArgumentParser(description="PyFlow CLI") + parser.add_argument("-m", "--mode", type=str, default="edit", choices=["edit", "run"]) + parser.add_argument("-f", "--filePath", type=str, default="untitled.json") + parsedArguments = parser.parse_args(sys.argv[1:]) - instance = PyFlow.instance(software="standalone") - if instance is not None: - app.setActiveWindow(instance) - instance.show() + filePath = parsedArguments.filePath - try: - sys.exit(app.exec_()) - except Exception as e: - print(e) + if not filePath.endswith(".json"): + filePath += ".json" + + if parsedArguments.mode == "edit": + + app = QApplication(sys.argv) + + instance = PyFlow.instance(software="standalone") + if instance is not None: + app.setActiveWindow(instance) + instance.show() + + try: + sys.exit(app.exec_()) + except Exception as e: + print(e) + + if parsedArguments.mode == "run": + graphUiParser.run(filePath) diff --git a/PyFlow/UI/Canvas/UINodeBase.py b/PyFlow/UI/Canvas/UINodeBase.py index 94029f3ef..5f1eb0b8a 100644 --- a/PyFlow/UI/Canvas/UINodeBase.py +++ b/PyFlow/UI/Canvas/UINodeBase.py @@ -1446,7 +1446,6 @@ def recreate(node): def REGISTER_UI_NODE_FACTORY(packageName, factory): if packageName not in UI_NODES_FACTORIES: UI_NODES_FACTORIES[packageName] = factory - print("registering", packageName, "ui nodes") def getUINodeInstance(raw_instance): diff --git a/PyFlow/UI/Canvas/UIPinBase.py b/PyFlow/UI/Canvas/UIPinBase.py index 8c937b1ba..575d3062a 100644 --- a/PyFlow/UI/Canvas/UIPinBase.py +++ b/PyFlow/UI/Canvas/UIPinBase.py @@ -571,7 +571,6 @@ def paint(self, painter, option, widget): def REGISTER_UI_PIN_FACTORY(packageName, factory): if packageName not in UI_PINS_FACTORIES: UI_PINS_FACTORIES[packageName] = factory - print("registering", packageName, "ui pins") def getUIPinInstance(owningNode, raw_instance): diff --git a/PyFlow/UI/Tool/__init__.py b/PyFlow/UI/Tool/__init__.py index 24211fe4d..cab427f2d 100644 --- a/PyFlow/UI/Tool/__init__.py +++ b/PyFlow/UI/Tool/__init__.py @@ -22,7 +22,6 @@ def REGISTER_TOOL(packageName, toolClass): if toolClass.name() not in registeredToolNames: __REGISTERED_TOOLS[packageName].append(toolClass) toolClass.packageName = packageName - print("registering", packageName, toolClass.name()) def GET_TOOLS(): diff --git a/PyFlow/UI/Widgets/InputWidgets.py b/PyFlow/UI/Widgets/InputWidgets.py index c233b9b23..3f5248f1b 100644 --- a/PyFlow/UI/Widgets/InputWidgets.py +++ b/PyFlow/UI/Widgets/InputWidgets.py @@ -119,7 +119,6 @@ def setWidget(self, widget): def REGISTER_UI_INPUT_WIDGET_PIN_FACTORY(packageName, factory): if packageName not in UI_INPUT_WIDGET_PINS_FACTORIES: UI_INPUT_WIDGET_PINS_FACTORIES[packageName] = factory - print("registering", packageName, "input widgets") def createInputWidget(dataType, dataSetter, defaultValue=None, widgetVariant=DEFAULT_WIDGET_VARIANT, **kwds): diff --git a/graphUiParser.py b/PyFlow/graphUiParser.py similarity index 79% rename from graphUiParser.py rename to PyFlow/graphUiParser.py index f916b672e..ad27dec9c 100644 --- a/graphUiParser.py +++ b/PyFlow/graphUiParser.py @@ -12,7 +12,7 @@ ## See the License for the specific language governing permissions and ## limitations under the License. - +import os import sys import json from Qt.QtWidgets import * @@ -26,37 +26,34 @@ import PyFlow.UI.resources -if __name__ == '__main__': - # New Qt App +def run(filePath): + print(filePath) app = QApplication(sys.argv) app.setStyle(QStyleFactory.create("plastique")) app.setStyleSheet(editableStyleSheet().getStyleSheet()) - # Load Graph File - name_filter = "Graph files (*.json)" - savepath = QFileDialog.getOpenFileName(filter=name_filter) - if type(savepath) in [tuple, list]: - fpath = savepath[0] - else: - fpath = savepath - if not fpath == '': - with open(fpath, 'r') as f: + msg = QMessageBox() + msg.setWindowIcon(QtGui.QIcon(":/LogoBpApp.png")) + msg.setIcon(QMessageBox.Critical) + + if os.path.exists(filePath): + with open(filePath, 'r') as f: data = json.load(f) - # Window to display Inputs + + # Window to display inputs prop = QDialog() prop.setLayout(QVBoxLayout()) - prop.setWindowTitle(fpath) + prop.setWindowTitle(filePath) prop.setWindowIcon(QtGui.QIcon(":/LogoBpApp.png")) - msg = QMessageBox() - msg.setWindowIcon(QtGui.QIcon(":/LogoBpApp.png")) - msg.setIcon(QMessageBox.Critical) - # Initalize Packages + + # Initalize packages try: INITIALIZE() man = GraphManager() man.deserialize(data) grph = man.findRootGraph() inputs = grph.getNodesByClassName("graphInputs") + # If no GraphInput Nodes Exit propgram if len(inputs) > 0: for inp in inputs: @@ -67,25 +64,29 @@ cat = uiNode.createOutputWidgets(prop.layout(), inp.name) prop.show() else: - msg.setInformativeText(fpath) + + msg.setInformativeText(filePath) msg.setDetailedText( "The file doesn't containt graphInputs nodes") msg.setWindowTitle("PyFlow Ui Graph Parser") msg.setStandardButtons(QMessageBox.Ok) msg.show() + except Exception as e: msg.setText("Error reading Graph") - msg.setInformativeText(fpath) + msg.setInformativeText(filePath) msg.setDetailedText(str(e)) msg.setWindowTitle("PyFlow Ui Graph Parser") msg.setStandardButtons(QMessageBox.Ok) msg.show() + else: msg.setText("File Not Found") - msg.setInformativeText(fpath) + msg.setInformativeText(filePath) msg.setWindowTitle("PyFlow Ui Graph Parser") msg.setStandardButtons(QMessageBox.Ok) msg.show() + try: sys.exit(app.exec_()) except Exception as e: diff --git a/pyflow_run.py b/pyflow_run.py new file mode 100644 index 000000000..549de8249 --- /dev/null +++ b/pyflow_run.py @@ -0,0 +1,20 @@ +## Copyright 2015-2019 Ilgar Lunin, Pedro Cabrera + +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at + +## http://www.apache.org/licenses/LICENSE-2.0 + +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. + + +import sys +from PyFlow import graphUiParser + +if __name__ == '__main__': + graphUiParser.run(sys.argv[1])