console.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 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         # Timer and Mutex for flushing recieved messages to datamodel.
00070         # Required since QSortProxyModel can not handle a high insert rate
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()


rqt_console
Author(s): Aaron Blasdel
autogenerated on Fri Jan 3 2014 11:54:30