def registerExtenderCallbacks(self, callbacks): # keep a reference to our callbacks object self._callbacks = callbacks # obtain an extension helpers object self._helpers = callbacks.getHelpers() # define stdout writer self._stdout = PrintWriter(callbacks.getStdout(), True) self._stdout.println(self.EXTENSION_NAME + ' by @luxcupitor') self._stdout.println('================================') self._stdout.println('') self._stdout.println('TIP: Go to "Custom Scanner" tab and click "Execute on Proxy History"') self._stdout.println('to run the scanner checks on recently imported session files.') self._stdout.println('') # set our extension name callbacks.setExtensionName(self.EXTENSION_NAME) callbacks.registerScannerCheck(self) # add the custom tab and button to Burp's UI self._newpanel = Panel() self._newpanel.setLayout(FlowLayout()) self._button = JButton("Execute on Proxy History", actionPerformed=self.checkProxyHistory) self._newpanel.add(self._button) callbacks.customizeUiComponent(self._newpanel) callbacks.addSuiteTab(self) return
def addControl(self, dialog): if self.control_type==MyControlDefinition.Numeric: dialog.addNumericField(self.label, self.default_val, 2); dialog.getNumericFields()[-1].setEnabled(self.enabled); elif self.control_type==MyControlDefinition.String: dialog.addStringField(self.label, self.default_val); dialog.getStringFields()[-1].setEnabled(self.enabled); elif self.control_type==MyControlDefinition.Choice: if not self.default_val in self.choices: raise IndexError("default value isn''t in list of choices"); dialog.addChoice(self.label, self.choices, self.default_val); dialog.getChoices()[-1].setEnabled(self.enabled); elif self.control_type==MyControlDefinition.Checkbox: if not isinstance(self.default_val, bool): raise TypeError(); dialog.addCheckbox(self.label, self.default_val); dialog.getCheckboxes()[-1].setEnabled(self.enabled); elif self.control_type==MyControlDefinition.RadioButtonGroup: if not self.default_val in self.choices: raise IndexError("default value isn''t in list of choices"); panel = Panel(); cbg = CheckboxGroup(); for ch in self.choices: cb = Checkbox(ch, cbg, ch==self.default_val) cb.setEnabled(self.enabled); self.checkboxes.append(cb); panel.add(cb); dialog.addPanel(panel);
def getUiComponent(self): panel = Panel() panel.setBackground(Color.gray) button = Button('Hello Burp Button!') panel.add(button) self.callbacks.customizeUiComponent( panel) # customize UI components in line with Burp's UI style return panel
def __init__(self, listCategories): """ listCategories: initial list of categories to fill the fields """ GenericDialogPlus.__init__(self, "Category names") self.addPanel( Panel(GridLayout(0,1)) ) self.panel = self.getComponent(0) for category in listCategories: self.panel.add( TextField(category) ) # Add string input to GUI self.addButton(CategoryDialog.ADD_CATEGORY, self)
def choose_series(filepath, params): """if input file contains more than one image series (xy position), prompt user to choose which one to use""" # todo: if necessary (e.g. if lots of series), can improve thumbnail visuals based loosely on https://github.com/ome/bio-formats-imagej/blob/master/src/main/java/loci/plugins/in/SeriesDialog.java import_opts = ImporterOptions(); import_opts.setId(filepath); reader = ImageReader(); ome_meta = MetadataTools.createOMEXMLMetadata(); reader.setMetadataStore(ome_meta); reader.setId(filepath); no_series = reader.getSeriesCount(); if no_series == 1: return import_opts, params; else: series_names = [ome_meta.getImageName(idx) for idx in range(no_series)]; dialog = GenericDialog("Select series to load..."); dialog.addMessage("There are multiple series in this file! \n" + "This is probably because there are multiple XY stage positions. \n " + "Please choose which series to load: "); thumbreader = BufferedImageReader(reader); cbg = CheckboxGroup(); for idx in range(no_series): p = Panel(); p.add(Box.createRigidArea(Dimension(thumbreader.getThumbSizeX(), thumbreader.getThumbSizeY()))); ThumbLoader.loadThumb(thumbreader, idx, p, True); dialog.addPanel(p); cb = Checkbox(series_names[idx], cbg, idx==0); p.add(cb); dialog.showDialog(); if dialog.wasCanceled(): raise KeyboardInterrupt("Run canceled"); if dialog.wasOKed(): selected_item = cbg.getSelectedCheckbox().getLabel(); selected_index = series_names.index(selected_item); params.setSelectedSeriesIndex(selected_index); for idx in range(0, no_series): import_opts.setSeriesOn(idx, True) if (idx==selected_index) else import_opts.setSeriesOn(idx, False); reader.close(); return import_opts, params
def gui(self): x = 10 # panel padding y = 5 # panel padding self.panel = Panel() self.panel.setLayout(None) self.scn_lbl = JLabel("Enable scanning") self.scn_lbl.setBounds(x, y, 100, 20) self.panel.add(self.scn_lbl) self.enable = JCheckBox() self.enable.setBounds(x + 120, y, 50, 20) self.panel.add(self.enable) self.rand_lbl = JLabel("Randomize payloads") self.rand_lbl.setBounds(x, y + 15, 100, 20) self.panel.add(self.rand_lbl) self.randomize = JCheckBox() self.randomize.setBounds(x + 120, y + 15, 50, 20) self.panel.add(self.randomize) self.pyld_lbl = JLabel("Payloads List (Line separated)") self.pyld_lbl.setBounds(x, y + 30, 180, 20) self.panel.add(self.pyld_lbl) self.payloads_list = JTextArea() self.pyld_scrl = JScrollPane(self.payloads_list) self.pyld_scrl.setBounds(x, y + 50, 600, 200) self.panel.add(self.pyld_scrl) self.save_btn = JButton("Save", actionPerformed=self.save_settings) self.save_btn.setBounds(x, y + 250, 100, 30) self.panel.add(self.save_btn) # Settings loader from [utils/Helpers/load_settings] self.load_settings() return self
headers = csvIterator.next() # read first header line n = len(headers) dropdowns = [ [] for i in range(n) ] # [[], [], [], [], []] such that dropdowns[i] contains the list of choices for dropdowns i for row in csvIterator: for i, entry in enumerate(row): # row is a list if entry: dropdowns[i].append( entry ) # dropdown[i] is the list of choices # if necessary since all columns might not have the same length # Create horizontal panel for dropdowns panel = Panel(GridLayout( 0, n)) # as many columns (n) as menus, as many rows as necessary (0) # First panel row -> dropdown labels for header in headers: panel.add(Label(header)) # Second panel row -> dropdown choices for i in range(n): label = headers[i] chooser = Choice() chooser.setName(label) # not display but easier to recover infos dropdown = dropdowns[i] for option in dropdown: chooser.add(option)
# inherits from the Java ActionListener interface. # 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()
if nCat <= 12: button.setToolTipText("Keyboard shortcut: F" + str(nCat)) # F shortcut labels are 1-based, ie match the len value return button ############### GUI - CATEGORY DIALOG - collect N classes names (N define at first line) ############# textFilePath = textFile.getPath() if textFile else "" listCategories = getCategoriesFrom(categorySource, textFilePath) # initial list, before user-edit catDialog = CategoryDialog(listCategories) catDialog.showDialog() ################# After OK clicking ########### # Recover fields from the formular if catDialog.wasOKed(): # Loop over categories and add a button to the panel for each catPanel = Panel(GridLayout(0,4)) # Unlimited number of rows - fix to 4 columns - not possible to use a JPanel, not supported by GenericDialog listCat = catDialog.getListCategories() listShortcut = range( 112, 112+len(listCat) ) for index, category in enumerate(listCat): # Create a Button button = JButton(category) # button label if index<12: button.setToolTipText( "Keyboard shortcut: F" + str(index+1) ) # index is 0-based, F shortcut are 1-based # Bind action to button button.addActionListener(categoryAction)
return checkbox ############### GUI - CATEGORY DIALOG ############# textFilePath = textFile.getPath() if textFile else "" listCategories = getCategoriesFrom(categorySource, textFilePath) # Initialize a category dialog with list of categories catDialog = CategoryDialog(listCategories) catDialog.showDialog() # Recover fields from the formular if catDialog.wasOKed(): # Loop over categories, adding a tickbox to the panel for each catPanel = Panel(GridLayout( 0, 4)) # Unlimited number of rows - fix to 4 columns for category in catDialog.getListCategories(): # Make a checkbox with the category name box = Checkbox(category, False) box.setFocusable( False) # important to have the keyboard shortcut working # Add checkbox to the gui for this category catPanel.add(box) ## Initialize dialog winButton = MainDialog(catPanel, browse_mode, run_measure) winButton.showDialog()
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 settings(): """ Settings """ # Calls potential config file to set defaults # for settings dialog. Sets all defaults to 0 # if no config file exists. con_path = os.path.join(str(Root), "FRET_params.cfg") if os.path.exists(con_path): dflt = config_read() print type(dflt.get("b_sub", "Rolling ball")) print (dflt.get("b_sub", "Rolling ball")) print type(int(dflt.get("b_sub", "Rolling ball"))) print (dflt.get("b_sub", "Rolling ball")) else: dflt = {} feat_model_strings = ["Translation", "Rigid", "Similarity", "Affine ] reg_model_strings = ["Translation", "Rigid", "Similarity", "Affine", "Elastic", "Least Squares" ] b_sub_strings = ["Rolling Ball", "Manual Selection"] # Registration parameters dialog. gd = GenericDialog("Advanced Settings") gd.addMessage("REGISTRATION PARAMETERS") gd.addNumericField("Steps per scale octave: ", float(dflt.get("steps", 6)), 0, 7, "") gd.addNumericField("Max Octave Size: ", float(dflt.get("max_oct", 1024)), 0, 7, "") gd.addNumericField("Feature Descriptor Size: ", float(dflt.get("fd_size", 12)), 1, 7, "") gd.addNumericField("Initial Sigma: ", float(dflt.get("sigma", 1.2)), 2, 7, "") gd.addNumericField("Max Epsilon: ", float(dflt.get("max_eps", 15)), 1, 7, "") gd.addNumericField("Min Inlier Ratio: ", float(dflt.get("min_inlier", 0.05)), 3, 7, "") gd.addCheckbox("Use Shrinkage Constraint", ast.literal_eval(dflt.get("shrinkage", "False"))) gd.addChoice("Feature extraction model", feat_model_strings, feat_model_strings[int(dflt.get("feat_model", 1))] ) gd.addChoice("Registration model", reg_model_strings, reg_model_strings[int(dflt.get("reg_model", 1))] ) # Background removal parameters dialog. gd.addPanel(Panel()) gd.addMessage("BACKGROUND REMOVAL") gd.addChoice("Subtraction method:", b_sub_strings, b_sub_strings[int(dflt.get("b_sub", 0))] ) gd.addNumericField("Rolling ball size: ", float(dflt.get("ballsize", 50)), 1, 7, "px" ) gd.addCheckbox("Create Background", ast.literal_eval(dflt.get("create_b", "False"))) gd.addCheckbox("Light Background", ast.literal_eval(dflt.get("light_b", "False"))) gd.addCheckbox("Use Parabaloid", ast.literal_eval(dflt.get("parab", "False"))) gd.addCheckbox("Do Pre-smoothing", ast.literal_eval(dflt.get("smooth", "False"))) gd.addCheckbox("Correct Corners", ast.literal_eval(dflt.get("corners", "False"))) # Measumrent parameters dialog. gd.addPanel(Panel()) gd.addMessage("MEASUREMENT PARAMETERS") gd.addNumericField("Max Cell Area", float(dflt.get("cell_max", 2200)), 0, 7, "px") gd.addNumericField("Min Cell Area", float(dflt.get("cell_min", 200)), 0, 7, "px") gd.addNumericField("Ratio Subtraction", float(dflt.get("subtr_ratio", 0.31)), 3, 7, "") # Plot parameters dialog. gd.addPanel(Panel()) gd.addMessage("PLOT PARAMETERS") gd.addNumericField("Max y, d and aFRET", float(dflt.get("p_max", 0.65)), 2, 7, "") gd.addNumericField("Min y, d and aFRET", float(dflt.get("p_min", 0.0)), 2, 7, "") gd.addNumericField("Max y, norm. d and aFRET", float(dflt.get("p_max_n", 1.65)), 2, 7, "") gd.addNumericField("Min y, norm. d and aFRET", float(dflt.get("p_min_n", 0.5)), 2, 7, "") # Set location of dialog on screen. #gd.setLocation(0,1000) gd.showDialog() # Checks if cancel was pressed, kills script. if gd.wasCanceled() is True: sys.exit("Cancel was pressed, script terminated.") # Parameters dictionary. parameters = {"steps" : gd.getNextNumber(), "max_oct" : gd.getNextNumber(), "fd_size" : gd.getNextNumber(), "sigma" : gd.getNextNumber(), "max_eps" : gd.getNextNumber(), "min_inlier" : gd.getNextNumber(), "shrinkage" : gd.getNextBoolean(), "feat_model" : gd.getNextChoiceIndex(), "reg_model" : gd.getNextChoiceIndex(), "b_sub" : gd.getNextChoiceIndex(), "ballsize" : gd.getNextNumber(), "create_b" : gd.getNextBoolean(), "light_b" : gd.getNextBoolean(), "parab" : gd.getNextBoolean(), "smooth" : gd.getNextBoolean(), "corners" : gd.getNextBoolean(), "cell_max" : gd.getNextNumber(), "cell_min" : gd.getNextNumber(), "subtr_ratio" : gd.getNextNumber(), "p_max" : gd.getNextNumber(), "p_min" : gd.getNextNumber(), "p_max_n" : gd.getNextNumber(), "p_min_n" : gd.getNextNumber() } parameters = config_write(parameters) return parameters