def __init__(self, program): self.setLayout(BorderLayout()) title = JLabel(program.title) title.setFont(Font("Arial", Font.BOLD, 28)) title.setHorizontalAlignment(JLabel.CENTER) title.setVerticalAlignment(JLabel.CENTER) title.setBorder(createEmptyBorder(15, 5, 15, 5)) if not program.public: lbl = JLabel("Private") lbl.setFont(Font("Arial", Font.BOLD, 20)) lbl.setForeground(Color(0xFF2424)) lbl.setBorder(createEmptyBorder(15, 15, 15, 15)) leftbox = lbl else: leftbox = Box.createHorizontalGlue() btnbox = TitleBtnBox(program) btnbox.setBorder(createEmptyBorder(5, 5, 5, 5)) self.add(leftbox, BorderLayout.LINE_START) self.add(title, BorderLayout.CENTER) self.add(btnbox, BorderLayout.LINE_END) same_size(leftbox, btnbox) self.setMaximumSize(Dimension(99999, self.getPreferredSize().height))
def __init__(self): self.setAlwaysOnTop(False); self.setSize(500, 500); menubar = JMenuBar(); menu = JMenu("A Menu"); menu_ac = menu.getAccessibleContext(); menu_ac.setAccessibleDescription("The only menu in this program"); menuitem = JMenuItem("A Menu Item"); menu.add(menuitem); menubar.add(menu); self.setJMenuBar(menubar); lbl = JLabel("A Label"); lbl.setHorizontalAlignment(JLabel.CENTER); lbl.setVerticalAlignment(JLabel.CENTER); self.setContentPane(lbl); self.setVisible(True);
def build_gui(self): """Construct GUI elements.""" panel = JPanel(BorderLayout(3, 3)) panel.setBorder(EmptyBorder(160, 160, 160, 160)) self.aws_access_key_inpt = JTextField(10) self.aws_secret_key_inpt = JTextField(10) self.aws_session_token_inpt = JTextField(10) self.gs_access_key_inpt = JTextField(10) self.gs_secret_key_inpt = JTextField(10) self.wordlist_path_inpt = JTextField(10) self.passive_mode = JCheckBox('Enabled') self.ssl_verification = JCheckBox('Enabled') save_btn = JButton('Save', actionPerformed=self.save_config) labels = JPanel(GridLayout(0, 1)) inputs = JPanel(GridLayout(0, 1)) panel.add(labels, BorderLayout.WEST) panel.add(inputs, BorderLayout.CENTER) top_label = JLabel('<html><b>Settings</b><br><br></html>') top_label.setHorizontalAlignment(JLabel.CENTER) panel.add(top_label, BorderLayout.NORTH) labels.add(JLabel('AWS Access Key:')) inputs.add(self.aws_access_key_inpt) labels.add(JLabel('AWS Secret Key:')) inputs.add(self.aws_secret_key_inpt) labels.add(JLabel('AWS Session Key (optional):')) inputs.add(self.aws_session_token_inpt) labels.add(JLabel('GS Access Key:')) inputs.add(self.gs_access_key_inpt) labels.add(JLabel('GS Secret Key:')) inputs.add(self.gs_secret_key_inpt) labels.add(JLabel('Wordlist Filepath (optional):')) inputs.add(self.wordlist_path_inpt) labels.add(JLabel('Passive Mode:')) inputs.add(self.passive_mode) labels.add(JLabel('SSL Verification:')) inputs.add(self.ssl_verification) panel.add(save_btn, BorderLayout.SOUTH) return panel
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 BurpExtender(IBurpExtender, ITab): def registerExtenderCallbacks(self, callbacks): self._cb = callbacks self._hp = callbacks.getHelpers() self._cb.setExtensionName('MiniProgram Decrypto') print 'successful!' self.mainPanel = JPanel() self.sessionKey = JLabel("sessionKey:") self.sessionKey.setHorizontalAlignment(SwingConstants.LEFT); self.iv = JLabel("iv:") self.tfsessionKey = JTextField(50) self.tfiv = JTextField(50) self.textAreaPlaintext = JTextArea(30, 40) self.textAreaPlaintext.setLineWrap(True) self.textAreaPlaintext2 = JTextArea(30, 40) self.textAreaPlaintext2.setLineWrap(True) self.DecryptoBtn = JButton('Decrypto >', actionPerformed=self.decrypto_onClick) self.CryptoBtn = JButton('< Crypto', actionPerformed=self.encrypto_onClick) self.mainPanel.add(self.sessionKey) self.mainPanel.add(self.tfsessionKey) self.mainPanel.add(self.iv) self.mainPanel.add(self.tfiv) self.mainPanel.add(self.textAreaPlaintext) self.mainPanel.add(self.CryptoBtn) self.mainPanel.add(self.DecryptoBtn) self.mainPanel.add(self.textAreaPlaintext2) self._cb.customizeUiComponent(self.mainPanel) self._cb.addSuiteTab(self) def decrypto_onClick(self, event): self.textAreaPlaintext2.setText("") session_key = self.tfsessionKey.getText() iv = self.tfiv.getText() payload = self.textAreaPlaintext.getText().rstrip() str = self.decrypto(payload, session_key, iv) self.textAreaPlaintext2.append(str) def encrypto_onClick(self, event): self.textAreaPlaintext.setText("") session_key = self.tfsessionKey.getText() iv = self.tfiv.getText() payload = self.textAreaPlaintext2.getText().rstrip() str = self.encrypto(payload, session_key, iv) self.textAreaPlaintext.append(String(str)) def getTabCaption(self): return 'MiniProgram Decrypto' def getUiComponent(self): return self.mainPanel def encrypto(self, payload, key, iv): aesKey = SecretKeySpec(base64.b64decode(key), "AES") aesIV = IvParameterSpec(base64.b64decode(iv)) cipher = Cipher.getInstance("AES/CBC/PKCS7Padding") cipher.init(Cipher.ENCRYPT_MODE, aesKey, aesIV) encrypted = cipher.doFinal(payload) return Base64.getEncoder().encode(encrypted) def decrypto(self, payload, key, iv): decoded = base64.b64decode(payload) aesKey = SecretKeySpec(base64.b64decode(key), "AES") aesIV = IvParameterSpec(base64.b64decode(iv)) cipher = Cipher.getInstance("AES/CBC/PKCS7Padding","BC") cipher.init(Cipher.DECRYPT_MODE, aesKey, aesIV) return String(cipher.doFinal(decoded))
class BurpExtender(IBurpExtender, ITab, IHttpListener, IMessageEditorTabFactory): def registerExtenderCallbacks(self, callbacks): self._callbacks = callbacks self._helpers = callbacks.getHelpers() callbacks.setExtensionName("HaE(Highlighter and Extractor)") self._stdout = PrintWriter(callbacks.getStdout(), True) callbacks.registerHttpListener(self) callbacks.registerMessageEditorTabFactory(self) print 'HaE(Highlighter and Extractor)\nAuthor: Vulkey_Chen\nBlog: gh0st.cn\nTeam: MSTSEC' self._callbacks.customizeUiComponent(self.getUiComponent()) self._callbacks.addSuiteTab(self) self.endColors = [] def getTabCaption(self): return 'HaE' def createNewInstance(self, controller, editable): return MarkINFOTab(self, controller, editable) def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo): if messageIsRequest: return content = messageInfo.getResponse() # content 为响应正文信息 info = getConfig() results = findContent(info, content) colorList = [] if results != {}: for i in results: if info[i]['highlight'] == 1: if info[i]['color'] == 'red': messageInfo.setHighlight(info[i]['color']) break else: colorList.append(info[i]['color']) if not messageInfo.getHighlight(): colorsList = [colors.index(i) for i in colorList] colorsList.sort() # print(colorsList) self.helper(colorsList) endColor = [colors.index(x) for x in self.endColors] # print(endColor) messageInfo.setHighlight(colors[min(endColor)]) # 颜色升级 def helper(self, mylist): l = len(mylist) i = 0 stack = [] while i < l: if not stack: stack.append(mylist[i]) i += 1 else: if mylist[i] != stack[-1]: stack.append(mylist[i]) i += 1 else: stack[-1] -= 1 i += 1 if len(stack) == len(set(stack)): self.endColors = [colors[i] for i in stack] else: self.helper(stack) def addConfig(self, event): nameText = self.nameTextField.getText() regexText = self.regexTextField.getText() colorText = self.colorTextField.getText() isHighlight = int(self.highlightCheckBox.isSelected()) isExtract = int(self.extractCheckBox.isSelected()) if colorText in colors: with open(configFile, 'r+') as content: dicts = json.load(content) # 解决r+写入问题 content.seek(0, 0) content.truncate() if nameText in dicts: self.tipString.setText("Name is existed!") elif not (isHighlight or isExtract): self.tipString.setText("Highlight or Extract?") else: dicts[nameText] = { "regex": regexText, "highlight": isHighlight, "extract": isExtract, "color": colorText } content.write(jsbeautifier.beautify(json.dumps(dicts))) #print(dicts) self.tipString.setText("Save Successfully!") else: self.tipString.setText("Not in colors list.") def reloadConfig(self, event): with open(configFile, 'r') as content: self.configTextArea.setText(content.read()) def getUiComponent(self): self.HaEPanel = JPanel() self.HaEPanel.setBorder(None) self.HaEPanel.setLayout(BorderLayout(0, 0)) self.panel = JPanel() self.HaEPanel.add(self.panel, BorderLayout.NORTH) self.panel.setLayout(BorderLayout(0, 0)) self.tabbedPane = JTabbedPane(JTabbedPane.TOP) self.panel.add(self.tabbedPane, BorderLayout.CENTER) self.setPanel = JPanel() self.tabbedPane.addTab("Set", None, self.setPanel, None) self.setPanel.setLayout(BorderLayout(0, 0)) self.setPanel_1 = JPanel() self.setPanel.add(self.setPanel_1, BorderLayout.NORTH) self.nameString = JLabel("Name") self.setPanel_1.add(self.nameString) self.nameTextField = JTextField() self.setPanel_1.add(self.nameTextField) self.nameTextField.setColumns(10) self.regexString = JLabel("Regex") self.setPanel_1.add(self.regexString) self.regexTextField = JTextField() self.setPanel_1.add(self.regexTextField) self.regexTextField.setColumns(10) self.extractCheckBox = JCheckBox("Extract") self.setPanel_1.add(self.extractCheckBox) self.highlightCheckBox = JCheckBox("Highlight") self.setPanel_1.add(self.highlightCheckBox) self.setPanel_2 = JPanel() self.setPanel.add(self.setPanel_2) self.colorString = JLabel("Color") self.setPanel_2.add(self.colorString) self.colorTextField = JTextField() self.setPanel_2.add(self.colorTextField) self.colorTextField.setColumns(5) self.addBottun = JButton("Add", actionPerformed=self.addConfig) self.setPanel_2.add(self.addBottun) self.tipString = JLabel("") self.setPanel_2.add(self.tipString) self.configPanel = JPanel() self.tabbedPane.addTab("Config", None, self.configPanel, None) self.configPanel.setLayout(BorderLayout(0, 0)) self.configString = JLabel("This is config file content.") self.configString.setHorizontalAlignment(SwingConstants.CENTER) self.configPanel.add(self.configString, BorderLayout.NORTH) self.configTextArea = JTextArea() self.configTextArea.setEnabled(False) self.configTextArea.setTabSize(4) self.configTextArea.setLineWrap(True) self.configTextArea.setRows(20) self.configPanel.add(self.configTextArea, BorderLayout.SOUTH) self.scrollPane = JScrollPane(self.configTextArea) self.configPanel.add(self.scrollPane, BorderLayout.SOUTH) self.reloadButton = JButton("Reload", actionPerformed=self.reloadConfig) self.configPanel.add(self.reloadButton, BorderLayout.CENTER) return self.HaEPanel
class BeautifierPanel(JPanel): def __init__(self): super(BeautifierPanel, self).__init__() self.setLayout(BorderLayout()) self.beautifyTextArea = JTextArea(5, 10) self.beautifyTextArea.setLineWrap(True) self.beautifyTextArea.setDocument(self.CustomUndoPlainDocument()) # The undo doesn't work well before replace text. Below is rough fix, so not need to know how undo work for now self.beautifyTextArea.setText(" ") self.beautifyTextArea.setText("") self.undoManager = UndoManager() self.beautifyTextArea.getDocument().addUndoableEditListener( self.undoManager) self.beautifyTextArea.getDocument().addDocumentListener( self.BeautifyDocumentListener(self)) beautifyTextWrapper = JPanel(BorderLayout()) beautifyScrollPane = JScrollPane(self.beautifyTextArea) beautifyTextWrapper.add(beautifyScrollPane, BorderLayout.CENTER) self.add(beautifyTextWrapper, BorderLayout.CENTER) self.beautifyButton = JButton("Beautify") self.beautifyButton.addActionListener(self.beautifyListener) self.undoButton = JButton("Undo") self.undoButton.addActionListener(self.undoListener) formatLabel = JLabel("Format:") self.formatsComboBox = JComboBox() for f in supportedFormats: self.formatsComboBox.addItem(f) self.statusLabel = JLabel("Status: Ready") preferredDimension = self.statusLabel.getPreferredSize() self.statusLabel.setPreferredSize( Dimension(preferredDimension.width + 20, preferredDimension.height)) self.sizeLabel = JLabel("0 B") preferredDimension = self.sizeLabel.getPreferredSize() self.sizeLabel.setPreferredSize( Dimension(preferredDimension.width + 64, preferredDimension.height)) self.sizeLabel.setHorizontalAlignment(SwingConstants.RIGHT) buttonsPanel = JPanel(FlowLayout()) buttonsPanel.add(formatLabel) buttonsPanel.add(self.formatsComboBox) buttonsPanel.add(Box.createHorizontalStrut(10)) buttonsPanel.add(self.beautifyButton) buttonsPanel.add(self.undoButton) bottomPanel = JPanel(BorderLayout()) bottomPanel.add(self.statusLabel, BorderLayout.WEST) bottomPanel.add(buttonsPanel, BorderLayout.CENTER) bottomPanel.add(self.sizeLabel, BorderLayout.EAST) self.add(bottomPanel, BorderLayout.SOUTH) self.currentBeautifyThread = None class CustomUndoPlainDocument(PlainDocument): # Code from: https://stackoverflow.com/questions/24433089/jtextarea-settext-undomanager compoundEdit = CompoundEdit() def fireUndoableEditUpdate(self, e): if self.compoundEdit == None: super(BeautifierPanel.CustomUndoPlainDocument, self).fireUndoableEditUpdate(e) else: self.compoundEdit.addEdit(e.getEdit()) def replace(self, offset, length, text, attrs): if length == 0: super(BeautifierPanel.CustomUndoPlainDocument, self).replace(offset, length, text, attrs) else: self.compoundEdit = CompoundEdit() super(BeautifierPanel.CustomUndoPlainDocument, self).fireUndoableEditUpdate( UndoableEditEvent(self, self.compoundEdit)) super(BeautifierPanel.CustomUndoPlainDocument, self).replace(offset, length, text, attrs) self.compoundEdit.end() self.compoundEdit = None def setText(self, text): self.beautifyTextArea.setText(text) def setRunningState(self): self.beautifyButton.setText("Cancel") self.undoButton.setEnabled(False) self.statusLabel.setText("Status: Running") def setReadyState(self): self.beautifyButton.setText("Beautify") self.undoButton.setEnabled(True) self.statusLabel.setText("Status: Ready") class BeautifyDocumentListener(DocumentListener): def __init__(self, beautifierPanel): super(BeautifierPanel.BeautifyDocumentListener, self).__init__() self.beautifierPanel = beautifierPanel def removeUpdate(self, e): self.updateSizeLabel() def insertUpdate(self, e): self.updateSizeLabel() def changedUpdate(self, e): pass def updateSizeLabel(self): length = len(self.beautifierPanel.beautifyTextArea.getText()) if length >= 1024: length = "%.2f KB" % (length / 1024.0) else: length = "%d B" % length self.beautifierPanel.sizeLabel.setText(length) def beautifyListener(self, e): selectedFormat = self.formatsComboBox.getSelectedItem() data = self.beautifyTextArea.getText( ) # variable "data" is "unicode" type if self.currentBeautifyThread and self.currentBeautifyThread.isAlive(): # TODO Need a graceful way to shutdown running beautify thread. self.currentBeautifyThread.callback = None self.currentBeautifyThread = None self.setReadyState() else: self.currentBeautifyThread = None self.setRunningState() def beautifyCallback(result): self.beautifyTextArea.setText(result) self.setReadyState() self.currentBeautifyThread = BeautifyThread( data, selectedFormat, beautifyCallback) self.currentBeautifyThread.start() def undoListener(self, e): if self.undoManager.canUndo(): self.undoManager.undo()
def build_gui(self): """Construct GUI elements.""" Mpanel = JPanel() # Mpanel.setLayout(GridLayout(0, 3)) Mpanel.setLayout(BoxLayout(Mpanel, BoxLayout.X_AXIS)) panel = JPanel() panel.setLayout(None) Mpanel.add(Box.createVerticalGlue()) Mpanel.add(panel) Mpanel.add(Box.createVerticalGlue()) img = os.path.abspath("gat_logo_sticky.png") logo = JLabel(ImageIcon(img)) logo.setBounds(150, 40, 165, 49) save_btn = JButton('Salvar', actionPerformed=self.save_config) save_btn.setBounds(100, 240, 75, 30) save_btn.setPreferredSize(Dimension(75, 30)) limpar_btn = JButton('Limpar ID Projeto', actionPerformed=self.clsProjectId) limpar_btn.setBounds(250, 240, 150, 30) limpar_btn.setPreferredSize(Dimension(150, 30)) label_h = JLabel('API Url:') label_h.setHorizontalAlignment(SwingConstants.RIGHT) label_h.setBounds(0, 120, 95, 30) label_h.setPreferredSize(Dimension(100, 30)) self.host_api = JTextField(50) self.host_api.setBounds(100, 120, 300, 30) self.host_api.setPreferredSize(Dimension(250, 30)) label_a = JLabel('API Token:') label_a.setHorizontalAlignment(SwingConstants.RIGHT) label_a.setBounds(0, 160, 95, 30) label_a.setPreferredSize(Dimension(100, 30)) self.api_token = JTextField(50) self.api_token.setBounds(100, 160, 300, 30) self.api_token.setPreferredSize(Dimension(250, 30)) label_p = JLabel('Project ID:') label_p.setHorizontalAlignment(SwingConstants.RIGHT) label_p.setBounds(0, 200, 95, 30) label_p.setPreferredSize(Dimension(100, 30)) self.project_id = JTextField(50) self.project_id.setForeground(Color.orange) self.project_id.setBackground(Color.gray) self.project_id.setBounds(100, 200, 300, 30) self.project_id.setPreferredSize(Dimension(250, 30)) self.project_id.editable = False panel.add(logo) panel.add(label_h) panel.add(self.host_api) panel.add(label_a) panel.add(self.api_token) panel.add(label_p) panel.add(self.project_id) panel.add(limpar_btn) panel.add(save_btn) return Mpanel
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]))