<s> import gc <EOL> from ilastik . gui . ribbons . ilastikTabBase import IlastikTabBase , TabButton <EOL> from ilastik . core . dataMgr import PropertyMgr <EOL> from ilastik . gui . overlayWidget import OverlayWidget <EOL> from ilastik . gui . iconMgr import ilastikIcons <EOL> from ilastik . modules . classification . gui . guiThreads import * <EOL> from ilastik . modules . classification . gui . labelWidget import LabelListWidget <EOL> from ilastik . modules . classification . gui . featureDlg import FeatureDlg <EOL> from ilastik . modules . classification . gui . classifierSelectionDialog import ClassifierSelectionDlg <EOL> class ClassificationTab ( IlastikTabBase , QtGui . QWidget ) : <EOL> name = '<STR_LIT>' <EOL> position = <NUM_LIT:1> <EOL> moduleName = "<STR_LIT>" <EOL> def __init__ ( self , parent = None ) : <EOL> IlastikTabBase . __init__ ( self , parent ) <EOL> QtGui . QWidget . __init__ ( self , parent ) <EOL> self . _initContent ( ) <EOL> self . _initConnects ( ) <EOL> def on_activation ( self ) : <EOL> if self . ilastik . project is None : <EOL> return <EOL> if self . ilastik . _activeImage . module [ self . name ] is None : <EOL> self . ilastik . _activeImage . module [ self . name ] = PropertyMgr ( self . ilastik . _activeImage ) <EOL> ovs = self . ilastik . _activeImage . module [ self . name ] . getOverlayRefs ( ) <EOL> raw = self . ilastik . _activeImage . overlayMgr [ "<STR_LIT>" ] <EOL> self . ilastik . labelWidget . _history . volumeEditor = self . ilastik . labelWidget <EOL> overlayWidget = OverlayWidget ( self . ilastik . labelWidget , self . ilastik . project . dataMgr ) <EOL> self . ilastik . labelWidget . setOverlayWidget ( overlayWidget ) <EOL> ov = self . ilastik . _activeImage . overlayMgr [ "<STR_LIT>" ] <EOL> overlayWidget . addOverlayRef ( ov . getRef ( ) ) <EOL> overlayWidget . addOverlayRef ( raw . getRef ( ) ) <EOL> self . ilastik . labelWidget . setLabelWidget ( LabelListWidget ( self . ilastik . project . dataMgr . module [ "<STR_LIT>" ] . labelMgr , self . ilastik . project . dataMgr . module [ "<STR_LIT>" ] [ "<STR_LIT>" ] , self . ilastik . labelWidget , ov ) ) <EOL> def on_deActivation ( self ) : <EOL> if self . ilastik . project is None : <EOL> return <EOL> if hasattr ( self . parent , "<STR_LIT>" ) : <EOL> self . btnStartLive . click ( ) <EOL> if self . ilastik . labelWidget is not None and self . ilastik . labelWidget . _history != self . ilastik . _activeImage . module [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> self . ilastik . _activeImage . module [ "<STR_LIT>" ] [ "<STR_LIT>" ] = self . ilastik . labelWidget . _history <EOL> def _initContent ( self ) : <EOL> tl = QtGui . QHBoxLayout ( ) <EOL> tl . setMargin ( <NUM_LIT:0> ) <EOL> self . btnSelectFeatures = TabButton ( '<STR_LIT>' , ilastikIcons . Select ) <EOL> self . btnStartLive = TabButton ( '<STR_LIT>' , ilastikIcons . Play ) <EOL> self . btnStartLive . setCheckable ( True ) <EOL> self . btnTrainPredict = TabButton ( '<STR_LIT>' , ilastikIcons . System ) <EOL> self . btnExportClassifier = TabButton ( '<STR_LIT>' , ilastikIcons . Select ) <EOL> self . btnClassifierOptions = TabButton ( '<STR_LIT>' , ilastikIcons . Select ) <EOL> self . btnSelectFeatures . setToolTip ( '<STR_LIT>' ) <EOL> self . btnStartLive . setToolTip ( '<STR_LIT>' ) <EOL> self . btnTrainPredict . setToolTip ( '<STR_LIT>' ) <EOL> self . btnExportClassifier . setToolTip ( '<STR_LIT>' ) <EOL> self . btnClassifierOptions . setToolTip ( '<STR_LIT>' ) <EOL> self . on_otherProject ( ) <EOL> tl . addWidget ( self . btnSelectFeatures ) <EOL> tl . addWidget ( self . btnStartLive ) <EOL> tl . addWidget ( self . btnTrainPredict ) <EOL> tl . addStretch ( ) <EOL> tl . addWidget ( self . btnExportClassifier ) <EOL> tl . addWidget ( self . btnClassifierOptions ) <EOL> self . setLayout ( tl ) <EOL> def _initConnects ( self ) : <EOL> self . connect ( self . btnSelectFeatures , QtCore . SIGNAL ( '<STR_LIT>' ) , self . on_btnSelectFeatures_clicked ) <EOL> self . connect ( self . btnStartLive , QtCore . SIGNAL ( '<STR_LIT>' ) , self . on_btnStartLive_clicked ) <EOL> self . connect ( self . btnTrainPredict , QtCore . SIGNAL ( '<STR_LIT>' ) , self . on_btnTrainPredict_clicked ) <EOL> self . connect ( self . btnExportClassifier , QtCore . SIGNAL ( '<STR_LIT>' ) , self . on_btnExportClassifier_clicked ) <EOL> self . connect ( self . btnClassifierOptions , QtCore . SIGNAL ( '<STR_LIT>' ) , self . on_btnClassifierOptions_clicked ) <EOL> def on_otherProject ( self ) : <EOL> self . btnSelectFeatures . setEnabled ( True ) <EOL> self . btnStartLive . setEnabled ( False ) <EOL> self . btnTrainPredict . setEnabled ( False ) <EOL> self . btnExportClassifier . setEnabled ( False ) <EOL> self . btnClassifierOptions . setEnabled ( True ) <EOL> def on_btnSelectFeatures_clicked ( self ) : <EOL> preview = self . parent . project . dataMgr [ <NUM_LIT:0> ] . _dataVol . _data [ <NUM_LIT:0> , <NUM_LIT:0> , : , : , <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> newFeatureDlg = FeatureDlg ( self . ilastik , preview ) <EOL> answer = newFeatureDlg . exec_ ( ) <EOL> if answer == QtGui . QDialog . Accepted : <EOL> self . featureComputation = FeatureComputation ( self . ilastik ) <EOL> newFeatureDlg . close ( ) <EOL> newFeatureDlg . deleteLater ( ) <EOL> del newFeatureDlg <EOL> gc . collect ( ) <EOL> def on_btnStartLive_clicked ( self , state ) : <EOL> if state : <EOL> self . ilastik . ribbon . getTab ( '<STR_LIT>' ) . btnStartLive . setText ( '<STR_LIT>' ) <EOL> self . classificationInteractive = ClassificationInteractive ( self . ilastik ) <EOL> else : <EOL> self . classificationInteractive . stop ( ) <EOL> self . ilastik . ribbon . getTab ( '<STR_LIT>' ) . btnStartLive . setText ( '<STR_LIT>' ) <EOL> def on_btnTrainPredict_clicked ( self ) : <EOL> self . classificationTrain = ClassificationTrain ( self . ilastik ) <EOL> self . connect ( self . classificationTrain , QtCore . SIGNAL ( "<STR_LIT>" ) , self . on_trainingFinished ) <EOL> def on_trainingFinished ( self ) : <EOL> print "<STR_LIT>" <EOL> self . classificationPredict = ClassificationPredict ( self . ilastik ) <EOL> def on_btnExportClassifier_clicked ( self ) : <EOL> fileName = QtGui . QFileDialog . getSaveFileName ( self , "<STR_LIT>" , filter = "<STR_LIT>" ) <EOL> try : <EOL> self . ilastik . project . dataMgr . Classification . exportClassifiers ( fileName ) <EOL> except ( RuntimeError , AttributeError , IOError ) as e : <EOL> QtGui . QMessageBox . warning ( self , '<STR_LIT>' , str ( e ) , QtGui . QMessageBox . Ok ) <EOL> return <EOL> try : <EOL> self . ilastik . project . dataMgr . Classification . featureMgr . exportFeatureItems ( fileName ) <EOL> except RuntimeError as e : <EOL> QtGui . QMessageBox . warning ( self , '<STR_LIT>' , str ( e ) , QtGui . QMessageBox . Ok ) <EOL> return <EOL> QtGui . QMessageBox . information ( self , '<STR_LIT>' , "<STR_LIT>" % str ( fileName ) , QtGui . QMessageBox . Ok ) <EOL> def on_btnClassifierOptions_clicked ( self ) : <EOL> dialog = ClassifierSelectionDlg ( self . parent ) <EOL> self . parent . project . dataMgr . module [ "<STR_LIT>" ] . classifier = dialog . exec_ ( ) </s>
