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
00034
00035 from __future__ import division
00036
00037 import os
00038
00039 from python_qt_binding import loadUi
00040 from python_qt_binding.QtGui import QWidget
00041 import rospkg
00042 import rospy
00043
00044
00045 class PluginContainerWidget(QWidget):
00046 """
00047 This widget accommodates a plugin widget that needs an area to show system
00048 message. A plugin widget is the pane that provides plugin's main
00049 functionalities. PluginContainerWidget visually encapsulates a plugin
00050 widget.
00051
00052 In order to print msg in the msg pane provided by this class, plugin widget
00053 MUST define and emit following signals:
00054
00055 - sig_sysmsg
00056 - sig_progress
00057
00058 Having said that this architecture is based on signals, it is recommended
00059 that exceptions raised in classes that are used in a plugin widget be
00060 aggregated in it, so that only plugin widget is responsible for emitting
00061 signals.
00062 """
00063
00064 def __init__(self, plugin_widget,
00065 on_sys_msg=True, on_sysprogress_bar=True):
00066 """
00067 @param plugin_widget: The main widget of an rqt plugin.
00068 @type plugin_widget: QWidget
00069 @type on_sys_msg: bool
00070 @param on_sys_msg: If True, a pane that accommodates str messages will
00071 appear in the plugin's region.
00072 @param on_sysprogress_bar: If True, a progress bar will appear in the
00073 plugin's region.
00074 """
00075 super(PluginContainerWidget, self).__init__()
00076
00077 ui_file = os.path.join(rospkg.RosPack().get_path('rqt_py_common'),
00078 'resource', 'plugin_container.ui')
00079 loadUi(ui_file, self)
00080
00081 self._plugin_widget = plugin_widget
00082 self._splitter.insertWidget(0, self._plugin_widget)
00083 self.setWindowTitle(self._plugin_widget.windowTitle())
00084
00085
00086
00087 if on_sys_msg:
00088 self._plugin_widget.sig_sysmsg.connect(self.set_sysmsg)
00089 else:
00090 self._sysmsg_widget.hide()
00091
00092 if on_sysprogress_bar:
00093 self._plugin_widget.sig_sysprogress.connect(self.set_sysprogress)
00094 else:
00095 self._sysprogress_bar.hide()
00096
00097 def set_sysprogress(self, sysprogress):
00098
00099 pass
00100
00101 def set_sysmsg(self, sysmsg):
00102 """
00103 Set system msg that's supposed to be shown in sys msg pane.
00104 @type sysmsg: str
00105 """
00106 rospy.loginfo('PluginContainerWidget; {}'.format(sysmsg))
00107
00108 self._sysmsg_widget.append(sysmsg)
00109
00110 def shutdown(self):
00111
00112
00113
00114 self._plugin_widget.shutdown()
00115
00116 def save_settings(self, plugin_settings, instance_settings):
00117
00118
00119 instance_settings.set_value('_splitter', self._splitter.saveState())
00120
00121
00122 self._plugin_widget.save_settings(plugin_settings, instance_settings)
00123
00124 def restore_settings(self, plugin_settings, instance_settings):
00125
00126
00127
00128 if instance_settings.contains('_splitter'):
00129 self._splitter.restoreState(instance_settings.value('_splitter'))
00130 else:
00131 self._splitter.setSizes([100, 100, 200])
00132
00133
00134 self._plugin_widget.restore_settings(plugin_settings,
00135 instance_settings)