<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import wx <EOL> from traits . api import Instance , Event , Str , Bool <EOL> from . image_resource import ImageResource <EOL> from . widget import Widget <EOL> from . util . font_helper import new_font_like <EOL> class ExpandableHeader ( Widget ) : <EOL> """<STR_LIT>""" <EOL> title = Str ( '<STR_LIT>' ) <EOL> collapsed_carat_image = Instance ( ImageResource , ImageResource ( '<STR_LIT>' ) ) <EOL> expanded_carat_image = Instance ( ImageResource , ImageResource ( '<STR_LIT>' ) ) <EOL> header_bar_image = Instance ( ImageResource , <EOL> ImageResource ( '<STR_LIT>' ) ) <EOL> header_mouseover_image = Instance ( ImageResource , <EOL> ImageResource ( '<STR_LIT>' ) ) <EOL> remove_image = Instance ( ImageResource , ImageResource ( '<STR_LIT>' ) ) <EOL> state = Bool ( False ) <EOL> panel_expanded = Event <EOL> _CARAT_X = <NUM_LIT:4> <EOL> _CARAT_Y = <NUM_LIT:2> <EOL> _TEXT_Y = <NUM_LIT:0> <EOL> _TEXT_X_OFFSET = <NUM_LIT:10> <EOL> def __init__ ( self , parent , container , ** traits ) : <EOL> """<STR_LIT>""" <EOL> super ( ExpandableHeader , self ) . __init__ ( ** traits ) <EOL> self . control = self . _create_control ( parent ) <EOL> self . _container = container <EOL> return <EOL> def _create_control ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> collapsed_carat = self . collapsed_carat_image . create_image ( ) <EOL> self . _collapsed_bmp = collapsed_carat . ConvertToBitmap ( ) <EOL> self . _carat_w = self . _collapsed_bmp . GetWidth ( ) <EOL> expanded_carat = self . expanded_carat_image . create_image ( ) <EOL> self . _expanded_bmp = expanded_carat . ConvertToBitmap ( ) <EOL> header_bar = self . header_bar_image . create_image ( ) <EOL> self . _header_bmp = header_bar . ConvertToBitmap ( ) <EOL> header_bar_over = self . header_mouseover_image . create_image ( ) <EOL> self . _header_mouseover_bmp = header_bar_over . ConvertToBitmap ( ) <EOL> self . _background_bmp = self . _header_bmp <EOL> close_image = self . remove_image . create_image ( ) <EOL> self . _remove_bmp = close_image . ConvertToBitmap ( ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> panel = wx . Panel ( parent , - <NUM_LIT:1> , style = wx . CLIP_CHILDREN ) <EOL> panel . SetSizer ( sizer ) <EOL> panel . SetAutoLayout ( True ) <EOL> panel . SetBackgroundStyle ( wx . BG_STYLE_CUSTOM ) <EOL> remove = wx . BitmapButton ( panel , - <NUM_LIT:1> , self . _remove_bmp , style = <NUM_LIT:0> , <EOL> pos = ( - <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> sizer . Add ( remove , <NUM_LIT:0> , wx . ALIGN_RIGHT , <NUM_LIT:5> ) <EOL> self . _font = new_font_like ( wx . NORMAL_FONT , <EOL> point_size = wx . NORMAL_FONT . GetPointSize ( ) - <NUM_LIT:1> ) <EOL> height = self . _get_preferred_height ( parent , self . title , self . _font ) <EOL> panel . SetSize ( ( - <NUM_LIT:1> , height ) ) <EOL> wx . EVT_ERASE_BACKGROUND ( panel , self . _on_erase_background ) <EOL> wx . EVT_ENTER_WINDOW ( panel , self . _on_enter_leave ) <EOL> wx . EVT_LEAVE_WINDOW ( panel , self . _on_enter_leave ) <EOL> wx . EVT_LEFT_DOWN ( panel , self . _on_down ) <EOL> wx . EVT_RIGHT_DOWN ( panel , self . _on_down ) <EOL> wx . EVT_BUTTON ( panel , remove . GetId ( ) , self . _on_remove ) <EOL> return panel <EOL> def _get_preferred_height ( self , parent , text , font ) : <EOL> """<STR_LIT>""" <EOL> dc = wx . MemoryDC ( ) <EOL> dc . SetFont ( font ) <EOL> text_w , text_h = dc . GetTextExtent ( text ) <EOL> text_h = text_h + self . _TEXT_Y <EOL> carat_h = self . _collapsed_bmp . GetHeight ( ) + self . _CARAT_Y <EOL> return max ( text_h , carat_h ) <EOL> def _draw_carat_button ( self , dc ) : <EOL> """<STR_LIT>""" <EOL> if self . state : <EOL> bmp = self . _expanded_bmp <EOL> else : <EOL> bmp = self . _collapsed_bmp <EOL> dc . DrawBitmap ( bmp , self . _CARAT_X , self . _CARAT_Y , True ) <EOL> return <EOL> def _tile_background_image ( self , dc , width , height ) : <EOL> """<STR_LIT>""" <EOL> w = self . _background_bmp . GetWidth ( ) <EOL> h = self . _background_bmp . GetHeight ( ) <EOL> x = <NUM_LIT:0> <EOL> while x < width : <EOL> y = <NUM_LIT:0> <EOL> while y < height : <EOL> dc . DrawBitmap ( self . _background_bmp , x , y ) <EOL> y = y + h <EOL> x = x + w <EOL> return <EOL> def _draw_title ( self , dc ) : <EOL> """<STR_LIT>""" <EOL> dc . SetFont ( self . _font ) <EOL> dc . DrawText ( self . title , self . _carat_w + self . _TEXT_X_OFFSET , <EOL> self . _TEXT_Y ) <EOL> def _draw ( self , dc ) : <EOL> """<STR_LIT>""" <EOL> size = self . control . GetClientSize ( ) <EOL> self . _tile_background_image ( dc , size . width , size . height ) <EOL> self . _draw_title ( dc ) <EOL> self . _draw_carat_button ( dc ) <EOL> return <EOL> def _on_erase_background ( self , event ) : <EOL> """<STR_LIT>""" <EOL> dc = event . GetDC ( ) <EOL> self . _draw ( dc ) <EOL> return <EOL> def _on_enter_leave ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . Entering ( ) : <EOL> self . _background_bmp = self . _header_mouseover_bmp <EOL> else : <EOL> self . _background_bmp = self . _header_bmp <EOL> self . control . Refresh ( ) <EOL> event . Skip ( ) <EOL> def _on_down ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . state = not self . state <EOL> self . control . Refresh ( ) <EOL> self . panel_expanded = self <EOL> event . Skip ( ) <EOL> def _on_remove ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . _container . remove_panel ( self . title ) </s>
