container_manager.py
Go to the documentation of this file.
00001 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
00002 # All rights reserved.
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 #   * Redistributions of source code must retain the above copyright
00009 #     notice, this list of conditions and the following disclaimer.
00010 #   * Redistributions in binary form must reproduce the above
00011 #     copyright notice, this list of conditions and the following
00012 #     disclaimer in the documentation and/or other materials provided
00013 #     with the distribution.
00014 #   * Neither the name of the TU Darmstadt nor the names of its
00015 #     contributors may be used to endorse or promote products derived
00016 #     from this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00028 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029 # POSSIBILITY OF SUCH DAMAGE.
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)


qt_gui
Author(s): Dirk Thomas
autogenerated on Fri Feb 3 2017 03:42:12