def createAndShowGUI(self): ''' Create and display the gui. ''' self.setLayout(FlowLayout()) serverLabel = Label("BIAFlows host: "); serverField =TextField(30) serverField.setName('host') serverField.setText(self.biaflows.getHost()) serverField.addTextListener(self) publicKeyLabel = Label("public key: ") publicKeyField=TextField(40) publicKeyField.setName('publicKey') publicKeyField.setText(self.biaflows.getPublicKey()) publicKeyField.addTextListener(self) privateKeyLabel = Label("private key: ") privateKeyField=TextField(40) privateKeyField.setName('privateKey') privateKeyField.setEchoChar('*') privateKeyField.setText(self.biaflows.getPrivateKey()) privateKeyField.addTextListener(self) closeButton = Button("Disconnect and close") closeButton.addActionListener(self) self.add(serverLabel) self.add(serverField) self.add(publicKeyLabel) self.add(publicKeyField) self.add(privateKeyLabel) self.add(privateKeyField) self.add(closeButton) self.setSize(400,250) self.setVisible(True)
# class TestButtonAction(ActionListener): def actionPerformed(self, e): textArea.append("Test Button Clicked!\n") # # Create the Frame, Panel, Button, # TextArea, and TestButtonAction objects. # frame = Frame("Hello World") panel = Panel() button = Button("Test Button") buttonAction = TestButtonAction() textArea = TextArea() # # Put everything together and show # the window. # button.addActionListener(buttonAction) panel.add(button) panel.add(textArea) frame.add(panel) frame.pack() frame.show()
class TestButtonAction(ActionListener): def actionPerformed(self, e): textArea.append("Test Button Clicked!\n") # # Create the Frame, Panel, Button, # TextArea, and TestButtonAction objects. # frame = Frame("Hello World") panel = Panel() button = Button("Test Button") buttonAction = TestButtonAction() textArea = TextArea() # # Put everything together and show # the window. # button.addActionListener(buttonAction) panel.add(button) panel.add(textArea) frame.add(panel) frame.pack() frame.show()
def perform_user_qc(in_imp, edges, alt_edges, fixed_anchors_list, params): """allow the user to intervene to fix erroneously identified membrane edges""" n_frames = in_imp.getNFrames(); n_channels = in_imp.getNChannels(); output_folder = params.output_path; current_edges = edges; rgbstack = ImageStack(in_imp.getWidth(), in_imp.getHeight()); if n_frames > 1: for tidx in range(n_frames): in_imp.setT(tidx+1); ip = in_imp.getProcessor(); rgbip = ip.convertToRGB(); rgbstack.addSlice(rgbip); else: for cidx in range(n_channels): in_imp.setC(cidx+1); ip = in_imp.getProcessor(); rgbip = ip.convertToRGB(); rgbstack.addSlice(rgbip); imp = ImagePlus(("RGB " + in_imp.getTitle()), rgbstack); IJ.run("Colors...", "foreground=red background=white selection=yellow"); for tidx in range(imp.getNSlices()): imp.setSlice(tidx+1); for anchor in params.manual_anchor_positions: imp.setRoi(PointRoi(anchor[0], anchor[1])); IJ.run(imp, "Draw", "slice"); imp.show(); autoset_zoom(imp); imp.setPosition(1); imp.setRoi(current_edges[0]); if n_frames > 1: listener = UpdateRoiImageListener(current_edges); imp.addImageListener(listener); IJ.setTool("freeline"); do_flip = True; while do_flip: dialog = NonBlockingGenericDialog("User quality control"); dialog.enableYesNoCancel("Continue", "Flip all edges"); dialog.setCancelLabel("Cancel analysis"); dialog.addMessage("Please redraw the membrane edges as necessary, \n" + "making sure to draw beyond anchor points at either end...\n" + "Click OK when done. "); p = Panel(); but = Button("Flip this edge"); al = Listener(edges, alt_edges, imp); but.addActionListener(al); p.add(but); dialog.addPanel(p); dialog.showDialog(); if dialog.wasCanceled(): raise KeyboardInterrupt("Run canceled"); elif dialog.wasOKed(): do_flip = False; else: print("flip edges"); do_flip = True; if n_frames > 1: imp.removeImageListener(listener); current_edges = alt_edges if (current_edges == edges) else edges; imp.setPosition(1); imp.setRoi(current_edges[0]); if n_frames > 1: listener = UpdateRoiImageListener(current_edges); imp.addImageListener(listener); last_roi = imp.getRoi(); if n_frames > 1: qcd_edges = listener.getRoiList(); if imp.getNFrames() > imp.getNSlices(): qcd_edges[imp.getT() - 1] = last_roi; else: qcd_edges[imp.getZ() - 1] = last_roi; imp.removeImageListener(listener); else: qcd_edges = [last_roi]; mbio.save_qcd_edges2(qcd_edges, output_folder); # next four lines are a quick and dirty hack... if n_frames > 1: nframes = imp.getNFrames() if imp.getNFrames()>imp.getNSlices() else imp.getNSlices(); else: nframes = n_frames; for fridx in range(0, nframes): if (qcd_edges[fridx].getType()==Roi.FREELINE) or (qcd_edges[fridx].getType()==Roi.POLYLINE): if (fridx == 0) or params.constrain_anchors: anchors = params.manual_anchor_positions; else: anchors = fixed_anchors_list[fridx - 1]; fixed_anchors = mb.fix_anchors_to_membrane(anchors, qcd_edges[fridx], params); fixed_anchors = mb.order_anchors(fixed_anchors, params.manual_anchor_midpoint); fixed_anchors_list[fridx] = fixed_anchors; poly = qcd_edges[fridx].getInterpolatedPolygon(0.25, False); polypoints = [(x,y) for x,y in zip(poly.xpoints, poly.ypoints)]; idx = [polypoints.index(fixed_anchors[0]), polypoints.index(fixed_anchors[1])]; idx.sort(); polypoints = polypoints[idx[0]:idx[1]]; newedge = PolygonRoi([x for (x,y) in polypoints], [y for (x,y) in polypoints], Roi.POLYLINE); newedge = mb.check_edge_order(anchors, newedge); imp.setPosition(fridx + 1); imp.setRoi(newedge); IJ.run(imp, "Interpolate", "interval=1.0 smooth adjust"); IJ.run(imp, "Fit Spline", ""); qcd_edges[fridx] = imp.getRoi(); mbio.save_qcd_edges2(qcd_edges, output_folder); imp.changes = False; imp.close(); return qcd_edges, fixed_anchors_list;
def createAndShowGUI(self): ''' Create and display the gui. ''' layout = GridBagLayout() c = GridBagConstraints() self.setLayout(layout) projectLabel = Label("Project: ") c.gridx = 0 c.gridy = 0 c.ipady = 5 c.ipadx = 5 c.anchor = GridBagConstraints.EAST layout.setConstraints(projectLabel, c) self.projectChoice = Choice() for name in self.projectNames: self.projectChoice.add(name) c.gridx = 1 c.gridy = 0 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.projectChoice, c) storageLabel = Label("Storage: ") c.gridx = 0 c.gridy = 1 c.fill = GridBagConstraints.NONE c.anchor = GridBagConstraints.EAST layout.setConstraints(storageLabel, c) self.storageChoice = Choice() for name in self.storageNames: self.storageChoice.add(name) c.gridx = 1 c.gridy = 1 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.storageChoice, c) self.convertToOMETIFCheckBox = Checkbox("convert to OME-TIF", True) c.gridx = 1 c.gridy = 2 layout.setConstraints(self.convertToOMETIFCheckBox, c) self.uploadAsGroundTruthCheckBox = Checkbox("upload as ground-truth images") c.gridx = 1 c.gridy = 3 layout.setConstraints(self.uploadAsGroundTruthCheckBox, c) self.folderTextField = TextField("", 15) self.folderTextField.setText("<Image-Folder>") c.gridx = 0 c.gridy = 4 layout.setConstraints(self.folderTextField, c) self.folderTextField.setEditable(False) browseButton = Button('Browse...') browseButton.addActionListener(self) c.gridx = 1 c.gridy = 4 layout.setConstraints(browseButton, c) statusLabel = Label("Status:") c.gridy = 5 c.gridx = 0 c.fill = GridBagConstraints.NONE c.anchor = GridBagConstraints.EAST layout.setConstraints(statusLabel, c) self.statusTextField = TextField("Select a folder!", 20) c.gridy = 5 c.gridx = 1 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.statusTextField, c) self.statusTextField.setEditable(False) self.uploadButton = Button("Upload Images") self.uploadButton.addActionListener(self) c.gridwidth = 2 c.gridheight = 2 c.gridy = 6 c.gridx = 0 c.weighty = 1.0 layout.setConstraints(self.uploadButton, c) self.add(projectLabel) self.add(self.projectChoice) self.add(storageLabel) self.add(self.storageChoice) self.add(self.convertToOMETIFCheckBox) self.add(self.uploadAsGroundTruthCheckBox) self.add(self.folderTextField) self.add(browseButton) self.add(statusLabel) self.add(self.statusTextField) self.add(self.uploadButton) self.setSize(400,300) self.setVisible(True)
class UploadWindow(Frame, WindowListener, ActionListener): ''' A window to upload images to the biaflows server. The images can be uploaded as inut or as ground-truth images. Input images can be converted to the ome-tif format. Ground-truth images are always converted to ome-tif, if they are not alread in ome-tif format. ''' def __init__(self): ''' Create and display the upload window. ''' super(UploadWindow, self).__init__("BIAFlows Image Upload") self.biaflows = ConnectionWindow.getInstance().getBiaflows() self.nrOfImagesToUpload = 0 projects = Projects() self.projectNames = projects.getNames() self.projectIDs = projects.getIDs() storages = Storages() self.storageNames = storages.getNames() self.storageIDs = storages.getIDs() self.createAndShowGUI() self.addWindowListener(self) WindowManager.addWindow(self) def windowClosing(self, e): ''' Close the image upload window and dispose of it. Also remove it from the ij-window-manager. ''' self.dispose() WindowManager.removeWindow(self) def windowActivated(self, e): ''' Nothing to do. ''' pass def windowDeactivated(self, e): ''' Nothing to do. ''' pass def windowClosed(self, e): ''' Nothing to do. ''' pass def createAndShowGUI(self): ''' Create and display the gui. ''' layout = GridBagLayout() c = GridBagConstraints() self.setLayout(layout) projectLabel = Label("Project: ") c.gridx = 0 c.gridy = 0 c.ipady = 5 c.ipadx = 5 c.anchor = GridBagConstraints.EAST layout.setConstraints(projectLabel, c) self.projectChoice = Choice() for name in self.projectNames: self.projectChoice.add(name) c.gridx = 1 c.gridy = 0 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.projectChoice, c) storageLabel = Label("Storage: ") c.gridx = 0 c.gridy = 1 c.fill = GridBagConstraints.NONE c.anchor = GridBagConstraints.EAST layout.setConstraints(storageLabel, c) self.storageChoice = Choice() for name in self.storageNames: self.storageChoice.add(name) c.gridx = 1 c.gridy = 1 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.storageChoice, c) self.convertToOMETIFCheckBox = Checkbox("convert to OME-TIF", True) c.gridx = 1 c.gridy = 2 layout.setConstraints(self.convertToOMETIFCheckBox, c) self.uploadAsGroundTruthCheckBox = Checkbox("upload as ground-truth images") c.gridx = 1 c.gridy = 3 layout.setConstraints(self.uploadAsGroundTruthCheckBox, c) self.folderTextField = TextField("", 15) self.folderTextField.setText("<Image-Folder>") c.gridx = 0 c.gridy = 4 layout.setConstraints(self.folderTextField, c) self.folderTextField.setEditable(False) browseButton = Button('Browse...') browseButton.addActionListener(self) c.gridx = 1 c.gridy = 4 layout.setConstraints(browseButton, c) statusLabel = Label("Status:") c.gridy = 5 c.gridx = 0 c.fill = GridBagConstraints.NONE c.anchor = GridBagConstraints.EAST layout.setConstraints(statusLabel, c) self.statusTextField = TextField("Select a folder!", 20) c.gridy = 5 c.gridx = 1 c.fill = GridBagConstraints.HORIZONTAL layout.setConstraints(self.statusTextField, c) self.statusTextField.setEditable(False) self.uploadButton = Button("Upload Images") self.uploadButton.addActionListener(self) c.gridwidth = 2 c.gridheight = 2 c.gridy = 6 c.gridx = 0 c.weighty = 1.0 layout.setConstraints(self.uploadButton, c) self.add(projectLabel) self.add(self.projectChoice) self.add(storageLabel) self.add(self.storageChoice) self.add(self.convertToOMETIFCheckBox) self.add(self.uploadAsGroundTruthCheckBox) self.add(self.folderTextField) self.add(browseButton) self.add(statusLabel) self.add(self.statusTextField) self.add(self.uploadButton) self.setSize(400,300) self.setVisible(True) def changed(self, sender, aspect, newValue): if aspect=='image upload': self.statusTextField.setText('Uploading image ' + str(newValue) + '.') if aspect=='image upload finished': self.statusTextField.setText('Upload finished, ' + str(newValue) + ' images uploaded.') self.removeTmpFiles() if aspect=='image upload error': self.statusTextField.setText('Error uploading ' + str(newValue) + '.') def removeTmpFiles(self): if self.convertToOMETIFCheckBox.getState(): shutil.rmtree(self.tmpFolder) def actionPerformed(self, e): ''' Event handler for the buttons. ''' cmd = e.getActionCommand() if cmd=='Browse...': folder = IJ.getDirectory("Select the image folder") if not folder: return self.folderTextField.setText(folder) images = Uploader.getImageList(folder) self.nrOfImagesToUpload = len(images) self.inputFolder = folder self.statusTextField.setText(str(self.nrOfImagesToUpload) + ' images to upload...') if cmd=='Upload Images': print('upload') if self.nrOfImagesToUpload < 1: return else: # convert if ome checked. Add _lbl if ground-truth checked. upload self.statusTextField.setText('Uploading ' + str(self.nrOfImagesToUpload) + ' images...') imageFolder = self.folderTextField.getText() uploader = Uploader.getInstance(self.biaflows) uploader.addObserver(self) self.tmpFolder = None if self.convertToOMETIFCheckBox.getState() or self.uploadAsGroundTruthCheckBox.getState(): self.statusTextField.setText('Converting ' + str(self.nrOfImagesToUpload) + ' images...') # convert and add '_lbl' if ground truth self.tmpFolder = imageFolder + 'biaflows_tmp/' suffix = '' if self.uploadAsGroundTruthCheckBox.getState(): suffix = '_lbl' uploader.convertImagesInFolderToOME(imageFolder, self.tmpFolder, suffix) imageFolder = self.tmpFolder # upload pid = self.projectIDs[self.projectChoice.getSelectedIndex()] sid = self.storageIDs[self.storageChoice.getSelectedIndex()] self.statusTextField.setText('Uploading ' + str(self.nrOfImagesToUpload) + ' images...') uploader.setInputFolder(imageFolder) uploader.setProject(str(pid)) uploader.setStorage(str(sid)) thread = Thread(uploader) thread.start() # cleanup self.statusTextField.setText('Upload started.')