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) 21 from PyQt5.QtWidgets
import QDialog, QFormLayout, QLabel, QLineEdit, QComboBox, \
22 QPushButton, QApplication, QHBoxLayout, QMessageBox
23 from PyQt5.QtCore
import pyqtSignal
24 from visualstates.configs.rosconfig
import RosConfig
25 from visualstates.configs.rospackage
import getAllTypes
30 topicAdded = pyqtSignal()
31 topicUpdated = pyqtSignal(int)
33 def __init__(self, topic=None, config=None, isPublisher=True):
43 titleText +=
'Publisher' 45 titleText +=
'Subscriber' 46 self.setWindowTitle(titleText)
51 layout = QFormLayout()
52 self.setLayout(layout)
57 methodNameLbl = QLabel(
'Method Name')
59 methodNameLbl = QLabel(
'Variable Name')
60 topicLbl = QLabel(
'Topic')
61 typeLbl = QLabel(
'Type')
64 self.methodNameEdit.setMinimumWidth(200)
66 self.topicEdit.setMinimumWidth(200)
68 self.typeCb.setEditable(
True)
69 self.typeCb.setMinimumWidth(200)
73 layout.addRow(typeLbl, self.
typeCb)
75 buttonLayout = QHBoxLayout()
76 cancelBtn = QPushButton(
'Cancel')
78 buttonLayout.addWidget(cancelBtn)
79 saveBtn = QPushButton(
'Add')
81 buttonLayout.addWidget(saveBtn)
82 layout.addRow(
None, buttonLayout)
85 self.typeCb.addItem(type, type)
88 if self.
topic is not None:
89 saveBtn.setText(
'Update')
91 self.methodNameEdit.setText(self.
topic[
'methodname'])
93 self.methodNameEdit.setText(self.
topic[
'variablename'])
94 self.topicEdit.setText(self.
topic[
'name'])
96 selectedTypeIndex = -1
97 for i
in range(self.typeCb.count()):
98 if self.typeCb.itemText(i) == topic[
'type']:
101 if selectedTypeIndex == -1:
102 self.typeCb.addItem(topic[
'type'], topic[
'type'])
103 self.typeCb.setCurrentIndex(self.typeCb.count()-1)
105 self.typeCb.setCurrentIndex(selectedTypeIndex)
112 if self.
topic is None:
115 methodname = self.methodNameEdit.text()
116 name = self.topicEdit.text()
117 type = self.typeCb.currentText()
118 if methodname ==
"" or name ==
"" or type ==
"" :
119 QMessageBox.warning(self,
"Fields empty",
120 "One or more fields are empty and are required")
123 for topic
in self.config.topics:
125 if self.
topic[
'id'] == topic[
'id']:
127 if topic[
'opType'] == RosConfig.PUBLISH:
129 if methodname == topic[
'methodname']:
130 QMessageBox.information(self,
"Method name present",
131 "Method name is already present in the publishers list")
134 if methodname == topic[
'methodname']:
135 QMessageBox.information(self,
"Variable name present",
136 "Variable name is already present in the publishers list as a method name")
140 if methodname == topic[
'variablename']:
141 QMessageBox.information(self,
"Method name present",
142 "Method name is already present in the subscribers list as a variable name")
145 if methodname == topic[
'variablename']:
146 QMessageBox.information(self,
"Variable name present",
147 "Variable name is already present in the subscribers list")
154 self.
topic[
'methodname'] = methodname
155 self.
topic[
'opType'] = RosConfig.PUBLISH
157 self.
topic[
'variablename'] = methodname
158 self.
topic[
'opType'] = RosConfig.SUBSCRIBE
159 self.
topic[
'name'] = name
160 self.
topic[
'type'] = type
163 self.
topic[
'id'] = self.config.getTopicID()
164 self.config.topics.append(self.
topic)
165 self.topicAdded.emit()
167 self.topicUpdated.emit(self.
topic[
'id'])
172 if __name__ ==
'__main__':
173 app = QApplication(sys.argv)
def __init__(self, topic=None, config=None, isPublisher=True)