1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 from PySide import QtGui
34 from PySide import QtCore
35
36 import os
37
38 import node_manager_fkie as nm
39 from detailed_msg_box import WarningMessageBox
40
41
43 '''
44 A dialog to run a ROS node without configuration
45 '''
46
48 QtGui.QDialog.__init__(self, parent)
49 self.host = host
50 self.setWindowTitle('Run')
51 self.verticalLayout = QtGui.QVBoxLayout(self)
52 self.verticalLayout.setObjectName("verticalLayout")
53
54 self.content = QtGui.QWidget()
55 self.contentLayout = QtGui.QFormLayout(self.content)
56 self.contentLayout.setVerticalSpacing(0)
57 self.verticalLayout.addWidget(self.content)
58
59
60 self.root_paths = [os.path.normpath(p) for p in os.getenv("ROS_PACKAGE_PATH").split(':')]
61 self.packages = {}
62 for p in self.root_paths:
63 ret = self._getPackages(p)
64 self.packages = dict(ret.items() + self.packages.items())
65
66 package_label = QtGui.QLabel("Package:", self.content)
67 self.package_field = QtGui.QComboBox(self.content)
68 self.package_field.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
69 self.package_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed))
70 self.package_field.setEditable(True)
71 self.contentLayout.addRow(package_label, self.package_field)
72 binary_label = QtGui.QLabel("Binary:", self.content)
73 self.binary_field = QtGui.QComboBox(self.content)
74
75 self.binary_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed))
76 self.binary_field.setEditable(True)
77 self.contentLayout.addRow(binary_label, self.binary_field)
78 ns_name_label = QtGui.QLabel("NS/Name:", self.content)
79 self.ns_field = QtGui.QComboBox(self.content)
80 self.ns_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed))
81 self.ns_field.setEditable(True)
82 ns_history = nm.history().cachedParamValues('run_dialog/NS')
83 ns_history.insert(0, '/')
84 self.ns_field.addItems(ns_history)
85 self.name_field = QtGui.QLineEdit(self.content)
86 self.name_field.setEnabled(False)
87 horizontalLayout = QtGui.QHBoxLayout()
88 horizontalLayout.addWidget(self.ns_field)
89 horizontalLayout.addWidget(self.name_field)
90 self.contentLayout.addRow(ns_name_label, horizontalLayout)
91 args_label = QtGui.QLabel("Args:", self.content)
92 self.args_field = QtGui.QComboBox(self.content)
93 self.args_field.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength)
94
95 self.args_field.setEditable(True)
96 self.contentLayout.addRow(args_label, self.args_field)
97 args_history = nm.history().cachedParamValues('run_dialog/Args')
98 args_history.insert(0, '')
99 self.args_field.addItems(args_history)
100
101 host_label = QtGui.QLabel("Host:", self.content)
102 self.host_field = QtGui.QComboBox(self.content)
103
104 self.host_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed))
105 self.host_field.setEditable(True)
106 host_label.setBuddy(self.host_field)
107 self.contentLayout.addRow(host_label, self.host_field)
108 self.host_history = host_history = nm.history().cachedParamValues('/Host')
109 if self.host in host_history:
110 host_history.remove(self.host)
111 host_history.insert(0, self.host)
112 self.host_field.addItems(host_history)
113
114 master_label = QtGui.QLabel("ROS Master URI:", self.content)
115 self.master_field = QtGui.QComboBox(self.content)
116 self.master_field.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed))
117 self.master_field.setEditable(True)
118 master_label.setBuddy(self.host_field)
119 self.contentLayout.addRow(master_label, self.master_field)
120 self.master_history = master_history = nm.history().cachedParamValues('/Optional Parameter/ROS Master URI')
121 self.masteruri = "ROS_MASTER_URI"
122 if self.masteruri in master_history:
123 master_history.remove(self.masteruri)
124 master_history.insert(0, self.masteruri)
125 self.master_field.addItems(master_history)
126
127 self.buttonBox = QtGui.QDialogButtonBox(self)
128 self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel)
129 self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
130 self.buttonBox.setObjectName("buttonBox")
131 self.verticalLayout.addWidget(self.buttonBox)
132
133 QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept)
134 QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
135 QtCore.QMetaObject.connectSlotsByName(self)
136 self.package_field.activated[str].connect(self.on_package_selected)
137 self.package_field.textChanged.connect(self.on_package_selected)
138 self.binary_field.activated[str].connect(self.on_binary_selected)
139
140 self.package_field.setFocus(QtCore.Qt.TabFocusReason)
141 self.package = ''
142 self.binary = ''
143
144 packages = self.packages.keys()
145 packages.sort()
146 self.package_field.addItems(packages)
147 if packages:
148 self.on_package_selected(packages[0])
149
151 '''
152 Runs the selected node, or do nothing.
153 '''
154 self.binary = self.binary_field.currentText()
155 self.host = self.host_field.currentText() if self.host_field.currentText() else self.host
156 self.masteruri = self.master_field.currentText() if self.master_field.currentText() else self.masteruri
157 if not self.host in self.host_history and self.host != 'localhost' and self.host != '127.0.0.1':
158 nm.history().add2HostHistory(self.host)
159 ns = self.ns_field.currentText()
160 if ns and ns != '/':
161 nm.history().addParamCache('run_dialog/NS', ns)
162 args = self.args_field.currentText()
163 if args:
164 nm.history().addParamCache('run_dialog/Args', args)
165 if self.package and self.binary:
166 nm.history().addParamCache('/Host', self.host)
167 try:
168 nm.starter().runNodeWithoutConfig(self.host, self.package, self.binary, str(self.name_field.text()), str(''.join(['__ns:=', ns, ' ', args])).split(' '), None if self.masteruri == 'ROS_MASTER_URI' else self.masteruri)
169 except Exception as e:
170 WarningMessageBox(QtGui.QMessageBox.Warning, "Run node",
171 ''.join(['Run node ', str(self.binary), '[', str(self.package), '] failed!']),
172 str(e)).exec_()
173
175 result = {}
176 if os.path.isdir(path):
177 fileList = os.listdir(path)
178 if 'manifest.xml' in fileList:
179 return {os.path.basename(path) : path}
180 for f in fileList:
181 ret = self._getPackages(os.path.sep.join([path, f]))
182 result = dict(ret.items() + result.items())
183 return result
184
186 result = {}
187 if os.path.isdir(path):
188 fileList = os.listdir(path)
189 for f in fileList:
190 if f and f[0] != '.' and not f in ['build'] and not f.endswith('.cfg') and not f.endswith('.so'):
191 ret = self._getBinaries(os.path.sep.join([path, f]))
192 result = dict(ret.items() + result.items())
193 elif os.path.isfile(path) and os.access(path, os.X_OK):
194
195 return {os.path.basename(path) : path}
196 return result
197
199 self.binary_field.clear()
200 if self.packages.has_key(package):
201 self.binary_field.setEnabled(True)
202 self.args_field.setEnabled(True)
203 self.ns_field.setEnabled(True)
204 self.name_field.setEnabled(True)
205 path = self.packages[package]
206 binaries = self._getBinaries(path).keys()
207 binaries.sort()
208 self.binary_field.addItems(binaries)
209 self.package = package
210 root, ext = os.path.splitext(os.path.basename(self.binary_field.currentText()))
211 self.name_field.setText(root)
212
214 root, ext = os.path.splitext(os.path.basename(binary))
215 self.name_field.setText(root)
216