container_manager.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, QObject, Qt
32 
33 from qt_gui.dock_widget import DockWidget
34 from qt_gui.plugin_descriptor import PluginDescriptor
35 from qt_gui.reparent_event import ReparentEvent
36 
37 
38 class ContainerManager(QObject):
39  """Manager of `DockWidgetContainer`s enabling reparenting to stored parent."""
40 
41  def __init__(self, root_main_window, parent=None):
42  super(ContainerManager, self).__init__(parent)
43  self._root_main_window = root_main_window
44  self._container_descriptor = PluginDescriptor('__DockWidgetContainer')
45  self._container_descriptor.set_action_attributes(
46  self.tr('Container'), self.tr('Container for other dock widgets'),
47  'folder-new', 'theme')
48 
49  self._containers = {}
50 
52  return self._root_main_window
53 
55  return self._container_descriptor
56 
57  def add_to_plugin_menu(self, plugin_menu):
58  plugin_menu.add_plugin_prefix(self._container_descriptor)
59 
60  def add_container(self, container):
61  self._containers[container.serial_number()] = container
62 
63  def remove_container(self, container):
64  del self._containers[container.serial_number()]
65 
66  def get_container(self, serial_number):
67  if serial_number in self._containers:
68  return self._containers[serial_number]
69  return None
70 
71  def get_containers(self):
72  return self._containers.values()
73 
74  def move_container_children_to_parent(self, container):
75  floating = container.isFloating()
76  for child in container.main_window.children():
77  if isinstance(child, DockWidget):
78  area = container.main_window.dockWidgetArea(child)
79  container.parent().addDockWidget(area, child)
80  if floating:
81  child.setFloating(floating)
82 
83  def get_container_of_dock_widget(self, dock_widget):
84  for container in self._containers.values():
85  for child in container.main_window.children():
86  if child == dock_widget:
87  return container
88  return None
89 
91  for container in self._containers.values():
92  container.restore_state()
93 
94  def event(self, e):
95  if e.type() == ReparentEvent.reparent_event_type:
96  qDebug('ContainerManager.event() reparent event: new parent=%s' %
97  e.new_parent.objectName())
98  floating = e.dock_widget.isFloating()
99  pos = e.dock_widget.pos()
100  e.new_parent.addDockWidget(Qt.BottomDockWidgetArea, e.dock_widget)
101  if floating:
102  e.dock_widget.setFloating(floating)
103  e.dock_widget.move(pos)
104  e.accept()
105  return True
106  return super(ContainerManager, self).event(e)
def get_container_of_dock_widget(self, dock_widget)
def __init__(self, root_main_window, parent=None)
def move_container_children_to_parent(self, container)


qt_gui
Author(s): Dirk Thomas
autogenerated on Sun Nov 1 2020 04:03:22