console_dash_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 from rosgraph_msgs.msg import Log
34 import rospkg
35 import rospy
36 from python_qt_binding.QtCore import QMutex, QMutexLocker, QSize, QTimer
37 
38 from rqt_console.console import Console
39 from rqt_console.console_widget import ConsoleWidget
40 from rqt_console.message_data_model import MessageDataModel
41 from rqt_console.message_proxy_model import MessageProxyModel
42 
43 from .icon_tool_button import IconToolButton
44 
45 
47  """
48  A widget which brings up the ROS console.
49 
50  :param context: The plugin context to create the monitor in.
51  :type context: qt_gui.plugin_context.PluginContext
52  """
53  def __init__(self, context, icon_paths=None, minimal=True):
54  ok_icon = ['bg-green.svg', 'ic-console.svg']
55  warn_icon = ['bg-yellow.svg', 'ic-console.svg', 'ol-warn-badge.svg']
56  err_icon = ['bg-red.svg', 'ic-console.svg', 'ol-err-badge.svg']
57  stale_icon = ['bg-grey.svg', 'ic-console.svg', 'ol-stale-badge.svg']
58 
59  icons = [ok_icon, warn_icon, err_icon, stale_icon]
60 
61  super(ConsoleDashWidget, self).__init__('Console Widget', icons, icon_paths=icon_paths)
62 
63  self.minimal = minimal
64  self.setFixedSize(self._icons[0].actualSize(QSize(50, 30)))
65 
68  self._proxymodel.setSourceModel(self._datamodel)
69 
70  self._console = None
71  self._rospack = rospkg.RosPack()
72  if self._console is None:
73  self._console = ConsoleWidget(self._proxymodel, self._rospack, minimal=self.minimal)
74  self._console.destroyed.connect(self._console_destroyed)
75 
76  self._message_queue = []
77  self._mutex = QMutex()
78  self._subscriber = rospy.Subscriber('/rosout_agg', Log, self._message_cb)
79 
80  self.context = context
81  self.clicked.connect(self._show_console)
82 
83  self.update_state(0)
84  self._timer = QTimer()
85  self._timer.timeout.connect(self._insert_messages)
86  self._timer.start(100)
87 
88  self._console_shown = False
89  self.setToolTip("Rosout")
90 
91  def _show_console(self):
92  if self._console is None:
93  self._console = ConsoleWidget(self._proxymodel, self._rospack, minimal=self.minimal)
94  self._console.destroyed.connect(self._console_destroyed)
95  try:
96  if self._console_shown:
97  self.context.remove_widget(self._console)
98  self._console_shown = not self._console_shown
99  else:
100  self.context.add_widget(self._console)
101  self._console_shown = not self._console_shown
102  except Exception:
103  self._console_shown = not self._console_shown
104  self._show_console()
105 
106  def _insert_messages(self):
107  with QMutexLocker(self._mutex):
108  msgs = self._message_queue
109  self._message_queue = []
110  if msgs:
111  self._datamodel.insert_rows(msgs)
112 
113  # The console may not yet be initialized or may have been closed
114  # So fail silently
115  try:
116  self.update_rosout()
117  except:
118  pass
119 
120  def _message_cb(self, log_msg):
121  if not self._console._paused:
122  msg = Console.convert_rosgraph_log_message(log_msg)
123  with QMutexLocker(self._mutex):
124  self._message_queue.append(msg)
125 
126  def update_rosout(self):
127  summary_dur = 30.0
128  if (rospy.get_time() < 30.0):
129  summary_dur = rospy.get_time() - 1.0
130 
131  if (summary_dur < 0):
132  summary_dur = 0.0
133 
134  summary = self._console.get_message_summary(summary_dur)
135 
136  if (summary.fatal or summary.error):
137  self.update_state(2)
138  elif (summary.warn):
139  self.update_state(1)
140  else:
141  self.update_state(0)
142 
143  tooltip = ""
144  if (summary.fatal):
145  tooltip += "\nFatal: %s" % (summary.fatal)
146  if (summary.error):
147  tooltip += "\nError: %s" % (summary.error)
148  if (summary.warn):
149  tooltip += "\nWarn: %s" % (summary.warn)
150  if (summary.info):
151  tooltip += "\nInfo: %s" % (summary.info)
152  if (summary.debug):
153  tooltip += "\nDebug: %s" % (summary.debug)
154 
155  if (len(tooltip) == 0):
156  tooltip = "Rosout: no recent activity"
157  else:
158  tooltip = "Rosout: recent activity:" + tooltip
159 
160  if tooltip != self.toolTip():
161  self.setToolTip(tooltip)
162 
164  if self._console:
165  self._console.cleanup_browsers_on_close()
166  self._console = None
167 
168  def shutdown_widget(self):
169  if self._console:
170  self._console.cleanup_browsers_on_close()
171  if self._subscriber:
172  self._subscriber.unregister()
173  self._timer.stop()
174 
175  def save_settings(self, plugin_settings, instance_settings):
176  self._console.save_settings(plugin_settings, instance_settings)
177 
178  def restore_settings(self, plugin_settings, instance_settings):
179  self._console.restore_settings(plugin_settings, instance_settings)
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget.restore_settings
def restore_settings(self, plugin_settings, instance_settings)
Definition: console_dash_widget.py:178
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._subscriber
_subscriber
Definition: console_dash_widget.py:78
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget
Definition: console_dash_widget.py:46
rqt_console::message_proxy_model::MessageProxyModel
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._show_console
def _show_console(self)
Definition: console_dash_widget.py:91
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._insert_messages
def _insert_messages(self)
Definition: console_dash_widget.py:106
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget.update_rosout
def update_rosout(self)
Definition: console_dash_widget.py:126
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._proxymodel
_proxymodel
Definition: console_dash_widget.py:67
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget.__init__
def __init__(self, context, icon_paths=None, minimal=True)
Definition: console_dash_widget.py:53
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget.context
context
Definition: console_dash_widget.py:80
rqt_console::console_widget::ConsoleWidget
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._mutex
_mutex
Definition: console_dash_widget.py:77
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget.shutdown_widget
def shutdown_widget(self)
Definition: console_dash_widget.py:168
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._console_destroyed
def _console_destroyed(self)
Definition: console_dash_widget.py:163
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._message_cb
def _message_cb(self, log_msg)
Definition: console_dash_widget.py:120
rqt_console::message_data_model
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._rospack
_rospack
Definition: console_dash_widget.py:71
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._datamodel
_datamodel
Definition: console_dash_widget.py:66
rqt_robot_dashboard.icon_tool_button.IconToolButton.update_state
def update_state(self, state)
Definition: icon_tool_button.py:92
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._console_shown
_console_shown
Definition: console_dash_widget.py:88
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._console
_console
Definition: console_dash_widget.py:70
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget.save_settings
def save_settings(self, plugin_settings, instance_settings)
Definition: console_dash_widget.py:175
rqt_console::console_widget
rqt_robot_dashboard.icon_tool_button.IconToolButton._icons
_icons
Definition: icon_tool_button.py:84
rqt_console::message_data_model::MessageDataModel
rqt_console::console
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._message_queue
_message_queue
Definition: console_dash_widget.py:76
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget.minimal
minimal
Definition: console_dash_widget.py:63
rqt_robot_dashboard.console_dash_widget.ConsoleDashWidget._timer
_timer
Definition: console_dash_widget.py:84
rqt_console::message_proxy_model
rqt_robot_dashboard.icon_tool_button.IconToolButton
Definition: icon_tool_button.py:42


rqt_robot_dashboard
Author(s): Ze'ev Klapow
autogenerated on Wed Mar 2 2022 00:58:48