packagetab.py
Go to the documentation of this file.
1 '''
2  Copyright (C) 1997-2017 JDERobot Developers Team
3 
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.
8 
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.
13 
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/>.
16 
17  Authors : Okan Asik (asik.okan@gmail.com)
18 
19  '''
20 import sys
21 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QGroupBox, QComboBox, QHBoxLayout, QPushButton, \
22  QApplication, QLabel, QScrollArea, QBoxLayout, QMessageBox
23 from PyQt5.QtCore import Qt
24 from visualstates.configs.rospackage import getAllPackages
25 
26 
27 class PackageTab(QWidget):
28  def __init__(self, config):
29  super(QWidget, self).__init__()
30 
31  # the list of packages for build and run dependencies
32  self.buildDependencies = config.getBuildDependencies()
34  self.runDependencies = config.getRunDependencies()
36 
37  layout = QVBoxLayout()
38  self.setLayout(layout)
39 
40  buildDependenciesScroll = QScrollArea()
41  buildDependenciesScroll.setMinimumHeight(200)
42  buildDependenciesScroll.setWidgetResizable(True)
43  buildDependenciesScroll.setStyleSheet('QScrollArea {border: 0;}')
44  layout.addWidget(buildDependenciesScroll)
45 
46  buildDependenciesBox = QGroupBox('Build Dependencies')
47  buildDependenciesScroll.setWidget(buildDependenciesBox)
48  self.buildLayout = QVBoxLayout()
49  self.buildLayout.setDirection(QBoxLayout.TopToBottom)
50  self.buildLayout.setAlignment(Qt.AlignTop)
51  buildDependenciesBox.setLayout(self.buildLayout)
52 
53  buildRowLayout = QHBoxLayout()
54  self.buildLayout.addLayout(buildRowLayout)
55  self.buildDependenciesCb = QComboBox()
56  self.buildDependenciesCb.setEditable(True)
57  buildRowLayout.addWidget(self.buildDependenciesCb)
58  buildAddButton = QPushButton('Add')
59  buildAddButton.setMaximumWidth(80)
60  buildAddButton.setObjectName('build')
61  buildAddButton.clicked.connect(self.addDependency)
62  buildRowLayout.addWidget(buildAddButton)
63 
64  runDependenciesScroll = QScrollArea()
65  runDependenciesScroll.setMinimumHeight(200)
66  runDependenciesScroll.setWidgetResizable(True)
67  runDependenciesScroll.setStyleSheet('QScrollArea { border: 0;}')
68  layout.addWidget(runDependenciesScroll)
69 
70  runDependenciesBox = QGroupBox('Run Dependencies')
71  runDependenciesScroll.setWidget(runDependenciesBox)
72  self.runLayout = QVBoxLayout()
73  self.runLayout.setDirection(QBoxLayout.TopToBottom)
74  self.runLayout.setAlignment(Qt.AlignTop)
75  runDependenciesBox.setLayout(self.runLayout)
76 
77  runRowLayout = QHBoxLayout()
78  self.runLayout.addLayout(runRowLayout)
79  self.runDependenciesCb = QComboBox()
80  self.runDependenciesCb.setEditable(True)
81  runRowLayout.addWidget(self.runDependenciesCb)
82  runAddButton = QPushButton('Add')
83  runAddButton.setMaximumWidth(80)
84  runAddButton.setObjectName('run')
85  runAddButton.clicked.connect(self.addDependency)
86  runRowLayout.addWidget(runAddButton)
87 
88  # fill the packages
89  packages = getAllPackages()
90  packages = sorted(packages)
91  for pkg in packages:
92  self.runDependenciesCb.addItem(pkg)
93  self.buildDependenciesCb.addItem(pkg)
94 
95  self.drawDependenciesUI()
96 
97  def addDependency(self):
98  layout = None
99  dependency = None
100  removeCallback = None
101  dependenciesUI = None
102  if self.sender().objectName() == 'build':
103  layout = self.buildLayout
104  dependency = self.buildDependenciesCb.currentText()
105  if len(dependency) > 0:
106  if dependency in self.buildDependencies:
107  QMessageBox.information(self, "Dependency present",
108  "This dependency is already present in the Build Dependencies list")
109  return
110  removeCallback = self.removeBuildDependency
111  dependenciesUI = self.buildDependenciesUI
112  self.buildDependencies.append(dependency)
113  elif self.sender().objectName() == 'run':
114  layout = self.runLayout
115  dependency = self.runDependenciesCb.currentText()
116  if len(dependency) > 0:
117  if dependency in self.runDependencies:
118  QMessageBox.information(self, "Dependency present",
119  "This dependency is already present in the Run Dependencies list")
120  return
121  removeCallback = self.removeRunDependency
122  dependenciesUI = self.runDependenciesUI
123  self.runDependencies.append(dependency)
124 
125  if dependenciesUI is not None:
126  self.addDependencyUIs(layout, dependency, dependenciesUI, removeCallback)
127 
128  def addDependencyUIs(self, layout, dependency, dependenciesUI, removeCallback):
129  dep = {}
130  rowLayout = QHBoxLayout()
131  dep['layout'] = rowLayout
132  layout.addLayout(rowLayout)
133  label = QLabel(dependency)
134  label.setStyleSheet('QLabel { border: 1px solid black; }')
135  dep['label'] = label
136  removeBtn = QPushButton('Remove')
137  removeBtn.setMaximumWidth(80)
138  removeBtn.clicked.connect(removeCallback)
139  removeBtn.setObjectName(dependency)
140  dep['btn'] = removeBtn
141  rowLayout.addWidget(label)
142  rowLayout.addWidget(removeBtn)
143  dependenciesUI.append(dep)
144 
145  def removeDep(self, dep, dependenciesUI):
146  removeItem = None
147  for runDep in dependenciesUI:
148  if runDep['label'].text() == dep:
149  removeItem = runDep
150  break
151 
152  if removeItem is not None:
153  dependenciesUI.remove(removeItem)
154  removeItem['label'].deleteLater()
155  removeItem['btn'].deleteLater()
156  removeItem['layout'].deleteLater()
157 
159  dep = self.sender().objectName()
160  self.runDependencies.remove(dep)
161  self.removeDep(dep, self.runDependenciesUI)
162 
164  dep = self.sender().objectName()
165  self.buildDependencies.remove(dep)
166  self.removeDep(dep, self.buildDependenciesUI)
167 
169  # remove previous UIs if exists
170  for depUI in self.runDependenciesUI:
171  depUI['label'].deleteLater()
172  depUI['btn'].deleteLater()
173  depUI['layout'].deleteLater()
174 
175  for depUI in self.buildDependenciesUI:
176  depUI['label'].deleteLater()
177  depUI['btn'].deleteLater()
178  depUI['layout'].deleteLater()
179 
180  # add dependency for given
181  for dep in self.runDependencies:
183 
184  for dep in self.buildDependencies:
186 
187 
188 if __name__ == '__main__':
189  app = QApplication(sys.argv)
190  widget = PackageTab()
191  widget.show()
192  app.exec_()
193 
def removeDep(self, dep, dependenciesUI)
Definition: packagetab.py:145
def addDependencyUIs(self, layout, dependency, dependenciesUI, removeCallback)
Definition: packagetab.py:128


visualstates
Author(s):
autogenerated on Thu Apr 1 2021 02:42:20