Skip to content

Commit

Permalink
fix drag issue with latest software updates
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed May 6, 2023
1 parent 3ca6a8f commit b709064
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 49 deletions.
12 changes: 5 additions & 7 deletions cellpose/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def interpZ(mask, zdraw):
""" find nearby planes and average their values using grid of points
zfill is in ascending order
"""
ifill = np.ones(mask.shape[0], np.bool)
ifill = np.ones(mask.shape[0], "bool")
zall = np.arange(0, mask.shape[0], 1, int)
ifill[zdraw] = False
zfill = zall[ifill]
Expand Down Expand Up @@ -1437,13 +1437,12 @@ def add_mask(self, points=None, color=(100,200,50)):
# loop over z values
median = []
if points.shape[1] < 3:
points = np.concatenate((np.zeros((points.shape[0],1), np.int32), points), axis=1)

points = np.concatenate((np.zeros((points.shape[0],1), "int32"), points), axis=1)
zdraw = np.unique(points[:,0])
zrange = np.arange(zdraw.min(), zdraw.max()+1, 1, int)
zmin = zdraw.min()
pix = np.zeros((2,0), np.uint16)
mall = np.zeros((len(zrange), self.Ly, self.Lx), np.bool)
pix = np.zeros((2,0), "uint16")
mall = np.zeros((len(zrange), self.Ly, self.Lx), "bool")
k=0
for z in zdraw:
iz = points[:,0] == z
Expand Down Expand Up @@ -1684,8 +1683,7 @@ def get_thresholds(self):
flow_threshold = float(self.flow_threshold.text())
cellprob_threshold = float(self.cellprob_threshold.text())
if flow_threshold==0.0 or self.NZ>1:
flow_threshold = None

flow_threshold = None
return flow_threshold, cellprob_threshold
except Exception as e:
print('flow threshold or cellprob threshold not a valid number, setting to defaults')
Expand Down
44 changes: 2 additions & 42 deletions cellpose/gui/guiparts.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,47 +471,6 @@ def keyPressEvent(self, ev):
self.scaleBy([0.9, 0.9])
else:
ev.ignore()

def mouseDragEvent(self, ev, axis=None):
## if axis is specified, event will only affect that axis.
if self.parent is None or (self.parent is not None and not self.parent.in_stroke):
ev.accept() ## we accept all buttons

pos = ev.pos()
lastPos = ev.lastPos()
dif = pos - lastPos
dif = dif * -1

## Ignore axes if mouse is disabled
mouseEnabled = np.array(self.state['mouseEnabled'], dtype=np.float)
mask = mouseEnabled.copy()
if axis is not None:
mask[1-axis] = 0.0

## Scale or translate based on mouse button
if ev.button() & (QtCore.Qt.LeftButton | QtCore.Qt.MidButton):
if self.state['mouseMode'] == pg.ViewBox.RectMode:
if ev.isFinish(): ## This is the final move in the drag; change the view scale now
#print "finish"
self.rbScaleBox.hide()
ax = QtCore.QRectF(Point(ev.buttonDownPos(ev.button())), Point(pos))
ax = self.childGroup.mapRectFromParent(ax)
self.showAxRect(ax)
self.axHistoryPointer += 1
self.axHistory = self.axHistory[:self.axHistoryPointer] + [ax]
else:
## update shape of scale box
self.updateScaleBox(ev.buttonDownPos(), ev.pos())
else:
tr = dif*mask
tr = self.mapToView(tr) - self.mapToView(Point(0,0))
x = tr.x() if mask[0] == 1 else None
y = tr.y() if mask[1] == 1 else None

self._resetTarget()
if x is not None or y is not None:
self.translateBy(x=x, y=y)
self.sigRangeChangedManually.emit(self.state['mouseEnabled'])

class ImageDraw(pg.ImageItem):
"""
Expand Down Expand Up @@ -589,7 +548,7 @@ def hoverEvent(self, ev):
self.drawAt(ev.pos())
if self.is_at_start(ev.pos()):
self.end_stroke()
self.parent.in_stroke = False

else:
ev.acceptClicks(QtCore.Qt.RightButton)
#ev.acceptClicks(QtCore.Qt.LeftButton)
Expand Down Expand Up @@ -633,6 +592,7 @@ def end_stroke(self):
self.parent.add_set()
if len(self.parent.current_point_set) > 0 and self.parent.autosave:
self.parent.add_set()
self.parent.in_stroke = False

def tabletEvent(self, ev):
pass
Expand Down

0 comments on commit b709064

Please sign in to comment.