Skip to content

Commit

Permalink
Merge pull request #11 from pnnl/CODEVERIFY-21
Browse files Browse the repository at this point in the history
GUI: empty png bug fix
  • Loading branch information
leijerry888 authored Jan 30, 2024
2 parents 4ba18f3 + 7e28d2c commit 25c6127
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
Empty file added constrain/app/__init__.py
Empty file.
19 changes: 17 additions & 2 deletions constrain/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .workflow_diagram import WorkflowDiagram
from .rect_connect import CustomItem
from .submit import Worker, SubmitPopup
from . import utils

from constrain.api.workflow import Workflow

Expand Down Expand Up @@ -148,6 +149,14 @@ def advancedPopupSetting(self):

def exportFile(self):
"""Exports current state as a .json to local storage"""

scene = self.states_form.scene
if not scene.items():
utils.send_error(
"Export Error", "Workflow is empty. Add a workflow to export"
)
return

fp, _ = QFileDialog.getSaveFileName(
self, "Save JSON File", "", "JSON Files (*.json);;All Files (*)"
)
Expand All @@ -162,11 +171,17 @@ def exportFile(self):

def exportAsPng(self):
"""Exports current state as a .png to local storage"""

scene = self.states_form.scene
if not scene.items():
utils.send_error(
"Export Error", "Workflow is empty. Add a workflow to export"
)
return

fp, _ = QFileDialog.getSaveFileName(self, "Save Image", "", "PNG Files (*.png)")

if fp:
scene = self.states_form.scene
scene.sceneRect().size()
pixmap = QPixmap(scene.sceneRect().size().toSize())
pixmap.fill(QColor(255, 255, 255))
painter = QPainter(pixmap)
Expand Down
17 changes: 6 additions & 11 deletions constrain/app/rect_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from PyQt6 import QtCore, QtGui, QtWidgets

from . import utils


class Path(QtWidgets.QGraphicsPathItem):
def __init__(self, start, p2, end=None):
Expand Down Expand Up @@ -241,23 +243,16 @@ def newLineErrorCheck(self, pathItem):
if existing.controlPoints() == pathItem.controlPoints():
return False

# define error message
def send_error(text):
error_msg = QtWidgets.QMessageBox()
error_msg.setIcon(QtWidgets.QMessageBox.Icon.Critical)
error_msg.setWindowTitle("Error in Path")
error_msg.setText(text)
error_msg.exec()

# only consider sending error message if self is the start of the path
if pathItem.start == self:
# determine if parent will have too many children states
rect_children_amt = len(self.parent.children)
if rect_children_amt >= 1:
if self.parent.state["Type"] != "Choice":
# MethodCall type CustomItem can only connect to 1 CustomItem
error_msg = "This type cannot connect to more than 1 state"
send_error(error_msg)
utils.send_error(
"Error in Path", "This type cannot connect to more than 1 state"
)
return False
elif self.parent.state["Type"] == "Choice":
# Choice type CustomItem can connect to more than 1 CustomItem, but need to see how many are defined in the state
Expand All @@ -267,7 +262,7 @@ def send_error(text):

if rect_children_amt >= choices_amt:
error_msg = f"This type cannot connect to more than {choices_amt} states"
send_error(error_msg)
utils.send_error("Error in Path", error_msg)
return False
# add new child node to parent.children since path is viable
self.parent.children.append(pathItem.end.parent)
Expand Down
14 changes: 14 additions & 0 deletions constrain/app/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from PyQt6.QtWidgets import QMessageBox


def send_error(window_title, text):
"""Displays an error message with given text
Args:
text (str): text to be displayed
"""
error_msg = QMessageBox()
error_msg.setIcon(QMessageBox.Icon.Critical)
error_msg.setWindowTitle(window_title)
error_msg.setText(text)
error_msg.exec()

0 comments on commit 25c6127

Please sign in to comment.