<s> """<STR_LIT>""" <EOL> import cPickle <EOL> import logging <EOL> import wx <EOL> from pyface . dock . api import DOCK_BOTTOM , DOCK_LEFT , DOCK_RIGHT <EOL> from pyface . dock . api import DOCK_TOP <EOL> from pyface . dock . api import DockControl , DockRegion , DockSection <EOL> from pyface . dock . api import DockSizer <EOL> from traits . api import Delegate <EOL> from traitsui . dockable_view_element import DockableViewElement <EOL> from pyface . workbench . i_workbench_window_layout import MWorkbenchWindowLayout <EOL> from . editor_set_structure_handler import EditorSetStructureHandler <EOL> from . view_set_structure_handler import ViewSetStructureHandler <EOL> from . workbench_dock_window import WorkbenchDockWindow <EOL> logger = logging . getLogger ( __name__ ) <EOL> _POSITION_MAP = { <EOL> '<STR_LIT>' : DOCK_TOP , <EOL> '<STR_LIT>' : DOCK_BOTTOM , <EOL> '<STR_LIT:left>' : DOCK_LEFT , <EOL> '<STR_LIT:right>' : DOCK_RIGHT <EOL> } <EOL> class WorkbenchWindowLayout ( MWorkbenchWindowLayout ) : <EOL> """<STR_LIT>""" <EOL> editor_area_id = Delegate ( '<STR_LIT>' ) <EOL> def activate_editor ( self , editor ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_editor_dock_window . activate_control ( editor . id ) <EOL> editor . set_focus ( ) <EOL> return editor <EOL> def activate_view ( self , view ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_view_dock_window . activate_control ( view . id ) <EOL> view . set_focus ( ) <EOL> return view <EOL> def add_editor ( self , editor , title ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _wx_add_editor ( editor , title ) <EOL> except Exception : <EOL> logger . exception ( '<STR_LIT>' , editor . id ) <EOL> return editor <EOL> def add_view ( self , view , position = None , relative_to = None , size = ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _wx_add_view ( view , position , relative_to , size ) <EOL> view . visible = True <EOL> except Exception : <EOL> logger . exception ( '<STR_LIT>' , view . id ) <EOL> view . destroy_control ( ) <EOL> self . window . error ( '<STR_LIT>' % view . id ) <EOL> return view <EOL> def close_editor ( self , editor ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_editor_dock_window . close_control ( editor . id ) <EOL> return editor <EOL> def close_view ( self , view ) : <EOL> """<STR_LIT>""" <EOL> self . hide_view ( view ) <EOL> return view <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_editor_dock_window . close ( ) <EOL> self . _wx_view_dock_window . close ( ) <EOL> return <EOL> def create_initial_layout ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_view_dock_window = WorkbenchDockWindow ( parent ) <EOL> self . _wx_editor_dock_window = WorkbenchDockWindow ( <EOL> self . _wx_view_dock_window . control <EOL> ) <EOL> editor_dock_window_sizer = DockSizer ( contents = DockSection ( ) ) <EOL> self . _wx_editor_dock_window . control . SetSizer ( editor_dock_window_sizer ) <EOL> editor_dock_window_control = DockControl ( <EOL> id = self . editor_area_id , <EOL> name = '<STR_LIT>' , <EOL> control = self . _wx_editor_dock_window . control , <EOL> style = '<STR_LIT>' , <EOL> width = self . window . editor_area_size [ <NUM_LIT:0> ] , <EOL> height = self . window . editor_area_size [ <NUM_LIT:1> ] , <EOL> ) <EOL> view_dock_window_sizer = DockSizer ( <EOL> contents = [ editor_dock_window_control ] <EOL> ) <EOL> self . _wx_view_dock_window . control . SetSizer ( view_dock_window_sizer ) <EOL> return self . _wx_view_dock_window . control <EOL> def contains_view ( self , view ) : <EOL> """<STR_LIT>""" <EOL> view_control = self . _wx_view_dock_window . get_control ( view . id , False ) <EOL> return view_control is not None <EOL> def hide_editor_area ( self ) : <EOL> """<STR_LIT>""" <EOL> dock_control = self . _wx_view_dock_window . get_control ( <EOL> self . editor_area_id , visible_only = False <EOL> ) <EOL> dock_control . show ( False , layout = True ) <EOL> return <EOL> def hide_view ( self , view ) : <EOL> """<STR_LIT>""" <EOL> dock_control = self . _wx_view_dock_window . get_control ( <EOL> view . id , visible_only = False <EOL> ) <EOL> dock_control . show ( False , layout = True ) <EOL> view . visible = False <EOL> return view <EOL> def refresh ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_view_dock_window . update_layout ( ) <EOL> return <EOL> def reset_editors ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_editor_dock_window . reset_regions ( ) <EOL> return <EOL> def reset_views ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_view_dock_window . reset_regions ( ) <EOL> return <EOL> def show_editor_area ( self ) : <EOL> """<STR_LIT>""" <EOL> dock_control = self . _wx_view_dock_window . get_control ( <EOL> self . editor_area_id , visible_only = False <EOL> ) <EOL> dock_control . show ( True , layout = True ) <EOL> return <EOL> def show_view ( self , view ) : <EOL> """<STR_LIT>""" <EOL> dock_control = self . _wx_view_dock_window . get_control ( <EOL> view . id , visible_only = False <EOL> ) <EOL> dock_control . show ( True , layout = True ) <EOL> view . visible = True <EOL> return <EOL> def is_editor_area_visible ( self ) : <EOL> dock_control = self . _wx_view_dock_window . get_control ( <EOL> self . editor_area_id , visible_only = False <EOL> ) <EOL> return dock_control . visible <EOL> def get_view_memento ( self ) : <EOL> structure = self . _wx_view_dock_window . get_structure ( ) <EOL> return cPickle . loads ( cPickle . dumps ( structure ) ) <EOL> def set_view_memento ( self , memento ) : <EOL> memento = cPickle . loads ( cPickle . dumps ( memento ) ) <EOL> handler = ViewSetStructureHandler ( self ) <EOL> self . _wx_view_dock_window . set_structure ( memento , handler ) <EOL> for view in self . window . views : <EOL> control = self . _wx_view_dock_window . get_control ( view . id ) <EOL> if control is not None : <EOL> self . _wx_initialize_view_dock_control ( view , control ) <EOL> view . visible = control . visible <EOL> else : <EOL> view . visible = False <EOL> return <EOL> def get_editor_memento ( self ) : <EOL> structure = self . _wx_editor_dock_window . get_structure ( ) <EOL> editor_references = self . _get_editor_references ( ) <EOL> return ( structure , editor_references ) <EOL> def set_editor_memento ( self , memento ) : <EOL> structure , editor_references = memento <EOL> if len ( structure . contents ) > <NUM_LIT:0> : <EOL> handler = EditorSetStructureHandler ( self , editor_references ) <EOL> self . _wx_editor_dock_window . set_structure ( structure , handler ) <EOL> for editor in self . window . editors : <EOL> control = self . _wx_editor_dock_window . get_control ( editor . id ) <EOL> if control is not None : <EOL> self . _wx_initialize_editor_dock_control ( editor , control ) <EOL> return <EOL> def _wx_add_editor ( self , editor , title ) : <EOL> """<STR_LIT>""" <EOL> editor_dock_control = self . _wx_create_editor_dock_control ( editor ) <EOL> controls = self . _wx_editor_dock_window . get_controls ( ) <EOL> if len ( controls ) == <NUM_LIT:0> : <EOL> sizer = self . _wx_editor_dock_window . control . GetSizer ( ) <EOL> section = sizer . GetContents ( ) <EOL> region = DockRegion ( contents = [ editor_dock_control ] ) <EOL> section . contents = [ region ] <EOL> else : <EOL> region = controls [ <NUM_LIT:0> ] . parent <EOL> region . add ( editor_dock_control ) <EOL> self . _wx_editor_dock_window . update_layout ( ) <EOL> return <EOL> def _wx_add_view ( self , view , position , relative_to , size ) : <EOL> """<STR_LIT>""" <EOL> if position is None : <EOL> position = view . position <EOL> dock_control = self . _wx_create_view_dock_control ( view ) <EOL> if position == '<STR_LIT>' : <EOL> with_item = self . _wx_view_dock_window . get_control ( relative_to . id ) <EOL> if with_item is not None : <EOL> self . _wx_add_view_with ( dock_control , relative_to ) <EOL> else : <EOL> self . _wx_add_view_relative ( dock_control , None , '<STR_LIT:left>' , size ) <EOL> else : <EOL> self . _wx_add_view_relative ( dock_control , relative_to , position , size ) <EOL> return <EOL> def _wx_add_view_relative ( self , dock_control , relative_to , position , size ) : <EOL> """<STR_LIT>""" <EOL> if relative_to is None : <EOL> relative_to_item = self . _wx_view_dock_window . get_control ( <EOL> self . editor_area_id , visible_only = False <EOL> ) <EOL> else : <EOL> relative_to_item = self . _wx_view_dock_window . get_control ( <EOL> relative_to . id <EOL> ) <EOL> self . _wx_set_item_size ( dock_control , size ) <EOL> region = relative_to_item . parent <EOL> section = region . parent <EOL> section . add ( dock_control , region , _POSITION_MAP [ position ] ) <EOL> return <EOL> def _wx_add_view_with ( self , dock_control , with_obj ) : <EOL> """<STR_LIT>""" <EOL> with_item = self . _wx_view_dock_window . get_control ( with_obj . id ) <EOL> if with_item is None : <EOL> raise ValueError ( '<STR_LIT>' % with_obj ) <EOL> with_item . parent . add ( dock_control ) <EOL> return <EOL> def _wx_set_item_size ( self , dock_control , size ) : <EOL> """<STR_LIT>""" <EOL> window_width , window_height = self . window . control . GetSize ( ) <EOL> width , height = size <EOL> if width != - <NUM_LIT:1> : <EOL> dock_control . width = int ( window_width * width ) <EOL> if height != - <NUM_LIT:1> : <EOL> dock_control . height = int ( window_height * height ) <EOL> return <EOL> def _wx_create_editor_dock_control ( self , editor ) : <EOL> """<STR_LIT>""" <EOL> self . _wx_get_editor_control ( editor ) <EOL> editor_dock_control = DockControl ( <EOL> id = editor . id , <EOL> name = editor . name , <EOL> closeable = True , <EOL> control = editor . control , <EOL> style = '<STR_LIT>' , <EOL> _editor = editor <EOL> ) <EOL> self . _wx_initialize_editor_dock_control ( editor , editor_dock_control ) <EOL> return editor_dock_control <EOL> def _wx_create_view_dock_control ( self , view ) : <EOL> """<STR_LIT>""" <EOL> control = self . _wx_get_view_control ( view ) <EOL> closeable = view . closeable <EOL> view_dock_control = DockControl ( <EOL> id = view . id , <EOL> name = view . name , <EOL> closeable = closeable , <EOL> control = control , <EOL> style = view . style_hint , <EOL> _view = view <EOL> ) <EOL> self . _wx_initialize_view_dock_control ( view , view_dock_control ) <EOL> return view_dock_control <EOL> def _wx_get_editor_control ( self , editor ) : <EOL> """<STR_LIT>""" <EOL> if editor . control is None : <EOL> parent = self . _wx_editor_dock_window . control <EOL> self . editor_opening = editor <EOL> editor . control = editor . create_control ( parent ) <EOL> self . editor_opened = editor <EOL> self . _wx_initialize_editor_control ( editor ) <EOL> return editor . control <EOL> def _wx_initialize_editor_control ( self , editor ) : <EOL> """<STR_LIT>""" <EOL> def on_set_focus ( event ) : <EOL> """<STR_LIT>""" <EOL> editor . has_focus = True <EOL> event . Skip ( ) <EOL> return <EOL> def on_kill_focus ( event ) : <EOL> """<STR_LIT>""" <EOL> editor . has_focus = False <EOL> event . Skip ( ) <EOL> return <EOL> self . _wx_add_focus_listeners ( editor . control , on_set_focus , on_kill_focus ) <EOL> return <EOL> def _wx_get_view_control ( self , view ) : <EOL> """<STR_LIT>""" <EOL> if view . control is None : <EOL> parent = self . _wx_view_dock_window . control <EOL> view . window = self . window <EOL> self . view_opening = view <EOL> view . control = view . create_control ( parent ) <EOL> self . view_opened = view <EOL> self . _wx_initialize_view_control ( view ) <EOL> return view . control <EOL> def _wx_initialize_view_control ( self , view ) : <EOL> """<STR_LIT>""" <EOL> def on_set_focus ( event ) : <EOL> """<STR_LIT>""" <EOL> view . has_focus = True <EOL> event . Skip ( ) <EOL> return <EOL> def on_kill_focus ( event ) : <EOL> """<STR_LIT>""" <EOL> view . has_focus = False <EOL> event . Skip ( ) <EOL> return <EOL> self . _wx_add_focus_listeners ( view . control , on_set_focus , on_kill_focus ) <EOL> return <EOL> def _wx_add_focus_listeners ( self , control , on_set_focus , on_kill_focus ) : <EOL> """<STR_LIT>""" <EOL> if on_set_focus is not None : <EOL> wx . EVT_SET_FOCUS ( control , on_set_focus ) <EOL> if on_kill_focus is not None : <EOL> wx . EVT_KILL_FOCUS ( control , on_kill_focus ) <EOL> for child in control . GetChildren ( ) : <EOL> self . _wx_add_focus_listeners ( child , on_set_focus , on_kill_focus ) <EOL> return <EOL> def _wx_initialize_editor_dock_control ( self , editor , editor_dock_control ) : <EOL> """<STR_LIT>""" <EOL> editor_dock_control . set_name ( editor . name ) <EOL> if hasattr ( editor , '<STR_LIT>' ) and editor . ui is not None : <EOL> editor_dock_control . dockable = DockableViewElement ( <EOL> should_close = True , ui = editor . ui <EOL> ) <EOL> editor_dock_control . on_close = self . _wx_on_editor_closed <EOL> def on_id_changed ( editor , trait_name , old , new ) : <EOL> editor_dock_control . id = editor . id <EOL> return <EOL> editor . on_trait_change ( on_id_changed , '<STR_LIT:id>' ) <EOL> def on_name_changed ( editor , trait_name , old , new ) : <EOL> editor_dock_control . set_name ( editor . name ) <EOL> return <EOL> editor . on_trait_change ( on_name_changed , '<STR_LIT:name>' ) <EOL> def on_activated_changed ( editor_dock_control , trait_name , old , new ) : <EOL> if editor_dock_control . _editor is not None : <EOL> editor_dock_control . _editor . set_focus ( ) <EOL> return <EOL> editor_dock_control . on_trait_change ( on_activated_changed , '<STR_LIT>' ) <EOL> return <EOL> def _wx_initialize_view_dock_control ( self , view , view_dock_control ) : <EOL> """<STR_LIT>""" <EOL> view_dock_control . set_name ( view . name ) <EOL> if hasattr ( view , '<STR_LIT>' ) and view . ui is not None : <EOL> if view . ui . view is not None : <EOL> view_dock_control . export = view . ui . view . export <EOL> view_dock_control . dockable = DockableViewElement ( <EOL> should_close = True , ui = view . ui <EOL> ) <EOL> view_dock_control . on_close = self . _wx_on_view_closed <EOL> def on_id_changed ( view , trait_name , old , new ) : <EOL> view_dock_control . id = view . id <EOL> return <EOL> view . on_trait_change ( on_id_changed , '<STR_LIT:id>' ) <EOL> def on_name_changed ( view , trait_name , old , new ) : <EOL> view_dock_control . set_name ( view . name ) <EOL> return <EOL> view . on_trait_change ( on_name_changed , '<STR_LIT:name>' ) <EOL> def on_activated_changed ( view_dock_control , trait_name , old , new ) : <EOL> if view_dock_control . _view is not None : <EOL> view_dock_control . _view . set_focus ( ) <EOL> return <EOL> view_dock_control . on_trait_change ( on_activated_changed , '<STR_LIT>' ) <EOL> return <EOL> def _window_changed ( self , old , new ) : <EOL> """<STR_LIT>""" <EOL> if old is not None : <EOL> old . on_trait_change ( <EOL> self . _wx_on_editor_area_size_changed , '<STR_LIT>' , <EOL> remove = True <EOL> ) <EOL> if new is not None : <EOL> new . on_trait_change ( <EOL> self . _wx_on_editor_area_size_changed , '<STR_LIT>' , <EOL> ) <EOL> def _wx_on_editor_area_size_changed ( self , new ) : <EOL> """<STR_LIT>""" <EOL> window_width , window_height = self . window . control . GetSize ( ) <EOL> control = self . _wx_view_dock_window . get_control ( self . editor_area_id ) <EOL> region = control . parent <EOL> region . width = int ( new [ <NUM_LIT:0> ] * window_width ) <EOL> region . height = int ( new [ <NUM_LIT:1> ] * window_height ) <EOL> return <EOL> def _wx_on_view_closed ( self , dock_control , force ) : <EOL> """<STR_LIT>""" <EOL> view = self . window . get_view_by_id ( dock_control . id ) <EOL> if view is not None : <EOL> logger . debug ( '<STR_LIT>' , view ) <EOL> try : <EOL> view . visible = False <EOL> self . view_closing = view <EOL> view . destroy_control ( ) <EOL> self . view_closed = view <EOL> except : <EOL> logger . exception ( '<STR_LIT>' , view ) <EOL> return True <EOL> def _wx_on_editor_closed ( self , dock_control , force ) : <EOL> """<STR_LIT>""" <EOL> dock_control . _editor = None <EOL> editor = self . window . get_editor_by_id ( dock_control . id ) <EOL> if editor is not None : <EOL> logger . debug ( '<STR_LIT>' , editor ) <EOL> try : <EOL> self . editor_closing = editor <EOL> editor . destroy_control ( ) <EOL> self . editor_closed = editor <EOL> except : <EOL> logger . exception ( '<STR_LIT>' , editor ) <EOL> return True </s>
