<s> """<STR_LIT>""" <EOL> import wx <EOL> from image_slice import paint_parent <EOL> from helper import BufferDC <EOL> class ImageText ( wx . PyWindow ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent , theme , text = '<STR_LIT>' , border = False ) : <EOL> """<STR_LIT>""" <EOL> self . _theme = theme <EOL> self . _border = border <EOL> if theme is not None : <EOL> self . _image_slice = theme . image_slice <EOL> super ( ImageText , self ) . __init__ ( parent , - <NUM_LIT:1> , <EOL> style = wx . FULL_REPAINT_ON_RESIZE ) <EOL> self . _text_size = None <EOL> self . _text = text <EOL> wx . EVT_ERASE_BACKGROUND ( self , self . _erase_background ) <EOL> wx . EVT_PAINT ( self , self . _on_paint ) <EOL> size = self . GetMinSize ( ) <EOL> self . SetMinSize ( size ) <EOL> self . SetSize ( size ) <EOL> def AcceptsFocus ( self ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def _erase_background ( self , event ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _on_paint ( self , event ) : <EOL> """<STR_LIT>""" <EOL> dc = BufferDC ( self ) <EOL> paint_parent ( dc , self ) <EOL> if self . _theme is not None : <EOL> wdx , wdy = self . GetClientSize ( ) <EOL> self . _image_slice . fill ( dc , <NUM_LIT:0> , <NUM_LIT:0> , wdx , wdy , True ) <EOL> dc . SetTextForeground ( self . _image_slice . content_color ) <EOL> dc . SetBackgroundMode ( wx . TRANSPARENT ) <EOL> dc . SetFont ( self . GetFont ( ) ) <EOL> tx , ty , tdx , tdy = self . _get_text_bounds ( ) <EOL> dc . DrawText ( self . _text , tx , ty ) <EOL> dc . copy ( ) <EOL> def GetMinSize ( self ) : <EOL> """<STR_LIT>""" <EOL> tdx , tdy , descent , leading = self . _get_text_size ( ) <EOL> if self . _theme is None : <EOL> return wx . Size ( tdx + <NUM_LIT:8> , tdy + <NUM_LIT:4> ) <EOL> content = self . _theme . content <EOL> tdx += ( content . left + content . right ) <EOL> tdy += ( content . top + content . bottom ) <EOL> slice = self . _image_slice <EOL> return wx . Size ( max ( slice . left + slice . right , <EOL> slice . xleft + slice . xright + tdx + <NUM_LIT:8> ) , <EOL> max ( slice . top + slice . bottom , <EOL> slice . xtop + slice . xbottom + tdy + <NUM_LIT:4> ) ) <EOL> def SetFont ( self , font ) : <EOL> """<STR_LIT>""" <EOL> super ( ImageText , self ) . SetFont ( font ) <EOL> self . _refresh ( ) <EOL> def SetLabel ( self , label ) : <EOL> """<STR_LIT>""" <EOL> self . _text = label <EOL> self . _refresh ( ) <EOL> def _refresh ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _text_size is not None : <EOL> self . RefreshRect ( wx . Rect ( * self . _get_text_bounds ( ) ) , False ) <EOL> self . _text_size = None <EOL> self . SetMinSize ( self . GetMinSize ( ) ) <EOL> self . RefreshRect ( wx . Rect ( * self . _get_text_bounds ( ) ) , False ) <EOL> def _get_text_size ( self , text = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _text_size is None : <EOL> if text is None : <EOL> text = self . _text <EOL> if text . strip ( ) == '<STR_LIT>' : <EOL> text = '<STR_LIT:M>' <EOL> self . _text_size = self . GetFullTextExtent ( text ) <EOL> return self . _text_size <EOL> def _get_text_bounds ( self ) : <EOL> """<STR_LIT>""" <EOL> tdx , tdy , descent , leading = self . _get_text_size ( ) <EOL> wdx , wdy = self . GetClientSize ( ) <EOL> theme = self . _theme <EOL> if theme is None : <EOL> return ( wdx - tdx , ( wdy - tdy ) / <NUM_LIT:2> , tdx , tdy ) <EOL> slice = self . _image_slice <EOL> content = theme . content <EOL> ady = wdy - slice . xtop - slice . xbottom <EOL> ty = ( wdy + slice . xtop + content . top - slice . xtop - <EOL> slice . xbottom - tdy ) / <NUM_LIT:2> <EOL> alignment = theme . alignment <EOL> if alignment == '<STR_LIT:left>' : <EOL> tx = slice . xleft + content . left <EOL> elif alignment == '<STR_LIT>' : <EOL> adx = wdx - slice . xleft - slice . xright <EOL> tx = slice . xleft + content . left + <NUM_LIT:4> + ( ( adx - tdx ) / <NUM_LIT:2> ) <EOL> else : <EOL> tx = wdx - tdx - slice . xright - content . right <EOL> return ( tx + theme . label . left , ty + theme . label . top , tdx , tdy ) </s>
