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'), 'folder-new', 'theme')
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 get_container_of_dock_widget(self, dock_widget):
00082 for container in self._containers.values():
00083 for child in container.main_window.children():
00084 if child == dock_widget:
00085 return container
00086 return None
00087
00088 def restore_state_of_containers(self):
00089 for container in self._containers.values():
00090 container.restore_state()
00091
00092 def event(self, e):
00093 if e.type() == ReparentEvent.reparent_event_type:
00094 qDebug('ContainerManager.event() reparent event: new parent=%s' % e.new_parent.objectName())
00095 floating = e.dock_widget.isFloating()
00096 pos = e.dock_widget.pos()
00097 e.new_parent.addDockWidget(Qt.BottomDockWidgetArea, e.dock_widget)
00098 if floating:
00099 e.dock_widget.setFloating(floating)
00100 e.dock_widget.move(pos)
00101 e.accept()
00102 return True
00103 return super(ContainerManager, self).event(e)