From 9aa4a224236477875e501e15549fc2df1a6bb345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Okan=20A=C5=9F=C4=B1k?= Date: Fri, 4 Oct 2019 19:58:52 +0300 Subject: [PATCH] accept and cancel buttons are removed from code dialogs. changes are directly set to the data model --- src/visualstates/gui/state/codedialog.py | 20 +------- .../gui/transition/transitioncodedialog.py | 48 ++++++++----------- 2 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/visualstates/gui/state/codedialog.py b/src/visualstates/gui/state/codedialog.py index 791ea87d..8d011f89 100644 --- a/src/visualstates/gui/state/codedialog.py +++ b/src/visualstates/gui/state/codedialog.py @@ -54,11 +54,7 @@ def __init__(self, name, currentValue): self.codeEdit.setIndentationGuides(True) self.codeEdit.setTabIndents(True) self.codeEdit.setAutoIndent(True) - - self.cancelButton = QPushButton('Cancel') - self.cancelButton.clicked.connect(self.cancel) - self.acceptButton = QPushButton('Accept') - self.acceptButton.clicked.connect(self.accept) + self.codeEdit.textChanged.connect(self.codeChangedListener) self.pythonButton = QRadioButton('Python') self.pythonButton.setChecked(True) @@ -75,24 +71,12 @@ def __init__(self, name, currentValue): verticalLayout = QVBoxLayout() verticalLayout.addWidget(container0) verticalLayout.addWidget(self.codeEdit) - - container = QWidget() - hLayout =QHBoxLayout() - hLayout.addWidget(self.cancelButton) - hLayout.addWidget(self.acceptButton) - container.setLayout(hLayout) - - verticalLayout.addWidget(container) self.setLayout(verticalLayout) self.language = 'python' - def cancel(self): - self.close() - - def accept(self): + def codeChangedListener(self): self.codeChanged.emit(self.codeEdit.text()) - self.close() def pythonClicked(self): fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) diff --git a/src/visualstates/gui/transition/transitioncodedialog.py b/src/visualstates/gui/transition/transitioncodedialog.py index dbb53e4f..9c83785a 100644 --- a/src/visualstates/gui/transition/transitioncodedialog.py +++ b/src/visualstates/gui/transition/transitioncodedialog.py @@ -60,11 +60,7 @@ def __init__(self, name, transition): self.codeEdit.setIndentationGuides(True) self.codeEdit.setTabIndents(True) self.codeEdit.setAutoIndent(True) - - self.cancelButton = QPushButton('Cancel') - self.cancelButton.clicked.connect(self.cancel) - self.acceptButton = QPushButton('Accept') - self.acceptButton.clicked.connect(self.accept) + self.codeEdit.textChanged.connect(self.codeChangedListener) self.language = 'python' self.pythonButton = QRadioButton('Python') @@ -93,6 +89,8 @@ def __init__(self, name, transition): self.transitionTypeCode = QTextEdit() self.transitionTypeCode.setFont(fixedWidthFont) + self.transitionTypeCode.textChanged.connect(self.transitionTypeCodeChanged) + self.transitionGroupBox = QGroupBox() self.transitionGroupBox.setTitle('Temporal (number in ms)') h3Layout = QHBoxLayout() @@ -109,14 +107,6 @@ def __init__(self, name, transition): verticalLayout.addWidget(typeContainer) verticalLayout.addWidget(codeLanguageContainer) verticalLayout.addWidget(self.codeEdit) - - container = QWidget() - hLayout =QHBoxLayout() - hLayout.addWidget(self.cancelButton) - hLayout.addWidget(self.acceptButton) - container.setLayout(hLayout) - - verticalLayout.addWidget(container) self.setLayout(verticalLayout) if self.transition.getType() == TransitionType.CONDITIONAL: @@ -126,37 +116,37 @@ def __init__(self, name, transition): self.temporalButton.setChecked(True) self.temporalToggled() - def cancel(self): - self.close() + def codeChangedListener(self): + transitionType = TransitionType.CONDITIONAL + if self.temporalButton.isChecked(): + transitionType = TransitionType.TEMPORAL - def accept(self): - type = None - typeValue = None + self.codeChanged.emit(transitionType, self.transitionTypeCode.toPlainText(), self.codeEdit.text()) + def transitionTypeCodeChanged(self): + # validate the input + typeCode = self.transitionTypeCode.toPlainText() + transitionType = TransitionType.CONDITIONAL if self.temporalButton.isChecked(): - if not self.transitionTypeCode.toPlainText().isdigit(): + transitionType = TransitionType.TEMPORAL + if typeCode and not typeCode.isdigit(): QMessageBox.warning(self, 'Input Error', 'Please input an integer in the Temporal box') return - type = int(TransitionType.TEMPORAL) - typeValue = self.transitionTypeCode.toPlainText() - elif self.conditionalButton.isChecked(): - type = int(TransitionType.CONDITIONAL) - typeValue = self.transitionTypeCode.toPlainText() - - self.codeChanged.emit(type, typeValue, self.codeEdit.text()) - self.close() + if not typeCode: + typeCode = '0' + self.codeChanged.emit(transitionType, typeCode, self.codeEdit.text()) def temporalToggled(self): if (self.temporalButton.isChecked()): self.transitionGroupBox.setTitle('Temporal (number in ms)') self.transitionTypeCode.setPlainText(str(self.transition.getTemporalTime())) - # print('temporal toggled') + self.codeChanged.emit(TransitionType.TEMPORAL, self.transitionTypeCode.toPlainText(), self.codeEdit.text()) def conditionalToggled(self): if (self.conditionalButton.isChecked()): self.transitionGroupBox.setTitle('Condition (evaluates to true or false)') self.transitionTypeCode.setPlainText(self.transition.getCondition()) - # print('conditional toggled') + self.codeChanged.emit(TransitionType.CONDITIONAL, self.transitionTypeCode.toPlainText(), self.codeEdit.text()) def pythonClicked(self): fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)