<s> """<STR_LIT>""" <EOL> import wx <EOL> import wx . html as wh <EOL> import re <EOL> from cgi import escape <EOL> from traits . api import Instance , Undefined <EOL> from traitsui . api import Group <EOL> from traitsui . undo import UndoHistory <EOL> from traitsui . dockable_view_element import DockableViewElement <EOL> from traitsui . help_template import help_template <EOL> from traitsui . menu import UndoButton , RevertButton , HelpButton <EOL> from pyface . dock . api import DockWindow , DockSizer , DockSection , DockRegion , DockControl <EOL> from pyface . sizers . flow import FlowSizer <EOL> from helper import position_window , TraitsUIPanel , TraitsUIScrolledPanel , GroupEditor <EOL> from constants import screen_dx , screen_dy , WindowColor <EOL> from ui_base import BaseDialog <EOL> from constants import is_mac <EOL> all_digits = re . compile ( r'<STR_LIT>' ) <EOL> emphasis_font = None <EOL> emphasis_color = wx . Colour ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) <EOL> def ui_panel ( ui , parent ) : <EOL> """<STR_LIT>""" <EOL> ui_panel_for ( ui , parent , True ) <EOL> def ui_subpanel ( ui , parent ) : <EOL> """<STR_LIT>""" <EOL> ui_panel_for ( ui , parent , False ) <EOL> def ui_panel_for ( ui , parent , buttons ) : <EOL> """<STR_LIT>""" <EOL> parent . Freeze ( ) <EOL> ui . control = control = Panel ( ui , parent , buttons ) . control <EOL> parent . Thaw ( ) <EOL> control . _parent = parent <EOL> control . _object = ui . context . get ( '<STR_LIT:object>' ) <EOL> control . _ui = ui <EOL> try : <EOL> ui . prepare_ui ( ) <EOL> except : <EOL> control . Destroy ( ) <EOL> ui . control = None <EOL> ui . result = False <EOL> raise <EOL> ui . restore_prefs ( ) <EOL> ui . result = True <EOL> class Panel ( BaseDialog ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ui , parent , allow_buttons ) : <EOL> """<STR_LIT>""" <EOL> self . ui = ui <EOL> history = None <EOL> view = ui . view <EOL> title = view . title <EOL> history = ui . history <EOL> if history is not None : <EOL> history . on_trait_change ( self . _on_undoable , <EOL> '<STR_LIT>' , remove = True ) <EOL> history . on_trait_change ( self . _on_redoable , <EOL> '<STR_LIT>' , remove = True ) <EOL> history . on_trait_change ( self . _on_revertable , <EOL> '<STR_LIT>' , remove = True ) <EOL> buttons = [ self . coerce_button ( button ) for button in view . buttons ] <EOL> nbuttons = len ( buttons ) <EOL> if nbuttons == <NUM_LIT:0> : <EOL> if view . undo : <EOL> self . check_button ( buttons , UndoButton ) <EOL> if view . revert : <EOL> self . check_button ( buttons , RevertButton ) <EOL> if view . help : <EOL> self . check_button ( buttons , HelpButton ) <EOL> if allow_buttons and ( history is None ) : <EOL> for button in buttons : <EOL> if ( self . is_button ( button , '<STR_LIT>' ) or <EOL> self . is_button ( button , '<STR_LIT>' ) ) : <EOL> history = UndoHistory ( ) <EOL> break <EOL> ui . history = history <EOL> cpanel = getattr ( self , '<STR_LIT>' , None ) <EOL> if cpanel is not None : <EOL> cpanel . SetSizer ( None ) <EOL> cpanel . DestroyChildren ( ) <EOL> else : <EOL> self . control = cpanel = TraitsUIPanel ( parent , - <NUM_LIT:1> ) <EOL> sw_sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> if ui . scrollable : <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> sw = TraitsUIScrolledPanel ( cpanel ) <EOL> sizer . Add ( panel ( ui , sw ) , <NUM_LIT:1> , wx . EXPAND ) <EOL> sw . SetSizerAndFit ( sizer ) <EOL> sw . SetScrollRate ( <NUM_LIT:16> , <NUM_LIT:16> ) <EOL> else : <EOL> sw = panel ( ui , cpanel ) <EOL> if ( ( title != '<STR_LIT>' ) and <EOL> ( not isinstance ( getattr ( parent , '<STR_LIT>' , None ) , DockWindow ) ) ) : <EOL> sw_sizer . Add ( heading_text ( cpanel , text = title ) . control , <NUM_LIT:0> , <EOL> wx . EXPAND ) <EOL> self . add_toolbar ( sw_sizer ) <EOL> sw_sizer . Add ( sw , <NUM_LIT:1> , wx . EXPAND ) <EOL> if ( allow_buttons and <EOL> ( ( nbuttons != <NUM_LIT:1> ) or ( not self . is_button ( buttons [ <NUM_LIT:0> ] , '<STR_LIT>' ) ) ) ) : <EOL> sw_sizer . Add ( wx . StaticLine ( cpanel , - <NUM_LIT:1> ) , <NUM_LIT:0> , wx . EXPAND ) <EOL> b_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> for button in buttons : <EOL> if self . is_button ( button , '<STR_LIT>' ) : <EOL> self . undo = self . add_button ( button , b_sizer , <EOL> self . _on_undo , False ) <EOL> self . redo = self . add_button ( button , b_sizer , <EOL> self . _on_redo , False , '<STR_LIT>' ) <EOL> history . on_trait_change ( self . _on_undoable , '<STR_LIT>' , <EOL> dispatch = '<STR_LIT>' ) <EOL> history . on_trait_change ( self . _on_redoable , '<STR_LIT>' , <EOL> dispatch = '<STR_LIT>' ) <EOL> elif self . is_button ( button , '<STR_LIT>' ) : <EOL> self . revert = self . add_button ( button , b_sizer , <EOL> self . _on_revert , False ) <EOL> history . on_trait_change ( self . _on_revertable , '<STR_LIT>' , <EOL> dispatch = '<STR_LIT>' ) <EOL> elif self . is_button ( button , '<STR_LIT>' ) : <EOL> self . add_button ( button , b_sizer , self . _on_help ) <EOL> elif not self . is_button ( button , '<STR_LIT>' ) : <EOL> self . add_button ( button , b_sizer ) <EOL> sw_sizer . Add ( b_sizer , <NUM_LIT:0> , wx . ALIGN_RIGHT | wx . ALL , <NUM_LIT:5> ) <EOL> cpanel . SetSizerAndFit ( sw_sizer ) <EOL> def _on_undo ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . ui . history . undo ( ) <EOL> def _on_redo ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . ui . history . redo ( ) <EOL> def _on_revert ( self , event ) : <EOL> """<STR_LIT>""" <EOL> ui = self . ui <EOL> ui . history . revert ( ) <EOL> ui . handler . revert ( ui . info ) <EOL> def _on_help ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . ui . handler . show_help ( self . ui . info , event . GetEventObject ( ) ) <EOL> def _on_undoable ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . undo . Enable ( state ) <EOL> def _on_redoable ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . redo . Enable ( state ) <EOL> def _on_revertable ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . revert . Enable ( state ) <EOL> def add_toolbar ( self , sizer ) : <EOL> """<STR_LIT>""" <EOL> toolbar = self . ui . view . toolbar <EOL> if toolbar is not None : <EOL> self . _last_group = self . _last_parent = None <EOL> sizer . Add ( toolbar . create_tool_bar ( self . control , self ) , <EOL> <NUM_LIT:0> , wx . EXPAND ) <EOL> self . _last_group = self . _last_parent = None <EOL> def panel ( ui , parent ) : <EOL> """<STR_LIT>""" <EOL> ui . info . bind_context ( ) <EOL> content = ui . _groups <EOL> if len ( content ) <= <NUM_LIT:1> : <EOL> panel = TraitsUIPanel ( parent , - <NUM_LIT:1> ) <EOL> if len ( content ) == <NUM_LIT:1> : <EOL> sg_sizer , resizable , contents = fill_panel_for_group ( panel , <EOL> content [ <NUM_LIT:0> ] , ui ) <EOL> sizer = panel . GetSizer ( ) <EOL> if sizer is not sg_sizer : <EOL> sizer . Add ( sg_sizer , <NUM_LIT:1> , wx . EXPAND ) <EOL> sizer . Fit ( panel ) <EOL> return panel <EOL> nb = create_notebook_for_items ( content , ui , parent , None ) <EOL> nb . ui = ui <EOL> return nb <EOL> def create_notebook_for_items ( content , ui , parent , group , <EOL> item_handler = None , is_dock_window = False ) : <EOL> """<STR_LIT>""" <EOL> if is_dock_window : <EOL> nb = parent <EOL> else : <EOL> dw = DockWindow ( parent , handler = ui . handler , <EOL> handler_args = ( ui . info , ) , <EOL> id = ui . id ) <EOL> if group is not None : <EOL> dw . theme = group . dock_theme <EOL> nb = dw . control <EOL> pages = [ ] <EOL> count = <NUM_LIT:0> <EOL> has_theme = ( ( group is not None ) and ( group . group_theme is not None ) ) <EOL> active = <NUM_LIT:0> <EOL> for index , item in enumerate ( content ) : <EOL> if isinstance ( item , Group ) : <EOL> if item . selected : <EOL> active = index <EOL> sg_sizer , resizable , contents = fill_panel_for_group ( nb , item , ui , suppress_label = True , <EOL> is_dock_window = True ) <EOL> if ( isinstance ( contents , DockRegion ) and <EOL> ( len ( contents . contents ) == <NUM_LIT:1> ) ) : <EOL> contents = contents . contents [ <NUM_LIT:0> ] <EOL> pages . append ( contents ) <EOL> else : <EOL> page_name = item . get_label ( ui ) <EOL> count += <NUM_LIT:1> <EOL> if page_name == '<STR_LIT>' : <EOL> page_name = '<STR_LIT>' % count <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> if has_theme : <EOL> image_panel , image_sizer = add_image_panel ( nb , group ) <EOL> panel = image_panel . control <EOL> image_sizer . Add ( sizer , <NUM_LIT:1> , wx . EXPAND ) <EOL> else : <EOL> panel = TraitsUIPanel ( nb , - <NUM_LIT:1> ) <EOL> panel . SetSizer ( sizer ) <EOL> pages . append ( DockControl ( name = page_name , <EOL> image = item . image , <EOL> id = item . get_id ( ) , <EOL> style = item . dock , <EOL> dockable = DockableViewElement ( <EOL> ui = ui , element = item ) , <EOL> export = item . export , <EOL> control = panel ) ) <EOL> item_handler ( item , panel , sizer ) <EOL> panel . GetSizer ( ) . Fit ( panel ) <EOL> region = DockRegion ( contents = pages , active = active ) <EOL> if is_dock_window : <EOL> return region <EOL> nb . SetSizer ( DockSizer ( contents = DockSection ( contents = [ region ] ) ) ) <EOL> return nb <EOL> def add_image_panel ( window , group ) : <EOL> """<STR_LIT>""" <EOL> from image_panel import ImagePanel <EOL> image_panel = ImagePanel ( theme = group . group_theme , text = group . label ) <EOL> panel = image_panel . create_control ( window ) <EOL> return ( image_panel , panel . GetSizer ( ) ) <EOL> def _page_changed ( event ) : <EOL> nb = event . GetEventObject ( ) <EOL> nb . ui . _active_group = event . GetSelection ( ) <EOL> def show_help ( ui , button ) : <EOL> """<STR_LIT>""" <EOL> group = ui . _groups [ ui . _active_group ] <EOL> template = help_template ( ) <EOL> if group . help != '<STR_LIT>' : <EOL> header = template . group_help % escape ( group . help ) <EOL> else : <EOL> header = template . no_group_help <EOL> fields = [ ] <EOL> for item in group . get_content ( False ) : <EOL> if not item . is_spacer ( ) : <EOL> fields . append ( template . item_help % ( <EOL> escape ( item . get_label ( ui ) ) , <EOL> escape ( item . get_help ( ui ) ) ) ) <EOL> html = template . group_html % ( header , '<STR_LIT:\n>' . join ( fields ) ) <EOL> HTMLHelpWindow ( button , html , <NUM_LIT> , <NUM_LIT> ) <EOL> def show_help_popup ( event ) : <EOL> """<STR_LIT>""" <EOL> control = event . GetEventObject ( ) <EOL> template = help_template ( ) <EOL> help = getattr ( control , '<STR_LIT>' , None ) <EOL> if help is not None : <EOL> html = template . item_html % ( control . GetLabel ( ) , help ) <EOL> HTMLHelpWindow ( control , html , <NUM_LIT> , <NUM_LIT> ) <EOL> def fill_panel_for_group ( panel , group , ui , suppress_label = False , <EOL> is_dock_window = False , create_panel = False ) : <EOL> """<STR_LIT>""" <EOL> fp = FillPanel ( panel , group , ui , suppress_label , is_dock_window , <EOL> create_panel ) <EOL> return ( fp . control or fp . sizer , fp . resizable , fp . dock_contents ) <EOL> class FillPanel ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , panel , group , ui , suppress_label , is_dock_window , <EOL> create_panel ) : <EOL> """<STR_LIT>""" <EOL> content = group . get_content ( ) <EOL> self . control = self . sizer = editor = None <EOL> self . ui = ui <EOL> self . group = group <EOL> self . is_horizontal = ( group . orientation == '<STR_LIT>' ) <EOL> layout = group . layout <EOL> is_scrolled_panel = group . scrollable <EOL> is_splitter = ( layout == '<STR_LIT>' ) <EOL> is_tabbed = ( layout == '<STR_LIT>' ) <EOL> id = group . id <EOL> self . resizable = False <EOL> if is_dock_window and ( is_splitter or is_tabbed ) : <EOL> if is_splitter : <EOL> self . dock_contents = self . add_dock_window_splitter_items ( <EOL> panel , content , group ) <EOL> else : <EOL> self . resizable = group . springy <EOL> self . dock_contents = create_notebook_for_items ( content , ui , <EOL> panel , group , self . add_notebook_item , True ) <EOL> return <EOL> theme = group . group_theme <EOL> if ( is_dock_window or <EOL> create_panel or <EOL> is_scrolled_panel or <EOL> ( id != '<STR_LIT>' ) or <EOL> ( theme is not None ) or <EOL> ( group . visible_when != '<STR_LIT>' ) or <EOL> ( group . enabled_when != '<STR_LIT>' ) ) : <EOL> if theme is not None : <EOL> image_panel , image_sizer = add_image_panel ( panel , group ) <EOL> new_panel = image_panel . control <EOL> suppress_label |= image_panel . can_show_text <EOL> elif is_scrolled_panel : <EOL> new_panel = TraitsUIScrolledPanel ( panel ) <EOL> new_panel . SetMinSize ( panel . GetMinSize ( ) ) <EOL> self . resizable = True <EOL> else : <EOL> new_panel = TraitsUIPanel ( panel , - <NUM_LIT:1> ) <EOL> sizer = panel . GetSizer ( ) <EOL> if sizer is None : <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> panel . SetSizer ( sizer ) <EOL> self . control = panel = new_panel <EOL> if is_splitter or is_tabbed : <EOL> editor = DockWindowGroupEditor ( control = panel , ui = ui ) <EOL> else : <EOL> editor = GroupEditor ( control = panel ) <EOL> if id != '<STR_LIT>' : <EOL> ui . info . bind ( group . id , editor ) <EOL> if group . visible_when != '<STR_LIT>' : <EOL> ui . add_visible ( group . visible_when , editor ) <EOL> if group . enabled_when != '<STR_LIT>' : <EOL> ui . add_enabled ( group . enabled_when , editor ) <EOL> self . panel = panel <EOL> self . dock_contents = None <EOL> if self . is_horizontal : <EOL> orientation = wx . HORIZONTAL <EOL> else : <EOL> orientation = wx . VERTICAL <EOL> label = '<STR_LIT>' <EOL> if not suppress_label : <EOL> label = group . label <EOL> if group . show_border : <EOL> box = wx . StaticBox ( panel , - <NUM_LIT:1> , label ) <EOL> self . _set_owner ( box , group ) <EOL> self . sizer = wx . StaticBoxSizer ( box , orientation ) <EOL> else : <EOL> if layout == '<STR_LIT>' : <EOL> self . sizer = FlowSizer ( orientation ) <EOL> else : <EOL> self . sizer = wx . BoxSizer ( orientation ) <EOL> if label != '<STR_LIT>' : <EOL> self . sizer . Add ( heading_text ( panel , text = label ) . control , <EOL> <NUM_LIT:0> , wx . EXPAND | wx . LEFT | wx . TOP | wx . RIGHT , <NUM_LIT:4> ) <EOL> if panel . GetSizer ( ) is None : <EOL> panel . SetSizer ( self . sizer ) <EOL> if is_scrolled_panel : <EOL> if self . is_horizontal : <EOL> panel . SetupScrolling ( scroll_y = False ) <EOL> else : <EOL> panel . SetupScrolling ( scroll_x = False ) <EOL> if is_splitter : <EOL> dw = DockWindow ( panel , handler = ui . handler , <EOL> handler_args = ( ui . info , ) , <EOL> id = ui . id , <EOL> theme = group . dock_theme ) . control <EOL> if editor is not None : <EOL> editor . dock_window = dw <EOL> dw . SetSizer ( DockSizer ( contents = <EOL> self . add_dock_window_splitter_items ( dw , content , group ) ) ) <EOL> self . sizer . Add ( dw , <NUM_LIT:1> , wx . EXPAND ) <EOL> elif len ( content ) > <NUM_LIT:0> : <EOL> if is_tabbed : <EOL> self . resizable = group . springy <EOL> dw = create_notebook_for_items ( content , ui , panel , group , <EOL> self . add_notebook_item ) <EOL> if editor is not None : <EOL> editor . dock_window = dw <EOL> self . sizer . Add ( dw , self . resizable , wx . EXPAND ) <EOL> elif layout == '<STR_LIT>' : <EOL> self . resizable = True <EOL> self . sizer . Add ( self . create_fold_for_items ( panel , content ) , <EOL> <NUM_LIT:1> , wx . EXPAND ) <EOL> elif isinstance ( content [ <NUM_LIT:0> ] , Group ) : <EOL> self . add_groups ( content , panel ) <EOL> else : <EOL> self . add_items ( content , panel , self . sizer ) <EOL> if is_dock_window : <EOL> self . dock_contents = DockRegion ( contents = [ <EOL> DockControl ( name = group . get_label ( self . ui ) , <EOL> image = group . image , <EOL> id = group . get_id ( ) , <EOL> style = group . dock , <EOL> dockable = DockableViewElement ( <EOL> ui = ui , element = group ) , <EOL> export = group . export , <EOL> control = panel ) ] ) <EOL> if theme is not None : <EOL> image_sizer . Add ( self . sizer , <NUM_LIT:1> , wx . EXPAND ) <EOL> def add_dock_window_splitter_items ( self , window , content , group ) : <EOL> """<STR_LIT>""" <EOL> contents = [ self . add_dock_window_splitter_item ( window , item , group ) <EOL> for item in content ] <EOL> result = DockSection ( contents = contents , is_row = self . is_horizontal ) <EOL> if not self . resizable : <EOL> for item in result . get_controls ( ) : <EOL> item . resizable = False <EOL> return result <EOL> def add_dock_window_splitter_item ( self , window , item , group ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( item , Group ) : <EOL> sizer , resizable , contents = fill_panel_for_group ( window , <EOL> item , self . ui , suppress_label = True , is_dock_window = True ) <EOL> self . resizable |= resizable <EOL> return contents <EOL> orientation = wx . VERTICAL <EOL> if self . is_horizontal : <EOL> orientation = wx . HORIZONTAL <EOL> sizer = wx . BoxSizer ( orientation ) <EOL> if group . group_theme is not None : <EOL> image_panel , image_sizer = add_image_panel ( window , group ) <EOL> panel = image_panel . control <EOL> image_sizer . Add ( sizer , <NUM_LIT:1> , wx . EXPAND ) <EOL> else : <EOL> panel = TraitsUIPanel ( window , - <NUM_LIT:1> ) <EOL> panel . SetSizer ( sizer ) <EOL> self . add_items ( [ item ] , panel , sizer ) <EOL> return DockRegion ( contents = [ <EOL> DockControl ( name = item . get_label ( self . ui ) , <EOL> image = item . image , <EOL> id = item . get_id ( ) , <EOL> style = item . dock , <EOL> dockable = DockableViewElement ( <EOL> ui = self . ui , element = item ) , <EOL> export = item . export , <EOL> control = panel ) ] ) <EOL> def create_fold_for_items ( self , window , content ) : <EOL> """<STR_LIT>""" <EOL> from themed_vertical_notebook import ThemedVerticalNotebook <EOL> nb = ThemedVerticalNotebook ( scrollable = True ) <EOL> result = nb . create_control ( window ) <EOL> nb . pages = [ self . create_fold_for_item ( nb , item ) for item in content ] <EOL> return result <EOL> def create_fold_for_item ( self , notebook , item ) : <EOL> """<STR_LIT>""" <EOL> page = notebook . create_page ( ) <EOL> if isinstance ( item , Group ) : <EOL> panel , resizable , contents = fill_panel_for_group ( page . parent , <EOL> item , self . ui , suppress_label = True , create_panel = True ) <EOL> else : <EOL> panel = TraitsUIPanel ( page . parent , - <NUM_LIT:1> ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> panel . SetSizer ( sizer ) <EOL> self . add_items ( [ item ] , panel , sizer ) <EOL> page . name = item . get_label ( self . ui ) <EOL> page . control = panel <EOL> return page <EOL> def add_notebook_item ( self , item , parent , sizer ) : <EOL> """<STR_LIT>""" <EOL> self . add_items ( [ item ] , parent , sizer ) <EOL> def add_groups ( self , content , panel ) : <EOL> """<STR_LIT>""" <EOL> sizer = self . sizer <EOL> for subgroup in content : <EOL> sg_sizer , sg_resizable , contents = fill_panel_for_group ( panel , subgroup , self . ui ) <EOL> if sg_resizable : <EOL> self . resizable = True <EOL> sizer . Add ( sg_sizer , <NUM_LIT:1> , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> else : <EOL> style = wx . EXPAND | wx . ALL <EOL> growable = <NUM_LIT:0> <EOL> if self . is_horizontal : <EOL> if subgroup . springy : <EOL> growable = <NUM_LIT:1> <EOL> if subgroup . orientation == '<STR_LIT>' : <EOL> style |= wx . ALIGN_CENTER_VERTICAL <EOL> sizer . Add ( sg_sizer , growable , style , <NUM_LIT:2> ) <EOL> def add_items ( self , content , panel , sizer ) : <EOL> """<STR_LIT>""" <EOL> ui = self . ui <EOL> info = ui . info <EOL> handler = ui . handler <EOL> group = self . group <EOL> show_left = group . show_left <EOL> padding = group . padding <EOL> col = - <NUM_LIT:1> <EOL> col_incr = <NUM_LIT:1> <EOL> self . label_flags = <NUM_LIT:0> <EOL> show_labels = False <EOL> for item in content : <EOL> show_labels |= item . show_label <EOL> if ( not self . is_horizontal ) and ( show_labels or ( group . columns > <NUM_LIT:1> ) ) : <EOL> self . label_pad = <NUM_LIT:0> <EOL> cols = group . columns <EOL> if show_labels : <EOL> cols *= <NUM_LIT:2> <EOL> col_incr = <NUM_LIT:2> <EOL> flags = wx . TOP | wx . BOTTOM <EOL> border_size = <NUM_LIT:1> <EOL> item_sizer = wx . FlexGridSizer ( <NUM_LIT:0> , cols , <NUM_LIT:0> , <NUM_LIT:5> ) <EOL> if show_left : <EOL> self . label_flags = wx . ALIGN_RIGHT <EOL> if show_labels : <EOL> for i in range ( <NUM_LIT:1> , cols , <NUM_LIT:2> ) : <EOL> item_sizer . AddGrowableCol ( i ) <EOL> else : <EOL> self . label_pad = <NUM_LIT:4> <EOL> cols = <NUM_LIT:1> <EOL> flags = wx . ALL <EOL> border_size = <NUM_LIT:1> <EOL> item_sizer = sizer <EOL> for item in content : <EOL> theme = item . item_theme <EOL> name = item . name <EOL> if name == '<STR_LIT>' : <EOL> label = item . label <EOL> if label != '<STR_LIT>' : <EOL> col += col_incr <EOL> if ( cols > <NUM_LIT:1> ) and show_labels : <EOL> item_sizer . Add ( ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> if theme is not None : <EOL> from image_text import ImageText <EOL> label = ImageText ( panel , theme , label ) <EOL> item_sizer . Add ( label , <NUM_LIT:0> , wx . EXPAND ) <EOL> elif item . style == '<STR_LIT>' : <EOL> label = wx . StaticText ( panel , - <NUM_LIT:1> , label , <EOL> style = wx . ALIGN_LEFT ) <EOL> item_sizer . Add ( label , <NUM_LIT:0> , wx . EXPAND ) <EOL> else : <EOL> label = heading_text ( panel , text = label ) . control <EOL> item_sizer . Add ( label , <NUM_LIT:0> , <EOL> wx . TOP | wx . BOTTOM | wx . EXPAND , <NUM_LIT:3> ) <EOL> if item . emphasized : <EOL> self . _add_emphasis ( label ) <EOL> continue <EOL> col += col_incr <EOL> if name == '<STR_LIT:_>' : <EOL> for i in range ( cols ) : <EOL> if self . is_horizontal : <EOL> line = wx . StaticLine ( panel , - <NUM_LIT:1> , <EOL> style = wx . LI_VERTICAL ) <EOL> item_sizer . Add ( line , <NUM_LIT:0> , <EOL> wx . LEFT | wx . RIGHT | wx . EXPAND , <NUM_LIT:2> ) <EOL> else : <EOL> line = wx . StaticLine ( panel , - <NUM_LIT:1> , <EOL> style = wx . LI_HORIZONTAL ) <EOL> item_sizer . Add ( line , <NUM_LIT:0> , <EOL> wx . TOP | wx . BOTTOM | wx . EXPAND , <NUM_LIT:2> ) <EOL> self . _set_owner ( line , item ) <EOL> continue <EOL> if name == '<STR_LIT:U+0020>' : <EOL> name = '<STR_LIT:5>' <EOL> if all_digits . match ( name ) : <EOL> n = int ( name ) <EOL> if self . is_horizontal : <EOL> item_sizer . Add ( ( n , <NUM_LIT:1> ) ) <EOL> else : <EOL> spacer = ( <NUM_LIT:1> , n ) <EOL> item_sizer . Add ( spacer ) <EOL> if show_labels : <EOL> item_sizer . Add ( spacer ) <EOL> continue <EOL> object = eval ( item . object_ , globals ( ) , ui . context ) <EOL> trait = object . base_trait ( name ) <EOL> desc = trait . desc or '<STR_LIT>' <EOL> label = None <EOL> if show_left : <EOL> if item . show_label : <EOL> label = self . create_label ( item , ui , desc , panel , <EOL> item_sizer , <EOL> border = group . show_border ) <EOL> elif ( cols > <NUM_LIT:1> ) and show_labels : <EOL> label = self . dummy_label ( panel , item_sizer ) <EOL> editor_factory = item . editor <EOL> if editor_factory is None : <EOL> editor_factory = trait . get_editor ( ) <EOL> if editor_factory is None : <EOL> from text_editor import ToolkitEditorFactory <EOL> editor_factory = ToolkitEditorFactory ( ) <EOL> if item . format_func is not None : <EOL> editor_factory . format_func = item . format_func <EOL> if item . format_str != '<STR_LIT>' : <EOL> editor_factory . format_str = item . format_str <EOL> if item . invalid != '<STR_LIT>' : <EOL> editor_factory . invalid = item . invalid <EOL> item_panel = panel <EOL> if theme is not None : <EOL> from image_panel import ImagePanel <EOL> text = '<STR_LIT>' <EOL> if item . show_label : <EOL> text = item . get_label ( ui ) <EOL> image_panel = ImagePanel ( theme = theme , text = text ) <EOL> item_panel = image_panel . create_control ( panel ) <EOL> factory_method = getattr ( editor_factory , item . style + '<STR_LIT>' ) <EOL> editor = factory_method ( ui , object , name , item . tooltip , <EOL> item_panel ) . set ( <EOL> item = item , <EOL> object_name = item . object ) <EOL> editor . prepare ( item_panel ) <EOL> editor . enabled = editor_factory . enabled <EOL> if item . emphasized : <EOL> self . _add_emphasis ( editor . control ) <EOL> if item . has_focus : <EOL> editor . control . SetFocus ( ) <EOL> border_size = min ( border_size , editor . border_size ) <EOL> control = editor . control <EOL> if theme is None : <EOL> width , height = control . GetSizeTuple ( ) <EOL> else : <EOL> item_panel . GetSizer ( ) . Add ( control , <NUM_LIT:1> , wx . EXPAND ) <EOL> control = item_panel <EOL> width , height = image_panel . adjusted_size <EOL> scrollable = editor . scrollable <EOL> item_width = item . width <EOL> item_height = item . height <EOL> growable = <NUM_LIT:0> <EOL> if ( item_width != - <NUM_LIT:1.0> ) or ( item_height != - <NUM_LIT:1.0> ) : <EOL> if ( <NUM_LIT:0.0> < item_width <= <NUM_LIT:1.0> ) and self . is_horizontal : <EOL> growable = int ( <NUM_LIT> * item_width ) <EOL> item_width = - <NUM_LIT:1> <EOL> item_width = int ( item_width ) <EOL> if item_width < - <NUM_LIT:1> : <EOL> item_width = - item_width <EOL> elif item_width != - <NUM_LIT:1> : <EOL> item_width = max ( item_width , width ) <EOL> if ( <NUM_LIT:0.0> < item_height <= <NUM_LIT:1.0> ) and ( not self . is_horizontal ) : <EOL> growable = int ( <NUM_LIT> * item_height ) <EOL> item_height = - <NUM_LIT:1> <EOL> item_height = int ( item_height ) <EOL> if item_height < - <NUM_LIT:1> : <EOL> item_height = - item_height <EOL> elif item_height != - <NUM_LIT:1> : <EOL> item_height = max ( item_height , height ) <EOL> control . SetMinSize ( wx . Size ( item_width , item_height ) ) <EOL> self . _set_owner ( control , item ) <EOL> id = item . id or name <EOL> info . bind ( id , editor , item . id ) <EOL> ui . _editors . append ( editor ) <EOL> defined = getattr ( handler , id + '<STR_LIT>' , None ) <EOL> if defined is not None : <EOL> ui . add_defined ( defined ) <EOL> if item . visible_when != '<STR_LIT>' : <EOL> ui . add_visible ( item . visible_when , editor ) <EOL> if item . enabled_when != '<STR_LIT>' : <EOL> ui . add_enabled ( item . enabled_when , editor ) <EOL> ui . _scrollable |= scrollable <EOL> item_resizable = ( ( item . resizable is True ) or <EOL> ( ( item . resizable is Undefined ) and scrollable ) ) <EOL> if item_resizable : <EOL> growable = growable or <NUM_LIT> <EOL> self . resizable = True <EOL> elif item . springy : <EOL> growable = growable or <NUM_LIT> <EOL> layout_style = editor . layout_style <EOL> if not show_labels : <EOL> layout_style |= wx . EXPAND <EOL> item_sizer . Add ( control , growable , <EOL> flags | layout_style | wx . ALIGN_CENTER_VERTICAL , <EOL> max ( <NUM_LIT:0> , border_size + padding + item . padding ) ) <EOL> if not show_left : <EOL> if item . show_label : <EOL> label = self . create_label ( item , ui , desc , panel , <EOL> item_sizer , '<STR_LIT>' , wx . RIGHT ) <EOL> elif ( cols > <NUM_LIT:1> ) and show_labels : <EOL> label = self . dummy_label ( panel , item_sizer ) <EOL> if item_resizable and ( cols > <NUM_LIT:1> ) : <EOL> item_sizer . AddGrowableRow ( col / cols ) <EOL> editor . label_control = label <EOL> if item_sizer is not sizer : <EOL> growable = <NUM_LIT:0> <EOL> if self . resizable : <EOL> growable = <NUM_LIT:1> <EOL> sizer . Add ( item_sizer , growable , wx . EXPAND | wx . ALL , <NUM_LIT:2> ) <EOL> def create_label ( self , item , ui , desc , parent , sizer , suffix = '<STR_LIT::>' , <EOL> pad_side = wx . LEFT , border = False ) : <EOL> """<STR_LIT>""" <EOL> from image_text import ImageText <EOL> label = item . get_label ( ui ) <EOL> if ( label == '<STR_LIT>' ) or ( label [ - <NUM_LIT:1> : ] in '<STR_LIT>' ) : <EOL> suffix = '<STR_LIT>' <EOL> control = ImageText ( parent , item . label_theme , label + suffix , <EOL> border = border ) <EOL> self . _set_owner ( control , item ) <EOL> if item . emphasized : <EOL> self . _add_emphasis ( control ) <EOL> control . help = item . get_help ( ui ) <EOL> sizer . Add ( control , <NUM_LIT:0> , self . label_flags | wx . ALIGN_CENTER_VERTICAL | <EOL> pad_side , self . label_pad ) <EOL> if desc != '<STR_LIT>' : <EOL> control . SetToolTipString ( '<STR_LIT>' + desc ) <EOL> return control <EOL> def dummy_label ( self , parent , sizer ) : <EOL> """<STR_LIT>""" <EOL> control = wx . StaticText ( parent , - <NUM_LIT:1> , '<STR_LIT>' , style = wx . ALIGN_RIGHT ) <EOL> sizer . Add ( control , <NUM_LIT:0> ) <EOL> return control <EOL> def _add_emphasis ( self , control ) : <EOL> """<STR_LIT>""" <EOL> global emphasis_font <EOL> control . SetForegroundColour ( emphasis_color ) <EOL> if emphasis_font is None : <EOL> font = control . GetFont ( ) <EOL> emphasis_font = wx . Font ( font . GetPointSize ( ) + <NUM_LIT:1> , <EOL> font . GetFamily ( ) , <EOL> font . GetStyle ( ) , <EOL> wx . BOLD ) <EOL> control . SetFont ( emphasis_font ) <EOL> def _set_owner ( self , control , owner ) : <EOL> control . _owner = owner <EOL> for child in control . GetChildren ( ) : <EOL> self . _set_owner ( child , owner ) <EOL> class DockWindowGroupEditor ( GroupEditor ) : <EOL> """<STR_LIT>""" <EOL> dock_window = Instance ( wx . Window ) <EOL> def restore_prefs ( self , prefs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( prefs , dict ) : <EOL> structure = prefs . get ( '<STR_LIT>' ) <EOL> else : <EOL> structure = prefs <EOL> self . dock_window . GetSizer ( ) . SetStructure ( self . dock_window , structure ) <EOL> self . dock_window . Layout ( ) <EOL> def save_prefs ( self ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT>' : self . dock_window . GetSizer ( ) . GetStructure ( ) } <EOL> class HTMLHelpWindow ( wx . Frame ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , html , scale_dx , scale_dy ) : <EOL> """<STR_LIT>""" <EOL> wx . Frame . __init__ ( self , parent , - <NUM_LIT:1> , '<STR_LIT>' , style = wx . SIMPLE_BORDER ) <EOL> self . SetBackgroundColour ( WindowColor ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> html_control = wh . HtmlWindow ( self ) <EOL> html_control . SetBorders ( <NUM_LIT:2> ) <EOL> html_control . SetPage ( html ) <EOL> sizer . Add ( html_control , <NUM_LIT:1> , wx . EXPAND ) <EOL> sizer . Add ( wx . StaticLine ( self , - <NUM_LIT:1> ) , <NUM_LIT:0> , wx . EXPAND ) <EOL> b_sizer = wx . BoxSizer ( wx . HORIZONTAL ) <EOL> button = wx . Button ( self , - <NUM_LIT:1> , '<STR_LIT:OK>' ) <EOL> wx . EVT_BUTTON ( self , button . GetId ( ) , self . _on_ok ) <EOL> b_sizer . Add ( button , <NUM_LIT:0> ) <EOL> sizer . Add ( b_sizer , <NUM_LIT:0> , wx . ALIGN_RIGHT | wx . ALL , <NUM_LIT:5> ) <EOL> self . SetSizer ( sizer ) <EOL> self . SetSize ( wx . Size ( int ( scale_dx * screen_dx ) , <EOL> int ( scale_dy * screen_dy ) ) ) <EOL> position_window ( self , parent = parent ) <EOL> self . Show ( ) <EOL> def _on_ok ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . Destroy ( ) <EOL> HeadingText = None <EOL> def heading_text ( * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> global HeadingText <EOL> if HeadingText is None : <EOL> from pyface . heading_text import HeadingText <EOL> return HeadingText ( * args , ** kw ) </s>
