<s> from pyface . qt import QtCore , QtGui <EOL> from traits . api import Instance , List <EOL> from pyface . tasks . i_task_window_backend import MTaskWindowBackend <EOL> from pyface . tasks . task_layout import PaneItem , TaskLayout <EOL> from . dock_pane import AREA_MAP , INVERSE_AREA_MAP <EOL> from . main_window_layout import MainWindowLayout <EOL> CORNER_MAP = { '<STR_LIT>' : QtCore . Qt . TopLeftCorner , <EOL> '<STR_LIT>' : QtCore . Qt . TopRightCorner , <EOL> '<STR_LIT>' : QtCore . Qt . BottomLeftCorner , <EOL> '<STR_LIT>' : QtCore . Qt . BottomRightCorner } <EOL> class TaskWindowBackend ( MTaskWindowBackend ) : <EOL> """<STR_LIT>""" <EOL> _main_window_layout = Instance ( MainWindowLayout ) <EOL> def create_contents ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QApplication . instance ( ) . focusChanged . connect ( <EOL> self . _focus_changed_signal ) <EOL> return QtGui . QStackedWidget ( parent ) <EOL> def destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QApplication . instance ( ) . focusChanged . disconnect ( <EOL> self . _focus_changed_signal ) <EOL> self . _main_window_layout . control = None <EOL> def hide_task ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . window . _active_state . layout = self . get_layout ( ) <EOL> self . control . centralWidget ( ) . removeWidget ( state . central_pane . control ) <EOL> for dock_pane in state . dock_panes : <EOL> dock_pane . control . hide ( ) <EOL> self . control . removeDockWidget ( dock_pane . control ) <EOL> def show_task ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . control . centralWidget ( ) . addWidget ( state . central_pane . control ) <EOL> self . _layout_state ( state ) <EOL> self . control . setUnifiedTitleAndToolBarOnMac ( <EOL> len ( state . tool_bar_managers ) <= <NUM_LIT:1> ) <EOL> def get_layout ( self ) : <EOL> """<STR_LIT>""" <EOL> layout = TaskLayout ( id = self . window . _active_state . task . id ) <EOL> self . _main_window_layout . state = self . window . _active_state <EOL> self . _main_window_layout . get_layout ( layout ) <EOL> for name , corner in CORNER_MAP . iteritems ( ) : <EOL> area = INVERSE_AREA_MAP [ int ( self . control . corner ( corner ) ) ] <EOL> setattr ( layout , name + '<STR_LIT>' , area ) <EOL> return layout <EOL> def set_layout ( self , layout ) : <EOL> """<STR_LIT>""" <EOL> self . window . _active_state . layout = layout <EOL> self . _layout_state ( self . window . _active_state ) <EOL> def _layout_state ( self , state ) : <EOL> """<STR_LIT>""" <EOL> for name , corner in CORNER_MAP . iteritems ( ) : <EOL> area = getattr ( state . layout , name + '<STR_LIT>' ) <EOL> self . control . setCorner ( corner , AREA_MAP [ area ] ) <EOL> self . _main_window_layout . state = state <EOL> self . _main_window_layout . set_layout ( state . layout ) <EOL> for dock_pane in state . dock_panes : <EOL> if dock_pane . control not in self . _main_window_layout . consumed : <EOL> self . control . addDockWidget ( AREA_MAP [ dock_pane . dock_area ] , <EOL> dock_pane . control ) <EOL> if dock_pane . visible : <EOL> dock_pane . control . show ( ) <EOL> def __main_window_layout_default ( self ) : <EOL> return TaskWindowLayout ( control = self . control ) <EOL> def _focus_changed_signal ( self , old , new ) : <EOL> if self . window . active_task : <EOL> panes = [ self . window . central_pane ] + self . window . dock_panes <EOL> for pane in panes : <EOL> if new and pane . control . isAncestorOf ( new ) : <EOL> pane . has_focus = True <EOL> elif old and pane . control . isAncestorOf ( old ) : <EOL> pane . has_focus = False <EOL> class TaskWindowLayout ( MainWindowLayout ) : <EOL> """<STR_LIT>""" <EOL> consumed = List <EOL> state = Instance ( '<STR_LIT>' ) <EOL> def set_layout ( self , layout ) : <EOL> """<STR_LIT>""" <EOL> self . consumed = [ ] <EOL> super ( TaskWindowLayout , self ) . set_layout ( layout ) <EOL> def _get_dock_widget ( self , pane ) : <EOL> """<STR_LIT>""" <EOL> for dock_pane in self . state . dock_panes : <EOL> if dock_pane . id == pane . id : <EOL> self . consumed . append ( dock_pane . control ) <EOL> return dock_pane . control <EOL> return None <EOL> def _get_pane ( self , dock_widget ) : <EOL> """<STR_LIT>""" <EOL> for dock_pane in self . state . dock_panes : <EOL> if dock_pane . control == dock_widget : <EOL> return PaneItem ( id = dock_pane . id ) <EOL> return None </s>
