<s> from muntjac . ui . abstract_select import AbstractSelect <EOL> from muntjac . data . container import IContainer <EOL> from muntjac . event . field_events import BlurEvent , IBlurListener , IBlurNotifier , FocusEvent , IFocusListener , IFocusNotifier <EOL> from muntjac . terminal . gwt . client . ui . v_option_group import VOptionGroup <EOL> class OptionGroup ( AbstractSelect , IBlurNotifier , IFocusNotifier ) : <EOL> """<STR_LIT>""" <EOL> CLIENT_WIDGET = None <EOL> def __init__ ( self , * args ) : <EOL> self . _disabledItemIds = set ( ) <EOL> self . _htmlContentAllowed = False <EOL> args = args <EOL> nargs = len ( args ) <EOL> if nargs == <NUM_LIT:0> : <EOL> super ( OptionGroup , self ) . __init__ ( ) <EOL> elif nargs == <NUM_LIT:1> : <EOL> caption , = args <EOL> super ( OptionGroup , self ) . __init__ ( caption ) <EOL> elif nargs == <NUM_LIT:2> : <EOL> if isinstance ( args [ <NUM_LIT:1> ] , IContainer ) : <EOL> caption , dataSource = args <EOL> super ( OptionGroup , self ) . __init__ ( caption , dataSource ) <EOL> else : <EOL> caption , options = args <EOL> super ( OptionGroup , self ) . __init__ ( caption , options ) <EOL> else : <EOL> raise ValueError , '<STR_LIT>' <EOL> def paintContent ( self , target ) : <EOL> target . addAttribute ( '<STR_LIT:type>' , '<STR_LIT>' ) <EOL> if self . isHtmlContentAllowed ( ) : <EOL> target . addAttribute ( VOptionGroup . HTML_CONTENT_ALLOWED , True ) <EOL> super ( OptionGroup , self ) . paintContent ( target ) <EOL> def paintItem ( self , target , itemId ) : <EOL> super ( OptionGroup , self ) . paintItem ( target , itemId ) <EOL> if not self . isItemEnabled ( itemId ) : <EOL> target . addAttribute ( '<STR_LIT>' , True ) <EOL> def changeVariables ( self , source , variables ) : <EOL> super ( OptionGroup , self ) . changeVariables ( source , variables ) <EOL> if FocusEvent . EVENT_ID in variables : <EOL> self . fireEvent ( FocusEvent ( self ) ) <EOL> if BlurEvent . EVENT_ID in variables : <EOL> self . fireEvent ( BlurEvent ( self ) ) <EOL> def addListener ( self , listener , iface = None ) : <EOL> if ( isinstance ( listener , IBlurListener ) and <EOL> ( iface is None or issubclass ( iface , IBlurListener ) ) ) : <EOL> self . registerListener ( BlurEvent . EVENT_ID , BlurEvent , <EOL> listener , IBlurListener . blurMethod ) <EOL> if ( isinstance ( listener , IFocusListener ) and <EOL> ( iface is None or issubclass ( iface , IFocusListener ) ) ) : <EOL> self . registerListener ( FocusEvent . EVENT_ID , FocusEvent , <EOL> listener , IFocusListener . focusMethod ) <EOL> super ( OptionGroup , self ) . addListener ( listener , iface ) <EOL> def addCallback ( self , callback , eventType = None , * args ) : <EOL> if eventType is None : <EOL> eventType = callback . _eventType <EOL> if issubclass ( eventType , BlurEvent ) : <EOL> self . registerCallback ( BlurEvent , callback , <EOL> BlurEvent . EVENT_ID , * args ) <EOL> elif issubclass ( eventType , FocusEvent ) : <EOL> self . registerCallback ( FocusEvent , callback , <EOL> FocusEvent . EVENT_ID , * args ) <EOL> else : <EOL> super ( OptionGroup , self ) . addCallback ( callback , eventType , * args ) <EOL> def removeListener ( self , listener , iface = None ) : <EOL> if ( isinstance ( listener , IBlurListener ) and <EOL> ( iface is None or issubclass ( iface , IBlurListener ) ) ) : <EOL> self . withdrawListener ( BlurEvent . EVENT_ID , BlurEvent , listener ) <EOL> if ( isinstance ( listener , IFocusListener ) and <EOL> ( iface is None or issubclass ( iface , IFocusListener ) ) ) : <EOL> self . withdrawListener ( FocusEvent . EVENT_ID , FocusEvent , listener ) <EOL> super ( OptionGroup , self ) . removeListener ( listener , iface ) <EOL> def removeCallback ( self , callback , eventType = None ) : <EOL> if eventType is None : <EOL> eventType = callback . _eventType <EOL> if issubclass ( eventType , BlurEvent ) : <EOL> self . withdrawCallback ( BlurEvent , callback , BlurEvent . EVENT_ID ) <EOL> elif issubclass ( eventType , FocusEvent ) : <EOL> self . withdrawCallback ( FocusEvent , callback , FocusEvent . EVENT_ID ) <EOL> else : <EOL> super ( OptionGroup , self ) . removeCallback ( callback , eventType ) <EOL> def setValue ( self , newValue , repaintIsNotNeeded = None ) : <EOL> if repaintIsNotNeeded is not None and repaintIsNotNeeded is True : <EOL> if self . isMultiSelect ( ) : <EOL> currentValueSet = self . getValue ( ) <EOL> newValueSet = newValue <EOL> for itemId in currentValueSet : <EOL> if ( not self . isItemEnabled ( itemId ) <EOL> and not ( itemId in newValueSet ) ) : <EOL> self . requestRepaint ( ) <EOL> return <EOL> for itemId in newValueSet : <EOL> if ( not self . isItemEnabled ( itemId ) <EOL> and not ( itemId in currentValueSet ) ) : <EOL> self . requestRepaint ( ) <EOL> return <EOL> else : <EOL> if newValue is None : <EOL> newValue = self . getNullSelectionItemId ( ) <EOL> if not self . isItemEnabled ( newValue ) : <EOL> self . requestRepaint ( ) <EOL> return <EOL> super ( OptionGroup , self ) . setValue ( newValue , repaintIsNotNeeded ) <EOL> def setItemEnabled ( self , itemId , enabled ) : <EOL> """<STR_LIT>""" <EOL> if itemId is not None : <EOL> if enabled : <EOL> self . _disabledItemIds . remove ( itemId ) <EOL> else : <EOL> self . _disabledItemIds . add ( itemId ) <EOL> self . requestRepaint ( ) <EOL> def isItemEnabled ( self , itemId ) : <EOL> """<STR_LIT>""" <EOL> if itemId is not None : <EOL> return not ( itemId in self . _disabledItemIds ) <EOL> return True <EOL> def setHtmlContentAllowed ( self , htmlContentAllowed ) : <EOL> """<STR_LIT>""" <EOL> self . _htmlContentAllowed = htmlContentAllowed <EOL> self . requestRepaint ( ) <EOL> def isHtmlContentAllowed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _htmlContentAllowed </s>
