1010import numpy as np
1111import pathlib , os
1212
13+ from cellpose import models
1314from cellpose .gui .io import _save_sets
1415
1516
@@ -111,32 +112,6 @@ def setup(self):
111112 )
112113
113114
114- # def create_channel_choose():
115- # # choose channel
116- # ChannelChoose = [QComboBox(), QComboBox()]
117- # ChannelLabels = []
118- # ChannelChoose[0].addItems(["gray", "red", "green", "blue"])
119- # ChannelChoose[1].addItems(["none", "red", "green", "blue"])
120- # cstr = ["chan to segment:", "chan2 (optional): "]
121- # for i in range(2):
122- # ChannelLabels.append(QLabel(cstr[i]))
123- # if i == 0:
124- # ChannelLabels[i].setToolTip(
125- # "this is the channel in which the cytoplasm or nuclei exist \
126- # that you want to segment")
127- # ChannelChoose[i].setToolTip(
128- # "this is the channel in which the cytoplasm or nuclei exist \
129- # that you want to segment")
130- # else:
131- # ChannelLabels[i].setToolTip(
132- # "if <em>cytoplasm</em> model is chosen, and you also have a \
133- # nuclear channel, then choose the nuclear channel for this option")
134- # ChannelChoose[i].setToolTip(
135- # "if <em>cytoplasm</em> model is chosen, and you also have a \
136- # nuclear channel, then choose the nuclear channel for this option")
137-
138- # return ChannelChoose, ChannelLabels
139-
140115def unsilence_exceptions (func ):
141116 """ Wrapper to unsilence Qt exceptions and re-raise them """
142117 def wrapper (* args , ** kwargs ):
@@ -148,19 +123,6 @@ def wrapper(*args, **kwargs):
148123 logger .debug ('' .join (traceback .format_exception (type (e ), e , e .__traceback__ )))
149124 return wrapper
150125
151- class ModelButton (QPushButton ):
152-
153- def __init__ (self , parent , model_name , text ):
154- super ().__init__ ()
155- self .setEnabled (False )
156- self .setText (text )
157- self .setFont (parent .boldfont )
158- self .clicked .connect (lambda : self .press (parent ))
159- self .model_name = "cpsam"
160-
161- def press (self , parent ):
162- parent .compute_segmentation (model_name = "cpsam" )
163-
164126
165127class FilterButton (QPushButton ):
166128
@@ -428,7 +390,7 @@ def niter(self):
428390
429391class TrainWindow (QDialog ):
430392
431- def __init__ (self , parent , model_strings ):
393+ def __init__ (self , parent ):
432394 super ().__init__ (parent )
433395 self .setGeometry (100 , 100 , 900 , 550 )
434396 self .setWindowTitle ("train settings" )
@@ -446,7 +408,7 @@ def __init__(self, parent, model_strings):
446408 # choose initial model
447409 yoff += 1
448410 self .ModelChoose = QComboBox ()
449- self .ModelChoose .addItems (model_strings )
411+ self .ModelChoose .addItems (models . MODEL_NAMES )
450412 self .ModelChoose .setFixedWidth (150 )
451413 self .ModelChoose .setCurrentIndex (parent .training_params ["model_index" ])
452414 self .l0 .addWidget (self .ModelChoose , yoff , 1 , 1 , 1 )
@@ -667,6 +629,7 @@ def mouseClickEvent(self, ev):
667629 if y >= 0 and y < self .parent .Ly and x >= 0 and x < self .parent .Lx :
668630 if ev .button () == QtCore .Qt .LeftButton and not ev .double ():
669631 idx = self .parent .cellpix [self .parent .currentZ ][y , x ]
632+ self .parent .logger .debug (f'clicked on idx: { idx } ' )
670633 if idx > 0 :
671634 if ev .modifiers () & QtCore .Qt .ControlModifier :
672635 # delete mask selected
@@ -686,9 +649,17 @@ def mouseClickEvent(self, ev):
686649 elif self .parent .masksOn and not self .parent .deleting_multiple :
687650 self .parent .unselect_cell ()
688651
652+ @unsilence_exceptions
653+ def mouseDoubleClickEvent (self , ev ) -> None :
654+ ev .accept ()
655+ return
656+
689657 @unsilence_exceptions
690658 def mouseDragEvent (self , ev ):
691- ev .ignore ()
659+ if ev .button () == QtCore .Qt .RightButton :
660+ ev .accept ()
661+ else :
662+ ev .ignore ()
692663 return
693664
694665 @unsilence_exceptions
@@ -717,6 +688,9 @@ def is_at_start(self, pos):
717688 # first check if you ever left the start
718689 if len (self .parent .current_stroke ) > 3 :
719690 stroke = np .array (self .parent .current_stroke )
691+ stroke = stroke [stroke [:, 0 ] == self .parent .currentZ ]
692+ if len (stroke ) <= 3 :
693+ return False
720694 dist = (((stroke [1 :, 1 :] -
721695 stroke [:1 , 1 :][np .newaxis , :, :])** 2 ).sum (axis = - 1 ))** 0.5
722696 dist = dist .flatten ()
@@ -731,10 +705,19 @@ def is_at_start(self, pos):
731705 else :
732706 return False
733707
734- def end_stroke (self ):
708+ def end_stroke (self , keep_stroke = True ):
735709 if hasattr (self , 'scatter' ) and self .scatter is not None :
736710 if self .scatter .scene () == self .parent .layer .scene ():
737711 self .parent .p0 .removeItem (self .scatter )
712+ if not keep_stroke :
713+ if not self .parent .stroke_appended :
714+ self .parent .strokes .append (self .parent .current_stroke )
715+ self .parent .stroke_appended = True
716+ self .parent .remove_stroke (delete_points = False )
717+ self .parent .current_stroke = [s for s in self .parent .current_stroke
718+ if s [0 ] != self .parent .currentZ ]
719+ self .parent .in_stroke = False
720+ return
738721 if not self .parent .stroke_appended :
739722 self .parent .strokes .append (self .parent .current_stroke )
740723 self .parent .stroke_appended = True
0 commit comments