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 from python_qt_binding.QtCore import qDebug, Qt, Signal
00032 from python_qt_binding.QtGui import QToolBar
00033
00034 from .dockable_main_window import DockableMainWindow
00035 from .settings import Settings
00036
00037
00038 class MainWindow(DockableMainWindow):
00039
00040 """Main window of the application managing the geometry and state of all top-level widgets."""
00041
00042 save_settings_before_close_signal = Signal(Settings, Settings)
00043
00044 def __init__(self):
00045 super(MainWindow, self).__init__()
00046 self.setObjectName('MainWindow')
00047
00048 self._save_on_close_signaled = False
00049 self._global_settings = None
00050 self._perspective_settings = None
00051 self._settings = None
00052
00053 def closeEvent(self, event):
00054 qDebug('MainWindow.closeEvent()')
00055 if not self._save_on_close_signaled:
00056 self._save_geometry_to_perspective()
00057 self._save_state_to_perspective()
00058 self._save_on_close_signaled = True
00059 self.save_settings_before_close_signal.emit(self._global_settings, self._perspective_settings)
00060 event.ignore()
00061 else:
00062 event.accept()
00063
00064 def save_settings(self, global_settings, perspective_settings):
00065 qDebug('MainWindow.save_settings()')
00066 self._global_settings = global_settings
00067 self._perspective_settings = perspective_settings
00068 self._settings = self._perspective_settings.get_settings('mainwindow')
00069
00070 self._save_geometry_to_perspective()
00071 self._save_state_to_perspective()
00072
00073 def restore_settings(self, global_settings, perspective_settings):
00074 qDebug('MainWindow.restore_settings()')
00075
00076 self._global_settings = global_settings
00077 self._perspective_settings = perspective_settings
00078 self._settings = self._perspective_settings.get_settings('mainwindow')
00079
00080 self._restore_geometry_from_perspective()
00081
00082 def save_setup(self):
00083 qDebug('MainWindow.save_setup()')
00084
00085 self._save_geometry_to_perspective()
00086 self._save_state_to_perspective()
00087
00088 def restore_state(self):
00089 qDebug('MainWindow.restore_state()')
00090
00091 self._restore_state_from_perspective()
00092
00093 def perspective_changed(self, name):
00094 self.setWindowTitle('%s - rqt' % str(name))
00095
00096 def _save_geometry_to_perspective(self):
00097 if self._settings is not None:
00098
00099
00100 maximized = self.isMaximized()
00101 if maximized:
00102 self.showNormal()
00103 self._settings.set_value('geometry', self.saveGeometry())
00104 if maximized:
00105 self.showMaximized()
00106
00107 def _restore_geometry_from_perspective(self):
00108 if self._settings.contains('geometry'):
00109 self.restoreGeometry(self._settings.value('geometry'))
00110
00111 def _save_state_to_perspective(self):
00112 if self._settings is not None:
00113 self._settings.set_value('state', self.saveState())
00114
00115 toolbar_settings = self._settings.get_settings('toolbar_areas')
00116 for toolbar in self.findChildren(QToolBar):
00117 area = self.toolBarArea(toolbar)
00118 if area in [Qt.LeftToolBarArea, Qt.RightToolBarArea, Qt.TopToolBarArea, Qt.BottomToolBarArea]:
00119 toolbar_settings.set_value(toolbar.objectName(), area)
00120
00121 def _restore_state_from_perspective(self):
00122 if self._settings.contains('state'):
00123 self.restoreState(self._settings.value('state'))
00124
00125 toolbar_settings = self._settings.get_settings('toolbar_areas')
00126 for toolbar in self.findChildren(QToolBar):
00127 area = Qt.ToolBarArea(int(toolbar_settings.value(toolbar.objectName(), Qt.NoToolBarArea)))
00128 if area in [Qt.LeftToolBarArea, Qt.RightToolBarArea, Qt.TopToolBarArea, Qt.BottomToolBarArea]:
00129 self.addToolBar(area, toolbar)