Skip to content

Instantly share code, notes, and snippets.

@petebankhead
Last active October 17, 2024 14:12
Show Gist options
  • Save petebankhead/20bada82db388a4af5e98219c46e0ab9 to your computer and use it in GitHub Desktop.
Save petebankhead/20bada82db388a4af5e98219c46e0ab9 to your computer and use it in GitHub Desktop.
Example QuPath startup script showing how to open specific dialogs
/**
* Example QuPath startup script to open the brightness/contrast dialog & channel viewer,
* optionally setting their location.
*
* Originally posted at https://forum.image.sc/t/saving-window-layout/103763/3
*
* Written for QuPath v0.5.x
*/
import javafx.application.Platform
import javafx.stage.Stage
import qupath.lib.gui.QuPathGUI
import qupath.lib.gui.commands.Commands
import javafx.stage.Window
Platform.runLater {
// Show brightness/contrast dialog
QuPathGUI.getInstance().getCommonActions().BRIGHTNESS_CONTRAST.handle(null)
moveWindow("Brightness & contrast", 10, 50)
// Show channel viewer
Commands.showChannelViewer(getCurrentViewer())
moveWindow("Channel viewer", 200, 100, 400, 200)
}
def moveWindow(String title, double x, double y, double width=-1, double height=-1) {
var window = Window.getWindows()
.stream()
.filter(w -> w instanceof Stage)
.map(w -> (Stage)w)
.filter(s -> s.getTitle() == title)
.findFirst()
.orElse(null)
if (window != null) {
window.x = x
window.y = y
if (width > 0)
window.width = width
if (height > 0)
window.height = height
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment