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, QObject, Qt
00032
00033 from .dock_widget import DockWidget
00034 from .plugin_descriptor import PluginDescriptor
00035 from .reparent_event import ReparentEvent
00036
00037
00038 class ContainerManager(QObject):
00039
00040 """Manager of `DockWidgetContainer`s enabling reparenting to stored parent."""
00041
00042 def __init__(self, root_main_window, parent=None):
00043 super(ContainerManager, self).__init__(parent)
00044 self._root_main_window = root_main_window
00045 self._container_descriptor = PluginDescriptor('__DockWidgetContainer')
00046 self._container_descriptor.set_action_attributes(self.tr('Container'), self.tr('Container for other dock widgets'))
00047 self._containers = {}
00048
00049 def get_root_main_window(self):
00050 return self._root_main_window
00051
00052 def get_container_descriptor(self):
00053 return self._container_descriptor
00054
00055 def add_to_plugin_menu(self, plugin_menu):
00056 plugin_menu.add_plugin_prefix(self._container_descriptor)
00057
00058 def add_container(self, container):
00059 self._containers[container.serial_number()] = container
00060
00061 def remove_container(self, container):
00062 del self._containers[container.serial_number()]
00063
00064 def get_container(self, serial_number):
00065 if serial_number in self._containers:
00066 return self._containers[serial_number]
00067 return None
00068
00069 def get_containers(self):
00070 return self._containers.values()
00071
00072 def move_container_children_to_parent(self, container):
00073 floating = container.isFloating()
00074 for child in container.main_window.children():
00075 if isinstance(child, DockWidget):
00076 area = container.main_window.dockWidgetArea(child)
00077 container.parent().addDockWidget(area, child)
00078 if floating:
00079 child.setFloating(floating)
00080
00081 def restore_state_of_containers(self):
00082 for container in self._containers.values():
00083 container.restore_state()
00084
00085 def event(self, e):
00086 if e.type() == ReparentEvent.reparent_event_type:
00087 qDebug('ContainerManager.event() reparent event: new parent=%s' % e.new_parent.objectName())
00088 floating = e.dock_widget.isFloating()
00089 pos = e.dock_widget.pos()
00090 e.new_parent.addDockWidget(Qt.BottomDockWidgetArea, e.dock_widget)
00091 if floating:
00092 e.dock_widget.setFloating(floating)
00093 e.dock_widget.move(pos)
00094 e.accept()
00095 return True
00096 return super(ContainerManager, self).event(e)