Skip to content

Commit

Permalink
Correctly handle multiple includes of the same launch file
Browse files Browse the repository at this point in the history
  • Loading branch information
pschillinger committed Apr 23, 2016
1 parent da501de commit 9cdcd1e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion resource/launchtree_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<item>
<widget class="QStackedWidget" name="main_view">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down
6 changes: 5 additions & 1 deletion src/rqt_launchtree/launchtree_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def __init__(self):

self._tree_stack = list()
self.tree = dict()
self.idx = 0

def push_level(self, tree_level):
def push_level(self, tree_level, unique=False):
if unique:
tree_level += ':%d' % self.idx
self.idx += 1
self._tree_stack.append(tree_level)

def pop_level(self):
Expand Down
2 changes: 1 addition & 1 deletion src/rqt_launchtree/launchtree_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LaunchtreeLoader(XmlLoader):

def _include_tag(self, tag, context, ros_config, default_machine, is_core, verbose):
inc_filename = self.resolve_args(tag.attributes['file'].value, context)
ros_config.push_level(inc_filename)
ros_config.push_level(inc_filename, unique=True)
result = super(LaunchtreeLoader, self)._include_tag(tag, context, ros_config, default_machine, is_core, verbose)
ros_config.pop_level()
return result
Expand Down
19 changes: 3 additions & 16 deletions src/rqt_launchtree/launchtree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _load_launch_items(self, filename, launchargs):
loader = LaunchtreeLoader()
loader.load(filename, self._launch_config, verbose=False, argv=['','',''] + launchargs)
items = self.display_config_tree(self._launch_config.tree)
except roslaunch.xmlloader.XmlParseException as e:
except Exception as e:
error_msg = re.sub(r'(\[?(?:/\w+)+\.launch\]?)',
lambda m: '[%s]'%self._filename_to_label(m.group(0)),
str(e)
Expand All @@ -140,7 +140,7 @@ def display_config_tree(self, config_tree):
i.addChildren(childItems)
i.instance = instance.get('_root', instance)
if isinstance(i.instance, dict):
i.setText(0, self._filename_to_label(key))
i.setText(0, self._filename_to_label(key.split(':')[0]))
i.setIcon(0, self._icon_include if not i.inconsistent else self._icon_warn)
else:
i.setText(0, key)
Expand Down Expand Up @@ -209,20 +209,7 @@ def launch_entry_changed(self, current, previous):
#clear properties
if current is None:
return
# traverse displayed tree up
tree_path = list()
item = current
while item is not None:
key = item.text(0)
if self._launch_separator in key:
(p, l) = key.split(self._launch_separator)
key = os.path.join(self._rp.get_path(p), l)
item = item.parent()
tree_path.append(key)
# traverse model tree down
data = self._launch_config.tree
for key in reversed(tree_path):
data = data[key]
data = current.instance
if isinstance(data, dict) and data.has_key('_root'):
data = data['_root']
if isinstance(data, roslaunch.core.Param):
Expand Down

0 comments on commit 9cdcd1e

Please sign in to comment.