File wellmet/qt_gui/qt_pairwise.py changed (mode: 100644) (index 40e542c..3678c21) |
... |
... |
class MatrixWindow(QtWidgets.QMainWindow): |
401 |
401 |
|
|
402 |
402 |
|
|
403 |
403 |
|
|
|
404 |
|
# piece of code from pyqtgraph examples |
|
405 |
|
class CustomViewBox(pg.ViewBox): |
|
406 |
|
## reimplement mouseDragEvent to disable continuous axis zoom |
|
407 |
|
def mouseDragEvent(self, ev, axis=None): |
|
408 |
|
if ev.button() == QtCore.Qt.MouseButton.RightButton: |
|
409 |
|
ev.ignore() |
|
410 |
|
else: |
|
411 |
|
pg.ViewBox.mouseDragEvent(self, ev, axis=axis) |
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
404 |
415 |
|
|
405 |
416 |
|
|
406 |
417 |
class MView(pg.ImageView): |
class MView(pg.ImageView): |
407 |
418 |
mouse_moved = QtCore.pyqtSignal(int, int) |
mouse_moved = QtCore.pyqtSignal(int, int) |
|
419 |
|
mouse_clicked = QtCore.pyqtSignal(int, int) |
|
420 |
|
mouse_double_clicked = QtCore.pyqtSignal(int, int) |
|
421 |
|
mouse_right_dragged = QtCore.pyqtSignal(int, int) |
|
422 |
|
|
|
423 |
|
right_button = QtCore.Qt.MouseButton.RightButton |
|
424 |
|
left_button = QtCore.Qt.MouseButton.LeftButton |
408 |
425 |
|
|
409 |
426 |
def __init__(self, w, *args, **kwargs): |
def __init__(self, w, *args, **kwargs): |
410 |
|
self.pi = pg.PlotItem() |
|
|
427 |
|
self.vb = CustomViewBox() |
|
428 |
|
self.pi = pg.PlotItem(viewBox=self.vb) |
411 |
429 |
super().__init__(*args, view=self.pi, **kwargs) #axisOrder='row-major', |
super().__init__(*args, view=self.pi, **kwargs) #axisOrder='row-major', |
412 |
430 |
|
|
413 |
431 |
w.slice_changed.connect(self.on_slice_changed) |
w.slice_changed.connect(self.on_slice_changed) |
|
432 |
|
self.app = w.app |
414 |
433 |
|
|
415 |
434 |
self.nsim = nsim = w.slider.value() |
self.nsim = nsim = w.slider.value() |
416 |
435 |
|
|
|
... |
... |
class MView(pg.ImageView): |
422 |
441 |
#self.setBackground('w') |
#self.setBackground('w') |
423 |
442 |
|
|
424 |
443 |
|
|
425 |
|
self.proxy = pg.SignalProxy(self.pi.scene().sigMouseMoved, |
|
426 |
|
rateLimit=60, slot=self._mouse_moved) |
|
427 |
|
|
|
|
444 |
|
self.proxy = pg.SignalProxy(self.pi.scene().sigMouseMoved, |
|
445 |
|
rateLimit=60, slot=self.on_mouse_moved) |
|
446 |
|
self.x = -1 |
|
447 |
|
self.y = -1 |
|
448 |
|
|
|
449 |
|
self.pi.scene().sigMouseClicked.connect(self.on_click) |
|
450 |
|
|
428 |
451 |
|
|
429 |
452 |
def __setattr__(self, attr, value): |
def __setattr__(self, attr, value): |
430 |
453 |
if attr == 'red': |
if attr == 'red': |
|
... |
... |
class MView(pg.ImageView): |
461 |
484 |
def update(self): |
def update(self): |
462 |
485 |
self.setImage(self.data.T, levelMode='rgba') |
self.setImage(self.data.T, levelMode='rgba') |
463 |
486 |
|
|
464 |
|
def _mouse_moved(self, evt): |
|
|
487 |
|
def on_mouse_moved(self, evt): |
465 |
488 |
pos = evt[0] ## using signal proxy turns original arguments into a tuple |
pos = evt[0] ## using signal proxy turns original arguments into a tuple |
466 |
489 |
if self.pi.sceneBoundingRect().contains(pos): |
if self.pi.sceneBoundingRect().contains(pos): |
467 |
490 |
mousePoint = self.pi.vb.mapSceneToView(pos) |
mousePoint = self.pi.vb.mapSceneToView(pos) |
468 |
491 |
x = int(mousePoint.x()) |
x = int(mousePoint.x()) |
469 |
492 |
y = int(mousePoint.y()) |
y = int(mousePoint.y()) |
470 |
493 |
if (x >= 0) and (x < self.nsim) and (y >= 0) and (y < self.nsim): |
if (x >= 0) and (x < self.nsim) and (y >= 0) and (y < self.nsim): |
471 |
|
self.mouse_moved.emit(x, y) |
|
472 |
|
|
|
|
494 |
|
self._mouse_moved(x, y) |
|
495 |
|
else: |
|
496 |
|
self._mouse_moved(-1, -1) |
|
497 |
|
else: |
|
498 |
|
self._mouse_moved(-1, -1) |
|
499 |
|
|
|
500 |
|
def _mouse_moved(self, x, y): |
|
501 |
|
if (x != self.x) or (y != self.y): |
|
502 |
|
self.x = x |
|
503 |
|
self.y = y |
|
504 |
|
self.mouse_moved.emit(x, y) |
|
505 |
|
if self.app.mouseButtons() == self.right_button: |
|
506 |
|
self.mouse_right_dragged.emit(x, y) |
|
507 |
|
|
|
508 |
|
|
|
509 |
|
|
|
510 |
|
def on_click(self, evt): |
|
511 |
|
if self.x == -1: |
|
512 |
|
return None |
|
513 |
|
if evt.double(): |
|
514 |
|
self.mouse_double_clicked.emit(self.x, self.y) |
|
515 |
|
elif evt.button() == self.left_button: |
|
516 |
|
self.mouse_clicked.emit(self.x, self.y) |
|
517 |
|
|
473 |
518 |
|
|
474 |
519 |
|
|
475 |
520 |
|
|
|
... |
... |
class DistanceMatrix: |
517 |
562 |
|
|
518 |
563 |
|
|
519 |
564 |
def on_mouse_moved(self, x, y): |
def on_mouse_moved(self, x, y): |
|
565 |
|
if x == -1: |
|
566 |
|
self.w.statusBar.showMessage("") |
|
567 |
|
return None |
|
568 |
|
|
520 |
569 |
if x != y: |
if x != y: |
521 |
570 |
m = self.nsim |
m = self.nsim |
522 |
571 |
i, j = min(x, y), max(x, y) |
i, j = min(x, y), max(x, y) |