<s> import sys <EOL> from atom . api import Typed <EOL> from enaml . widgets . widget import ProxyWidget <EOL> from . QtCore import Qt , QSize <EOL> from . QtGui import QFont , QWidget , QWidgetItem , QApplication <EOL> from . q_resource_helpers import get_cached_qcolor , get_cached_qfont <EOL> from . qt_toolkit_object import QtToolkitObject <EOL> class QtWidget ( QtToolkitObject , ProxyWidget ) : <EOL> """<STR_LIT>""" <EOL> widget = Typed ( QWidget ) <EOL> widget_item = Typed ( QWidgetItem ) <EOL> def _default_widget_item ( self ) : <EOL> return QWidgetItem ( self . widget ) <EOL> def create_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget = QWidget ( self . parent_widget ( ) ) <EOL> def init_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QtWidget , self ) . init_widget ( ) <EOL> d = self . declaration <EOL> if d . background : <EOL> self . set_background ( d . background ) <EOL> if d . foreground : <EOL> self . set_foreground ( d . foreground ) <EOL> if d . font : <EOL> self . set_font ( d . font ) <EOL> if d . show_focus_rect is not None : <EOL> self . set_show_focus_rect ( d . show_focus_rect ) <EOL> if - <NUM_LIT:1> not in d . minimum_size : <EOL> self . set_minimum_size ( d . minimum_size ) <EOL> if - <NUM_LIT:1> not in d . maximum_size : <EOL> self . set_maximum_size ( d . maximum_size ) <EOL> if d . tool_tip : <EOL> self . set_tool_tip ( d . tool_tip ) <EOL> if d . status_tip : <EOL> self . set_status_tip ( d . status_tip ) <EOL> self . set_enabled ( d . enabled ) <EOL> if self . widget . parent ( ) or not d . visible : <EOL> self . set_visible ( d . visible ) <EOL> def set_minimum_size ( self , min_size ) : <EOL> """<STR_LIT>""" <EOL> if - <NUM_LIT:1> in min_size : <EOL> min_size = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . widget . setMinimumSize ( QSize ( * min_size ) ) <EOL> def set_maximum_size ( self , max_size ) : <EOL> """<STR_LIT>""" <EOL> if - <NUM_LIT:1> in max_size : <EOL> max_size = ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . widget . setMaximumSize ( QSize ( * max_size ) ) <EOL> def set_enabled ( self , enabled ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setEnabled ( enabled ) <EOL> def set_visible ( self , visible ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setVisible ( visible ) <EOL> def set_background ( self , background ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> role = widget . backgroundRole ( ) <EOL> if background is not None : <EOL> qcolor = get_cached_qcolor ( background ) <EOL> widget . setAutoFillBackground ( True ) <EOL> else : <EOL> app_palette = QApplication . instance ( ) . palette ( widget ) <EOL> qcolor = app_palette . color ( role ) <EOL> widget . setAutoFillBackground ( False ) <EOL> palette = widget . palette ( ) <EOL> palette . setColor ( role , qcolor ) <EOL> widget . setPalette ( palette ) <EOL> def set_foreground ( self , foreground ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> role = widget . foregroundRole ( ) <EOL> if foreground is not None : <EOL> qcolor = get_cached_qcolor ( foreground ) <EOL> else : <EOL> app_palette = QApplication . instance ( ) . palette ( widget ) <EOL> qcolor = app_palette . color ( role ) <EOL> palette = widget . palette ( ) <EOL> palette . setColor ( role , qcolor ) <EOL> widget . setPalette ( palette ) <EOL> def set_font ( self , font ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> if font is not None : <EOL> widget . setFont ( get_cached_qfont ( font ) ) <EOL> else : <EOL> widget . setFont ( QFont ( ) ) <EOL> def set_show_focus_rect ( self , show ) : <EOL> """<STR_LIT>""" <EOL> if sys . platform == '<STR_LIT>' : <EOL> self . widget . setAttribute ( Qt . WA_MacShowFocusRect , bool ( show ) ) <EOL> def set_tool_tip ( self , tool_tip ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setToolTip ( tool_tip ) <EOL> def set_status_tip ( self , status_tip ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setStatusTip ( status_tip ) <EOL> def ensure_visible ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setVisible ( True ) <EOL> def ensure_hidden ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setVisible ( False ) </s>
