pyqtUsrObj.py work...
This commit is contained in:
101
pyqtUsrObj.py
101
pyqtUsrObj.py
@@ -1,25 +1,28 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# *-----------------------------------------------------------------------*
|
||||||
"""
|
# | |
|
||||||
Demonstrates a variety of uses for ROI. This class provides a user-adjustable
|
# | Copyright (c) 2022 by Paul Scherrer Institute (http://www.psi.ch) |
|
||||||
region of interest marker. It is possible to customize the layout and
|
# | Based on Zac great first implementation |
|
||||||
function of the scale/rotate handles in very flexible ways.
|
# | Author Thierry Zamofing (thierry.zamofing@psi.ch) |
|
||||||
"""
|
# *-----------------------------------------------------------------------*
|
||||||
|
'''
|
||||||
|
User pyqtgraph objects and functions.
|
||||||
|
|
||||||
|
TODO: Dimension of pyqtgraph is in um not pixel (as now)
|
||||||
|
'''
|
||||||
|
|
||||||
#import initExample ## Add path to library (just for examples; you do not need this)
|
#import initExample ## Add path to library (just for examples; you do not need this)
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from pyqtgraph.Qt import QtCore, QtGui
|
from pyqtgraph.Qt import QtCore, QtGui
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from PyQt5.QtGui import QPolygon,QPolygonF
|
||||||
|
from PyQt5.QtCore import QPointF
|
||||||
|
|
||||||
class BeamMark(pg.ROI):
|
class BeamMark(pg.ROI):
|
||||||
"""A crosshair ROI whose position is at the center of the crosshairs. By default, it is scalable, rotatable and translatable."""
|
"""A crosshair ROI whose position is at the center of the crosshairs. By default, it is scalable, rotatable and translatable."""
|
||||||
|
|
||||||
def __init__(self, pos=None, size=None, parent=None, **kargs):
|
def __init__(self, pos=None, size=None, **kargs):
|
||||||
#self._size=size
|
|
||||||
#self._pos=pos
|
|
||||||
#self._shape=None
|
|
||||||
pg.ROI.__init__(self, pos, size, **kargs)
|
pg.ROI.__init__(self, pos, size, **kargs)
|
||||||
|
|
||||||
def paint(self, p, *args):
|
def paint(self, p, *args):
|
||||||
@@ -47,6 +50,75 @@ class BeamMark(pg.ROI):
|
|||||||
## p.drawText(-w, -h, '{:.0f}x{:.0f}'.format(*self._size))
|
## p.drawText(-w, -h, '{:.0f}x{:.0f}'.format(*self._size))
|
||||||
|
|
||||||
|
|
||||||
|
class Grid(pg.ROI):
|
||||||
|
'''a grid'''
|
||||||
|
|
||||||
|
def __init__( self, pos=(0,0), size=(30,20), cnt=(6,4), **kargs):
|
||||||
|
pg.ROI.__init__(self, pos, size, **kargs)
|
||||||
|
self._cnt=cnt
|
||||||
|
self.addScaleHandle([1, 1], [0, 0])
|
||||||
|
self.addScaleHandle([0, 0], [1, 1])
|
||||||
|
self.addScaleRotateHandle([1, 0], [0, 0])
|
||||||
|
|
||||||
|
def paint(self, p, *args):
|
||||||
|
#pg.ROI.paint(self, p, *args)
|
||||||
|
sz=self.state['size']
|
||||||
|
nx, ny=self._cnt
|
||||||
|
px, py=sz[0]/(nx-1), sz[1]/(ny-1)
|
||||||
|
r=QtCore.QRectF(0, 0, sz[0], sz[1]).normalized()
|
||||||
|
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||||
|
p.setPen(self.currentPen)
|
||||||
|
for i in range(nx):
|
||||||
|
x=i*px
|
||||||
|
p.drawLine(pg.Point(x, 0), pg.Point(x, sz[1]))
|
||||||
|
|
||||||
|
for i in range(ny):
|
||||||
|
y=i*py
|
||||||
|
p.drawLine(pg.Point(0, y), pg.Point(sz[0] ,y ))
|
||||||
|
|
||||||
|
#p.translate(r.left(), r.top())
|
||||||
|
#p.scale(r.width(), r.height())
|
||||||
|
#p.drawEllipse(0, 0, 1, 1)
|
||||||
|
#p.drawRect(0, 0, 1, 1)
|
||||||
|
|
||||||
|
|
||||||
|
class Path(pg.ROI):
|
||||||
|
'''a grid'''
|
||||||
|
|
||||||
|
def __init__( self, pos=(0,0), mark=np.array(((3,4),)), path=np.array(((6,4),(16,24),(-5,7),(3,12))), **kargs):
|
||||||
|
all=np.vstack((mark,path))
|
||||||
|
mn=all.min(0)
|
||||||
|
mx=all.max(0)
|
||||||
|
size=mx-mn
|
||||||
|
|
||||||
|
pg.ROI.__init__(self, pos, size, **kargs)
|
||||||
|
self._mark=mark
|
||||||
|
self._path=path
|
||||||
|
self.addScaleHandle([1, 1], [0, 0])
|
||||||
|
self.addScaleHandle([0, 0], [1, 1])
|
||||||
|
self.addScaleRotateHandle([1, 0], [0, 0])
|
||||||
|
|
||||||
|
def paint(self, p, *args):
|
||||||
|
#pg.ROI.paint(self, p, *args)
|
||||||
|
pos=self.state['pos']
|
||||||
|
sz=self.state['size']
|
||||||
|
mark=self._mark
|
||||||
|
path=self._path
|
||||||
|
|
||||||
|
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||||
|
p.setPen(self.currentPen)
|
||||||
|
#p.translate(pos[0], pos[1])
|
||||||
|
p.drawEllipse(0, 0, int(sz[0]), int(sz[1]))
|
||||||
|
p.drawRect(0, 0, int(sz[0]), int(sz[1]))
|
||||||
|
|
||||||
|
qPlg=QPolygonF()
|
||||||
|
for pt in path:
|
||||||
|
qPlg.append(QPointF(*pt))
|
||||||
|
#pp =QPolygonF(path)
|
||||||
|
p.drawPolyline(qPlg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Start Qt event loop unless running in interactive mode or using pyside.
|
## Start Qt event loop unless running in interactive mode or using pyside.
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
@@ -126,6 +198,13 @@ if __name__=='__main__':
|
|||||||
vb.addItem(viRoi)
|
vb.addItem(viRoi)
|
||||||
viUsrRoi=BeamMark([10, 20], [30, 20])
|
viUsrRoi=BeamMark([10, 20], [30, 20])
|
||||||
vb.addItem(viUsrRoi)
|
vb.addItem(viUsrRoi)
|
||||||
|
vi=Grid( (50,10), (200,150), (30,20))
|
||||||
|
#vi=Grid( (50,10), (200,150), (6,4))
|
||||||
|
vb.addItem(vi) #vi= visual item
|
||||||
|
|
||||||
|
vi=Path()
|
||||||
|
vb.addItem(vi)
|
||||||
|
|
||||||
childTree(vb)
|
childTree(vb)
|
||||||
|
|
||||||
w.scene().sigMouseClicked.connect(mouse_click_event)
|
w.scene().sigMouseClicked.connect(mouse_click_event)
|
||||||
|
|||||||
11
swissmx.py
11
swissmx.py
@@ -243,15 +243,16 @@ class Main(QMainWindow, Ui_MainWindow):
|
|||||||
self.microscope_page.layout().addWidget(self.glw)
|
self.microscope_page.layout().addWidget(self.glw)
|
||||||
self.glw.show()
|
self.glw.show()
|
||||||
|
|
||||||
self.vb = self.glw.addViewBox(invertY=True)#,enableMenu=False)
|
self.vb=vb=self.glw.addViewBox(invertY=True)#,enableMenu=False)
|
||||||
self.img = pg.ImageItem()
|
self.img = pg.ImageItem()
|
||||||
self.img._swissmx_name = "microscope_image_item"
|
|
||||||
# self.graphicsView.setCentralItem(self.vb)
|
# self.graphicsView.setCentralItem(self.vb)
|
||||||
self.glw.scene().sigMouseMoved.connect(self.mouse_move_event)
|
self.glw.scene().sigMouseMoved.connect(self.mouse_move_event)
|
||||||
self.glw.scene().sigMouseClicked.connect(self.mouse_click_event)
|
self.glw.scene().sigMouseClicked.connect(self.mouse_click_event)
|
||||||
self.vb.setAspectLocked(True)
|
vb.setAspectLocked(True)
|
||||||
self.vb.setBackgroundColor((120, 90, 90))
|
vb.setBackgroundColor((120, 90, 90))
|
||||||
self.vb.addItem(self.img)
|
vb.addItem(self.img)
|
||||||
|
grid=pg.GridItem()
|
||||||
|
vb.addItem(grid)
|
||||||
|
|
||||||
self._escape_current_state = "Maintenance"
|
self._escape_current_state = "Maintenance"
|
||||||
self._pin_mounting_offset = 0.0
|
self._pin_mounting_offset = 0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user