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 QWidget, QVBoxLayout, QGroupBox, QHBoxLayout, QPushButton, \
22 QApplication, QLabel, QScrollArea, QBoxLayout, QFileDialog, QMessageBox
23 from PyQt5.QtCore
import Qt
24 from visualstates.configs.rospackage
import readWorkspaces
25 from visualstates.configs.rospackage
import writeWorkspaces
32 layout = QVBoxLayout()
33 self.setLayout(layout)
35 scrollArea = QScrollArea()
36 scrollArea.setMinimumHeight(200)
37 scrollArea.setWidgetResizable(
True)
38 scrollArea.setStyleSheet(
'QScrollArea {border: 0;}')
39 layout.addWidget(scrollArea)
41 workspaceBox = QGroupBox(
'Catkin Workspaces')
42 scrollArea.setWidget(workspaceBox)
44 self.workspaceLayout.setDirection(QBoxLayout.TopToBottom)
45 self.workspaceLayout.setAlignment(Qt.AlignTop)
48 buildRowLayout = QHBoxLayout()
49 self.workspaceLayout.addLayout(buildRowLayout)
50 chooseDirButton = QPushButton(
'Choose File')
51 chooseDirButton.setMaximumWidth(100)
52 chooseDirButton.setObjectName(
'choose')
53 chooseDirButton.clicked.connect(self.
chooseDir)
54 buildRowLayout.addWidget(chooseDirButton)
56 self.dirLabel.setMinimumWidth(400)
57 buildRowLayout.addWidget(self.
dirLabel)
59 addButton = QPushButton(
'Add')
60 addButton.setMaximumWidth(100)
61 addButton.setObjectName(
'build')
63 buildRowLayout.addWidget(addButton)
70 selectedDir = QFileDialog.getExistingDirectory(self,
'Choose Catkin Workspace Directory')
71 self.dirLabel.setText(selectedDir)
74 newDir = self.dirLabel.text()
76 QMessageBox.warning(self,
'Invalid Workspace',
'This is not a catkin workspace or specified path was not found')
79 if newDir
in workspaces:
80 QMessageBox.information(self,
'Workspace present',
'The workspace entered is already present in the list')
82 workspaces.append(newDir)
86 QMessageBox.warning(self,
'Invalid Workspace',
'The catkin workspace dir:' + newDir +
87 ' is not a valid. Please make sure that the directory has src, devel and build directories.')
90 files = os.listdir(dir)
91 return '.catkin_workspace' in files
95 rowLayout = QHBoxLayout()
96 uiData[
'layout'] = rowLayout
97 layout.addLayout(rowLayout)
99 label.setStyleSheet(
'QLabel { border: 1px solid black; }')
100 uiData[
'label'] = label
101 removeBtn = QPushButton(
'Remove')
102 removeBtn.setMaximumWidth(80)
103 removeBtn.clicked.connect(removeCallback)
104 removeBtn.setObjectName(dir)
105 uiData[
'btn'] = removeBtn
106 rowLayout.addWidget(label)
107 rowLayout.addWidget(removeBtn)
108 workspaceUIs.append(uiData)
111 dir = self.sender().objectName()
113 workspaces.remove(dir)
120 uiData[
'label'].deleteLater()
121 uiData[
'btn'].deleteLater()
122 uiData[
'layout'].deleteLater()
125 for dir
in workspaces:
129 if __name__ ==
'__main__':
130 app = QApplication(sys.argv)
def drawWorkspaces(self, workspaces)
def removeWorkspace(self)
def addWorkspaceUI(self, layout, dir, workspaceUIs, removeCallback)
def isValidWorkspace(self, dir)
def writeWorkspaces(workspaces)