<s> from __main__ import vtk , qt , ctk , slicer <EOL> import string <EOL> import collections <EOL> import FeatureWidgetHelperLib <EOL> class CheckableTabsWidget ( qt . QTabWidget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> super ( CheckableTabsWidget , self ) . __init__ ( parent ) <EOL> self . featureClassFeatureWidgets = collections . OrderedDict ( ) <EOL> self . tab_bar = self . findChildren ( qt . QTabBar ) [ <NUM_LIT:0> ] <EOL> self . boldFont = qt . QFont ( ) <EOL> self . boldFont . setBold ( True ) <EOL> self . tab_bar . setFont ( self . boldFont ) <EOL> self . tab_bar . setContextMenuPolicy ( <NUM_LIT:3> ) <EOL> self . tab_bar . installEventFilter ( self ) <EOL> def addTab ( self , widget , featureClass , featureWidgets , checkStatus = True ) : <EOL> qt . QTabWidget . addTab ( self , widget , featureClass ) <EOL> checkBox = FeatureWidgetHelperLib . FeatureWidget ( ) <EOL> checkBox . Setup ( featureName = featureClass , featureClassFlag = True , checkStatus = checkStatus ) <EOL> self . featureClassFeatureWidgets [ featureClass ] = checkBox <EOL> self . tab_bar . setTabButton ( self . tab_bar . count - <NUM_LIT:1> , qt . QTabBar . LeftSide , checkBox ) <EOL> self . connect ( checkBox , qt . SIGNAL ( '<STR_LIT>' ) , <EOL> lambda checkState : self . stateChanged ( checkBox , checkState , featureWidgets ) ) <EOL> def isChecked ( self , index ) : <EOL> return self . tab_bar . tabButton ( index , qt . QTabBar . LeftSide ) . checkState ( ) != <NUM_LIT:0> <EOL> def setCheckState ( self , index , checkState ) : <EOL> self . tab_bar . tabButton ( index , qt . QTabBar . LeftSide ) . setCheckState ( checkState ) <EOL> def stateChanged ( self , checkBox , checkState , featureWidgets ) : <EOL> index = self . featureClassFeatureWidgets . values ( ) . index ( checkBox ) <EOL> if checkState == <NUM_LIT:0> : <EOL> for widget in featureWidgets : <EOL> widget . checked = False <EOL> elif checkState == <NUM_LIT:2> : <EOL> for widget in featureWidgets : <EOL> widget . checked = True <EOL> def eventFilter ( self , object , event ) : <EOL> if object == self . tab_bar and event . type ( ) == qt . QEvent . ContextMenu : <EOL> tabIndex = object . tabAt ( event . pos ( ) ) <EOL> pos = self . featureClassFeatureWidgets . values ( ) [ tabIndex ] . mapFrom ( self . tab_bar , event . pos ( ) ) <EOL> if tabIndex > - <NUM_LIT:1> : <EOL> qt . QCoreApplication . sendEvent ( self . featureClassFeatureWidgets . values ( ) [ tabIndex ] , <EOL> qt . QContextMenuEvent ( <NUM_LIT:0> , pos ) ) <EOL> return True <EOL> return False <EOL> def getFeatureClassWidgets ( self ) : <EOL> return ( self . featureClassFeatureWidgets . values ( ) ) <EOL> def addParameter ( self , featureClass , parameter ) : <EOL> self . featureClassFeatureWidgets [ featureClass ] . addParameter ( parameter ) <EOL> class FeatureWidget ( qt . QCheckBox ) : <EOL> def __init__ ( self , parent = None ) : <EOL> super ( FeatureWidget , self ) . __init__ ( parent ) <EOL> def Setup ( self , featureName = "<STR_LIT>" , featureClassFlag = False , checkStatus = True ) : <EOL> self . featureName = featureName <EOL> self . checked = checkStatus <EOL> if featureClassFlag : <EOL> self . descriptionLabel = FeatureWidgetHelperLib . FeatureClassDescriptionLabel ( ) <EOL> self . descriptionLabel . setDescription ( self . featureName ) <EOL> else : <EOL> self . descriptionLabel = FeatureWidgetHelperLib . FeatureDescriptionLabel ( ) <EOL> self . descriptionLabel . setDescription ( self . featureName ) <EOL> self . setText ( self . featureName ) <EOL> self . setContextMenuPolicy ( <NUM_LIT:3> ) <EOL> self . widgetMenu = FeatureWidgetHelperLib . ContextMenu ( self ) <EOL> self . widgetMenu . Setup ( self . featureName , self . descriptionLabel ) <EOL> self . customContextMenuRequested . connect ( lambda point : self . connectMenu ( point ) ) <EOL> def connectMenu ( self , pos ) : <EOL> self . widgetMenu . popup ( self . mapToGlobal ( pos ) ) <EOL> def addParameter ( self , parameterName ) : <EOL> self . widgetMenu . addParameter ( parameterName ) <EOL> def getParameterDict ( self ) : <EOL> parameterDict = collections . OrderedDict ( ) <EOL> for k , v in self . widgetMenu . parameters . items ( ) : <EOL> value = v [ '<STR_LIT>' ] . getValue ( ) <EOL> parameterDict [ k ] = value <EOL> return ( parameterDict ) <EOL> def getParameterEditWindow ( self , parameterName ) : <EOL> return ( self . widgetMenu . parameters [ parameterName ] [ '<STR_LIT>' ] ) <EOL> def getName ( self ) : <EOL> return ( self . featureName ) <EOL> class ContextMenu ( qt . QMenu ) : <EOL> def __init__ ( self , parent = None ) : <EOL> super ( ContextMenu , self ) . __init__ ( parent ) <EOL> def Setup ( self , featureName , descriptionLabel = "<STR_LIT>" ) : <EOL> self . featureName = featureName <EOL> self . descriptionLabel = descriptionLabel <EOL> self . parameters = collections . OrderedDict ( ) <EOL> self . descriptionAction = qt . QWidgetAction ( self ) <EOL> self . descriptionAction . setDefaultWidget ( self . descriptionLabel ) <EOL> self . closeAction = qt . QAction ( "<STR_LIT>" , self ) <EOL> self . reloadActions ( ) <EOL> def reloadActions ( self ) : <EOL> self . addAction ( self . descriptionAction ) <EOL> for parameter in self . parameters : <EOL> self . addAction ( self . parameters [ parameter ] [ '<STR_LIT>' ] ) <EOL> self . addAction ( self . closeAction ) <EOL> def addParameter ( self , parameterName ) : <EOL> self . parameters [ parameterName ] = { } <EOL> self . parameters [ parameterName ] [ '<STR_LIT>' ] = qt . QAction ( ( '<STR_LIT>' % parameterName ) , self ) <EOL> self . parameters [ parameterName ] [ '<STR_LIT>' ] = FeatureWidgetHelperLib . ParameterEditWindow ( self , <EOL> self . featureName , <EOL> parameterName ) <EOL> self . parameters [ parameterName ] [ '<STR_LIT>' ] . connect ( '<STR_LIT>' , lambda parameterName = parameterName : <EOL> self . parameters [ parameterName ] [ '<STR_LIT>' ] . showWindow ( ) ) <EOL> self . reloadActions ( ) <EOL> def getParameters ( self ) : <EOL> return ( self . parameters ) <EOL> class ParameterEditWindow ( qt . QInputDialog ) : <EOL> def __init__ ( self , parent = None , featureName = "<STR_LIT>" , parameterName = "<STR_LIT>" ) : <EOL> super ( ParameterEditWindow , self ) . __init__ ( parent ) <EOL> self . featureName = featureName <EOL> self . parameterName = parameterName <EOL> self . helpString = "<STR_LIT>" + parameterName + "<STR_LIT>" + self . featureName + "<STR_LIT:)>" <EOL> self . setLabelText ( self . helpString + "<STR_LIT>" + str ( self . getValue ( ) ) + "<STR_LIT>" ) <EOL> self . setInputMode ( <NUM_LIT:1> ) <EOL> def showWindow ( self ) : <EOL> self . resetLabel ( ) <EOL> self . open ( ) <EOL> def resetLabel ( self ) : <EOL> self . setLabelText ( self . helpString + "<STR_LIT>" + str ( self . getValue ( ) ) + "<STR_LIT>" ) <EOL> def getValue ( self ) : <EOL> return ( self . intValue ( ) ) </s>
