<s> from atom . api import Typed <EOL> from enaml . widgets . flow_item import ProxyFlowItem <EOL> from . QtCore import QSize , QEvent <EOL> from . QtGui import QFrame , QLayout <EOL> from . q_flow_layout import QFlowLayout , AbstractFlowWidget , FlowLayoutData <EOL> from . q_single_widget_layout import QSingleWidgetLayout <EOL> from . qt_container import QtContainer <EOL> from . qt_widget import QtWidget <EOL> _ALIGN_MAP = { <EOL> '<STR_LIT>' : QFlowLayout . AlignLeading , <EOL> '<STR_LIT>' : QFlowLayout . AlignTrailing , <EOL> '<STR_LIT>' : QFlowLayout . AlignCenter , <EOL> } <EOL> class QFlowItem ( QFrame ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> super ( QFlowItem , self ) . __init__ ( parent ) <EOL> self . _flow_widget = None <EOL> self . _layout_data = FlowLayoutData ( ) <EOL> self . setLayout ( QSingleWidgetLayout ( ) ) <EOL> self . layout ( ) . setSizeConstraint ( QLayout . SetMinAndMaxSize ) <EOL> def layoutData ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _layout_data <EOL> def preferredSize ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _layout_data . preferred_size <EOL> def setPreferredSize ( self , size ) : <EOL> """<STR_LIT>""" <EOL> d = self . _layout_data <EOL> d . preferred_size = size <EOL> d . dirty = True <EOL> self . updateGeometry ( ) <EOL> def alignment ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _layout_data . alignment <EOL> def setAlignment ( self , alignment ) : <EOL> """<STR_LIT>""" <EOL> d = self . _layout_data <EOL> d . alignment = alignment <EOL> d . dirty = True <EOL> self . updateGeometry ( ) <EOL> def stretch ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _layout_data . stretch <EOL> def setStretch ( self , stretch ) : <EOL> """<STR_LIT>""" <EOL> d = self . _layout_data <EOL> d . stretch = stretch <EOL> d . dirty = True <EOL> self . updateGeometry ( ) <EOL> def orthoStretch ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _layout_data . stretch <EOL> def setOrthoStretch ( self , stretch ) : <EOL> """<STR_LIT>""" <EOL> d = self . _layout_data <EOL> d . ortho_stretch = stretch <EOL> d . dirty = True <EOL> self . updateGeometry ( ) <EOL> def flowWidget ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _flow_widget <EOL> def setFlowWidget ( self , widget ) : <EOL> """<STR_LIT>""" <EOL> self . _flow_widget = widget <EOL> self . layout ( ) . setWidget ( widget ) <EOL> def event ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . type ( ) == QEvent . LayoutRequest : <EOL> self . _layout_data . dirty = True <EOL> return super ( QFlowItem , self ) . event ( event ) <EOL> AbstractFlowWidget . register ( QFlowItem ) <EOL> class QtFlowItem ( QtWidget , ProxyFlowItem ) : <EOL> """<STR_LIT>""" <EOL> widget = Typed ( QFlowItem ) <EOL> def create_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget = QFlowItem ( self . parent_widget ( ) ) <EOL> def init_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QtFlowItem , self ) . init_widget ( ) <EOL> d = self . declaration <EOL> self . set_preferred_size ( d . preferred_size ) <EOL> self . set_align ( d . align ) <EOL> self . set_stretch ( d . stretch ) <EOL> self . set_ortho_stretch ( d . ortho_stretch ) <EOL> def init_layout ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QtFlowItem , self ) . init_layout ( ) <EOL> self . widget . setFlowWidget ( self . flow_widget ( ) ) <EOL> def flow_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . declaration . flow_widget ( ) <EOL> if d is not None : <EOL> return d . proxy . widget <EOL> def child_added ( self , child ) : <EOL> """<STR_LIT>""" <EOL> super ( QtFlowItem , self ) . child_added ( child ) <EOL> if isinstance ( child , QtContainer ) : <EOL> self . widget . setFlowWidget ( self . flow_widget ( ) ) <EOL> def child_removed ( self , child ) : <EOL> """<STR_LIT>""" <EOL> super ( QtFlowItem , self ) . child_removed ( child ) <EOL> if isinstance ( child , QtContainer ) : <EOL> self . widget . setFlowWidget ( self . flow_widget ( ) ) <EOL> def set_preferred_size ( self , size ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setPreferredSize ( QSize ( * size ) ) <EOL> def set_align ( self , align ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setAlignment ( _ALIGN_MAP [ align ] ) <EOL> def set_stretch ( self , stretch ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setStretch ( stretch ) <EOL> def set_ortho_stretch ( self , stretch ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setOrthoStretch ( stretch ) </s>
