def snapshot(delay): time.sleep(delay) IJ.doCommand('Capture Screen')
for roi in rois: bounds = roi.getBounds() x1 = (float(bounds.x) + float(bounds.x + bounds.width)) / 2. y1 = (float(bounds.y) + float(bounds.y + bounds.height)) / 2. fileh.write("\t".join([ roi.getName(), str(x1), str(y1), str(bounds.width), str(bounds.height) ]) + "\n") fileh.close() #Export overlay IJ.doCommand("Flatten") time.sleep(1) ids = WindowManager.getIDList() imp_overlay = None print ids for id_img in ids: if imp.getID() != id_img: imp_overlay = WindowManager.getImage(id_img) break if imp_overlay is None: sys.exit(1) fs = FileSaver(imp_overlay) fs.saveAsJpeg(dirToSave + imp.getShortTitle() + "_cells.jpg") imp_overlay.hide()
#commands = [c for c in ij.Menus.getCommands().keySet()] # Above, equivalent list as below: commands = Menus.getCommands().keySet().toArray() gd = GenericDialog('Command Launcher') gd.addStringField('Command: ', ''); prompt = gd.getStringFields().get(0) prompt.setForeground(Color.red) class TypeListener(TextListener): def textValueChanged(self, tvc): if prompt.getText() in commands: prompt.setForeground(Color.black) return prompt.setForeground(Color.red) # or loop: #for c in commands: # if c == text: # prompt.setForeground(Color.black) # return # #prompt.setForeground(Color.red) prompt.addTextListener(TypeListener()) gd.showDialog() if not gd.wasCanceled(): IJ.doCommand(gd.getNextString()) # This python version does not encapsulate the values of the variables, so they are all global when defined outside the class definition. # In contrast, the lisp 'let' definitions encapsulates them in full # As an advantage, each python script executes within its own namespace, whereas clojure scripts run all within a unique static interpreter.