Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Remove Accept and Cancel buttons from code dialogs #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/visualstates/gui/state/codedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
48 changes: 19 additions & 29 deletions src/visualstates/gui/transition/transitioncodedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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)
Expand Down