Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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.QtWidgets import QWidget
00039
00040
00041 class LoggerLevelWidget(QWidget):
00042
00043 """
00044 Widget for use with LoggerLevelServiceCaller class to alter the ROS logger levels
00045 """
00046
00047 def __init__(self, caller):
00048 """
00049 :param caller:
00050 service caller instance for sending service calls, ''LoggerLevelServiceCaller''
00051 """
00052 super(LoggerLevelWidget, self).__init__()
00053 rp = rospkg.RosPack()
00054 ui_file = os.path.join(rp.get_path('rqt_logger_level'), 'resource', 'logger_level.ui')
00055 loadUi(ui_file, self)
00056 self.setObjectName('LoggerLevelWidget')
00057 self._caller = caller
00058
00059 self.node_list.currentRowChanged[int].connect(self.node_changed)
00060 self.logger_list.currentRowChanged[int].connect(self.logger_changed)
00061 self.level_list.currentRowChanged[int].connect(self.level_changed)
00062 self.refresh_button.clicked[bool].connect(self.refresh_nodes)
00063
00064 self.refresh_nodes()
00065 if self.node_list.count() > 0:
00066 self.node_list.setCurrentRow(0)
00067
00068 def refresh_nodes(self):
00069 """
00070 Refreshes the top level node list and repoulates the node_list widget.
00071 As a side effect the level and logger lists are cleared
00072 """
00073 self.level_list.clear()
00074 self.logger_list.clear()
00075 self.node_list.clear()
00076 for name in self._caller.get_node_names():
00077 self.node_list.addItem(name)
00078
00079 def node_changed(self, row):
00080 """
00081 Handles the rowchanged event for the node_list widget
00082 Populates logger_list with the loggers for the node selected
00083 :param row: the selected row in node_list, ''int''
00084 """
00085 if row == -1:
00086 return
00087 if row < 0 or row >= self.node_list.count():
00088 qWarning('Node row %s out of bounds. Current count: %s' % (row, self.node_list.count()))
00089 return
00090 self.logger_list.clear()
00091 self.level_list.clear()
00092 loggers = self._caller.get_loggers(self.node_list.item(row).text())
00093 if len(loggers) == 0:
00094 return
00095 for logger in sorted(loggers):
00096 self.logger_list.addItem(logger)
00097 if self.logger_list.count() != 0:
00098 self.logger_list.setCurrentRow(0)
00099
00100 def logger_changed(self, row):
00101 """
00102 Handles the rowchanged event for the logger_list widget
00103 Populates level_list with the levels for the logger selected
00104 :param row: the selected row in logger_list, ''int''
00105 """
00106 if row == -1:
00107 return
00108 if row < 0 or row >= self.logger_list.count():
00109 qWarning('Logger row %s out of bounds. Current count: %s' %
00110 (row, self.logger_list.count()))
00111 return
00112 if self.level_list.count() == 0:
00113 for level in self._caller.get_levels():
00114 self.level_list.addItem(level)
00115 for index in range(self.level_list.count()):
00116 if self.level_list.item(index).text().lower() == \
00117 self._caller._current_levels[self.logger_list.currentItem().text()].lower():
00118 self.level_list.setCurrentRow(index)
00119
00120 def level_changed(self, row):
00121 """
00122 Handles the rowchanged event for the level_list widget
00123 Makes a service call to change the logger level for the indicated node/logger to the
00124 selected value
00125 :param row: the selected row in level_list, ''int''
00126 """
00127 if row == -1:
00128 return
00129 if row < 0 or row >= self.level_list.count():
00130 qWarning('Level row %s out of bounds. Current count: %s' %
00131 (row, self.level_list.count()))
00132 return
00133 self._caller.send_logger_change_message(
00134 self.node_list.currentItem().text(),
00135 self.logger_list.currentItem().text(),
00136 self.level_list.item(row).text())