def _show_navview(self): with QMutexLocker(self._show_mutex): if self._navview is None: self._navview = NavViewWidget() try: if self._navview_shown: self.context.remove_widget(self._navview) self._navview_shown = not self._navview_shown else: self.context.add_widget(self._navview) self._navview_shown = not self._navview_shown except Exception: self._navview_shown = not self._navview_shown self._show_navview()
class NavViewDashWidget(IconToolButton): """ A widget which launches a nav_view widget in order to view and interact with the ROS nav stack :param context: The plugin context in which to dsiplay the nav_view, ''qt_gui.plugin_context.PluginContext'' :param name: The widgets name, ''str'' """ def __init__(self, context, name='NavView', icon_paths=None): self._icons = [['bg-grey.svg', 'ic-navigation.svg']] super(NavViewDashWidget, self).__init__(name, icons=self._icons, suppress_overlays=True, icon_paths=icon_paths) self.context = context self.update_state(0) self.setFixedSize(self._icons[0].actualSize(QSize(50, 30))) self._navview = None self._navview_shown = False self.clicked.connect(self._show_navview) self._show_mutex = QMutex() def _show_navview(self): with QMutexLocker(self._show_mutex): if self._navview is None: self._navview = NavViewWidget() try: if self._navview_shown: self.context.remove_widget(self._navview) self._navview_shown = not self._navview_shown else: self.context.add_widget(self._navview) self._navview_shown = not self._navview_shown except Exception: self._navview_shown = not self._navview_shown self._show_navview() def shutdown_widget(self): if self._navview: self._navview.close() def save_settings(self, plugin_settings, instance_settings): self._navview.save_settings(plugin_settings, instance_settings) def restore_settings(self, plugin_settings, instance_settings): self._navview.restore_settings(plugin_settings, instance_settings)