<s> from muntjac . demo . sampler . CodeLabel import CodeLabel <EOL> from muntjac . demo . sampler . FeatureSet import FeatureSet <EOL> from muntjac . demo . sampler . ActiveLink import ActiveLink <EOL> from muntjac . terminal . theme_resource import ThemeResource <EOL> from muntjac . terminal . external_resource import ExternalResource <EOL> from muntjac . ui . themes import Reindeer , BaseTheme <EOL> from muntjac . ui . button import IClickListener <EOL> from muntjac . demo . sampler . ActiveLink import ILinkActivatedListener <EOL> from muntjac . api import ( HorizontalLayout , Label , VerticalLayout , Panel , NativeButton , <EOL> Link , Window ) <EOL> class FeatureView ( HorizontalLayout ) : <EOL> _MSG_SHOW_SRC = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> super ( FeatureView , self ) . __init__ ( ) <EOL> self . _right = None <EOL> self . _left = None <EOL> self . _controls = None <EOL> self . _title = Label ( "<STR_LIT>" , Label . CONTENT_XHTML ) <EOL> self . _showSrc = None <EOL> self . _exampleCache = dict ( ) <EOL> self . _currentFeature = None <EOL> self . _srcWindow = None <EOL> self . setWidth ( '<STR_LIT>' ) <EOL> self . setMargin ( True ) <EOL> self . setSpacing ( True ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . _left = VerticalLayout ( ) <EOL> self . _left . setWidth ( '<STR_LIT>' ) <EOL> self . _left . setSpacing ( True ) <EOL> self . _left . setMargin ( False ) <EOL> self . addComponent ( self . _left ) <EOL> self . setExpandRatio ( self . _left , <NUM_LIT:1> ) <EOL> rightLayout = VerticalLayout ( ) <EOL> self . _right = Panel ( rightLayout ) <EOL> rightLayout . setMargin ( True , False , False , False ) <EOL> self . _right . setStyleName ( Reindeer . PANEL_LIGHT ) <EOL> self . _right . addStyleName ( '<STR_LIT>' ) <EOL> self . _right . setWidth ( '<STR_LIT>' ) <EOL> self . addComponent ( self . _right ) <EOL> self . _controls = HorizontalLayout ( ) <EOL> self . _controls . setWidth ( '<STR_LIT>' ) <EOL> self . _controls . setStyleName ( '<STR_LIT>' ) <EOL> self . _title . setStyleName ( '<STR_LIT:title>' ) <EOL> self . _controls . addComponent ( self . _title ) <EOL> self . _controls . setExpandRatio ( self . _title , <NUM_LIT:1> ) <EOL> resetExample = NativeButton ( '<STR_LIT>' , ResetListener ( self ) ) <EOL> resetExample . setStyleName ( BaseTheme . BUTTON_LINK ) <EOL> resetExample . addStyleName ( '<STR_LIT>' ) <EOL> resetExample . setDescription ( '<STR_LIT>' ) <EOL> self . _controls . addComponent ( resetExample ) <EOL> self . _showSrc = ActiveLink ( ) <EOL> self . _showSrc . setDescription ( '<STR_LIT>' ) <EOL> self . _showSrc . addListener ( ShowSrcListener ( self ) , ILinkActivatedListener ) <EOL> self . _showSrc . setCaption ( self . _MSG_SHOW_SRC ) <EOL> self . _showSrc . addStyleName ( '<STR_LIT>' ) <EOL> self . _showSrc . setTargetBorder ( Link . TARGET_BORDER_NONE ) <EOL> self . _controls . addComponent ( self . _showSrc ) <EOL> def showSource ( self , source ) : <EOL> if self . _srcWindow is None : <EOL> self . _srcWindow = Window ( '<STR_LIT>' ) <EOL> self . _srcWindow . getContent ( ) . setSizeUndefined ( ) <EOL> self . _srcWindow . setWidth ( '<STR_LIT>' ) <EOL> self . _srcWindow . setHeight ( '<STR_LIT>' ) <EOL> self . _srcWindow . setPositionX ( <NUM_LIT:100> ) <EOL> self . _srcWindow . setPositionY ( <NUM_LIT:100> ) <EOL> self . _srcWindow . removeAllComponents ( ) <EOL> self . _srcWindow . addComponent ( CodeLabel ( source ) ) <EOL> if self . _srcWindow . getParent ( ) is None : <EOL> self . getWindow ( ) . addWindow ( self . _srcWindow ) <EOL> def resetExample ( self ) : <EOL> if self . _currentFeature is not None : <EOL> w = self . getWindow ( ) <EOL> w . removeSubwindows ( ) <EOL> f = self . _currentFeature <EOL> self . _currentFeature = None <EOL> if f in self . _exampleCache : <EOL> del self . _exampleCache [ f ] <EOL> self . setFeature ( f ) <EOL> def setFeature ( self , feature ) : <EOL> from muntjac . demo . sampler . SamplerApplication import SamplerApplication <EOL> if feature != self . _currentFeature : <EOL> self . _currentFeature = feature <EOL> self . _right . removeAllComponents ( ) <EOL> self . _left . removeAllComponents ( ) <EOL> self . _left . addComponent ( self . _controls ) <EOL> self . _title . setValue ( '<STR_LIT>' + feature . getName ( ) + '<STR_LIT>' ) <EOL> self . _left . addComponent ( self . getExampleFor ( feature ) ) <EOL> self . _right . setCaption ( '<STR_LIT>' ) <EOL> alll = SamplerApplication . getAllFeatures ( ) <EOL> parent = alll . getParent ( feature ) <EOL> isRoot = alll . getParent ( parent ) is None <EOL> desc = parent . getDescription ( ) <EOL> hasParentDesc = False <EOL> if parent is not None and not isRoot : <EOL> parentLabel = Label ( parent . getDescription ( ) ) <EOL> if desc is not None and desc != '<STR_LIT>' : <EOL> parentLabel . setContentMode ( Label . CONTENT_XHTML ) <EOL> self . _right . addComponent ( parentLabel ) <EOL> hasParentDesc = True <EOL> desc = feature . getDescription ( ) <EOL> if desc is not None and desc != '<STR_LIT>' : <EOL> l = Label ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> + desc + "<STR_LIT>" , Label . CONTENT_XHTML ) <EOL> self . _right . addComponent ( l ) <EOL> if hasParentDesc : <EOL> l . setStyleName ( '<STR_LIT>' ) <EOL> else : <EOL> l . setStyleName ( '<STR_LIT:description>' ) <EOL> self . _showSrc . setTargetName ( self . _currentFeature . getFragmentName ( ) ) <EOL> er = ExternalResource ( self . getApplication ( ) . getURL ( ) <EOL> + '<STR_LIT>' + self . _currentFeature . getFragmentName ( ) ) <EOL> self . _showSrc . setResource ( er ) <EOL> resources = feature . getRelatedResources ( ) <EOL> if resources is not None : <EOL> res = VerticalLayout ( ) <EOL> self . caption = Label ( "<STR_LIT>" , <EOL> Label . CONTENT_XHTML ) <EOL> self . caption . setStyleName ( '<STR_LIT>' ) <EOL> self . caption . setWidth ( '<STR_LIT>' ) <EOL> res . addComponent ( self . caption ) <EOL> res . setMargin ( False , False , True , False ) <EOL> for r in resources : <EOL> l = Link ( r . getName ( ) , r ) <EOL> l . setIcon ( ThemeResource ( '<STR_LIT>' ) ) <EOL> res . addComponent ( l ) <EOL> self . _right . addComponent ( res ) <EOL> apis = feature . getRelatedAPI ( ) <EOL> if apis is not None : <EOL> api = VerticalLayout ( ) <EOL> self . caption = Label ( "<STR_LIT>" , <EOL> Label . CONTENT_XHTML ) <EOL> self . caption . setStyleName ( '<STR_LIT>' ) <EOL> self . caption . setWidth ( '<STR_LIT>' ) <EOL> api . addComponent ( self . caption ) <EOL> api . setMargin ( False , False , True , False ) <EOL> for r in apis : <EOL> l = Link ( r . getName ( ) , r ) <EOL> ic = ThemeResource ( '<STR_LIT>' ) <EOL> l . setIcon ( ic ) <EOL> api . addComponent ( l ) <EOL> self . _right . addComponent ( api ) <EOL> features = feature . getRelatedFeatures ( ) <EOL> if features is not None : <EOL> rel = VerticalLayout ( ) <EOL> self . caption = Label ( "<STR_LIT>" , <EOL> Label . CONTENT_XHTML ) <EOL> self . caption . setStyleName ( '<STR_LIT>' ) <EOL> self . caption . setWidth ( '<STR_LIT>' ) <EOL> rel . addComponent ( self . caption ) <EOL> rel . setMargin ( False , False , True , False ) <EOL> for c in features : <EOL> f = SamplerApplication . getFeatureFor ( c ) <EOL> if f is not None : <EOL> er = ExternalResource ( self . getApplication ( ) . getURL ( ) <EOL> + '<STR_LIT:#>' + f . getFragmentName ( ) ) <EOL> al = ActiveLink ( f . getName ( ) , er ) <EOL> if isinstance ( f , FeatureSet ) : <EOL> ic = ThemeResource ( '<STR_LIT>' ) <EOL> else : <EOL> ic = ThemeResource ( '<STR_LIT>' ) <EOL> al . setIcon ( ic ) <EOL> al . addListener ( LinkListener ( self , f ) , <EOL> ILinkActivatedListener ) <EOL> rel . addComponent ( al ) <EOL> self . _right . addComponent ( rel ) <EOL> def getExampleFor ( self , f ) : <EOL> ex = self . _exampleCache . get ( f ) <EOL> if ex is None : <EOL> ex = f . getExample ( ) <EOL> self . _exampleCache [ f ] = ex <EOL> return ex <EOL> class ResetListener ( IClickListener ) : <EOL> def __init__ ( self , view ) : <EOL> self . _view = view <EOL> def buttonClick ( self , event ) : <EOL> self . _view . resetExample ( ) <EOL> class ShowSrcListener ( ILinkActivatedListener ) : <EOL> def __init__ ( self , view ) : <EOL> self . _view = view <EOL> def linkActivated ( self , event ) : <EOL> if not event . isLinkOpened ( ) : <EOL> self . _view . showSource ( <EOL> self . _view . _currentFeature . getSource ( ) ) <EOL> class LinkListener ( ILinkActivatedListener ) : <EOL> def __init__ ( self , view , feature ) : <EOL> self . _view = view <EOL> self . _feature = feature <EOL> def linkActivated ( self , event ) : <EOL> if event . isLinkOpened ( ) : <EOL> self . _view . getWindow ( ) . showNotification ( <EOL> ( self . _feature . getName ( ) <EOL> + '<STR_LIT>' ) ) <EOL> else : <EOL> w = self . _view . getWindow ( ) <EOL> w . setFeature ( self . _feature ) </s>
