ocs_plugin.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 
5 from python_qt_binding.QtCore import Slot, QCoreApplication, QBasicTimer, QSettings
6 from python_qt_binding.QtGui import QWidget
7 
8 from std_msgs.msg import Int8
9 
10 
11 class OCSPlugin(QWidget):
12 
13  def __init__(self, widget_class, name, window, *args):
14  super(OCSPlugin, self).__init__(None)
15 
16  if len(args) > 0:
17  self._widget = widget_class(self, args[0])
18  else:
19  self._widget = widget_class(self)
20 
21  self._name = name
22  self._window = window
23 
24  self._window_control_sub = rospy.Subscriber("/flor/ocs/window_control", Int8, self.processWindowControl)
25  self._window_control_pub = rospy.Publisher("/flor/ocs/window_control", Int8, queue_size=10)
26 
27  # window visibility configuration variables
30 
31  # this is only used to make sure we close window if ros::shutdown has already been called
32  self._timer = QBasicTimer()
33  self._timer.start(33, self)
34 
35  settings = QSettings("OCS", self._name)
36  if settings.value("mainWindowGeometry") is not None:
37  self.restoreGeometry(settings.value("mainWindowGeometry"))
38  self.geometry_ = self.geometry()
39 
40  def processWindowControl(self, visible):
41  # set window visibility changed flag
42  self._set_window_visibility = True
43  self._last_window_control_data = visible.data
44 
45  def timerEvent(self, event):
46  if rospy.is_shutdown():
47  QCoreApplication.instance().quit()
48 
49  # needed to move qt calls out of the ros callback, otherwise qt crashes because of inter-thread communication
50  if self._set_window_visibility:
51  self._set_window_visibility = False
52  if not self.isVisible() and self._last_window_control_data == self._window:
53  self.show()
54  self.setGeometry(self._geometry)
55  elif self.isVisible() and (not self._last_window_control_data or self._last_window_control_data == -self._window):
56  self._geometry = self.geometry()
57  self.hide()
58 
59  def closeEvent(self, event):
60  settings = QSettings("OCS", self._name)
61  settings.setValue("mainWindowGeometry", self.saveGeometry())
62  msg = Int8()
63  msg.data = -self._window
64  self._window_control_pub.publish(msg)
65  event.ignore()
66 
67  def resizeEvent(self, event):
68  settings = QSettings("OCS", self._name)
69  settings.setValue("mainWindowGeometry", self.saveGeometry())
70 
71  def moveEvent(self, event):
72  settings = QSettings("OCS", self._name)
73  settings.setValue("mainWindowGeometry", self.saveGeometry())
def __init__(self, widget_class, name, window, args)
Definition: ocs_plugin.py:13


vigir_footstep_planning_lib
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:33