paramedit_widget.py
Go to the documentation of this file.
1 # Copyright (c) 2012, Willow Garage, Inc.
2 # All rights reserved.
3 #
4 # Software License Agreement (BSD License 2.0)
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 rqt_reconfigure 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._param_client_widgets = 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, param_client_widget):
85  """
86  Callback when user chooses a node.
87 
88  @param param_client_widget:
89  """
90  node_grn = param_client_widget.get_node_grn()
91  logging.debug('ParameditWidget.show'
92  ' str(node_grn)={}'.format(str(node_grn)))
93 
94  if node_grn not in self._param_client_widgets.keys():
95  # Add param widget if there isn't already one.
96 
97  # Client gets renewed every time different node_grn was clicked.
98 
99  self._param_client_widgets.__setitem__(node_grn, param_client_widget)
100  self.vlayout.addWidget(param_client_widget)
101  param_client_widget.sig_node_disabled_selected.connect(
102  self._node_disabled)
103 
104  else: # If there has one already existed, remove it.
105  self._remove_node(node_grn)
106  # LayoutUtil.clear_layout(self.vlayout)
107 
108  # Re-add the rest of existing items to layout.
109  # for k, v in self._param_client_widgets.items():
110  # logging.info('added to layout k={} v={}'.format(k, v))
111  # self.vlayout.addWidget(v)
112 
113  # Add color to alternate the rim of the widget.
114  LayoutUtil.alternate_color(
115  self._param_client_widgets.values(),
116  [self.palette().window().color().lighter(125),
117  self.palette().window().color().darker(125)])
118 
119  def close(self):
120  for dc in self._param_client_widgets:
121  # Clear out the old widget
122  dc.close()
123  dc = None
124 
125  self._paramedit_scrollarea.deleteLater()
126 
127  def get_active_grns(self):
128  return self._param_client_widgets.keys()
129 
130  def filter_param(self, filter_key):
131  """
132  :type filter_key:
133  """
134  # TODO Pick nodes that match filter_key.
135 
136  # TODO For the nodes that are kept in previous step, call
137  # ParamClientWidget.filter_param for all of its existing
138  # instances.
139  pass
140 
141  def _remove_node(self, node_grn):
142  try:
143  i = list(self._param_client_widgets.keys()).index(node_grn)
144  except ValueError:
145  # ValueError occurring here means that the specified key is not
146  # found, most likely already removed, which is possible in the
147  # following situation/sequence:
148  #
149  # Node widget on ParameditWidget removed by clicking disable button
150  # --> Node deselected on tree widget gets updated
151  # --> Tree widget detects deselection
152  # --> Tree widget emits deselection signal, which is captured by
153  # ParameditWidget's slot. Thus reaches this method again.
154  return
155 
156  item = self.vlayout.itemAt(i)
157  if isinstance(item, QWidgetItem):
158  item.widget().close()
159  w = self._param_client_widgets.pop(node_grn)
160 
161  logging.debug('popped={} Len of left clients={}'.format(
162  w, len(self._param_client_widgets)
163  ))
164 
165  def _node_disabled(self, node_grn):
166  logging.debug('paramedit_w _node_disabled grn={}'.format(node_grn))
167 
168  # Signal to notify other GUI components (eg. nodes tree pane) that
169  # a node widget is disabled.
170  self.sig_node_disabled_selected.emit(node_grn)
171 
172  # Remove the selected node widget from the internal list of nodes.
173  self._remove_node(node_grn)
def _set_index_widgets(self, view, paramitems_dict)


rqt_reconfigure
Author(s): Isaac Saito, Ze'ev Klapow
autogenerated on Sat Mar 20 2021 02:51:58