logger_level_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 import os
34 import rospkg
35 
36 from python_qt_binding import loadUi
37 from python_qt_binding.QtCore import qWarning
38 from python_qt_binding.QtWidgets import QWidget
39 
40 
41 class LoggerLevelWidget(QWidget):
42 
43  """
44  Widget for use with LoggerLevelServiceCaller class to alter the ROS logger levels
45  """
46 
47  def __init__(self, caller):
48  """
49  :param caller:
50  service caller instance for sending service calls, ''LoggerLevelServiceCaller''
51  """
52  super(LoggerLevelWidget, self).__init__()
53  rp = rospkg.RosPack()
54  ui_file = os.path.join(rp.get_path('rqt_logger_level'), 'resource', 'logger_level.ui')
55  loadUi(ui_file, self)
56  self.setObjectName('LoggerLevelWidget')
57  self._caller = caller
58 
59  self.node_list.currentRowChanged[int].connect(self.node_changed)
60  self.logger_list.currentRowChanged[int].connect(self.logger_changed)
61  self.level_list.currentRowChanged[int].connect(self.level_changed)
62  self.refresh_button.clicked[bool].connect(self.refresh_nodes)
63 
64  self.refresh_nodes()
65  if self.node_list.count() > 0:
66  self.node_list.setCurrentRow(0)
67 
68  def refresh_nodes(self):
69  """
70  Refreshes the top level node list and repoulates the node_list widget.
71  As a side effect the level and logger lists are cleared
72  """
73  self.level_list.clear()
74  self.logger_list.clear()
75  self.node_list.clear()
76  for name in self._caller.get_node_names():
77  self.node_list.addItem(name)
78 
79  def node_changed(self, row):
80  """
81  Handles the rowchanged event for the node_list widget
82  Populates logger_list with the loggers for the node selected
83  :param row: the selected row in node_list, ''int''
84  """
85  if row == -1:
86  return
87  if row < 0 or row >= self.node_list.count():
88  qWarning('Node row %s out of bounds. Current count: %s' % (row, self.node_list.count()))
89  return
90  self.logger_list.clear()
91  self.level_list.clear()
92  loggers = self._caller.get_loggers(self.node_list.item(row).text())
93  if len(loggers) == 0:
94  return
95  for logger in sorted(loggers):
96  self.logger_list.addItem(logger)
97  if self.logger_list.count() != 0:
98  self.logger_list.setCurrentRow(0)
99 
100  def logger_changed(self, row):
101  """
102  Handles the rowchanged event for the logger_list widget
103  Populates level_list with the levels for the logger selected
104  :param row: the selected row in logger_list, ''int''
105  """
106  if row == -1:
107  return
108  if row < 0 or row >= self.logger_list.count():
109  qWarning('Logger row %s out of bounds. Current count: %s' %
110  (row, self.logger_list.count()))
111  return
112  if self.level_list.count() == 0:
113  for level in self._caller.get_levels():
114  self.level_list.addItem(level)
115  for index in range(self.level_list.count()):
116  if self.level_list.item(index).text().lower() == \
117  self._caller._current_levels[self.logger_list.currentItem().text()].lower():
118  self.level_list.setCurrentRow(index)
119 
120  def level_changed(self, row):
121  """
122  Handles the rowchanged event for the level_list widget
123  Makes a service call to change the logger level for the indicated node/logger to the
124  selected value
125  :param row: the selected row in level_list, ''int''
126  """
127  if row == -1:
128  return
129  if row < 0 or row >= self.level_list.count():
130  qWarning('Level row %s out of bounds. Current count: %s' %
131  (row, self.level_list.count()))
132  return
133  self._caller.send_logger_change_message(
134  self.node_list.currentItem().text(),
135  self.logger_list.currentItem().text(),
136  self.level_list.item(row).text())


rqt_logger_level
Author(s): Aaron Blasdel
autogenerated on Sun May 24 2020 03:49:54