Skip to content

Commit

Permalink
BIG WIP: Switch to confuse
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Sep 6, 2022
1 parent e12d6f8 commit 60b5c17
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/napari_imagej/settings.toml → config_default.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# napari-imagej Settings

# USERS BEWARE:
# This toml file will soon be replaced with napari's contribution configuration.
# This yaml file will soon be replaced with napari's contribution configuration.

# Path to a local ImageJ2 installation (e.g. /Applications/Fiji.app),
# OR version of net.imagej:imagej artifact to launch (e.g. 2.3.0),
# OR endpoint of another artifact built on ImageJ2 (e.g. sc.fiji:fiji),
# OR list of Maven artifacts to include (e.g.
# ['net.imagej:imagej:2.3.0', 'net.imagej:imagej-legacy', 'net.preibisch:BigStitcher']).
# The default is the latest version of ImageJ2.
imagej_directory_or_endpoint = "net.imagej:imagej"
# The default (null) will use the latest version of ImageJ2, downloading it if needed.
imagej_directory_or_endpoint: null

# This can be used to identify whether transferred data between ImageJ2 and napari
# should be selected via activation or by user selection via a dialog.
# By default, the active layer/window is chosen for transfer between applications.
# By setting this value to false, a popup will be shown instead.
choose_active_layer = true
choose_active_layer: true
2 changes: 1 addition & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ channels:
- defaults
dependencies:
# Project dependencies
- dynaconf
- confuse
- labeling >= 0.1.12
- magicgui >= 0.5.1
- napari
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ channels:
- defaults
dependencies:
# Project depenencies
- dynaconf
- confuse
- labeling >= 0.1.12
- magicgui >= 0.5.1
- napari
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dev =
autopep8
black
build
confuse
flake8
isort
pyqt5
Expand Down
4 changes: 4 additions & 0 deletions src/napari_imagej/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
napari-imagej is built upon the PyImageJ project:
https://pyimagej.readthedocs.io/en/latest/
"""
import confuse

__version__ = "0.0.1.dev0"

settings = confuse.Configuration("napari-imagej", __name__)
8 changes: 4 additions & 4 deletions src/napari_imagej/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from jpype import JClass
from scyjava import config, jimport

from napari_imagej.settings import preferences
from napari_imagej import settings
from napari_imagej.utilities.logging import log_debug

# -- ImageJ API -- #
Expand Down Expand Up @@ -74,14 +74,14 @@ def _imagej_init():
log_debug("Completed JVM Configuration")

# Configure PyImageJ settings
settings = {
"ij_dir_or_version_or_endpoint": preferences.imagej_directory_or_endpoint,
ij_settings = {
"ij_dir_or_version_or_endpoint": settings["imagej_directory_or_endpoint"],
"mode": get_mode(),
"add_legacy": False,
}

# Launch PyImageJ
_ij = imagej.init(**settings)
_ij = imagej.init(**ij_settings)
log_debug(f"Initialized at version {_ij.getVersion()}")

# Return the ImageJ gateway
Expand Down
13 changes: 0 additions & 13 deletions src/napari_imagej/settings.py

This file was deleted.

30 changes: 27 additions & 3 deletions src/napari_imagej/widgets/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from qtpy.QtGui import QIcon, QPixmap
from qtpy.QtWidgets import QHBoxLayout, QMessageBox, QPushButton, QWidget

from napari_imagej import settings
from napari_imagej.java import ensure_jvm_started, ij, jc, log_debug, running_headless
from napari_imagej.settings import preferences
from napari_imagej.utilities._module_utils import _get_layers_hack
from napari_imagej.widgets.resources import resource_path

Expand All @@ -35,6 +35,9 @@ def __init__(self, viewer: Viewer):
self.gui_button: GUIButton = GUIButton()
self.layout().addWidget(self.gui_button)

self.settings_button: SettingsButton = SettingsButton(viewer)
self.layout().addWidget(self.settings_button)

if running_headless():
self.gui_button.clicked.connect(self.gui_button.disable_popup)
else:
Expand Down Expand Up @@ -129,7 +132,7 @@ def __init__(self, viewer: Viewer):
icon = QColoredSVGIcon.from_resources("long_right_arrow")
self.setIcon(icon.colored(theme=viewer.theme))
self.setToolTip("Export active napari layer to ImageJ2")
if preferences.choose_active_layer:
if settings["choose_active_layer"]:
self.clicked.connect(self.send_active_layer)
else:
self.clicked.connect(self.send_chosen_layer)
Expand Down Expand Up @@ -174,7 +177,7 @@ def __init__(self, viewer: Viewer):
icon = QColoredSVGIcon.from_resources("long_left_arrow")
self.setIcon(icon.colored(theme=viewer.theme))
self.setToolTip("Import active ImageJ2 Dataset to napari")
if preferences.choose_active_layer:
if settings["choose_active_layer"]:
self.clicked.connect(self.get_active_layer)
else:
self.clicked.connect(self.get_chosen_layer)
Expand Down Expand Up @@ -281,3 +284,24 @@ def disable_popup(self):
msg.setTextFormat(Qt.RichText)
msg.setTextInteractionFlags(Qt.TextBrowserInteraction)
msg.exec()


class SettingsButton(QPushButton):
def __init__(self, viewer: Viewer):
super().__init__()
self.viewer = viewer

icon = QColoredSVGIcon(resource_path("gear"))
self.setIcon(icon.colored(theme=viewer.theme))

self.clicked.connect(self._update_settings)

def _update_settings(self):
args = {}
for k, v in settings.items():
args[k] = {}
args[k]["value"] = v
choices = request_values(title="napari-imagej Settings", values=args)
if choices is not None:
for k, v in choices.items():
settings.set(k, v)
54 changes: 54 additions & 0 deletions src/napari_imagej/widgets/resources/export.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 60b5c17

Please sign in to comment.