-
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 - start work on NapariImageJ model class
Unfortunately, to make the REPL output work will require changes to SciJava Common. So that's next I guess... then we can utilize the new API here in napari-imagej, with an updated scijava-common min version.
- Loading branch information
Showing
8 changed files
with
88 additions
and
67 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,45 @@ | ||
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_output_stream = None | ||
self._repl_callbacks = None | ||
|
||
@property | ||
def ij(self): | ||
if self._ij is None: | ||
self._ij = _initialize_imagej() | ||
return self._ij | ||
|
||
@property | ||
def repl(self) -> "jc.ScriptREPL": | ||
if self._repl is None: | ||
ctx = self.ij.context() | ||
# CTR START HERE -- we need to pass a smarter OutputStream, | ||
# but unfortunately java.io.OutputStream is not an interface, | ||
# so we cannot implement it from Python. Probably the best | ||
# solution is to update ScriptREPL on the SciJava Common side | ||
# to support a functional interface for emitting output lines, | ||
# rather than using the OutputStream class for this purpose. | ||
# There is only one place in ScriptREPL where anything besides | ||
# println is called -- it calls print repeatedly -- and we | ||
# could instead do that in a StringBuilder per line. | ||
# | ||
# Anyway, once we have a way to receive lines of output from | ||
# the REPL, we can forward them to callbacks registered here, | ||
# and the REPL widget can register callbacks that take care | ||
# of dumping the output to its output pane as desired. | ||
self._repl_output_stream = jc.ByteArrayOutputStream() | ||
self._repl = jc.ScriptREPL(ctx, self._repl_output_stream) | ||
self._repl.lang("jython") | ||
return self._repl | ||
|
||
def add_repl_callback(self, repl_callback) -> None: | ||
self._repl_callbacks.append(repl_callback) | ||
def repl_output(self) -> str: | ||
return self._repl_output_stream |
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