class MenueFrame(object):
   def __init__(self):
      self.mainDir = ""
   
      self.frame = JFrame("Dots Quality Check", size=(250,300))
      self.frame.setLocation(20,120)
      self.Panel = JPanel(GridLayout(0,1))
      self.frame.add(self.Panel)

      self.openNextButton = JButton('Open Next Random',actionPerformed=openRandom)
      self.Panel.add(self.openNextButton)
      
      self.saveButton = JButton('Save',actionPerformed=save)
      self.saveButton.setEnabled(False)
      self.Panel.add(self.saveButton)

      self.cropButton = JButton('Crop values from here', actionPerformed=cropVals)
      self.Panel.add(self.cropButton)

      self.DiscardButton = JButton('Discard cell', actionPerformed=discardCell)
      self.DiscardButton.setEnabled(True)
      self.Panel.add(self.DiscardButton)

      self.quitButton = JButton('Quit script',actionPerformed=quit)
      self.Panel.add(self.quitButton)

      annoPanel = JPanel()
      #add gridlayout
      wtRButton = JRadioButton("wt", actionCommand="wt")
      defectRButton = JRadioButton("Defect", actionCommand="defect")
      annoPanel.add(wtRButton)
      annoPanel.add(defectRButton)
      self.aButtonGroup = ButtonGroup()
      self.aButtonGroup.add(wtRButton)
      self.aButtonGroup.add(defectRButton)
      
      self.Panel.add(annoPanel)

      self.ProgBar = JProgressBar()
      self.ProgBar.setStringPainted(True)
      self.ProgBar.setValue(0)
      self.Panel.add(self.ProgBar)

      self.pathLabel = JLabel("-- No main directory chosen --")
      self.pathLabel.setHorizontalAlignment( SwingConstants.CENTER )
      self.Panel.add(self.pathLabel)

      
      WindowManager.addWindow(self.frame)
      self.show()

   def show(self):
      self.frame.visible = True

   def getFrame(self):
      return self.frame

   def setSaveActive(self):
      self.saveButton.setEnabled(True)
      self.show()

   def setSaveInactive(self):
      self.saveButton.setEnabled(False)
      self.show()

   def setMainDir(self, path):
      self.mainDir = path
      self.pathLabel.setText("MainDir: " + os.path.basename(os.path.split(self.mainDir)[0]))

   def getMainDir(self):
      return self.mainDir

   def setProgBarMax(self, maximum):
      self.ProgBar.setMaximum(maximum)

   def setProgBarVal(self, value):
      self.ProgBar.setValue(value)

   def close():
      WindowManager.removeWindow(self.frame)
      self.frame.dispose()     
class DetermineCookieFrame(JFrame):
    """ This is the GUI for for the user to control the actions when
        determining which cookie is the session cookie.
    """
    def __init__(self, callbacks, selected_message):
        super(DetermineCookieFrame, self).__init__()
        self.callbacks = callbacks
        self.selected_message = selected_message
        self.windowClosing = self.close

    def loadPanel(self):
        panel = JPanel()

        panel.setLayout(BoxLayout(panel, BoxLayout.Y_AXIS))

        bottomButtonBarPanel = JPanel()
        bottomButtonBarPanel.setLayout(
            BoxLayout(bottomButtonBarPanel, BoxLayout.X_AXIS))
        bottomButtonBarPanel.setAlignmentX(1.0)

        self.runButton = JButton("Run", actionPerformed=self.start)
        self.cancelButton = JButton("Close", actionPerformed=self.cancel)

        bottomButtonBarPanel.add(Box.createHorizontalGlue())
        bottomButtonBarPanel.add(self.runButton)
        bottomButtonBarPanel.add(self.cancelButton)

        # Dimension(width,height)
        bottom = JPanel()
        bottom.setLayout(BoxLayout(bottom, BoxLayout.X_AXIS))
        bottom.setAlignmentX(1.0)

        self.progressBar = JProgressBar()
        self.progressBar.setIndeterminate(False)
        self.progressBar.setMaximum(100)
        self.progressBar.setValue(0)

        bottom.add(self.progressBar)

        self.statusTextArea = JTextArea()
        self.statusTextArea.setEditable(False)
        scrollPane = JScrollPane(self.statusTextArea)
        scrollPanel = JPanel()
        scrollPanel.setLayout(BoxLayout(scrollPanel, BoxLayout.X_AXIS))
        scrollPanel.setAlignmentX(1.0)
        scrollPanel.add(scrollPane)

        panel.add(scrollPanel)
        panel.add(bottomButtonBarPanel)
        panel.add(bottom)

        self.add(panel)
        self.setTitle("Determine Session Cookie(s)")
        self.setSize(450, 300)
        self.setLocationRelativeTo(None)
        self.setVisible(True)

        original_request_bytes = self.selected_message.getRequest()
        http_service = self.selected_message.getHttpService()
        helpers = self.callbacks.getHelpers()
        request_info = helpers.analyzeRequest(http_service,
                                              original_request_bytes)
        parameters = request_info.getParameters()
        cookie_parameters = [
            parameter for parameter in parameters
            if parameter.getType() == IParameter.PARAM_COOKIE
        ]
        num_requests_needed = len(cookie_parameters) + 2
        self.statusTextArea.append(
            "This may require up to " + str(num_requests_needed) +
            " requests to be made. Hit 'Run' to begin.\n")

    def start(self, event):
        global cancelThread
        cancelThread = False
        self.runButton.setEnabled(False)
        self.cancelButton.setText("Cancel")
        thread = ThreadDetermineCookie(self.callbacks, self.selected_message,
                                       self.statusTextArea, self.progressBar)
        thread.start()

    def cancel(self, event):
        self.setVisible(False)
        self.dispose()

    def close(self, event):
        global cancelThread
        cancelThread = True
Example #3
0
class BottomPanel(JPanel):
    def __init__(self):

        self.holdPanel = JPanel()
        self.topPanel = JPanel()
        self.bottomPanel = JPanel()

        self.holdPanel.setBackground(Color.decode('#dddee6'))
        self.topPanel.setBackground(Color.decode('#dddee6'))
        self.bottomPanel.setBackground(Color.decode('#dddee6'))

        self.topPanel.setPreferredSize(Dimension(300, 30))

        self.regBar = JProgressBar()
        self.gatePassBar = JProgressBar()
        self.regLabel = JLabel('Register : ')
        self.gatepassLabel = JLabel('          Gate Pass : '******'')
        self.gatePercentlabel = JLabel('')

        self.refreshButton = JButton('Refresh',
                                     actionPerformed=self.updateProgress)

        self.regBar.setMinimum(0)
        self.regBar.setMaximum(100)
        self.regBar.setStringPainted(True)

        self.gatePassBar.setMinimum(0)
        self.gatePassBar.setMaximum(100)
        self.gatePassBar.setStringPainted(True)

        self.setLayout(BorderLayout())

        self.updateProgress(None)

    def updateProgress(self, e):

        progress = client.get_progress()
        regTotal = progress[0]
        regRecog = progress[1]
        gateTotal = progress[2]
        gateRecog = progress[3]

        regPercent = int((regRecog * 100) / regTotal)
        gatePercent = int((gateRecog * 100) / gateTotal)

        self.regBar.setValue(regPercent)
        self.gatePassBar.setValue(gatePercent)

        self.regBar.setString(str(regPercent) + '%')
        self.gatePassBar.setString(str(gatePercent) + '%')

        self.regPercentlabel.setText(str(regRecog) + '/' + str(regTotal))
        self.gatePercentlabel.setText(
            str(gateRecog) + '/' + str(gateTotal) + '           ')

        if regPercent <= 30:
            regColor = Color.RED
        elif regPercent > 30 and regPercent < 50:
            regColor = Color.ORANGE
        elif regPercent >= 50 and regPercent <= 100:
            regColor = Color.GREEN

        if gatePercent <= 30:
            gateColor = Color.RED
        elif gatePercent > 30 and gatePercent < 50:
            gateColor = Color.ORANGE
        elif gatePercent >= 50 and gatePercent <= 100:
            gateColor = Color.GREEN

        self.regBar.setForeground(regColor)
        self.gatePassBar.setForeground(gateColor)

        self.holdPanel.add(self.regLabel)
        self.holdPanel.add(self.regBar)
        self.holdPanel.add(self.regPercentlabel)
        self.holdPanel.add(self.gatepassLabel)
        self.holdPanel.add(self.gatePassBar)
        self.holdPanel.add(self.gatePercentlabel)
        self.holdPanel.add(self.refreshButton)

        self.add(self.holdPanel, BorderLayout.CENTER)
        self.add(self.topPanel, BorderLayout.PAGE_START)
        self.add(self.bottomPanel, BorderLayout.PAGE_END)

        self.validate()
class DetermineCookieFrame(JFrame):
    """ This is the GUI for for the user to control the actions when
        determining which cookie is the session cookie.
    """

    def __init__(self, callbacks, selected_message):
        super(DetermineCookieFrame, self).__init__()
        self.callbacks = callbacks
        self.selected_message = selected_message
        self.windowClosing = self.close

    def loadPanel(self):
        panel = JPanel()

        panel.setLayout(BoxLayout(panel, BoxLayout.Y_AXIS))

        bottomButtonBarPanel = JPanel()
        bottomButtonBarPanel.setLayout(BoxLayout(bottomButtonBarPanel, BoxLayout.X_AXIS))
        bottomButtonBarPanel.setAlignmentX(1.0)

        self.runButton = JButton("Run", actionPerformed=self.start)
        self.cancelButton = JButton("Close", actionPerformed=self.cancel)

        bottomButtonBarPanel.add(Box.createHorizontalGlue());
        bottomButtonBarPanel.add(self.runButton)
        bottomButtonBarPanel.add(self.cancelButton)

        # Dimension(width,height)    
        bottom = JPanel()
        bottom.setLayout(BoxLayout(bottom, BoxLayout.X_AXIS))
        bottom.setAlignmentX(1.0)

        self.progressBar = JProgressBar()
        self.progressBar.setIndeterminate(False)
        self.progressBar.setMaximum(100)
        self.progressBar.setValue(0)

        bottom.add(self.progressBar)

        self.statusTextArea = JTextArea()
        self.statusTextArea.setEditable(False)
        scrollPane = JScrollPane(self.statusTextArea)
        scrollPanel = JPanel()
        scrollPanel.setLayout(BoxLayout(scrollPanel, BoxLayout.X_AXIS))
        scrollPanel.setAlignmentX(1.0)
        scrollPanel.add(scrollPane)

        panel.add(scrollPanel)
        panel.add(bottomButtonBarPanel)
        panel.add(bottom)

        self.add(panel)
        self.setTitle("Determine Session Cookie(s)")
        self.setSize(450, 300)
        self.setLocationRelativeTo(None)
        self.setVisible(True)


        original_request_bytes = self.selected_message.getRequest()
        http_service = self.selected_message.getHttpService()
        helpers = self.callbacks.getHelpers()
        request_info = helpers.analyzeRequest(http_service, original_request_bytes)
        parameters = request_info.getParameters();
        cookie_parameters = [parameter for parameter in parameters if parameter.getType() == IParameter.PARAM_COOKIE]
        num_requests_needed = len(cookie_parameters) + 2
        self.statusTextArea.append("This may require up to " + str(num_requests_needed) + " requests to be made. Hit 'Run' to begin.\n")

    def start(self, event):
        global cancelThread
        cancelThread = False
        self.runButton.setEnabled(False)
        self.cancelButton.setText("Cancel")
        thread = ThreadDetermineCookie(self.callbacks, self.selected_message, self.statusTextArea, self.progressBar)
        thread.start()

    def cancel(self, event):
        self.setVisible(False);
        self.dispose();

    def close(self, event):
        global cancelThread
        cancelThread = True
Example #5
0
    def __init__(self, imgData):
        n = imgData.size()
        win = JFrame("Point Marker Panel")
        win.setPreferredSize(Dimension(350, 590))
        win.setSize(win.getPreferredSize())
        pan = JPanel()
        pan.setLayout(BoxLayout(pan, BoxLayout.Y_AXIS))
        win.getContentPane().add(pan)

        progressPanel = JPanel()
        progressPanel.setLayout(BoxLayout(progressPanel, BoxLayout.Y_AXIS))
        positionBar = JProgressBar()
        positionBar.setMinimum(0)
        positionBar.setMaximum(n)
        positionBar.setStringPainted(True)
        progressPanel.add(Box.createGlue())
        progressPanel.add(positionBar)

        progressBar = JProgressBar()
        progressBar.setMinimum(0)
        progressBar.setMaximum(n)
        progressBar.setStringPainted(True)
        progressPanel.add(progressBar)
        progressPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(progressPanel)

        pan.add(Box.createRigidArea(Dimension(5, 5)))
        savePanel = JPanel()
        savePanel.setLayout(BoxLayout(savePanel, BoxLayout.Y_AXIS))
        saveMessageLabel = JLabel("<html><u>Save Often</u></html>")
        savePanel.add(saveMessageLabel)
        savePanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        savePanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(savePanel)
        # pan.add(saveMessageLabel)

        pan.add(Box.createRigidArea(Dimension(5, 5)))
        calPanel = JPanel()
        calPanel.setLayout(BoxLayout(calPanel, BoxLayout.Y_AXIS))
        calPanelIn = JPanel()
        calPanelIn.setLayout(BoxLayout(calPanelIn, BoxLayout.X_AXIS))
        pixelSizeText = JTextField(12)
        pixelSizeText.setHorizontalAlignment(JTextField.RIGHT)
        # pixelSizeText.setMaximumSize(pixelSizeText.getPreferredSize())
        unitText = JTextField(10)
        # unitText.setMaximumSize(unitText.getPreferredSize())
        pixelSizeText.setText("Enter Pixel Size Here")
        calPanelIn.add(pixelSizeText)
        unitText.setText("Unit")
        calPanelIn.add(unitText)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanelIn.setBorder(
            BorderFactory.createTitledBorder("Custom Calibration"))
        calPanel.add(calPanelIn)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(calPanel)

        pan.add(Box.createRigidArea(Dimension(5, 5)))
        helpPanel = JPanel()
        helpPanel.setLayout(BoxLayout(helpPanel, BoxLayout.Y_AXIS))
        helpLable = JLabel("<html><ul>\
                            <li>Focus on Image Window</li>\
                            <li>Select multi-point Tool</li>\
                            <li>Click to Draw Points</li>\
                            <li>Drag to Move Points</li>\
                            <li>\"Alt\" + Click to Erase Points</li>\
                            <li>Optional: Customize Calibration Above\
                                 and Refresh Images\
                                (won't be written to files)</li>\
                            </html>")
        helpLable.setBorder(BorderFactory.createTitledBorder("Usage"))
        keyTagOpen = "<span style=\"background-color: #FFFFFF\"><b><kbd>"
        keyTagClose = "</kbd></b></span>"
        keyLable = JLabel("<html><ul>\
                            <li>Next Image --- "                                                 + keyTagOpen + "&lt" + \
                                keyTagClose + "</li>\
                            <li>Previous Image --- "                                                     + keyTagOpen + ">" + \
                                keyTagClose + "</li>\
                            <li>Save --- "                                           + keyTagOpen + "`" + keyTagClose + \
                                " (upper-left to TAB key)</li>\
                            <li>Next Unmarked Image --- "                                                          + keyTagOpen + \
                                "TAB" + keyTagClose + "</li></ul>\
                            </html>"                                    )
        keyLable.setBorder(
            BorderFactory.createTitledBorder("Keyboard Shortcuts"))
        helpPanel.add(helpLable)
        helpPanel.add(keyLable)
        helpPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        helpPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(helpPanel)

        # pan.add(Box.createRigidArea(Dimension(0, 10)))
        infoPanel = JPanel()
        infoPanel.setLayout(BoxLayout(infoPanel, BoxLayout.Y_AXIS))
        infoLabel = JLabel()
        infoLabel.setBorder(BorderFactory.createTitledBorder("Project Info"))
        infoPanel.add(infoLabel)
        infoPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        infoPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(infoPanel)

        win.setVisible(True)

        self.imgData = imgData
        self.win = win
        # self.progressPanel = progressPanel
        self.positionBar = positionBar
        self.progressBar = progressBar
        self.saveMessageLabel = saveMessageLabel
        self.infoLabel = infoLabel
        self.pixelSizeText = pixelSizeText
        self.unitText = unitText
        self.update()
    def __init__(self, imgData):
        n = imgData.size()
        win = JFrame("Point Marker Panel")
        win.setPreferredSize(Dimension(350, 590))
        win.setSize(win.getPreferredSize())
        pan = JPanel()
        pan.setLayout(BoxLayout(pan, BoxLayout.Y_AXIS))
        win.getContentPane().add(pan)

        progressPanel = JPanel()
        progressPanel.setLayout(BoxLayout(progressPanel, BoxLayout.Y_AXIS))
        positionBar = JProgressBar()
        positionBar.setMinimum(0)
        positionBar.setMaximum(n)
        positionBar.setStringPainted(True)
        progressPanel.add(Box.createGlue())
        progressPanel.add(positionBar)

        progressBar = JProgressBar()
        progressBar.setMinimum(0)
        progressBar.setMaximum(n)
        progressBar.setStringPainted(True)
        progressPanel.add(progressBar)
        progressPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(progressPanel)

        pan.add(Box.createRigidArea(Dimension(5,5)))
        savePanel = JPanel()
        savePanel.setLayout(BoxLayout(savePanel, BoxLayout.Y_AXIS))
        saveMessageLabel = JLabel("<html><u>Save Often</u></html>")
        savePanel.add(saveMessageLabel)
        savePanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        savePanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(savePanel)
        # pan.add(saveMessageLabel)

        pan.add(Box.createRigidArea(Dimension(5,5)))
        calPanel = JPanel()
        calPanel.setLayout(BoxLayout(calPanel, BoxLayout.Y_AXIS))
        calPanelIn = JPanel()
        calPanelIn.setLayout(BoxLayout(calPanelIn, BoxLayout.X_AXIS))
        pixelSizeText = JTextField(12)
        pixelSizeText.setHorizontalAlignment(JTextField.RIGHT)
        # pixelSizeText.setMaximumSize(pixelSizeText.getPreferredSize())
        unitText = JTextField(10)
        # unitText.setMaximumSize(unitText.getPreferredSize())
        pixelSizeText.setText("Enter Pixel Size Here")
        calPanelIn.add(pixelSizeText)
        unitText.setText("Unit")
        calPanelIn.add(unitText)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanelIn.setBorder(BorderFactory.createTitledBorder("Custom Calibration"))
        calPanel.add(calPanelIn)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(calPanel)

        pan.add(Box.createRigidArea(Dimension(5,5)))
        helpPanel = JPanel()
        helpPanel.setLayout(BoxLayout(helpPanel, BoxLayout.Y_AXIS))
        helpLable = JLabel("<html><ul>\
                            <li>Focus on Image Window</li>\
                            <li>Select multi-point Tool</li>\
                            <li>Click to Draw Points</li>\
                            <li>Drag to Move Points</li>\
                            <li>\"Alt\" + Click to Erase Points</li>\
                            <li>Optional: Customize Calibration Above\
                                 and Refresh Images\
                                (won't be written to files)</li>\
                            </html>")
        helpLable.setBorder(BorderFactory.createTitledBorder("Usage"))
        keyTagOpen = "<span style=\"background-color: #FFFFFF\"><b><kbd>"
        keyTagClose = "</kbd></b></span>"
        keyLable = JLabel("<html><ul>\
                            <li>Next Image --- " + keyTagOpen + "&lt" + \
                                keyTagClose + "</li>\
                            <li>Previous Image --- " + keyTagOpen + ">" + \
                                keyTagClose + "</li>\
                            <li>Save --- " + keyTagOpen + "`" + keyTagClose + \
                                " (upper-left to TAB key)</li>\
                            <li>Next Unmarked Image --- " + keyTagOpen + \
                                "TAB" + keyTagClose + "</li></ul>\
                            </html>")
        keyLable.setBorder(BorderFactory.createTitledBorder("Keyboard Shortcuts"))
        helpPanel.add(helpLable)
        helpPanel.add(keyLable)
        helpPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        helpPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(helpPanel)

        # pan.add(Box.createRigidArea(Dimension(0, 10)))
        infoPanel = JPanel()
        infoPanel.setLayout(BoxLayout(infoPanel, BoxLayout.Y_AXIS))
        infoLabel = JLabel()
        infoLabel.setBorder(BorderFactory.createTitledBorder("Project Info"))
        infoPanel.add(infoLabel)
        infoPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        infoPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(infoPanel)

        win.setVisible(True)

        self.imgData = imgData
        self.win = win
        # self.progressPanel = progressPanel
        self.positionBar = positionBar
        self.progressBar = progressBar
        self.saveMessageLabel = saveMessageLabel
        self.infoLabel = infoLabel
        self.pixelSizeText = pixelSizeText
        self.unitText = unitText
        self.update()
class MenueFrame(JFrame, ActionListener, WindowFocusListener): # should extend JFrame
    def __init__(self):
        self.mainDir = ""

        self.setTitle("Dots Quality Check")
        self.setSize(250, 300)
        self.setLocation(20,120)
        self.addWindowFocusListener(self)
        
        self.Panel = JPanel(GridLayout(0,1))
        self.add(self.Panel)
        self.openNextButton = JButton("Open Next Random", actionPerformed=self.openRandom)
        self.Panel.add(self.openNextButton)
        self.saveButton = JButton("Save", actionPerformed=self.save, enabled=False)
        self.Panel.add(self.saveButton)
        self.cropButton = JButton("Crop values from here", actionPerformed=self.cropVals)
        self.Panel.add(self.cropButton)
        self.DiscardButton = JButton("Discard cell", actionPerformed=self.discardCell)
        self.Panel.add(self.DiscardButton)
        self.quitButton = JButton("Quit script",actionPerformed=self.quit)
        self.Panel.add(self.quitButton)

        annoPanel = JPanel()
        #add gridlayout
        self.wtRButton = JRadioButton("wt", actionCommand="wt")
        self.wtRButton.addActionListener(self)
        self.defectRButton = JRadioButton("Defect", actionCommand="defect")
        self.defectRButton.addActionListener(self)
        annoPanel.add(self.wtRButton)
        annoPanel.add(self.defectRButton)
        self.aButtonGroup = ButtonGroup()
        self.aButtonGroup.add(self.wtRButton)
        self.aButtonGroup.add(self.defectRButton)
      
        self.Panel.add(annoPanel)

        self.ProgBar = JProgressBar()
        self.ProgBar.setStringPainted(True)
        self.ProgBar.setValue(0)
        self.Panel.add(self.ProgBar)

        self.pathLabel = JLabel("-- No main directory chosen --")
        self.pathLabel.setHorizontalAlignment( SwingConstants.CENTER )
        self.Panel.add(self.pathLabel)
      
        WindowManager.addWindow(self)
        self.show()

    # - - - -   B U T T O N   M E T H O D S  - - - -
    # - - - - - -  - - - - - - - - - - - - - - - - -
    def openRandom(self, event):      # when click here: get random cell and meas.measure(csv, tif, savePath)
        if self.mainDir == "":
            self.mainDir = DirectoryChooser("Random QC - Please choose main directory containing ctrl and test folders").getDirectory()
            self.pathLabel.setText("MainDir: " + os.path.basename(os.path.split(self.mainDir)[0]))
        try:
            # should be complete disposal!
            self.cT.closeWindows()
        finally:
            inFiles = glob.glob(os.path.join(self.mainDir, "*", G_OPENSUBDIR, "val_*.csv"))  # glob.glob returns list of paths
            uncheckedCells = [cell(csvPath) for csvPath in inFiles if cell(csvPath).processed == False]
            if len(uncheckedCells) > 0:
                self.cell = random.choice(uncheckedCells)
                #update progressbar
                self.ProgBar.setMaximum(len(inFiles)-1)
                self.ProgBar.setValue(len(inFiles)-len(uncheckedCells))
                # open imp and resultstable
                self.cT = correctionTable(self.cell, self) #self, openPath_csv, mF
                self.RBActionListener.setCell(self.cell)
                # delete previous Radiobutton annotation
                self.wtRButton.setSelected(False)
                self.defectRButton.setSelected(True)
            else:
                print "All cells measured!"

    def save(self, event):
        savepath = self.cell.getQcCsvPath()
        anaphase = self.cell.getAnOn()
        timeInterval = self.cT.getImp().getCalibration().frameInterval
        annotation = self.getAnnotation()
        position = str(self.cell.position)
        cellIndex = str(self.cell.cellNo)
        if not os.path.exists(os.path.split(savepath)[0]): # check if save folder present.
            os.makedirs(os.path.split(savepath)[0]) # create save folder, if not present
        f = open(savepath, "w")
        # Position Cell Phenotype Frame Time AnOn Distance ch0x ch0y ch0z ch0vol ch1x ch1y ch1z ch1vol
        f.write("Position,Cell,Phenotype,Frame,Time,Anaphase,Distance,ch0x,ch0y,ch0z,ch0vol,ch1x,ch1y,ch1z,ch1vol\n")
        for i in range(self.cT.getLineCount()):
            frame, distance, a = self.cT.getLine(i).split("\t")
            corrFrame = str(int(frame)-int(anaphase))
            time = "%.f" % (round(timeInterval) * int(corrFrame))
            if distance == "NA":
                ch0x, ch0y, ch0z, ch0vol, ch1x, ch1y, ch1z, ch1vol = ("NA," * 7 + "NA\n").split(",")
            else:
                ch0x, ch0y, ch0z, ch0vol, ch1x, ch1y, ch1z, ch1vol = self.cT.getXYZtable()[i]
            f.write(position+","+cellIndex+","+annotation+","+corrFrame+","+time+","+anaphase+","+distance+","+ch0x+","+ch0y+","+ch0z+","+ch0vol+","+ch1x+","+ch1y+","+ch1z+","+ch1vol)
        f.close()
        print "Successfully saved!"

    def cropVals(self, event): #"this function deletes all values with frame > current cursor"   
        for line in range(self.cT.getSelectionEnd(), self.cT.getLineCount(), 1):
            frame, distance, AOCol = self.cT.getLine(line).split("\t")
            self.cT.setLine(line, frame + "\tNA" + "\t" + AOCol)

    def discardCell(self, event):
        if not os.path.exists(os.path.split(self.cell.getQcCsvPath() )[0]): # check if save folder present.
            os.makedirs(os.path.split(self.cell.getQcCsvPath() )[0]) # create save folder, if not present.
        f = open(self.cell.getQcCsvPath() ,"w")
        # Write dummy header. Position Cell Phenotype Frame Time AnOn Distance ch0x ch0y ch0z ch0vol ch1x ch1y ch1z ch1vol
        f.write("Position,Cell,Phenotype,Frame,Time,AnOn,Distance,ch0x,ch0y,ch0z,ch0vol,ch1x,ch1y,ch1z,ch1vol\n")
        f.close()
        print "Discarded cell - saved dummy" 

    def quit(self, event):
        try:
            self.cT.closeWindows()
        finally:
            WindowManager.removeWindow(self)
            self.dispose()

    # Methods implementing ActionListener interfaces:
    def actionPerformed(self, e):
        # this function is called when RadioButtons are changed
        self.cell.annotate( e.getSource().getActionCommand() )
        self.setSaveActive()

    def windowGainedFocus(self, e):
        pass

    def windowLostFocus(self, e):
        pass
        

    # - - - - - - - - - - - - -
    # - get and set methods - -
    # - - - - - - - - - - - - -
    def getAnnotation(self):
        return self.aButtonGroup.getSelection().getActionCommand()

    def getMainDir(self):
        return self.mainDir

    def setSaveActive(self):
        if (self.cell.getAnnotation() != None and self.cell.getAnOn() != None):
            self.saveButton.setEnabled(True)
            self.show()

    def setSaveInactive(self):
        self.saveButton.setEnabled(False)
        self.show()

    def setMainDir(self, path):
        self.mainDir = path
        self.pathLabel.setText("MainDir: " + os.path.basename(os.path.split(self.mainDir)[0]))