main_window.py
Go to the documentation of this file.
1 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution.
14 # * Neither the name of the TU Darmstadt nor the names of its
15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 from python_qt_binding.QtCore import qDebug, Qt, Signal
32 from python_qt_binding.QtWidgets import QToolBar
33 
34 from qt_gui.dockable_main_window import DockableMainWindow
35 from qt_gui.settings import Settings
36 
37 
39  """Main window of the application managing the geometry and state of all top-level widgets."""
40 
41  save_settings_before_close_signal = Signal(Settings, Settings)
42 
43  def __init__(self):
44  super(MainWindow, self).__init__()
45  self.setObjectName('MainWindow')
46 
48  self._global_settings = None
50  self._settings = None
51 
52  def closeEvent(self, event):
53  qDebug('MainWindow.closeEvent()')
54  if not self._save_on_close_signaled:
57  self._save_on_close_signaled = True
58  self.save_settings_before_close_signal.emit(
60  event.ignore()
61  else:
62  event.accept()
63 
64  def save_settings(self, global_settings, perspective_settings):
65  qDebug('MainWindow.save_settings()')
66  self._global_settings = global_settings
67  self._perspective_settings = perspective_settings
68  self._settings = self._perspective_settings.get_settings('mainwindow')
69  # store current setup to current _settings
72 
73  def restore_settings(self, global_settings, perspective_settings):
74  qDebug('MainWindow.restore_settings()')
75  # remember new _settings
76  self._global_settings = global_settings
77  self._perspective_settings = perspective_settings
78  self._settings = self._perspective_settings.get_settings('mainwindow')
79  # only restore geometry, restoring state is triggered after PluginManager has been updated
81 
82  def save_setup(self):
83  qDebug('MainWindow.save_setup()')
84  # store current setup to current _settings
87 
88  def restore_state(self):
89  qDebug('MainWindow.restore_state()')
90  # restore state from _settings
92 
93  def perspective_changed(self, name):
94  self.setWindowTitle('%s - rqt' % str(name))
95 
97  if self._settings is not None:
98  # unmaximizing widget before saveGeometry works around bug to restore dock-widgets
99  # still the non-maximized size can not correctly be restored
100  maximized = self.isMaximized()
101  if maximized:
102  self.showNormal()
103  self._settings.set_value('geometry', self.saveGeometry())
104  if maximized:
105  self.showMaximized()
106 
108  if self._settings.contains('geometry'):
109  self.restoreGeometry(self._settings.value('geometry'))
110 
112  if self._settings is not None:
113  self._settings.set_value('state', self.saveState())
114  # safe area for all toolbars
115  toolbar_settings = self._settings.get_settings('toolbar_areas')
116  for toolbar in self.findChildren(QToolBar):
117  area = self.toolBarArea(toolbar)
118  if area in [Qt.LeftToolBarArea,
119  Qt.RightToolBarArea,
120  Qt.TopToolBarArea,
121  Qt.BottomToolBarArea]:
122  toolbar_settings.set_value(toolbar.objectName(), area)
123 
125  if self._settings.contains('state'):
126  self.restoreState(self._settings.value('state'))
127  # restore area for all toolbars
128  toolbar_settings = self._settings.get_settings('toolbar_areas')
129  for toolbar in self.findChildren(QToolBar):
130  if not toolbar.objectName():
131  continue
132  area = Qt.ToolBarArea(
133  int(toolbar_settings.value(toolbar.objectName(), Qt.NoToolBarArea)))
134  if area in [Qt.LeftToolBarArea,
135  Qt.RightToolBarArea,
136  Qt.TopToolBarArea,
137  Qt.BottomToolBarArea]:
138  self.addToolBar(area, toolbar)
def perspective_changed(self, name)
Definition: main_window.py:93
def _restore_state_from_perspective(self)
Definition: main_window.py:124
def restore_settings(self, global_settings, perspective_settings)
Definition: main_window.py:73
def _restore_geometry_from_perspective(self)
Definition: main_window.py:107
def _save_geometry_to_perspective(self)
Definition: main_window.py:96
def closeEvent(self, event)
Definition: main_window.py:52
def save_settings(self, global_settings, perspective_settings)
Definition: main_window.py:64


qt_gui
Author(s): Dirk Thomas
autogenerated on Thu Jun 6 2019 19:54:27