launchtree_plugin.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import rospy
00003 from rqt_gui_py.plugin import Plugin
00004 
00005 from python_qt_binding.QtCore import Qt
00006 from python_qt_binding.QtGui import QInputDialog
00007 
00008 from rqt_launchtree.launchtree_widget import LaunchtreeWidget
00009 
00010 
00011 class LaunchtreePlugin(Plugin):
00012 
00013     _SETTING_LASTPKG = 'last_pkg'
00014     _SETTING_LASTLAUNCHFILE = 'last_launch'
00015     _SETTING_LASTLAUNCHARGS = 'last_args'
00016 
00017     def __init__(self, context):
00018         super(LaunchtreePlugin, self).__init__(context)
00019 
00020         self._widget = LaunchtreeWidget(context)
00021         if context.serial_number() > 1:
00022             self._widget.setWindowTitle(self._widget.windowTitle() +
00023                                         (' (%d)' % context.serial_number()))
00024         context.add_widget(self._widget)
00025 
00026     def shutdown_plugin(self):
00027         self._widget.shutdown()
00028 
00029     def save_settings(self, plugin_settings, instance_settings):
00030         instance_settings.set_value('editor', self._widget.editor)
00031         _curr_pkg = self._widget.package_select.currentText()
00032         rospy.logdebug('save_settings) currentIndex={}'.format(_curr_pkg))
00033         instance_settings.set_value(self._SETTING_LASTPKG, _curr_pkg)
00034         instance_settings.set_value(self._SETTING_LASTLAUNCHFILE, self._widget.launchfile_select.currentText())
00035         instance_settings.set_value(self._SETTING_LASTLAUNCHARGS, self._widget.args_input.text())
00036 
00037     def restore_settings(self, plugin_settings, instance_settings):
00038         self._widget.editor = instance_settings.value('editor', 'gedit')
00039         self._widget.args_input.setText(instance_settings.value(self._SETTING_LASTLAUNCHARGS, ''))
00040         pkg_idx = self._widget.package_select.findText(instance_settings.value(self._SETTING_LASTPKG))
00041         if pkg_idx >= 0:
00042             self._widget.package_select.blockSignals(True)
00043             self._widget.package_select.setCurrentIndex(pkg_idx)
00044             self._widget.package_select.blockSignals(False)
00045             self._widget.update_launchfiles(pkg_idx)
00046             # only set launch file if pkg was restored
00047             launch_idx = self._widget.launchfile_select.findText(instance_settings.value(self._SETTING_LASTLAUNCHFILE))
00048             if launch_idx >= 0:
00049                 self._widget.launchfile_select.blockSignals(True)
00050                 self._widget.launchfile_select.setCurrentIndex(launch_idx)
00051                 self._widget.launchfile_select.blockSignals(False)
00052         self._widget.block_load(False)
00053         self._widget.load_launchfile()
00054 
00055     def trigger_configuration(self):
00056         (text, ok) = QInputDialog.getText(self._widget,
00057             'Settings for %s' % self._widget.windowTitle(),
00058             'Command to edit launch files (vim, gedit, ...), can accept args:',
00059             text = self._widget.editor
00060         )
00061         if ok:
00062             self._widget.editor = text


rqt_launchtree
Author(s): Philipp Schillinger
autogenerated on Thu Apr 6 2017 02:42:55