logger_level_widget.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 import os
00034 import rospkg
00035 
00036 from python_qt_binding import loadUi
00037 from python_qt_binding.QtCore import qWarning
00038 from python_qt_binding.QtGui import QWidget
00039 
00040 
00041 class LoggerLevelWidget(QWidget):
00042     """
00043     Widget for use with LoggerLevelServiceCaller class to alter the ROS logger levels
00044     """
00045     def __init__(self, caller):
00046         """
00047         :param caller: service caller instance for sending service calls, ''LoggerLevelServiceCaller''
00048         """
00049         super(LoggerLevelWidget, self).__init__()
00050         rp = rospkg.RosPack()
00051         ui_file = os.path.join(rp.get_path('rqt_logger_level'), 'resource', 'logger_level.ui')
00052         loadUi(ui_file, self)
00053         self.setObjectName('LoggerLevelWidget')
00054         self._caller = caller
00055 
00056         self.node_list.currentRowChanged[int].connect(self.node_changed)
00057         self.logger_list.currentRowChanged[int].connect(self.logger_changed)
00058         self.level_list.currentRowChanged[int].connect(self.level_changed)
00059         self.refresh_button.clicked[bool].connect(self.refresh_nodes)
00060 
00061         self.refresh_nodes()
00062         if self.node_list.count() > 0:
00063             self.node_list.setCurrentRow(0)
00064 
00065     def refresh_nodes(self):
00066         """
00067         Refreshes the top level node list and repoulates the node_list widget.
00068         As a side effect the level and logger lists are cleared
00069         """
00070         self.level_list.clear()
00071         self.logger_list.clear()
00072         self.node_list.clear()
00073         for name in self._caller.get_node_names():
00074             self.node_list.addItem(name)
00075 
00076     def node_changed(self, row):
00077         """
00078         Handles the rowchanged event for the node_list widget
00079         Populates logger_list with the loggers for the node selected
00080         :param row: the selected row in node_list, ''int''
00081         """
00082         if row == -1:
00083             return
00084         if row < 0 or row >= self.node_list.count():
00085             qWarning('Node row %s out of bounds. Current count: %s' % (row, self.node_list.count()))
00086             return
00087         self.logger_list.clear()
00088         self.level_list.clear()
00089         loggers = self._caller.get_loggers(self.node_list.item(row).text())
00090         if len(loggers) == 0:
00091             return
00092         for logger in sorted(loggers):
00093             self.logger_list.addItem(logger)
00094         if self.logger_list.count() != 0:
00095             self.logger_list.setCurrentRow(0)
00096 
00097     def logger_changed(self, row):
00098         """
00099         Handles the rowchanged event for the logger_list widget
00100         Populates level_list with the levels for the logger selected
00101         :param row: the selected row in logger_list, ''int''
00102         """
00103         if row == -1:
00104             return
00105         if row < 0 or row >= self.logger_list.count():
00106             qWarning('Logger row %s out of bounds. Current count: %s' % (row, self.logger_list.count()))
00107             return
00108         if self.level_list.count() == 0:
00109             for level in self._caller.get_levels():
00110                 self.level_list.addItem(level)
00111         for index in range(self.level_list.count()):
00112             if self.level_list.item(index).text().lower() == self._caller._current_levels[self.logger_list.currentItem().text()].lower():
00113                 self.level_list.setCurrentRow(index)
00114 
00115     def level_changed(self, row):
00116         """
00117         Handles the rowchanged event for the level_list widget
00118         Makes a service call to change the logger level for the indicated node/logger to the selected value
00119         :param row: the selected row in level_list, ''int''
00120         """
00121         if row == -1:
00122             return
00123         if row < 0 or row >= self.level_list.count():
00124             qWarning('Level row %s out of bounds. Current count: %s' % (row, self.level_list.count()))
00125             return
00126         self._caller.send_logger_change_message(self.node_list.currentItem().text(), self.logger_list.currentItem().text(), self.level_list.item(row).text())


rqt_logger_level
Author(s): Aaron Blasdel
autogenerated on Wed Sep 16 2015 06:57:55