<s> import sys <EOL> from atom . api import Typed <EOL> from enaml . widgets . group_box import ProxyGroupBox <EOL> from . QtCore import Qt , QSize , Signal <EOL> from . QtGui import QGroupBox <EOL> from . qt_container import QtContainer <EOL> QT_ALIGNMENTS = { <EOL> '<STR_LIT:left>' : Qt . AlignLeft , <EOL> '<STR_LIT:right>' : Qt . AlignRight , <EOL> '<STR_LIT>' : Qt . AlignHCenter , <EOL> } <EOL> class QResizingGroupBox ( QGroupBox ) : <EOL> """<STR_LIT>""" <EOL> resized = Signal ( ) <EOL> _size_hint = QSize ( ) <EOL> def resizeEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> super ( QResizingGroupBox , self ) . resizeEvent ( event ) <EOL> self . resized . emit ( ) <EOL> def sizeHint ( self ) : <EOL> """<STR_LIT>""" <EOL> hint = self . _size_hint <EOL> if not hint . isValid ( ) : <EOL> return super ( QResizingGroupBox , self ) . sizeHint ( ) <EOL> return QSize ( hint ) <EOL> def setSizeHint ( self , hint ) : <EOL> """<STR_LIT>""" <EOL> self . _size_hint = QSize ( hint ) <EOL> def minimumSizeHint ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . sizeHint ( ) <EOL> class QtGroupBox ( QtContainer , ProxyGroupBox ) : <EOL> """<STR_LIT>""" <EOL> widget = Typed ( QResizingGroupBox ) <EOL> def create_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> widget = QResizingGroupBox ( self . parent_widget ( ) ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> widget . setAttribute ( Qt . WA_LayoutUsesWidgetRect , True ) <EOL> self . widget = widget <EOL> def init_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QtGroupBox , self ) . init_widget ( ) <EOL> d = self . declaration <EOL> self . set_title ( d . title , cm_update = False ) <EOL> self . set_flat ( d . flat ) <EOL> self . set_title_align ( d . title_align ) <EOL> @ staticmethod <EOL> def margins_func ( widget_item ) : <EOL> """<STR_LIT>""" <EOL> m = widget_item . widget ( ) . contentsMargins ( ) <EOL> return ( m . top ( ) , m . right ( ) , m . bottom ( ) , m . left ( ) ) <EOL> def set_title ( self , title , cm_update = True ) : <EOL> """<STR_LIT>""" <EOL> if not cm_update : <EOL> self . widget . setTitle ( title ) <EOL> return <EOL> widget = self . widget <EOL> old_margins = widget . contentsMargins ( ) <EOL> widget . setTitle ( title ) <EOL> new_margins = widget . contentsMargins ( ) <EOL> if old_margins != new_margins : <EOL> self . margins_updated ( ) <EOL> def set_flat ( self , flat ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setFlat ( flat ) <EOL> def set_title_align ( self , align ) : <EOL> """<STR_LIT>""" <EOL> qt_align = QT_ALIGNMENTS [ align ] <EOL> self . widget . setAlignment ( qt_align ) <EOL> def set_border ( self , border ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
