Go to the documentation of this file.00001
00002
00003 import rospy
00004
00005 from python_qt_binding.QtCore import Slot, QCoreApplication, QBasicTimer, QSettings
00006 from python_qt_binding.QtGui import QWidget
00007
00008 from std_msgs.msg import Int8
00009
00010
00011 class OCSPlugin(QWidget):
00012
00013 def __init__(self, widget_class, name, window, *args):
00014 super(OCSPlugin, self).__init__(None)
00015
00016 if len(args) > 0:
00017 self._widget = widget_class(self, args[0])
00018 else:
00019 self._widget = widget_class(self)
00020
00021 self._name = name
00022 self._window = window
00023
00024 self._window_control_sub = rospy.Subscriber("/flor/ocs/window_control", Int8, self.processWindowControl)
00025 self._window_control_pub = rospy.Publisher("/flor/ocs/window_control", Int8, queue_size=10)
00026
00027
00028 self._last_window_control_data = -self._window
00029 self._set_window_visibility = True
00030
00031
00032 self._timer = QBasicTimer()
00033 self._timer.start(33, self)
00034
00035 settings = QSettings("OCS", self._name)
00036 if settings.value("mainWindowGeometry") is not None:
00037 self.restoreGeometry(settings.value("mainWindowGeometry"))
00038 self.geometry_ = self.geometry()
00039
00040 def processWindowControl(self, visible):
00041
00042 self._set_window_visibility = True
00043 self._last_window_control_data = visible.data
00044
00045 def timerEvent(self, event):
00046 if rospy.is_shutdown():
00047 QCoreApplication.instance().quit()
00048
00049
00050 if self._set_window_visibility:
00051 self._set_window_visibility = False
00052 if not self.isVisible() and self._last_window_control_data == self._window:
00053 self.show()
00054 self.setGeometry(self._geometry)
00055 elif self.isVisible() and (not self._last_window_control_data or self._last_window_control_data == -self._window):
00056 self._geometry = self.geometry()
00057 self.hide()
00058
00059 def closeEvent(self, event):
00060 settings = QSettings("OCS", self._name)
00061 settings.setValue("mainWindowGeometry", self.saveGeometry())
00062 msg = Int8()
00063 msg.data = -self._window
00064 self._window_control_pub.publish(msg)
00065 event.ignore()
00066
00067 def resizeEvent(self, event):
00068 settings = QSettings("OCS", self._name)
00069 settings.setValue("mainWindowGeometry", self.saveGeometry())
00070
00071 def moveEvent(self, event):
00072 settings = QSettings("OCS", self._name)
00073 settings.setValue("mainWindowGeometry", self.saveGeometry())