Beispiel #1
0
class FileSelect(Frame):

  def __init__(self, parent, file_types = None, directory = None,
               single_callback = None, double_callback = None,
               prompt = None, show_file = True, file = '', multiSelect=False,
               default_dir = None, getRowColor = None,
               getExtraCell = None, extraHeadings = None, extraJustifies = None,
               displayExtra = True, *args, **kw):

    if file_types is None:
      file_types = [ FileType("All", ["*"]) ]

    if directory is None:
      directory = normalisePath(os.getcwd())

    if extraHeadings is None:
      extraHeadings = ()
    else:
      extraHeadings = tuple(extraHeadings)

    if extraJustifies is None:
      extraJustifies = ()
    else:
      extraJustifies = tuple(extraJustifies)

    if extraHeadings or extraJustifies:
      assert len(extraHeadings) == len(extraJustifies)
      assert getExtraCell

    self.extraHeadings = extraHeadings
    self.extraJustifies = extraJustifies
    self.displayExtra = displayExtra

    Frame.__init__(self, parent, *args, **kw)

    self.file_types = file_types
    self.fileType = file_types[0]
    self.single_callback = single_callback
    self.double_callback = double_callback
    self.show_file = show_file
    self.directory = None
    self.historyBack = []
    self.historyFwd = []
    self.determineDir(directory)
    self.default_dir = default_dir
    self.getRowColor = getRowColor
    self.getExtraCell = getExtraCell

    
    self.grid_columnconfigure(0, weight=1)

    row = 0
    if prompt:
      label = Label(self, text=prompt, grid=(row,0))
      row += 1

    self.grid_rowconfigure(row, weight=1)
    if show_file:
      headings = ('Name', 'Size', 'Date')
      justifies = ('left','right','right')
    else:
      headings = ('Directory',)
      justifies = ('left',)
    self.normalHeadings = headings
    self.normalJustifies = justifies
    headings = headings + extraHeadings
    justifies = justifies + extraJustifies

    self.fileList = ScrolledMatrix(self, headingList=headings, justifyList=justifies,
                                    initialRows=10, callback=self.singleCallback,
                                    doubleCallback=self.doubleCallback,
                                    multiSelect=multiSelect, grid=(row,0))

    row += 1
    texts = ['Back', 'Up', 'Forward', 'Top', 'Home', 'New', 'Refresh']
    commands = [self.backDir, self.fwdDir, self.upDir, self.topDir,
                self.homeDir, self.createDir, self.updateFileList ]

    if self.default_dir:
      texts.append('Default')
      commands.append(self.setDefaultDir)
      
    self.icons = []
    for name in ICON_NAMES:
      icon = Tkinter.PhotoImage(file=os.path.join(GFX_DIR,name+'.gif'))
      self.icons.append(icon)
      
    self.buttons = ButtonList(self, texts=texts, commands=commands,
                              images=self.icons, grid=(row,0))


    if show_file:
      row += 1
      self.file_entry = LabeledEntry(self, label='File name',
                              label_width=10, entry_width=40,
                              returnCallback=self.setSelectedFile)
      self.file_entry.grid(row=row, column=0, sticky=Tkinter.EW)
    else:
      self.file_entry = None

    row += 1
    self.directory_entry = LabeledEntry(self, label='Directory',
                                        entry = directory,
                                        label_width=10, entry_width=40,
                                        returnCallback=self.entryDir)
    self.directory_entry.grid(row=row, column=0, sticky=Tkinter.EW)


    row += 1
    subFrame = Frame(self, grid=(row,0))
    subFrame.expandGrid(None,6)

    if show_file:

      label = Label(subFrame, text='File type:', grid=(0,0))

      type_labels = self.determineTypeLabels()
      self.fileType_menu = PulldownList(subFrame, callback=self.typeCallback,
                                        texts=type_labels, objects=self.file_types,
                                        grid=(0,1))

    label = Label(subFrame, text=' Show hidden:', grid=(0,2))

    self.hidden_checkbutton = CheckButton(subFrame, text='', selected=False,
                                          callback=self.updateFileList, grid=(0,3))

    label = Label(subFrame, text='Dir path:', grid=(0,4))

    self.pathMenu = PulldownList(subFrame, callback=self.dirCallback,
                                 objects=range(len(self.dirs)),
                                 texts=self.dirs, index=len(self.dirs)-1,
                                 indent='  ', prefix=dirsep, grid=(0,5))

    self.updateFileList()
    self.updateButtons()

    if file:
      self.setFile(file)

  def updateDisplayExtra(self, displayExtra):

    self.displayExtra = displayExtra
    self.updateFileList()

  def isRootDirectory(self, directory = ''):

    if not directory:
      directory = self.directory

    if directory:
      return os.path.dirname(directory) == directory

    return True  # arbitrary

  def updateButtons(self):
  
    buttons = self.buttons.buttons
    isRoot = self.isRootDirectory

    if self.historyBack:
      buttons[0].enable()
    else:  
      buttons[0].disable()
    
    if self.historyFwd:
      buttons[1].enable()
    else:  
      buttons[1].disable()
    
    if self.directory and not isRoot(self.directory):
      buttons[2].enable()
      buttons[3].enable()
    else:  
      buttons[2].disable()
      buttons[3].disable()
   
    homeDir = self.getHomeDir()
    if homeDir and os.path.isdir(homeDir):
      buttons[4].enable()
    else:  
      buttons[4].disable()

  def backDir(self):

    if self.historyBack:
      self.historyFwd.insert(0, self.directory)
      dirName = self.historyBack.pop()
      self.changeDir(dirName, addHistory=False)

  def fwdDir(self):

    if self.historyFwd:
      self.historyBack.append(self.directory)
      dirName = self.historyFwd.pop(0)
      self.changeDir(dirName, addHistory=False)
  
  def topDir(self):
  
    if self.directory:
      isRoot = self.isRootDirectory
      dirName = self.directory
      while not isRoot(dirName):
        dirName = joinPath(dirName, os.pardir)
  
      self.changeDir(dirName)
  
  def homeDir(self):
  
    homeDir = self.getHomeDir()
    if homeDir:
      self.changeDir(homeDir)

  def getHomeDir(self):
  
    return os.environ.get('HOME') or os.environ.get('HOMEPATH')

  def upDir(self):

    self.changeDir(joinPath(self.directory, os.pardir))

  def setDefaultDir(self):

    self.changeDir(self.default_dir)

  def createDir(self):

    from memops.gui.DataEntry import askString
    
    msg = 'Enter new sub-directory name'
    dirName = askString('New directory', msg, parent=self)
    if dirName:
      dirName = joinPath(self.directory, dirName)
      if os.path.exists(dirName):
        msg = 'Directory "%s" already exists' % dirName
        showError('Directory exists', msg, parent=self)
      else:
        os.mkdir(dirName)
        self.updateFileList()

  def determineTypeLabels(self):

    type_labels = []
    for t in self.file_types:
      s = t.message + ' (' + ', '.join(t.filters) + ')'
      type_labels.append(s)

    return type_labels

  def setFileTypes(self, file_types):

    self.file_types = file_types
    if self.fileType not in file_types:
      self.fileType = file_types[0]

    if self.show_file:
      ind = self.file_types.index(self.fileType)
      type_labels = self.determineTypeLabels()
      self.fileType_menu.setup(type_labels, self.file_types, ind)
      self.updateFileList()

  def determineDir(self, directory):

    directory = normalisePath(directory)

    assert os.path.isdir(directory), '"%s" is not a directory' % directory

    self.prev_directory = self.directory

    if not os.path.isabs(directory):
      if self.directory is None: # first time around
        directory = joinPath(normalisePath(os.getcwd()), directory)
      else:
        directory = joinPath(self.directory, directory)

    self.directory = directory
    self.dirs = self.directory.split(dirsep)

  def setSelectedFile(self, *event):

    file = self.file_entry.getEntry()
    try:
      self.fileList.selectObject(file)
    except:
      showError('Some err', 'some err')

  def entryDir(self, *event):

    dirName = self.directory_entry.getEntry()
    try:
      self.changeDir(dirName)
    except:
      showError('Not a directory', '"' + dirName + '" is not a directory.')

  def changeDir(self, dirName, addHistory=True):

    if not os.path.isdir(dirName):
      return

    oldDir = self.directory


    self.determineDir(dirName)
    self.updateFileList()
    self.directory_entry.setEntry(self.directory)
    
    nDirs = len(self.dirs)
    
    self.pathMenu.setup(self.dirs, range(nDirs), index=nDirs-1)
    
    if addHistory:
      if oldDir and (self.directory != oldDir):
        self.historyBack.append(oldDir)
      self.historyFwd = []
    
    self.updateButtons()

  def getEntryInfo(self, entry):

    file = joinPath(self.directory, entry)

    if os.path.islink(file):
      # plain arrow: u' \u2192 '
      entry = entry + u' \u21D2 ' + os.readlink(file)
      size  = None
      color = '#E0D0C0'
      
    elif os.path.isdir(file):
      if not self.isRootDirectory(entry):
        entry = entry + dirsep
      size = None
      color = '#C0D0C0'
      
    else:
      color = '#C0C0D0'
      
      if self.show_file:
        try:
          size = str(os.path.getsize(file))
        except:
          size = None
      else:
        size = None
        
    try:
      fileTime = self.fileTime(file)
    except:
      fileTime = ''

    return (entry, size, fileTime, color)

  def getDrives(self):

    if isWindowsOS():
      import win32api
      drives = win32api.GetLogicalDriveStrings()
      drives = drives.split('\x00')
      drives = [normalisePath(drive) for drive in drives if drive]
      drives.sort()
    else:
      drives = []

    return drives

  def updateFileList(self, *extra):

    try:
      if self.directory:
        dir = self.directory
      else:
        dir = dirsep
      entries = self.getFilterFiles(dir)
    except OSError, e:
      showError('OS Error', str(e))
      if self.prev_directory:
        self.directory = None
        self.changeDir(self.prev_directory)
      return
    entries.sort()
    if self.directory:
      if self.isRootDirectory():
        entries[:0] = [drive for drive in self.getDrives() if drive not in self.directory]
      else:
        entries[:0] = [os.pardir] # add parent directory at front of list

    # DJOD: Not elegant, but robust !?!
    show_ent = []
    for entry in entries:
      if not self.hidden_checkbutton.getSelected():
        if not entry.startswith('.'):
          show_ent.append( entry )
      else:
        show_ent.append( entry )

    # if not show_ent.__contains__('.'):
    #   show_ent.append('.')

    if not show_ent.__contains__('..'):
      show_ent.append('..')

    entries = show_ent
    entries.sort()

    textMatrix = []
    colorMatrix = []
    for entry in entries:

      (entry, size, fileTime, color) = self.getEntryInfo(entry)
      fullEntry = joinPath(dir, entry)
      if self.getRowColor:
        color = self.getRowColor(fullEntry)

      if self.displayExtra and self.getExtraCell:
        data = self.getExtraCell(fullEntry)
        headingList = self.normalHeadings + self.extraHeadings
        justifyList = self.normalJustifies + self.extraJustifies
      else:
        data = ()
        headingList = self.normalHeadings
        justifyList = self.normalJustifies

      if self.show_file:
        text = [entry, size, fileTime]
      else:
        text = [entry,]
      text = text + list(data)

      textMatrix.append(text)
      numCols = len(headingList)
      colorMatrix.append(numCols*[color])

    self.fileList.update(objectList=entries, textMatrix=textMatrix, colorMatrix=colorMatrix,
                          headingList=headingList, justifyList=justifyList, resetScrollbars=True)
Beispiel #2
0
class FileSelect(Frame):
    def __init__(self,
                 parent,
                 file_types=None,
                 directory=None,
                 single_callback=None,
                 double_callback=None,
                 select_dir_callback=None,
                 change_dir_callback=None,
                 should_change_dir_callback=None,
                 prompt=None,
                 show_file=True,
                 file='',
                 multiSelect=False,
                 default_dir=None,
                 getRowColor=None,
                 getExtraCell=None,
                 extraHeadings=None,
                 extraJustifies=None,
                 displayExtra=True,
                 manualFileFilter=False,
                 extraTipTexts=None,
                 *args,
                 **kw):

        if file_types is None:
            file_types = [FileType("All", ["*"])]

        if manualFileFilter:
            self.manualFilter = FileType("Manual")
            file_types.append(self.manualFilter)
        else:
            self.manualFilter = None

        if directory is None:
            directory = normalisePath(os.getcwd())

        if extraHeadings is None:
            extraHeadings = ()
        else:
            extraHeadings = tuple(extraHeadings)

        if extraJustifies is None:
            extraJustifies = ()
        else:
            extraJustifies = tuple(extraJustifies)

        if extraHeadings or extraJustifies:
            assert len(extraHeadings) == len(extraJustifies)
            assert getExtraCell

        self.extraHeadings = extraHeadings
        self.extraJustifies = extraJustifies
        self.extraTipTexts = extraTipTexts or []
        self.displayExtra = displayExtra

        Frame.__init__(self, parent, *args, **kw)

        self.file_types = file_types
        self.fileType = file_types[0]
        self.single_callback = single_callback
        self.double_callback = double_callback
        self.select_dir_callback = select_dir_callback
        self.change_dir_callback = change_dir_callback
        self.should_change_dir_callback = should_change_dir_callback
        self.show_file = show_file
        self.directory = None
        self.historyBack = []
        self.historyFwd = []
        self.determineDir(directory)
        self.default_dir = default_dir
        self.getRowColor = getRowColor
        self.getExtraCell = getExtraCell

        self.grid_columnconfigure(0, weight=1)

        row = 0
        if prompt:
            label = Label(self, text=prompt, grid=(row, 0))
            row += 1

        self.grid_rowconfigure(row, weight=1)
        if show_file:
            headings = ('Name', 'Size', 'Date')
            justifies = ('left', 'right', 'right')
            tipTexts = [
                'Name of file, directory or link', 'Size of file in bytes',
                'Date of last modification'
            ]
        else:
            headings = ('Directory', )
            justifies = ('left', )
            tipTexts = ['Name of directory']

        self.normalHeadings = headings
        self.normalJustifies = justifies
        self.normalTipTexts = tipTexts
        headings = headings + extraHeadings
        justifies = justifies + extraJustifies
        tipTexts += [None] * len(extraHeadings)

        self.fileList = ScrolledMatrix(self,
                                       headingList=headings,
                                       justifyList=justifies,
                                       initialRows=10,
                                       callback=self.singleCallback,
                                       doubleCallback=self.doubleCallback,
                                       tipTexts=tipTexts,
                                       multiSelect=multiSelect,
                                       grid=(row, 0))

        row += 1
        tipTexts = [
            'Go to previous location in history',
            'Go forward in location history', 'Go up one directory level',
            'Go to root directory', 'Go to home directory',
            'Make a new directory', 'Refresh directory listing'
        ]

        texts = ['Back', 'Forward', 'Up', 'Top', 'Home', 'New', 'Refresh']
        commands = [
            self.backDir, self.fwdDir, self.upDir, self.topDir, self.homeDir,
            self.createDir, self.updateFileList
        ]

        if self.default_dir:
            texts.append('Default')
            commands.append(self.setDefaultDir)
            tipTexts.append('Set the current directory as the default')

        self.icons = []
        for name in ICON_NAMES:
            icon = Tkinter.PhotoImage(
                file=os.path.join(GFX_DIR, name + '.gif'))
            self.icons.append(icon)

        self.buttons = ButtonList(self,
                                  texts=texts,
                                  commands=commands,
                                  images=self.icons,
                                  grid=(row, 0),
                                  tipTexts=tipTexts)

        if show_file:
            row += 1
            self.file_entry = LabeledEntry(self,
                                           label='File name',
                                           label_width=10,
                                           entry_width=40,
                                           returnCallback=self.setSelectedFile)
            self.file_entry.grid(row=row, column=0, sticky=Tkinter.EW)
        else:
            self.file_entry = None

        row += 1
        self.directory_entry = LabeledEntry(self,
                                            label='Directory',
                                            entry=directory,
                                            label_width=10,
                                            entry_width=40,
                                            returnCallback=self.entryDir)
        self.directory_entry.grid(row=row, column=0, sticky=Tkinter.EW)

        row += 1
        subFrame = Frame(self, grid=(row, 0))
        subFrame.expandGrid(None, 6)

        if show_file:

            label = Label(subFrame, text='File type:', grid=(0, 0))

            type_labels = self.determineTypeLabels()
            self.fileType_menu = PulldownList(
                subFrame,
                callback=self.typeCallback,
                texts=type_labels,
                objects=self.file_types,
                grid=(0, 1),
                tipText='Restrict listed files to selected suffix')

        label = Label(subFrame, text=' Show hidden:', grid=(0, 2))

        self.hidden_checkbutton = CheckButton(
            subFrame,
            text='',
            selected=False,
            callback=self.updateFileList,
            grid=(0, 3),
            tipText='Show hidden files beginning with "." etc.')

        label = Label(subFrame, text='Dir path:', grid=(0, 4))

        self.pathMenu = PulldownList(
            subFrame,
            callback=self.dirCallback,
            objects=range(len(self.dirs)),
            texts=self.dirs,
            index=len(self.dirs) - 1,
            indent='  ',
            prefix=dirsep,
            grid=(0, 5),
            tipText='Directory navigation to current location')

        if show_file and self.manualFilter is not None:
            row += 1
            self.manual_filter_entry = LabeledEntry(
                self,
                label='Manual Select',
                entry=defaultFilter,
                label_width=13,
                entry_width=40,
                returnCallback=self.entryFilter,
                tipText=
                'Path specification with wildcards to select multiple files')
            self.manual_filter_entry.grid(row=row, column=0, sticky=Tkinter.EW)

        self.updateFileList()
        self.updateButtons()

        if file:
            self.setFile(file)

    def updateDisplayExtra(self, displayExtra):

        self.displayExtra = displayExtra
        self.updateFileList()

    def isRootDirectory(self, directory=''):

        if not directory:
            directory = self.directory

        if directory:
            return os.path.dirname(directory) == directory

        return True  # arbitrary

    def updateButtons(self):

        buttons = self.buttons.buttons
        isRoot = self.isRootDirectory

        if self.historyBack:
            buttons[0].enable()
        else:
            buttons[0].disable()

        if self.historyFwd:
            buttons[1].enable()
        else:
            buttons[1].disable()

        if self.directory and not isRoot(self.directory):
            buttons[2].enable()
            buttons[3].enable()
        else:
            buttons[2].disable()
            buttons[3].disable()

        homeDir = self.getHomeDir()
        if homeDir and os.path.isdir(homeDir):
            buttons[4].enable()
        else:
            buttons[4].disable()

    def backDir(self):

        if self.historyBack:
            self.historyFwd.insert(0, self.directory)
            dirName = self.historyBack.pop()
            self.changeDir(dirName, addHistory=False)

    def fwdDir(self):

        if self.historyFwd:
            self.historyBack.append(self.directory)
            dirName = self.historyFwd.pop(0)
            self.changeDir(dirName, addHistory=False)

    def topDir(self):

        if self.directory:
            isRoot = self.isRootDirectory
            dirName = self.directory
            while not isRoot(dirName):
                dirName = joinPath(dirName, os.pardir)

            self.changeDir(dirName)

    def homeDir(self):

        homeDir = self.getHomeDir()
        if homeDir:
            self.changeDir(homeDir)

    def getHomeDir(self):

        return os.environ.get('HOME') or os.environ.get('HOMEPATH')

    def upDir(self):

        self.changeDir(joinPath(self.directory, os.pardir))

    def setDefaultDir(self):

        self.changeDir(self.default_dir)

    def createDir(self):

        from memops.gui.DataEntry import askString

        msg = 'Enter new sub-directory name'
        dirName = askString('New directory', msg, parent=self)
        if dirName:
            dirName = joinPath(self.directory, dirName)
            if os.path.exists(dirName):
                msg = 'Directory "%s" already exists' % dirName
                showError('Directory exists', msg, parent=self)
            else:
                os.mkdir(dirName)
                self.updateFileList()

    def determineTypeLabels(self):

        type_labels = []
        for t in self.file_types:
            s = t.message + ' (' + ', '.join(t.filters) + ')'
            type_labels.append(s)

        return type_labels

    def setFileTypes(self, file_types):

        self.file_types = file_types
        if self.fileType not in file_types:
            self.fileType = file_types[0]
        if self.show_file:
            ind = self.file_types.index(self.fileType)
            type_labels = self.determineTypeLabels()
            self.fileType_menu.setup(type_labels, self.file_types, ind)
            self.updateFileList()

    def determineDir(self, directory):

        directory = normalisePath(directory)

        assert os.path.isdir(directory), '"%s" is not a directory' % directory

        self.prev_directory = self.directory

        if not os.path.isabs(directory):
            if self.directory is None:  # first time around
                directory = joinPath(normalisePath(os.getcwd()), directory)
            else:
                directory = joinPath(self.directory, directory)

        self.directory = directory
        self.dirs = self.directory.split(dirsep)

    def setSelectedFile(self, *event):

        file = self.file_entry.getEntry()
        try:
            self.fileList.selectObject(file)
        except:
            showError('Some err', 'some err')

    def entryDir(self, *event):

        dirName = self.directory_entry.getEntry()
        try:
            self.changeDir(dirName)
        except:
            showError('Not a directory',
                      '"' + dirName + '" is not a directory.')

    def entryFilter(self, *event):

        filterString = self.manual_filter_entry.getEntry()
        filters = [str.strip(x) for x in filterString.split(',')]
        self.manualFilter.filters = filters
        self.fileType = self.manualFilter

        self.setFileTypes(
            self.file_types)  # to trigger update after filter change
        self.updateFileList()

        self.manual_filter_entry.setEntry(filterString)

    def changeDir(self, dirName, addHistory=True):

        if not os.path.isdir(dirName):
            return

        if self.should_change_dir_callback:
            if not self.should_change_dir_callback(dirName):
                return

        oldDir = self.directory

        self.determineDir(dirName)
        self.updateFileList()
        self.directory_entry.setEntry(self.directory)

        if self.change_dir_callback:
            self.change_dir_callback(self.directory)

        nDirs = len(self.dirs)

        self.pathMenu.setup(self.dirs, range(nDirs), index=nDirs - 1)

        if addHistory:
            if oldDir and (self.directory != oldDir):
                self.historyBack.append(oldDir)
            self.historyFwd = []

        self.updateButtons()

    def getEntryInfo(self, entry):

        file = joinPath(self.directory, entry)

        if os.path.islink(file):
            # plain arrow: u' \u2192 '
            entry = entry + u' \u21D2 ' + unicode(os.readlink(file), 'utf-8')
            size = None
            color = '#E0D0C0'

        elif os.path.isdir(file):
            if not self.isRootDirectory(entry):
                entry = entry + dirsep
            size = None
            color = '#C0D0C0'

        else:
            color = '#C0C0D0'

            if self.show_file:
                try:
                    size = str(os.path.getsize(file))
                except:
                    size = None
            else:
                size = None

        try:
            fileTime = self.fileTime(file)
        except:
            fileTime = ''

        return (entry, size, fileTime, color)

    def getDrives(self):

        if isWindowsOS():
            #import win32api
            #drives = win32api.GetLogicalDriveStrings()
            #drives = drives.split('\x00')
            #drives = [normalisePath(drive) for drive in drives if drive]
            #drives.sort()
            # 19 Mar 2012: do not use win32api because not standard
            from ctypes import windll
            import string
            drives = []
            bitmask = windll.kernel32.GetLogicalDrives()
            for letter in string.ascii_uppercase:
                if bitmask & 1:
                    drives.append(letter)
                bitmask >>= 1
            drives = [drive + ':\\' for drive in drives]
            drives = [normalisePath(drive) for drive in drives]
        else:
            drives = []

        return drives

    def updateFileList(self, *extra):

        try:
            if self.directory:
                directory = self.directory
            else:
                directory = dirsep
            entries = self.getFilterFiles(directory)
        except OSError, e:
            showError('OS Error', str(e))
            if self.prev_directory:
                self.directory = None
                self.changeDir(self.prev_directory)
            return

        if self.directory:
            if self.isRootDirectory():
                entries[:0] = [
                    drive for drive in self.getDrives()
                    if drive not in self.directory
                ]
            else:
                entries[:0] = [os.pardir
                               ]  # add parent directory at front of list

        # DJOD: Not elegant, but robust !?!
        showHidden = self.hidden_checkbutton.getSelected()
        show_ent = []
        for entry in entries:
            if not showHidden:
                if not entry.startswith('.'):
                    show_ent.append(entry)
            else:
                show_ent.append(entry)

        # if not show_ent.__contains__('.'):
        #   show_ent.append('.')

        if not show_ent.__contains__('..'):
            show_ent.insert(0, '..')

        entries = show_ent

        textMatrix = []
        colorMatrix = []
        for entryActual in entries:

            (entry, size, fileTime, color) = self.getEntryInfo(entryActual)
            fullEntry = joinPath(directory, entryActual)
            if self.getRowColor:
                color = self.getRowColor(fullEntry)

            if self.displayExtra and self.getExtraCell:
                data = self.getExtraCell(fullEntry)
                headingList = self.normalHeadings + self.extraHeadings
                justifyList = self.normalJustifies + self.extraJustifies
                tipTexts = self.normalTipTexts + self.extraTipTexts
            else:
                data = ()
                headingList = self.normalHeadings
                justifyList = self.normalJustifies
                tipTexts = self.normalTipTexts
                # in case we had sorted on a now removed line :
                self.fileList.lastSortLine = None

            if self.show_file:
                text = [entry, size, fileTime]
            else:
                text = [
                    entry,
                ]
            text = text + list(data)

            textMatrix.append(text)
            numCols = len(headingList)
            colorMatrix.append(numCols * [color])

        self.fileList.update(objectList=entries,
                             textMatrix=textMatrix,
                             colorMatrix=colorMatrix,
                             headingList=headingList,
                             justifyList=justifyList,
                             tipTexts=tipTexts)
class HaddockServerUpload(BasePopup):

    def __init__(self,parent,hProject=None,latestRun=None,ccpnProject=None):

        self.parent         = parent  #GUI parent
        self.hProject        = hProject
        self.latestRun         = latestRun
        self.ccpnProject     = ccpnProject
        
        self.username        = None
        self.password        = None
        
        BasePopup.__init__(self, parent=parent, title='HADDOCK server upload')

    def body(self, guiFrame):

        guiFrame.grid_columnconfigure(1, weight=1)
        guiFrame.grid_rowconfigure(1, weight=1)

        self.usernameEntry = LabeledEntry(guiFrame, 'username')
        self.usernameEntry.grid(row=0)

        self.passwordEntry = LabeledEntry(guiFrame, 'password', show="*")
        self.passwordEntry.grid(row=1)
        
        texts = ['Upload']
        commands = [self.serverUpload]
        buttonList = createDismissHelpButtonList(guiFrame, texts=texts, commands=commands, expands=True)
        buttonList.grid(row=2)

    def serverUpload(self):
        
        """Process username and password. If both valid then start uploading otherwise issue warning.
           Export the project and run as a .web file to disk. Than upload this file
        """
        warning = ''
        
        if self.usernameEntry.getEntry(): self.username = self.usernameEntry.getEntry()
        else: warning += ' No username defined ' 
        
        if self.passwordEntry.getEntry(): self.password = self.passwordEntry.getEntry()
        else: warning += ' No password defined '            
        
        if len(warning): showWarning('Warning', warning, parent=self)
        else:
            exportParams = exportParam(hProject=self.hProject,
                                       latestRun=self.latestRun,
                                       ccpnProject=self.ccpnProject)
            if len(exportParams.filestring): upload = ServerUpload(exportParams.filestring,
                                                                     self.hProject.name,
                                                                     str(self.latestRun.serial),
                                                                     self.username,
                                                                     self.password)
            else: print("ERROR: Export project as parameter file failed")
                
    def open(self):

        BasePopup.open(self)    

    def destroy(self):

        BasePopup.destroy(self)