Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XDG-compliant paths for cache and config files #506

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ dependencies {
implementation("net.imglib2:imglib2")
implementation("net.imglib2:imglib2-roi")

// XDG support
implementation("dev.dirs:directories:26")

// Math dependencies
// implementation(commons.math3)
// implementation(misc.joml)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/sc/iview/Controls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ open class Controls(val sciview: SciView) {
h.addBehaviour("ruler: keep the button pressed and drag with the mouse", ruler)
h.addKeyBinding("ruler: keep the button pressed and drag with the mouse", "E")

val configFile = File(System.getProperty("user.home")).resolve(".sciview.keybindings.yaml")
val configFile = File(sciview.getProjectDirectories().configDir, ".keybindings.yaml")
if( configFile.exists() )
inputHandler.readFromFile(configFile)
else
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/sc/iview/SciView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import bdv.util.RandomAccessibleIntervalSource4D
import bdv.util.volatiles.VolatileView
import bdv.viewer.Source
import bdv.viewer.SourceAndConverter
import dev.dirs.ProjectDirectories
import graphics.scenery.*
import graphics.scenery.Scene.RaycastResult
import graphics.scenery.backends.Renderer
Expand Down Expand Up @@ -1796,6 +1797,17 @@ fun deleteNode(node: Node?, activePublish: Boolean = true) {
return availableLUTs.map {entry -> entry.key}
}

/**
* Return ProjectDirectories for sciview.
*
* Use this to find the location of cache, etc.
*
* @return a [ProjectDirectories] for sciview
*/
fun getProjectDirectories(): ProjectDirectories {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to gather all sciview options into an options/config class, accessible via sciview.getOptions() or some such. This class could have the ProjectDirectories and also have any other state for managing configuration. What do you think? Is there significant other configuration to be managed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mouse and key config is blurred between scenery and sciview, which is part of the issue with folks current input config concerns. I'm looking at the most surgical way of ensuring consistent input controls, but there are a lot of layers here...

return ProjectDirectories.from("sc", "iview", "sciview")
}

companion object {
//bounds for the controls
const val FPSSPEED_MINBOUND_SLOW = 0.01f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package sc.iview.commands.demo.advanced
import bdv.util.DefaultInterpolators
import bdv.viewer.Interpolation
import ch.systemsx.cisd.hdf5.HDF5Factory
import dev.dirs.ProjectDirectories
import graphics.scenery.Origin
import graphics.scenery.utils.extensions.xyz
import graphics.scenery.volumes.Colormap
Expand Down Expand Up @@ -130,10 +131,16 @@ class LoadCremiDatasetAndNeurons : Command {
}

// val files = ui.chooseFiles(null, emptyList(), filter, FileWidget.OPEN_STYLE)
val file = File(System.getProperty("user.home") + "/.sciview/examples/sample_A_20160501.hdf")
var projDirs = sciview.getProjectDirectories()

val file = File(projDirs.cacheDir,"sample_A_20160501.hdf")
if (file.exists() == false) {
task.status = "Downloading dataset"
log.info("Downloading dataset")
// ensure this exists projDirs.cacheDir
if (!File(projDirs.cacheDir).exists()) {
File(projDirs.cacheDir).mkdirs()
}
copyURLToFile(URL("https://cremi.org/static/data/sample_A_20160501.hdf"), file)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import sc.iview.SciView
import sc.iview.commands.MenuWeights
import java.io.File

/**
* A command for interactively editing input controls.
Expand All @@ -47,6 +48,6 @@ class KeyBindings : Command {
private lateinit var sciView: SciView

override fun run() {
sciView.sceneryInputHandler?.openKeybindingsGuiEditor("SciView's Key bindings editor", ".sciview.keybindings.yaml", "all")
sciView.sceneryInputHandler?.openKeybindingsGuiEditor("SciView's Key bindings editor", File(sciView.getProjectDirectories().configDir, ".keybindings.yaml").path, "all")
}
}
Loading