-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Centralize ImageJ2 gateway into nij object
This provides a place to keep track of not only the ImageJ2 gateway, but also any affiliated data structures, such as our singleton ScriptREPL.
- Loading branch information
Showing
17 changed files
with
170 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,6 @@ on: | |
- main | ||
tags: | ||
- "*-[0-9]+.*" | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
NAPARI_IMAGEJ_TEST_TIMEOUT: 60000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from jpype import JImplements, JOverride | ||
|
||
from napari_imagej.java import init_ij, jc | ||
|
||
|
||
class NapariImageJ: | ||
""" | ||
An object offering a central access point to napari-imagej's core business logic. | ||
""" | ||
def __init__(self): | ||
self._ij = None | ||
self._repl = None | ||
self._repl_callbacks = [] | ||
|
||
@property | ||
def ij(self): | ||
if self._ij is None: | ||
self._ij = init_ij() | ||
return self._ij | ||
|
||
@property | ||
def repl(self) -> "jc.ScriptREPL": | ||
if self._repl is None: | ||
ctx = self.ij.context() | ||
model = self | ||
|
||
@JImplements("java.util.consumer.Consumer") | ||
class REPLOutput: | ||
@JOverride | ||
def accept(self, t): | ||
s = str(t) | ||
for callback in model._repl_callbacks: | ||
callback(s) | ||
|
||
self._repl = jc.ScriptREPL(ctx, "jython", REPLOutput()) | ||
self._repl.lang("jython") | ||
return self._repl | ||
|
||
def add_repl_callback(self, repl_callback) -> None: | ||
self._repl_callbacks.append(repl_callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.