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 roslib
00034 roslib.load_manifest('rqt_console')
00035
00036 from python_qt_binding.QtCore import QMutex, QTimer
00037
00038 from qt_gui.plugin import Plugin
00039
00040 from .console_subscriber import ConsoleSubscriber
00041 from .console_widget import ConsoleWidget
00042 from .message_data_model import MessageDataModel
00043 from .message_proxy_model import MessageProxyModel
00044
00045
00046 class Console(Plugin):
00047 """
00048 rqt_console plugin's main class. Handles communication with ros_gui and contains
00049 callbacks to handle incoming message
00050 """
00051 def __init__(self, context):
00052 """
00053 :param context: plugin context hook to enable adding widgets as a ROS_GUI pane, ''PluginContext''
00054 """
00055 super(Console, self).__init__(context)
00056 self.setObjectName('Console')
00057
00058 self._datamodel = MessageDataModel()
00059 self._proxymodel = MessageProxyModel()
00060 self._proxymodel.setSourceModel(self._datamodel)
00061
00062 self._mainwindow = ConsoleWidget(self._proxymodel)
00063 if context.serial_number() > 1:
00064 self._mainwindow.setWindowTitle(self._mainwindow.windowTitle() + (' (%d)' % context.serial_number()))
00065 context.add_widget(self._mainwindow)
00066
00067 self._consolesubscriber = ConsoleSubscriber(self.message_callback)
00068
00069
00070
00071 self._mutex = QMutex()
00072 self._timer = QTimer()
00073 self._timer.timeout.connect(self.insert_messages)
00074 self._timer.start(100)
00075
00076 def insert_messages(self):
00077 """
00078 Callback for flushing incoming Log messages from the queue to the datamodel
00079 """
00080 self._mutex.lock()
00081 msgs = self._datamodel._insert_message_queue
00082 self._datamodel._insert_message_queue = []
00083 self._mutex.unlock()
00084 self._datamodel.insert_rows(msgs)
00085 self._mainwindow.update_status()
00086
00087 def message_callback(self, msg):
00088 """
00089 Callback for adding an incomming message to the queue
00090 """
00091 if not self._datamodel._paused:
00092 self._mutex.lock()
00093 self._datamodel._insert_message_queue.append(msg)
00094 self._mutex.unlock()
00095
00096 def shutdown_plugin(self):
00097 self._consolesubscriber.unsubscribe_topic()
00098 self._timer.stop()
00099 self._mainwindow.cleanup_browsers_on_close()
00100
00101 def save_settings(self, plugin_settings, instance_settings):
00102 self._mainwindow.save_settings(plugin_settings, instance_settings)
00103
00104 def restore_settings(self, plugin_settings, instance_settings):
00105 self._mainwindow.restore_settings(plugin_settings, instance_settings)
00106
00107 def trigger_configuration(self):
00108 self._consolesubscriber.set_message_limit(self._datamodel._message_limit)
00109 ok = self._consolesubscriber.show_dialog()
00110 if ok:
00111 self._datamodel._message_limit = self._consolesubscriber.get_message_limit()