Skip to content

Commit

Permalink
cli wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgarlunin committed Aug 5, 2019
1 parent 127ce24 commit 1f26f42
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
35 changes: 26 additions & 9 deletions PyFlow/Scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion PyFlow/UI/Canvas/UINodeBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion PyFlow/UI/Canvas/UIPinBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion PyFlow/UI/Tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 0 additions & 1 deletion PyFlow/UI/Widgets/InputWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
43 changes: 22 additions & 21 deletions graphUiParser.py → PyFlow/graphUiParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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:
Expand All @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions pyflow_run.py
Original file line number Diff line number Diff line change
@@ -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])

0 comments on commit 1f26f42

Please sign in to comment.