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) 20 from PyQt5.QtWidgets
import QWidget, QPushButton, \
21 QVBoxLayout, QHBoxLayout, QLabel, \
22 QGroupBox, QScrollArea, QBoxLayout
23 from PyQt5.QtCore
import Qt
24 from visualstates.configs.rosconfig
import RosConfig
25 from visualstates.gui.dialogs.pubsubdialog
import PubSubDialog
36 layout = QVBoxLayout()
37 self.setLayout(layout)
39 publishersBox = QGroupBox(
'Publishers')
40 pubVLayout = QVBoxLayout()
41 publishersBox.setLayout(pubVLayout)
42 layout.addWidget(publishersBox)
44 addPublisherBtn = QPushButton(
'Add Publisher')
45 addPublisherBtn.setMaximumWidth(200)
47 pubVLayout.addWidget(addPublisherBtn)
49 pubRowLayout = QHBoxLayout()
50 pubVLayout.addLayout(pubRowLayout)
53 pubRowLayout.addSpacing(10)
54 titleLblStyleSheet =
'QLabel { font-weight: bold;}' 55 methodLbl = QLabel(
'Method Name')
56 methodLbl.setStyleSheet(titleLblStyleSheet)
57 methodLbl.setMinimumWidth(200)
58 pubRowLayout.addWidget(methodLbl)
59 topicLbl = QLabel(
'Topic')
60 topicLbl.setStyleSheet(titleLblStyleSheet)
61 topicLbl.setMinimumWidth(200)
62 pubRowLayout.addWidget(topicLbl)
63 typeLbl = QLabel(
'Type')
64 typeLbl.setStyleSheet(titleLblStyleSheet)
65 typeLbl.setMinimumWidth(200)
66 pubRowLayout.addWidget(typeLbl)
67 actionLbl = QLabel(
'Actions')
68 actionLbl.setStyleSheet(titleLblStyleSheet)
69 actionLbl.setMaximumWidth(200)
70 actionLbl.setMinimumWidth(200)
71 pubRowLayout.addWidget(actionLbl)
72 pubRowLayout.addSpacing(10)
74 pubScrollArea = QScrollArea()
75 pubScrollArea.setWidgetResizable(
True)
77 pubScrollArea.setStyleSheet(
'QScrollArea {border: 0px;}')
79 self.pubScrollVlayout.setDirection(QBoxLayout.TopToBottom)
80 self.pubScrollVlayout.setAlignment(Qt.AlignTop)
81 dummyBox = QGroupBox()
82 dummyBox.setStyleSheet(
'QGroupBox {padding: 0px; margin: 0px;}')
84 pubScrollArea.setWidget(dummyBox)
85 pubVLayout.addWidget(pubScrollArea)
87 subscribersBox = QGroupBox(
'Subscribers')
88 subsVLayout = QVBoxLayout()
89 subscribersBox.setLayout(subsVLayout)
90 layout.addWidget(subscribersBox)
92 addSubscriberBtn = QPushButton(
'Add Subscriber')
93 addSubscriberBtn.setMaximumWidth(200)
95 subsVLayout.addWidget(addSubscriberBtn)
97 subsRowLayout = QHBoxLayout()
98 subsVLayout.addLayout(subsRowLayout)
101 subsRowLayout.addSpacing(10)
102 titleLblStyleSheet =
'QLabel {font-weight: bold;}' 103 varLbl = QLabel(
'Variable Name')
104 varLbl.setStyleSheet(titleLblStyleSheet)
105 varLbl.setMinimumWidth(200)
106 subsRowLayout.addWidget(varLbl)
107 topicLbl = QLabel(
'Topic')
108 topicLbl.setStyleSheet(titleLblStyleSheet)
109 topicLbl.setMinimumWidth(200)
110 subsRowLayout.addWidget(topicLbl)
111 typeLbl = QLabel(
'Type')
112 typeLbl.setStyleSheet(titleLblStyleSheet)
113 typeLbl.setMinimumWidth(200)
114 subsRowLayout.addWidget(typeLbl)
115 actionLbl = QLabel(
'Actions')
116 actionLbl.setStyleSheet(titleLblStyleSheet)
117 actionLbl.setMaximumWidth(200)
118 actionLbl.setMinimumWidth(200)
119 subsRowLayout.addWidget(actionLbl)
120 subsRowLayout.addSpacing(10)
122 subsScrollArea = QScrollArea()
123 subsScrollArea.setWidgetResizable(
True)
125 subsScrollArea.setStyleSheet(
'QScrollArea {border: 0px;}')
127 self.subsScrollVlayout.setDirection(QBoxLayout.TopToBottom)
128 self.subsScrollVlayout.setAlignment(Qt.AlignTop)
129 dummyBox = QGroupBox()
130 dummyBox.setStyleSheet(
'QGroupBox {padding: 0px; margin: 0px;}')
132 subsScrollArea.setWidget(dummyBox)
133 subsVLayout.addWidget(subsScrollArea)
136 for topic
in self.config.topics:
140 dialog = PubSubDialog(config=self.
config, isPublisher=
True)
145 dialog = PubSubDialog(config=self.
config, isPublisher=
False)
150 rowLayout = QHBoxLayout()
151 topicStyle =
'QLabel {border: 1px solid black;}' 153 nameLbl.setStyleSheet(topicStyle)
154 nameLbl.setMinimumWidth(200)
155 rowLayout.addWidget(nameLbl)
156 topicLbl = QLabel(topic[
'name'])
157 topicLbl.setStyleSheet(topicStyle)
158 topicLbl.setMinimumWidth(200)
159 rowLayout.addWidget(topicLbl)
160 typeLbl = QLabel(topic[
'type'])
161 typeLbl.setStyleSheet(topicStyle)
162 typeLbl.setMinimumWidth(200)
163 rowLayout.addWidget(typeLbl)
165 editBtn = QPushButton(
'Edit')
166 editBtn.setMinimumWidth(96)
167 editBtn.setMaximumWidth(96)
168 editBtn.setObjectName(str(topic[
'id']))
170 rowLayout.addWidget(editBtn)
171 removeBtn = QPushButton(
'Remove')
172 removeBtn.setMinimumWidth(96)
173 removeBtn.setMaximumWidth(96)
174 removeBtn.setObjectName(str(topic[
'id']))
176 rowLayout.addWidget(removeBtn)
177 UIs = [nameLbl, topicLbl, typeLbl, editBtn, removeBtn, rowLayout]
179 if topic[
'opType'] == RosConfig.PUBLISH:
180 nameLbl.setText(topic[
'methodname'])
181 self.pubScrollVlayout.addLayout(rowLayout)
182 elif topic[
'opType'] == RosConfig.SUBSCRIBE:
183 nameLbl.setText(topic[
'variablename'])
184 self.subsScrollVlayout.addLayout(rowLayout)
187 addedTopic = self.config.topics[len(self.config.topics)-1]
191 editID = int(self.sender().objectName())
194 for topic
in self.config.topics:
195 if topic[
'id'] == editID:
198 if editTopic
is not None:
199 if editTopic[
'opType'] == RosConfig.PUBLISH:
200 dialog = PubSubDialog(topic=editTopic, config=self.
config, isPublisher=
True)
201 elif editTopic[
'opType'] == RosConfig.SUBSCRIBE:
202 dialog = PubSubDialog(topic=editTopic, config=self.
config, isPublisher=
False)
208 for topic
in self.config.topics:
209 if topic[
'id'] == updatedID:
213 if updatedTopic
is not None:
215 if updatedTopic[
'opType'] == RosConfig.PUBLISH:
216 UIs[0].setText(updatedTopic[
'methodname'])
217 elif updatedTopic[
'opType'] == RosConfig.SUBSCRIBE:
218 UIs[0].setText(updatedTopic[
'variablename'])
220 UIs[1].setText(updatedTopic[
'name'])
221 UIs[2].setText(updatedTopic[
'type'])
224 removeID = int(self.sender().objectName())
226 for topic
in self.config.topics:
227 if topic[
'id'] == removeID:
230 if removeItem
is not None:
231 self.config.topics.remove(removeItem)
def __init__(self, config)
def topicAddedHandler(self)
def addTopic(self, topic)
def topicUpdatedHandler(self, updatedID)