<s> from atom . api import Int , Typed <EOL> from enaml . widgets . dock_pane import ProxyDockPane <EOL> from . QtCore import Qt , Signal <EOL> from . QtGui import QDockWidget , QWidget <EOL> from . qt_container import QtContainer <EOL> from . qt_widget import QtWidget <EOL> _DOCK_AREA_MAP = { <EOL> '<STR_LIT>' : Qt . TopDockWidgetArea , <EOL> '<STR_LIT:right>' : Qt . RightDockWidgetArea , <EOL> '<STR_LIT>' : Qt . BottomDockWidgetArea , <EOL> '<STR_LIT:left>' : Qt . LeftDockWidgetArea , <EOL> '<STR_LIT:all>' : Qt . AllDockWidgetAreas , <EOL> } <EOL> _DOCK_AREA_INV_MAP = { <EOL> Qt . TopDockWidgetArea : '<STR_LIT>' , <EOL> Qt . RightDockWidgetArea : '<STR_LIT:right>' , <EOL> Qt . BottomDockWidgetArea : '<STR_LIT>' , <EOL> Qt . LeftDockWidgetArea : '<STR_LIT:left>' , <EOL> Qt . AllDockWidgetAreas : '<STR_LIT:all>' , <EOL> } <EOL> class QCustomDockWidget ( QDockWidget ) : <EOL> """<STR_LIT>""" <EOL> closed = Signal ( ) <EOL> floated = Signal ( ) <EOL> docked = Signal ( object ) <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> super ( QCustomDockWidget , self ) . __init__ ( parent ) <EOL> self . _title_bar_visible = True <EOL> self . _dock_area = Qt . LeftDockWidgetArea <EOL> self . topLevelChanged . connect ( self . _onTopLevelChanged ) <EOL> def _onTopLevelChanged ( self , top_level ) : <EOL> """<STR_LIT>""" <EOL> if top_level : <EOL> self . _showTitleBar ( ) <EOL> self . floated . emit ( ) <EOL> else : <EOL> if not self . _title_bar_visible : <EOL> self . _hideTitleBar ( ) <EOL> parent = self . parent ( ) <EOL> if parent is not None : <EOL> self . _dock_area = parent . dockWidgetArea ( self ) <EOL> self . docked . emit ( self . _dock_area ) <EOL> def _showTitleBar ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . titleBarWidget ( ) is not None : <EOL> self . setTitleBarWidget ( None ) <EOL> def _hideTitleBar ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . titleBarWidget ( ) is None : <EOL> self . setTitleBarWidget ( QWidget ( ) ) <EOL> def closeEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> super ( QCustomDockWidget , self ) . closeEvent ( event ) <EOL> self . closed . emit ( ) <EOL> def dockArea ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _dock_area <EOL> def setDockArea ( self , area ) : <EOL> """<STR_LIT>""" <EOL> self . _dock_area = area <EOL> parent = self . parent ( ) <EOL> if parent is not None : <EOL> parent . setDockWidgetArea ( area , self ) <EOL> def titleBarVisible ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _title_bar_visible <EOL> def setTitleBarVisible ( self , visible ) : <EOL> """<STR_LIT>""" <EOL> self . _title_bar_visible = visible <EOL> if visible : <EOL> self . _showTitleBar ( ) <EOL> else : <EOL> if not self . isFloating ( ) : <EOL> self . _hideTitleBar ( ) <EOL> FLOATED_GUARD = <NUM_LIT> <EOL> class QtDockPane ( QtWidget , ProxyDockPane ) : <EOL> """<STR_LIT>""" <EOL> widget = Typed ( QCustomDockWidget ) <EOL> _guard = Int ( <NUM_LIT:0> ) <EOL> def create_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget = QCustomDockWidget ( self . parent_widget ( ) ) <EOL> def init_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QtDockPane , self ) . init_widget ( ) <EOL> d = self . declaration <EOL> self . set_title ( d . title ) <EOL> self . set_title_bar_visible ( d . title_bar_visible ) <EOL> self . set_title_bar_orientation ( d . title_bar_orientation ) <EOL> self . set_closable ( d . closable ) <EOL> self . set_movable ( d . movable ) <EOL> self . set_floatable ( d . floatable ) <EOL> self . set_floating ( d . floating ) <EOL> self . set_dock_area ( d . dock_area ) <EOL> self . set_allowed_dock_areas ( d . allowed_dock_areas ) <EOL> widget = self . widget <EOL> widget . closed . connect ( self . on_closed ) <EOL> widget . floated . connect ( self . on_floated ) <EOL> widget . docked . connect ( self . on_docked ) <EOL> def init_layout ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QtDockPane , self ) . init_layout ( ) <EOL> self . widget . setWidget ( self . dock_widget ( ) ) <EOL> def dock_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . declaration . dock_widget ( ) <EOL> if d is not None : <EOL> return d . proxy . widget <EOL> def child_added ( self , child ) : <EOL> """<STR_LIT>""" <EOL> super ( QtDockPane , self ) . child_added ( child ) <EOL> if isinstance ( child , QtContainer ) : <EOL> self . widget . setWidget ( self . dock_widget ( ) ) <EOL> def child_removed ( self , child ) : <EOL> """<STR_LIT>""" <EOL> super ( QtDockPane , self ) . child_removed ( child ) <EOL> if isinstance ( child , QtContainer ) : <EOL> self . widget . setWidget ( self . dock_widget ( ) ) <EOL> def on_closed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . declaration . visible = False <EOL> self . declaration . closed ( ) <EOL> def on_floated ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _guard & FLOATED_GUARD : <EOL> self . _guard |= FLOATED_GUARD <EOL> try : <EOL> self . declaration . floating = True <EOL> finally : <EOL> self . _guard &= ~ FLOATED_GUARD <EOL> def on_docked ( self , area ) : <EOL> """<STR_LIT>""" <EOL> if not self . _guard & FLOATED_GUARD : <EOL> self . _guard |= FLOATED_GUARD <EOL> try : <EOL> self . declaration . floating = False <EOL> self . declaration . dock_area = _DOCK_AREA_INV_MAP [ area ] <EOL> finally : <EOL> self . _guard &= ~ FLOATED_GUARD <EOL> def set_title ( self , title ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setWindowTitle ( title ) <EOL> def set_title_bar_visible ( self , visible ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setTitleBarVisible ( visible ) <EOL> def set_title_bar_orientation ( self , orientation ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> features = widget . features ( ) <EOL> if orientation == '<STR_LIT>' : <EOL> features |= QDockWidget . DockWidgetVerticalTitleBar <EOL> else : <EOL> features &= ~ QDockWidget . DockWidgetVerticalTitleBar <EOL> widget . setFeatures ( features ) <EOL> def set_closable ( self , closable ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> features = widget . features ( ) <EOL> if closable : <EOL> features |= QDockWidget . DockWidgetClosable <EOL> else : <EOL> features &= ~ QDockWidget . DockWidgetClosable <EOL> widget . setFeatures ( features ) <EOL> def set_movable ( self , movable ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> features = widget . features ( ) <EOL> if movable : <EOL> features |= QDockWidget . DockWidgetMovable <EOL> else : <EOL> features &= ~ QDockWidget . DockWidgetMovable <EOL> widget . setFeatures ( features ) <EOL> def set_floatable ( self , floatable ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> features = widget . features ( ) <EOL> if floatable : <EOL> features |= QDockWidget . DockWidgetFloatable <EOL> else : <EOL> features &= ~ QDockWidget . DockWidgetFloatable <EOL> widget . setFeatures ( features ) <EOL> def set_floating ( self , floating ) : <EOL> """<STR_LIT>""" <EOL> if not self . _guard & FLOATED_GUARD : <EOL> self . _guard |= FLOATED_GUARD <EOL> try : <EOL> self . widget . setFloating ( floating ) <EOL> finally : <EOL> self . _guard &= ~ FLOATED_GUARD <EOL> def set_dock_area ( self , dock_area ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setDockArea ( _DOCK_AREA_MAP [ dock_area ] ) <EOL> def set_allowed_dock_areas ( self , dock_areas ) : <EOL> """<STR_LIT>""" <EOL> qt_areas = Qt . NoDockWidgetArea <EOL> for area in dock_areas : <EOL> qt_areas |= _DOCK_AREA_MAP [ area ] <EOL> self . widget . setAllowedAreas ( qt_areas ) </s>
