<s> import glob <EOL> import os <EOL> import ilastik . gui <EOL> from ilastik . gui import loadOptionsWidget <EOL> from ilastik . core import loadOptionsMgr <EOL> from PyQt4 import QtCore , QtGui <EOL> class StackLoader ( QtGui . QDialog ) : <EOL> def __init__ ( self , parent = None ) : <EOL> QtGui . QWidget . __init__ ( self , parent ) <EOL> self . setWindowTitle ( "<STR_LIT>" ) <EOL> self . setMinimumWidth ( <NUM_LIT> ) <EOL> self . layout = QtGui . QVBoxLayout ( ) <EOL> self . setLayout ( self . layout ) <EOL> self . fileList = [ ] <EOL> self . channelIDs = [ ] <EOL> self . options = loadOptionsMgr . loadOptions ( ) <EOL> tempLayout = QtGui . QHBoxLayout ( ) <EOL> self . path = QtGui . QLineEdit ( "<STR_LIT>" ) <EOL> self . connect ( self . path , QtCore . SIGNAL ( "<STR_LIT>" ) , self . pathChanged ) <EOL> self . pathButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> self . connect ( self . pathButton , QtCore . SIGNAL ( '<STR_LIT>' ) , self . slotDir ) <EOL> tempLayout . addWidget ( self . path ) <EOL> tempLayout . addWidget ( self . pathButton ) <EOL> self . layout . addWidget ( QtGui . QLabel ( "<STR_LIT>" ) ) <EOL> self . layout . addLayout ( tempLayout ) <EOL> tempLayout = QtGui . QHBoxLayout ( ) <EOL> self . multiChannel = QtGui . QCheckBox ( "<STR_LIT>" ) <EOL> self . connect ( self . multiChannel , QtCore . SIGNAL ( "<STR_LIT>" ) , self . toggleMultiChannel ) <EOL> tempLayout . addWidget ( self . multiChannel ) <EOL> self . layout . addLayout ( tempLayout ) <EOL> self . multiChannelFrame = QtGui . QFrame ( ) <EOL> tempLayout = QtGui . QFormLayout ( ) <EOL> self . addChannelButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> self . connect ( self . addChannelButton , QtCore . SIGNAL ( '<STR_LIT>' ) , self . slotAddChannel ) <EOL> tempLayout . addRow ( QtGui . QLabel ( "<STR_LIT:U+0020>" ) , self . addChannelButton ) <EOL> self . multiChannelFrame . setLayout ( tempLayout ) <EOL> self . multiChannelFrame . setVisible ( False ) <EOL> self . layout . addWidget ( self . multiChannelFrame ) <EOL> tempLayout = QtGui . QHBoxLayout ( ) <EOL> self . optionsWidget = loadOptionsWidget . LoadOptionsWidget ( ) <EOL> tempLayout . addWidget ( self . optionsWidget ) <EOL> self . layout . addLayout ( tempLayout ) <EOL> tempLayout = QtGui . QHBoxLayout ( ) <EOL> self . loadButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> self . connect ( self . loadButton , QtCore . SIGNAL ( '<STR_LIT>' ) , self . slotLoad ) <EOL> self . cancelButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> self . connect ( self . cancelButton , QtCore . SIGNAL ( '<STR_LIT>' ) , self . reject ) <EOL> self . previewFilesButton = QtGui . QPushButton ( "<STR_LIT>" ) <EOL> self . connect ( self . previewFilesButton , QtCore . SIGNAL ( '<STR_LIT>' ) , self . slotPreviewFiles ) <EOL> tempLayout . addWidget ( self . previewFilesButton ) <EOL> tempLayout . addStretch ( ) <EOL> tempLayout . addWidget ( self . cancelButton ) <EOL> tempLayout . addWidget ( self . loadButton ) <EOL> self . layout . addStretch ( ) <EOL> self . layout . addLayout ( tempLayout ) <EOL> self . logger = QtGui . QPlainTextEdit ( ) <EOL> self . logger . setVisible ( False ) <EOL> self . layout . addWidget ( self . logger ) <EOL> self . image = None <EOL> def toggleMultiChannel ( self , int ) : <EOL> if self . multiChannel . checkState ( ) == <NUM_LIT:0> : <EOL> self . multiChannelFrame . setVisible ( False ) <EOL> else : <EOL> self . multiChannelFrame . setVisible ( True ) <EOL> if len ( self . channelIDs ) == <NUM_LIT:0> : <EOL> self . slotAddChannel ( ) <EOL> def slotAddChannel ( self ) : <EOL> newID = QtGui . QLineEdit ( ) <EOL> newID . setToolTip ( "<STR_LIT>" ) <EOL> self . channelIDs . append ( newID ) <EOL> nch = len ( self . channelIDs ) <EOL> label = "<STR_LIT>" % nch <EOL> receiver = lambda callingChannel = nch - <NUM_LIT:1> : self . channelIDChanged ( callingChannel ) <EOL> self . connect ( self . channelIDs [ nch - <NUM_LIT:1> ] , QtCore . SIGNAL ( '<STR_LIT>' ) , receiver ) <EOL> self . multiChannelFrame . layout ( ) . addRow ( QtGui . QLabel ( label ) , newID ) <EOL> if len ( self . channelIDs ) > <NUM_LIT:1> : <EOL> self . fileList . append ( [ ] ) <EOL> def channelIDChanged ( self , channel ) : <EOL> if len ( self . fileList ) < channel + <NUM_LIT:1> : <EOL> print "<STR_LIT>" <EOL> return <EOL> temp = os . path . splitext ( str ( self . path . text ( ) ) ) [ <NUM_LIT:0> ] <EOL> chfiles = temp + "<STR_LIT:*>" + str ( self . channelIDs [ channel ] . text ( ) ) + "<STR_LIT:*>" <EOL> self . fileList [ channel ] = sorted ( glob . glob ( chfiles ) , key = str . lower ) <EOL> self . optionsWidget . setShapeInfo ( self . fileList , self . options . channels ) <EOL> def pathChanged ( self , text ) : <EOL> self . fileList = [ ] <EOL> self . options . channels = [ ] <EOL> if self . multiChannel . checkState ( ) == <NUM_LIT:0> : <EOL> pathone = str ( self . path . text ( ) ) <EOL> self . fileList . append ( sorted ( glob . glob ( pathone ) , key = str . lower ) ) <EOL> self . options . channels . append ( <NUM_LIT:0> ) <EOL> else : <EOL> nch = len ( self . channelIDs ) <EOL> temp = os . path . splitext ( str ( self . path . text ( ) ) ) [ <NUM_LIT:0> ] <EOL> for ich in range ( nch ) : <EOL> chfiles = temp + "<STR_LIT:*>" + str ( self . channelIDs [ ich ] . text ( ) ) + "<STR_LIT:*>" <EOL> self . fileList [ ich ] = sorted ( glob . glob ( chfiles ) , key = str . lower ) <EOL> self . options . channels . append ( ich ) <EOL> self . optionsWidget . setShapeInfo ( self . fileList , self . options . channels ) <EOL> def slotDir ( self ) : <EOL> path = ilastik . gui . LAST_DIRECTORY <EOL> filename = QtGui . QFileDialog . getExistingDirectory ( self , "<STR_LIT>" , path ) <EOL> ilastik . gui . LAST_DIRECTORY = QtCore . QFileInfo ( filename ) . path ( ) <EOL> tempname = filename + "<STR_LIT>" <EOL> self . path . setText ( str ( QtCore . QDir . convertSeparators ( tempname ) ) ) <EOL> def slotPreviewFiles ( self ) : <EOL> self . fileTableWidget = loadOptionsWidget . previewTable ( self . fileList ) <EOL> self . fileTableWidget . exec_ ( ) <EOL> def slotLoad ( self ) : <EOL> self . optionsWidget . fillOptions ( self . options ) <EOL> self . accept ( ) <EOL> def exec_ ( self ) : <EOL> if QtGui . QDialog . exec_ ( self ) == QtGui . QDialog . Accepted : <EOL> return str ( self . path . text ( ) ) , self . fileList , self . options <EOL> else : <EOL> return None , None , None <EOL> def test ( ) : <EOL> """<STR_LIT>""" <EOL> app = QtGui . QApplication ( [ "<STR_LIT>" ] ) <EOL> dialog = StackLoader ( ) <EOL> print dialog . show ( ) <EOL> app . exec_ ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test ( ) </s>
