Skip to content

Commit

Permalink
update with new actor model
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed May 18, 2023
1 parent cad559f commit 3bcc227
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 54 deletions.
77 changes: 43 additions & 34 deletions mikroj/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
from arkitekt.apps.fakts import ArkitektFakts
from arkitekt.apps.rekuest import ArkitektAgent
from arkitekt.apps.rekuest import ArkitektRekuest
from rekuest.agents.stateful import StatefulAgent
from arkitekt import easy
from herre import Herre
from herre.grants import CacheGrant as HerreCacheGrant
from herre.grants.oauth2.refresh import RefreshGrant
from herre.grants.fakts import FaktsGrant
from herre.grants.fakts.fakts_login_screen import FaktsQtLoginScreen, LoginWidget
from herre.grants.fakts.fakts_login_screen import FaktsQtLoginScreen
from fakts.grants.remote.base import Manifest
from herre.grants.qt.login_screen import LoginWidget
from qtpy.QtWidgets import QMessageBox


packaged = True
packaged = False
identifier = "github.io.jhnnsrs.mikroj"
version = "v0.0.1"

Expand Down Expand Up @@ -82,9 +83,11 @@ def __init__(self, *args, **kwargs) -> None:
grant=FailsafeGrant(
grants=[
RetrieveGrant(
identifier=identifier,
version=version,
redirect_uri="http://localhost:6767",
manifest=Manifest(
identifier=identifier,
version=version,
scopes=["read"],
),
discovery=QtSelectableDiscovery(
widget=self.selectBeaconWidget,
),
Expand All @@ -95,16 +98,16 @@ def __init__(self, *args, **kwargs) -> None:
assert_groups={"mikro", "rekuest"},
),
herre=Herre(
grant=HerreCacheGrant(
cache_file=f"{identifier}-{version}_herre_cache.json",
hash=f"{identifier}-{version}",
grant=FaktsQtLoginScreen(
widget=self.loginWindow,
auto_login=True,
grant=RefreshGrant(grant=FaktsGrant()),
grant=HerreCacheGrant(
cache_file=f"{identifier}-{version}_herre_cache.json",
hash=f"{identifier}-{version}",
grant=FaktsQtLoginScreen(
widget=self.loginWindow,
auto_login=True,
grant=RefreshGrant(grant=FaktsGrant()),
),
),
),
),
)

self.app.enter()
Expand All @@ -130,9 +133,6 @@ def __init__(self, *args, **kwargs) -> None:
if self.image_j_path and self.auto_initialize:
self.initialize()




def request_imagej_dir(self):
dir = QtWidgets.QFileDialog.getExistingDirectory(
parent=self, caption="Select ImageJ directory"
Expand Down Expand Up @@ -160,26 +160,38 @@ def initialize(self):
self.request_imagej_dir()

if self.plugins_dir:
scyjava.config.add_option(f"-Dplugins.dir={self.plugins_dir}")
# scyjava.config.add_option(f"-Dplugins.dir={self.plugins_dir}")
pass

self.imagej_button.setDisabled(True)
self.imagej_button.setText("Initializing...")
self._ij = imagej.init(self.image_j_path, headless=self.headless)
self.imagej_button.setText("ImageJ Initialized")
self.magic_bar.magicb.setDisabled(False)
try:
self.imagej_button.setDisabled(True)
self.imagej_button.setText("Initializing...")
self._ij = imagej.init(self.image_j_path, mode="interactive")
self.imagej_button.setText("ImageJ Initialized")
self.magic_bar.magicb.setDisabled(False)

self.vlayout.update()

self.macro_registry.helper.set_ij_instance(self._ij)

self.vlayout.update()


self.macro_registry.helper.set_ij_instance(self._ij)
if not self.headless:
self._ij.ui().showUI()
except Exception as e:
self.image_j_path = None
self.imagej_button.setText("ImageJ Failed to Initialize")
self.magic_bar.magicb.setDisabled(True)
self.imagej_button.setDisabled(False)
self.show_exception(e)

if not self.headless:
self._ij.ui().showUI()
def show_exception(self, exception: Exception):
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText("Error")
msg.setInformativeText(str(exception))
msg.setWindowTitle("Error")
msg.exec_()

def add_testing_ui(self):

self.get_rois_button = QtWidgets.QPushButton("Get ROIs")
self.vlayout.addWidget(self.get_rois_button)

Expand All @@ -190,12 +202,9 @@ def add_testing_ui(self):
self.get_results_button.clicked.connect(self.get_results)



def main(**kwargs):

app = QtWidgets.QApplication(sys.argv)
try:

from qt_material import apply_stylesheet

apply_stylesheet(app, theme="dark_teal.xml")
Expand Down
28 changes: 20 additions & 8 deletions mikroj/registries/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
from mikroj.registries.base import Macro
from qtpy import QtCore
from mikroj.registries.utils import load_macro, define_macro
from rekuest.structures.registry import StructureRegistry, get_current_structure_registry
from rekuest.structures.registry import (
StructureRegistry,
get_current_structure_registry,
)
from rekuest.structures.default import get_default_structure_registry

logger = logging.getLogger(__name__)


Expand All @@ -29,17 +34,21 @@ class MacroBuilder:
MacroBuilder is a builder for FuncMacroActor.
"""
__definition__: DefinitionInput

def __init__(self, definition: DefinitionInput, macro: Macro, helper: ImageJMacroHelper, structure_registry: StructureRegistry) -> None:
self.__definition__ = definition
def __init__(
self,
definition: DefinitionInput,
macro: Macro,
helper: ImageJMacroHelper,
structure_registry: StructureRegistry,
) -> None:
self.definition = definition
self.macro = macro
self.helper = helper
self.structure_registry = structure_registry

def __call__(self, *args, **kwargs):
return FuncMacroActor(
definition=self.__definition__,
structure_registry=self.structure_registry,
macro=self.macro,
helper=self.helper,
Expand Down Expand Up @@ -96,9 +105,12 @@ def load_macros(self):
# because path is object not string
path_in_str = str(path)
macro = load_macro(path_in_str)
structure_registry = self.structure_registry or get_current_structure_registry()
structure_registry = get_default_structure_registry()

interface = macro.name
definition = define_macro(macro)
actorBuilder = MacroBuilder(definition, macro, self.helper, structure_registry)
actorBuilder = MacroBuilder(
definition, macro, self.helper, structure_registry
)

self.register_actorBuilder(actorBuilder)
self.register_at_interface(interface, definition, actorBuilder)
33 changes: 22 additions & 11 deletions mikroj/registries/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
DefinitionInput,
NodeKind,
PortKindInput,
ChildPortInput
ChildPortInput,
Scope,
)
from pydantic.main import BaseModel
from mikro.widgets import MY_TOP_REPRESENTATIONS
from mikroj.registries.base import Macro, RESULTS_KEY, ROIS_KEY, ACTIVE_IN_KEY, ACTIVE_OUT_KEY
from mikroj.registries.base import (
Macro,
RESULTS_KEY,
ROIS_KEY,
ACTIVE_IN_KEY,
ACTIVE_OUT_KEY,
)

doc = re.compile("\/\*(?P<name>(.|\n)*)\*\/*")

Expand All @@ -26,20 +33,19 @@
activein_re = re.compile(".*\@setactivein.*")
interfaces_re = re.compile(".*@interface:(\w*)\n")
activeout_re = re.compile(".*\@takeactiveout*")
getroisout_re = re.compile(".*\@getroisout*") # should we extract the rois from the roi manager?
getresults_re = re.compile(".*\@getresults*") # should we extract the results from the results table?



getroisout_re = re.compile(
".*\@getroisout*"
) # should we extract the rois from the roi manager?
getresults_re = re.compile(
".*\@getresults*"
) # should we extract the results from the results table?


donecloseactive_re = re.compile(".*\@donecloseactive*")
filter_re = re.compile(".*\@filter*")
rgb_re = re.compile(".*\@rgb*")




params_re = re.compile(r"#@[^\(]*\((?P<params>[^\)]*)\)") # line has params


Expand Down Expand Up @@ -90,6 +96,7 @@ def define_macro(macro: Macro) -> DefinitionInput:
description="Image to be processed",
assignWidget=MY_TOP_REPRESENTATIONS,
nullable=False,
scope=Scope.GLOBAL,
)
]

Expand All @@ -101,6 +108,7 @@ def define_macro(macro: Macro) -> DefinitionInput:
identifier="@mikro/representation",
description="Image to be processed",
nullable=False,
scope=Scope.GLOBAL,
)
]

Expand All @@ -115,7 +123,9 @@ def define_macro(macro: Macro) -> DefinitionInput:
identifier="@mikro/roi",
kind=PortKindInput.STRUCTURE,
nullable=False,
)
scope=Scope.GLOBAL,
),
scope=Scope.GLOBAL,
)
]

Expand All @@ -127,6 +137,7 @@ def define_macro(macro: Macro) -> DefinitionInput:
nullable=False,
description="The results table",
identifier="@mikro/table",
scope=Scope.GLOBAL,
)
]

Expand All @@ -136,6 +147,6 @@ def define_macro(macro: Macro) -> DefinitionInput:
args=args,
interfaces=macro.interfaces,
returns=returns,
interface=macro.name,
kind=NodeKind.FUNCTION,
portGroups=[],
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mikroj"
version = "0.1.19"
version = "0.1.20"
description = ""
authors = ["jhnnsrs <jhnnsrs@gmail.com>"]
license = "CC BY-NC 3.0"
Expand Down

0 comments on commit 3bcc227

Please sign in to comment.