Skip to content
Snippets Groups Projects
Commit 6568ebbd authored by Jacob Wahlman's avatar Jacob Wahlman :ok_hand:
Browse files

added float as valid input, and fixed some crash with load

parent 56e81186
No related branches found
No related tags found
1 merge request!61Fixed save/load, sfg creating, simulation, bug fixes
Pipeline #16189 passed
This commit is part of merge request !61. Comments created here will be created in the context of that merge request.
......@@ -261,6 +261,9 @@ class MainWindow(QMainWindow):
def check_equality(signal, signal_2):
# check operation types
if not (signal.source is not None or signal_2.source is not None):
return False
if not (signal.source.operation.type_name() == signal_2.source.operation.type_name() \
and signal.destination.operation.type_name() == signal_2.destination.operation.type_name()):
return False
......
from PySide2.QtWidgets import QDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout,\
QLabel, QCheckBox, QGridLayout
from PySide2.QtCore import Qt
from PySide2.QtGui import QIntValidator
from PySide2.QtGui import QDoubleValidator
class PropertiesWindow(QDialog):
def __init__(self, operation, main_window):
......@@ -25,10 +25,10 @@ class PropertiesWindow(QDialog):
if hasattr(self.operation.operation, "value"):
self.constant_layout = QHBoxLayout()
self.constant_layout.setSpacing(50)
self.constant_value = QLabel("Constant:")
self.constant_value = QLabel("Value:")
self.edit_constant = QLineEdit(str(self.operation.operation.value))
self.only_accept_int = QIntValidator()
self.edit_constant.setValidator(self.only_accept_int)
self.only_accept_float = QDoubleValidator()
self.edit_constant.setValidator(self.only_accept_float)
self.constant_layout.addWidget(self.constant_value)
self.constant_layout.addWidget(self.edit_constant)
self.vertical_layout.addLayout(self.constant_layout)
......@@ -66,7 +66,7 @@ class PropertiesWindow(QDialog):
input_value.setPlaceholderText(str(self.operation.operation.latency))
except ValueError:
input_value.setPlaceholderText("-1")
int_valid = QIntValidator()
int_valid = QDoubleValidator()
int_valid.setBottom(-1)
input_value.setValidator(int_valid)
input_value.setFixedWidth(50)
......@@ -101,7 +101,7 @@ class PropertiesWindow(QDialog):
input_value.setPlaceholderText(str(self.operation.operation.latency))
except ValueError:
input_value.setPlaceholderText("-1")
int_valid = QIntValidator()
int_valid = QDoubleValidator()
int_valid.setBottom(-1)
input_value.setValidator(int_valid)
input_value.setFixedWidth(50)
......@@ -125,7 +125,7 @@ class PropertiesWindow(QDialog):
self.operation.operation.name = self.edit_name.text()
self.operation.label.setPlainText(self.operation.name)
if hasattr(self.operation.operation, "value"):
self.operation.operation.value = int(self.edit_constant.text())
self.operation.operation.value = float(self.edit_constant.text().replace(",", "."))
if self.check_show_name.isChecked():
self.operation.label.setOpacity(1)
self.operation.is_show_name = True
......@@ -133,6 +133,6 @@ class PropertiesWindow(QDialog):
self.operation.label.setOpacity(0)
self.operation.is_show_name = False
self.operation.operation.set_latency_offsets({port: int(self.latency_fields[port].text()) if self.latency_fields[port].text() and int(self.latency_fields[port].text()) > 0 else None for port in self.latency_fields})
self.operation.operation.set_latency_offsets({port: float(self.latency_fields[port].text().replace(",", ".")) if self.latency_fields[port].text() and float(self.latency_fields[port].text().replace(",", ".")) > 0 else None for port in self.latency_fields})
self.reject()
\ No newline at end of file
from PySide2.QtWidgets import QDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout,\
QLabel, QCheckBox, QSpinBox, QGroupBox, QFrame, QFormLayout, QGridLayout, QSizePolicy, QFileDialog, QShortcut
from PySide2.QtCore import Qt, Signal
from PySide2.QtGui import QIntValidator, QKeySequence
from PySide2.QtGui import QDoubleValidator, QKeySequence
from matplotlib.backends import qt_compat
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
......@@ -70,7 +70,7 @@ class SimulateSFGWindow(QDialog):
input_layout.addWidget(input_label)
input_value = QLineEdit()
input_value.setPlaceholderText("0")
input_value.setValidator(QIntValidator())
input_value.setValidator(QDoubleValidator())
input_value.setFixedWidth(50)
input_layout.addWidget(input_value)
input_layout.addStretch()
......@@ -97,7 +97,7 @@ class SimulateSFGWindow(QDialog):
"iteration_count": self.input_fields[sfg]["iteration_count"].value(),
"show_plot": self.input_fields[sfg]["show_plot"].isChecked(),
"all_results": self.input_fields[sfg]["all_results"].isChecked(),
"input_values": [int(widget.text()) if widget.text() else 0 for widget in self.input_fields[sfg]["input_values"]]
"input_values": [float(widget.text().replace(",", ".")) if widget.text() else 0 for widget in self.input_fields[sfg]["input_values"]]
}
# If we plot we should also print the entire data, since you can't really interact with the graph.
......
......@@ -76,4 +76,4 @@ def python_to_sfg(path: str) -> SFG:
code = compile(f.read(), path, 'exec')
exec(code, globals(), locals())
return locals()["prop"]["name"], locals()["positions"] if "positions" in locals() else None
\ No newline at end of file
return locals()["prop"]["name"], locals()["positions"] if "positions" in locals() else {}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment