2 Copyright (C) 1997-2017 JDERobot Developers Team 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Library General Public License for more details. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. 17 Authors : Okan Asik (asik.okan@gmail.com) 22 from PyQt5.Qsci
import QsciScintilla, QsciLexerPython, QsciLexerCPP
23 from PyQt5.QtCore
import pyqtSignal
24 from PyQt5.QtGui
import QFontDatabase, QFontMetrics, QColor
25 from PyQt5.QtWidgets
import QDialog, QTextEdit, QPushButton, QVBoxLayout, QWidget, QHBoxLayout, QApplication, \
26 QRadioButton, QGroupBox, QMessageBox
28 from visualstates.gui.transition.transitiontype
import TransitionType
32 codeChanged = pyqtSignal(
'int',
'QString',
'QString')
37 self.setWindowTitle(name)
41 self.codeEdit.setText(self.transition.getCode())
42 fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
43 self.codeEdit.setFont(fixedWidthFont)
44 fontmetrics = QFontMetrics(fixedWidthFont)
45 self.codeEdit.setMarginWidth(0, fontmetrics.width(
"000"))
46 self.codeEdit.setMarginLineNumbers(0,
True)
47 self.codeEdit.setMarginsBackgroundColor(QColor(
"#cccccc"))
49 self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
50 self.codeEdit.setCaretLineVisible(
True)
51 self.codeEdit.setCaretLineBackgroundColor(QColor(
"#ffe4e4"))
52 lexer = QsciLexerPython()
53 lexer.setDefaultFont(fixedWidthFont)
54 self.codeEdit.setLexer(lexer)
55 self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
56 self.codeEdit.setUtf8(
True)
58 self.codeEdit.setTabWidth(4)
59 self.codeEdit.setIndentationsUseTabs(
True)
60 self.codeEdit.setIndentationGuides(
True)
61 self.codeEdit.setTabIndents(
True)
62 self.codeEdit.setAutoIndent(
True)
65 self.cancelButton.clicked.connect(self.
cancel)
67 self.acceptButton.clicked.connect(self.
accept)
71 self.pythonButton.setChecked(
True)
74 self.cppButton.clicked.connect(self.
cppClicked)
76 codeLanguageContainer = QWidget()
77 hLayout0 = QHBoxLayout()
80 codeLanguageContainer.setLayout(hLayout0)
87 radioButtonContainer = QGroupBox()
88 radioButtonContainer.setTitle(
'Transition Type')
89 vLayout = QVBoxLayout()
92 radioButtonContainer.setLayout(vLayout)
95 self.transitionTypeCode.setFont(fixedWidthFont)
97 self.transitionGroupBox.setTitle(
'Temporal (number in ms)')
98 h3Layout = QHBoxLayout()
100 self.transitionGroupBox.setLayout(h3Layout)
102 typeContainer = QWidget()
103 h2Layout = QHBoxLayout()
104 h2Layout.addWidget(radioButtonContainer)
106 typeContainer.setLayout(h2Layout)
108 verticalLayout = QVBoxLayout()
109 verticalLayout.addWidget(typeContainer)
110 verticalLayout.addWidget(codeLanguageContainer)
111 verticalLayout.addWidget(self.
codeEdit)
113 container = QWidget()
114 hLayout =QHBoxLayout()
117 container.setLayout(hLayout)
119 verticalLayout.addWidget(container)
120 self.setLayout(verticalLayout)
122 if self.transition.getType() == TransitionType.CONDITIONAL:
123 self.conditionalButton.setChecked(
True)
125 elif self.transition.getType() == TransitionType.TEMPORAL:
126 self.temporalButton.setChecked(
True)
136 if self.temporalButton.isChecked():
137 if not self.transitionTypeCode.toPlainText().isdigit():
138 QMessageBox.warning(self,
'Input Error',
'Please input an integer in the Temporal box')
140 type = int(TransitionType.TEMPORAL)
141 typeValue = self.transitionTypeCode.toPlainText()
142 elif self.conditionalButton.isChecked():
143 type = int(TransitionType.CONDITIONAL)
144 typeValue = self.transitionTypeCode.toPlainText()
146 self.codeChanged.emit(type, typeValue, self.codeEdit.text())
150 if (self.temporalButton.isChecked()):
151 self.transitionGroupBox.setTitle(
'Temporal (number in ms)')
152 self.transitionTypeCode.setPlainText(str(self.transition.getTemporalTime()))
156 if (self.conditionalButton.isChecked()):
157 self.transitionGroupBox.setTitle(
'Condition (evaluates to true or false)')
158 self.transitionTypeCode.setPlainText(self.transition.getCondition())
162 fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
163 lexer = QsciLexerPython()
164 lexer.setDefaultFont(fixedWidthFont)
165 self.codeEdit.setLexer(lexer)
169 fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont)
170 lexer = QsciLexerCPP()
171 lexer.setDefaultFont(fixedWidthFont)
172 self.codeEdit.setLexer(lexer)
175 if __name__ ==
'__main__':
176 app = QApplication(sys.argv)
def __init__(self, name, transition)
def temporalToggled(self)
def conditionalToggled(self)