add app_utils for motion_assert, contextMenu og GraphItem, further fixes

This commit is contained in:
2022-09-21 11:06:10 +02:00
parent 158150a954
commit 1393269ceb
11 changed files with 177 additions and 144 deletions

View File

@@ -20,6 +20,8 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
from PyQt5.QtGui import QPolygon,QPolygonF
from PyQt5.QtCore import Qt,QPointF,QLineF
from PyQt5.QtWidgets import QMenu
def itr2str(itr):
return '('+', '.join(tuple(map(lambda x:f'{x:.6g}', itr)))+')'
@@ -145,10 +147,28 @@ class Marker(pg.ROI):
p.setTransform(tr)
return ofx,ofy
class Fiducial(pg.ROI):
def __init__(self, pos, size, z:float, **kargs):
class UsrROI(pg.ROI):
def __init__(self, pos, size, **kargs):
pg.ROI.__init__(self, pos, size, **kargs)
def cb_toggle_movable(self):
self.translatable=not self.translatable
def contextMenuEvent(self, event):
#pg.ROI.contextMenuEvent(self,event)
_log.debug('ContextMenu')
menu = QMenu("ctx")
act=menu.addAction('locked')
act.setCheckable(True)
act.setChecked(not self.translatable)
act.triggered.connect(self.cb_toggle_movable)
#menu.addAction('center in view')
#menu.addAction('delete')
menu.exec(event.screenPos())
class Fiducial(UsrROI):
def __init__(self, pos, size, z:float, **kargs):
UsrROI.__init__(self, pos, size, **kargs)
self._z=z
def paint(self, p, *args):
@@ -195,7 +215,7 @@ class Fiducial(pg.ROI):
return jsn
class Grid(pg.ROI):
class Grid(UsrROI):
'''a grid'''
def __init__( self, pos=(0,0), size=(30,20), cnt=(6,4), fiducialSize=.2, **kargs):
@@ -271,7 +291,7 @@ class Grid(pg.ROI):
return pts
class Path(pg.ROI):
class Path(UsrROI):
'''
a path object with fiducials
path=np.array(n,2) of path points
@@ -347,7 +367,7 @@ class Path(pg.ROI):
}
return jsn
class FixTargetFrame(pg.ROI):
class FixTargetFrame(UsrROI):
'''fixed target frame'''
tpl={
'test':{
@@ -664,7 +684,7 @@ if __name__=='__main__':
pass
else:
obj_info(o)
print(o.state)
#print(o.state)
## Create image to display
@@ -689,7 +709,7 @@ if __name__=='__main__':
w=pg.GraphicsLayoutWidget(show=True, size=(1000, 800), border=True)
w.setWindowTitle('pyqtgraph example: ROI Examples')
vb=w.addViewBox(row=1, col=0, lockAspect=True,invertY=False)
vb=w.addViewBox(row=1, col=0, lockAspect=True,invertY=False,enableMenu=False)
vb.enableAutoRange(enable=False)
try:
g=pg.GridItem(pen=(0, 255, 0), textPen=(0, 255, 0)) # green grid and labels
@@ -748,9 +768,13 @@ if __name__=='__main__':
vi=FixTargetFrame((400,-200),(400,400),tpl='12.5x12.5')
vb.addItem(vi)
vi=Fiducial((0,200),(40,40),3)
vi=Fiducial((0,200),(40,40),3,movable=False,removable=True)
vb.addItem(vi)
vi=pg.PolyLineROI([(22, -19), (40, -30), (23, -10), (22, -19)], closed=True)
vb.addItem(vi)
viRoi=pg.ROI([-200, -200], [100, 80],movable=True, rotatable=True, resizable=True)
viRoi.addFreeHandle(pos=[.7, .5], axes=None, item=None, name=None, index=None) # rechteck , frei beweglich ??? verschwinden anch bewegung