Skip to content

Commit

Permalink
Update some default values, add new text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSNelson committed Dec 6, 2023
1 parent 8aaf8d6 commit 0e9c09a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 46 deletions.
Binary file modified .gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
98 changes: 52 additions & 46 deletions src/main/groovy/qupath/ext/qp_scope/functions/QP_scope_GUI.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,85 @@ import qupath.lib.gui.dialogs.Dialogs

class QP_scope_GUI {

// Existing text fields
static TextField x1Field = new TextField("");
static TextField y1Field = new TextField("");
static TextField x2Field = new TextField("");
static TextField y2Field = new TextField("");
static TextField scanBox = new TextField("");

// New text fields for the coordinates
static TextField x1Field = new TextField("")
static TextField y1Field = new TextField("")
static TextField x2Field = new TextField("")
static TextField y2Field = new TextField("")
static TextField scanBox = new TextField("")
// New text fields for Python environment and script path
static TextField virtualEnvField = new TextField("c:/Users/lociuser/miniconda3/envs/spath");
static TextField pythonScriptField = new TextField("c:/Users/lociuser/pythontest.py");

static void createGUI() {
// Create the dialog
def dlg = new Dialog<ButtonType>()
dlg.initModality(Modality.APPLICATION_MODAL)
dlg.setTitle("qp_scope")
dlg.setHeaderText("Enter coordinates:")
def dlg = new Dialog<ButtonType>();
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.setTitle("qp_scope");
dlg.setHeaderText("Enter details:");

// Set the content
dlg.getDialogPane().setContent(createContent())
dlg.getDialogPane().setContent(createContent());

// Add Okay and Cancel buttons
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL)
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

// Show the dialog and capture the response
def result = dlg.showAndWait()
def result = dlg.showAndWait();

// Handling the response
if (result.isPresent() && result.get() == ButtonType.OK) {
// Retrieve values from text fields
def x1 = x1Field.getText()
def y1 = y1Field.getText()
def x2 = x2Field.getText()
def y2 = y2Field.getText()
def boxString = scanBox.getText()
def x1 = x1Field.getText();
def y1 = y1Field.getText();
def x2 = x2Field.getText();
def y2 = y2Field.getText();
def virtualEnvPath = virtualEnvField.getText();
def pythonScriptPath = pythonScriptField.getText();

// Handle full bounding box input
def boxString = scanBox.getText();
if (boxString != "") {
// Remove non-numeric/non-comma characters and split by comma
def values = boxString.replaceAll("[^0-9.,]", "").split(",")
def values = boxString.replaceAll("[^0-9.,]", "").split(",");
if (values.length == 4) {
x1 = values[0]
y1 = values[1]
x2 = values[2]
y2 = values[3]
x1 = values[0];
y1 = values[1];
x2 = values[2];
y2 = values[3];
}
}

// Check if any value is empty and show warning
if ([x1, y1, x2, y2].any { it == null || it.isEmpty() }) {
// Show warning if the format is incorrect
Dialogs.showWarningNotification("Warning!", "Incomplete data to define bounding box.")
// Check if any value is empty
if ([x1, y1, x2, y2, virtualEnvPath, pythonScriptPath].any { it == null || it.isEmpty() }) {
Dialogs.showWarningNotification("Warning!", "Incomplete data entered.");
} else {
// Call the specified function
String virtualEnvPath2 = "C:/Anaconda/envs/paquo"
String pythonScriptPath = "C:/ImageAnalysis/python/py_dummydoc.py"
utilityFunctions.runPythonCommand(virtualEnvPath2,pythonScriptPath, x1, y1, x2, y2)
utilityFunctions.runPythonCommand(virtualEnvPath, pythonScriptPath, x1, y1, x2, y2);
}
}
}

private static GridPane createContent() {
GridPane pane = new GridPane()
pane.setHgap(10)
pane.setVgap(10)
def row = 0
// Add coordinate components to the grid
addToGrid(pane, new Label('X1:') as Node, x1Field as Node, row++)
addToGrid(pane, new Label('Y1:') as Node, y1Field as Node, row++)
addToGrid(pane, new Label('X2:') as Node, x2Field as Node, row++)
addToGrid(pane, new Label('Y2:') as Node, y2Field as Node, row++)
addToGrid(pane, new Label('Full bounding box:') as Node, scanBox as Node, row++)
GridPane pane = new GridPane();
pane.setHgap(10);
pane.setVgap(10);
def row = 0;
// Add existing components to the grid
addToGrid(pane, new Label('X1:'), x1Field, row++);
addToGrid(pane, new Label('Y1:'), y1Field, row++);
addToGrid(pane, new Label('X2:'), x2Field, row++);
addToGrid(pane, new Label('Y2:'), y2Field, row++);
addToGrid(pane, new Label('Full bounding box:'), scanBox, row++);

// Add new components for Python environment and script path
addToGrid(pane, new Label('Python Virtual Env Location:'), virtualEnvField, row++);
addToGrid(pane, new Label('.py file path:'), pythonScriptField, row++);

return pane
return pane;
}

private static void addToGrid(GridPane pane, Node label, Node control, int rowIndex) {
pane.add(label as Node, 0, rowIndex)
pane.add(control as Node, 1, rowIndex)
pane.add(label, 0, rowIndex);
pane.add(control, 1, rowIndex);
}
}
}

0 comments on commit 0e9c09a

Please sign in to comment.