Skip to content

Commit a65f0d7

Browse files
committed
Merge branch 'main' of https://github.com/AdaptiveMotorControlLab/CellSeg3d into v0.0.1rc3
2 parents 7ac4ccc + ec8ab8b commit a65f0d7

File tree

12 files changed

+342
-214
lines changed

12 files changed

+342
-214
lines changed

napari_cellseg3d/interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Union
33
from typing import List
44

5+
56
from qtpy.QtCore import Qt
67
from qtpy.QtCore import QUrl
78
from qtpy.QtGui import QDesktopServices

napari_cellseg3d/log_utility.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import threading
2+
import warnings
23

4+
from qtpy import QtCore
35
from qtpy.QtGui import QTextCursor
46
from qtpy.QtWidgets import QTextEdit
57

@@ -22,23 +24,66 @@ def __init__(self, parent):
2224

2325
# def receive_log(self, text):
2426
# self.print_and_log(text)
27+
def write(self, message):
28+
self.lock.acquire()
29+
try:
30+
if not hasattr(self, "flag"):
31+
self.flag = False
32+
message = message.replace("\r", "").rstrip()
33+
if message:
34+
method = "replace_last_line" if self.flag else "append"
35+
QtCore.QMetaObject.invokeMethod(
36+
self,
37+
method,
38+
QtCore.Qt.QueuedConnection,
39+
QtCore.Q_ARG(str, message),
40+
)
41+
self.flag = True
42+
else:
43+
self.flag = False
44+
45+
finally:
46+
self.lock.release()
2547

26-
def print_and_log(self, text):
48+
@QtCore.Slot(str)
49+
def replace_last_line(self, text):
50+
self.lock.acquire()
51+
try:
52+
cursor = self.textCursor()
53+
cursor.movePosition(QTextCursor.End)
54+
cursor.select(QTextCursor.BlockUnderCursor)
55+
cursor.removeSelectedText()
56+
cursor.insertBlock()
57+
self.setTextCursor(cursor)
58+
self.insertPlainText(text)
59+
finally:
60+
self.lock.release()
61+
62+
def print_and_log(self, text, printing=True):
2763
"""Utility used to both print to terminal and log text to a QTextEdit
2864
item in a thread-safe manner. Use only for important user info.
2965
3066
Args:
3167
text (str): Text to be printed and logged
68+
printing (bool): Whether to print the message as well or not using print(). Defaults to True.
3269
3370
"""
3471
self.lock.acquire()
3572
try:
36-
print(text)
37-
# causes issue if you clik on terminal (tied to CMD QuickEdit mode)
73+
if printing:
74+
print(text)
75+
# causes issue if you clik on terminal (tied to CMD QuickEdit mode on Windows)
3876
self.moveCursor(QTextCursor.End)
3977
self.insertPlainText(f"\n{text}")
4078
self.verticalScrollBar().setValue(
4179
self.verticalScrollBar().maximum()
4280
)
4381
finally:
4482
self.lock.release()
83+
84+
def warn(self, warning):
85+
self.lock.acquire()
86+
try:
87+
warnings.warn(warning)
88+
finally:
89+
self.lock.release()

napari_cellseg3d/model_framework.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from napari_cellseg3d.models import model_SegResNet as SegResNet
1616
from napari_cellseg3d.models import model_TRAILMAP as TRAILMAP
1717
from napari_cellseg3d.models import model_VNet as VNet
18-
from napari_cellseg3d.models import TRAILMAP_MS as TMAP
18+
from napari_cellseg3d.models import model_TRAILMAP_MS as TRAILMAP_MS
1919
from napari_cellseg3d.plugin_base import BasePluginFolder
2020

2121
warnings.formatwarning = utils.format_Warning
@@ -62,8 +62,8 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
6262
self.models_dict = {
6363
"VNet": VNet,
6464
"SegResNet": SegResNet,
65-
"TRAILMAP pre-trained": TRAILMAP,
66-
"TRAILMAP_MS": TMAP,
65+
"TRAILMAP": TRAILMAP,
66+
"TRAILMAP_MS": TRAILMAP_MS,
6767
}
6868
"""dict: dictionary of available models, with string for widget display as key
6969

0 commit comments

Comments
 (0)