paramedit_widget.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 #
33 # Author: Isaac Saito, Ze'ev Klapow
34 
35 from collections import OrderedDict
36 import os
37 
38 from python_qt_binding import loadUi
39 from python_qt_binding.QtCore import Signal
40 from python_qt_binding.QtWidgets import QVBoxLayout, QWidget, QWidgetItem
41 
42 from rqt_py_common.layout_util import LayoutUtil
43 
44 from . import logging
45 
46 
47 class ParameditWidget(QWidget):
48  """
49  This class represents a pane where parameter editor widgets of multiple
50  nodes are shown. In rqt_reconfigure, this pane occupies right half of the
51  entire visible area.
52  """
53 
54  # public signal
55  sig_node_disabled_selected = Signal(str)
56 
57  def __init__(self, rospack):
58  """"""
59  super(ParameditWidget, self).__init__()
60 
61  ui_file = os.path.join(rospack.get_path('rqt_reconfigure'),
62  'resource', 'paramedit_pane.ui')
63  loadUi(ui_file, self, {'ParameditWidget': ParameditWidget})
64 
65  self._dynreconf_clients = OrderedDict()
66 
67  # Adding the list of Items
68  self.vlayout = QVBoxLayout(self.scrollarea_holder_widget)
69 
70  # causes error
71  # self._set_index_widgets(self.listview, paramitems_dict)
72 
73  self.destroyed.connect(self.close)
74 
75  def _set_index_widgets(self, view, paramitems_dict):
76  """
77  @deprecated: Causes error
78  """
79  i = 0
80  for p in paramitems_dict:
81  view.setIndexWidget(i, p)
82  i += 1
83 
84  def show_reconf(self, dynreconf_widget):
85  """
86  Callback when user chooses a node.
87 
88  @param dynreconf_widget:
89  """
90  node_grn = dynreconf_widget.get_node_grn()
91  logging.debug('ParameditWidget.show str(node_grn)=%s', str(node_grn))
92 
93  if node_grn not in self._dynreconf_clients.keys():
94  # Add dynreconf widget if there isn't already one.
95 
96  # Client gets renewed every time different node_grn was clicked.
97 
98  self._dynreconf_clients.__setitem__(node_grn, dynreconf_widget)
99  self.vlayout.addWidget(dynreconf_widget)
100  dynreconf_widget.sig_node_disabled_selected.connect(
101  self._node_disabled)
102 
103  else: # If there has one already existed, remove it.
104  self._remove_node(node_grn)
105  # LayoutUtil.clear_layout(self.vlayout)
106 
107  # Re-add the rest of existing items to layout.
108  # for k, v in self._dynreconf_clients.items():
109  # logging.info('added to layout k={} v={}'.format(k, v))
110  # self.vlayout.addWidget(v)
111 
112  # Add color to alternate the rim of the widget.
113  LayoutUtil.alternate_color(
114  self._dynreconf_clients.values(),
115  [self.palette().window().color().lighter(125),
116  self.palette().window().color().darker(125)])
117 
118  def close(self):
119  for dc in self._dynreconf_clients:
120  # Clear out the old widget
121  dc.close()
122  dc = None
123 
124  self._paramedit_scrollarea.deleteLater()
125 
126  def filter_param(self, filter_key):
127  """
128  :type filter_key:
129  """
130  # TODO Pick nodes that match filter_key.
131 
132  # TODO For the nodes that are kept in previous step, call
133  # DynreconfWidget.filter_param for all of its existing
134  # instances.
135  pass
136 
137  def _remove_node(self, node_grn):
138  try:
139  i = self._dynreconf_clients.keys().index(node_grn)
140  except ValueError:
141  # ValueError occurring here means that the specified key is not
142  # found, most likely already removed, which is possible in the
143  # following situation/sequence:
144  #
145  # Node widget on ParameditWidget removed by clicking disable button
146  # --> Node deselected on tree widget gets updated
147  # --> Tree widget detects deselection
148  # --> Tree widget emits deselection signal, which is captured by
149  # ParameditWidget's slot. Thus reaches this method again.
150  return
151 
152  item = self.vlayout.itemAt(i)
153  if isinstance(item, QWidgetItem):
154  item.widget().close()
155  w = self._dynreconf_clients.pop(node_grn)
156 
157  logging.debug('popped={} Len of left clients={}'.format(
158  w, len(self._dynreconf_clients)
159  ))
160 
161  def _node_disabled(self, node_grn):
162  logging.debug('paramedit_w _node_disabled grn={}'.format(node_grn))
163 
164  # Signal to notify other GUI components (eg. nodes tree pane) that
165  # a node widget is disabled.
166  self.sig_node_disabled_selected.emit(node_grn)
167 
168  # Remove the selected node widget from the internal list of nodes.
169  self._remove_node(node_grn)
def _set_index_widgets(self, view, paramitems_dict)


rqt_reconfigure
Author(s): Isaac Saito, Ze'ev Klapow
autogenerated on Wed Jul 10 2019 04:02:40