optimize view iteractions
This commit is contained in:
@@ -515,34 +515,58 @@ class FixTargetFrame(pg.ROI):
|
|||||||
param['trf']=trf
|
param['trf']=trf
|
||||||
return param
|
return param
|
||||||
|
|
||||||
class TxtROI(pg.ROI):
|
|
||||||
def __init__(self, pos, size, **kargs):
|
|
||||||
pg.ROI.__init__(self, pos, size, **kargs)
|
|
||||||
|
|
||||||
def paint(self, p, *args):
|
|
||||||
#pg.ROI.paint(self, p, *args)
|
|
||||||
r=QtCore.QRectF(0, 0, self.state['size'][0], self.state['size'][1]).normalized()
|
|
||||||
|
|
||||||
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
|
||||||
p.setPen(self.currentPen)
|
|
||||||
#p.translate(r.left(), r.top())
|
|
||||||
#p.scale(r.width(), r.height())
|
|
||||||
#p.drawRect(0, 0, 1, 1)
|
|
||||||
p.drawRect(r)
|
|
||||||
tr=p.worldTransform()
|
|
||||||
obj_info(tr)
|
|
||||||
tr.setMatrix(tr.m11(),tr.m12(),tr.m13(),tr.m21(),-tr.m22(),tr.m23(),tr.m31(),tr.m32(),tr.m33())
|
|
||||||
p.setWorldTransform(tr)
|
|
||||||
obj_info(tr)
|
|
||||||
obj_info(p.transform())
|
|
||||||
obj_info(p.worldTransform())
|
|
||||||
f=p.font();
|
|
||||||
f.setPixelSize(15)
|
|
||||||
p.setFont(f)
|
|
||||||
p.drawText(0, 5, 'Thierry')
|
|
||||||
|
|
||||||
## 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__':
|
||||||
|
# TODO: pg.ItemGroup does not support bounding box and therefore vb.autoRange() does not work
|
||||||
|
class ItemGroup(pg.ItemGroup):
|
||||||
|
# own item group that supports bounding rect
|
||||||
|
def __init__(self, *args, **kargs):
|
||||||
|
pg.ItemGroup.__init__(self, *args, **kargs)
|
||||||
|
|
||||||
|
def boundingRect(self):
|
||||||
|
# tr=self.transform()
|
||||||
|
boRects=[]
|
||||||
|
for item in self.childItems():
|
||||||
|
boRects.append(item.boundingRect())
|
||||||
|
if boRects:
|
||||||
|
# r=QtCore.QRectF(tr.map(boRects[0].bottomRight()),tr.map(boRects[0].topLeft()))
|
||||||
|
return boRects[0]
|
||||||
|
else:
|
||||||
|
return pg.ItemGroup.boundingRect(self)
|
||||||
|
|
||||||
|
def addItem(self, *args, **kargs):
|
||||||
|
self.setFlag(self.ItemHasNoContents, False)
|
||||||
|
pg.ItemGroup.addItem(self, *args, **kargs)
|
||||||
|
|
||||||
|
|
||||||
|
class TxtROI(pg.ROI):
|
||||||
|
def __init__(self, pos, size, **kargs):
|
||||||
|
pg.ROI.__init__(self, pos, size, **kargs)
|
||||||
|
|
||||||
|
def paint(self, p, *args):
|
||||||
|
# pg.ROI.paint(self, p, *args)
|
||||||
|
r=QtCore.QRectF(0, 0, self.state['size'][0], self.state['size'][1]).normalized()
|
||||||
|
|
||||||
|
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||||
|
p.setPen(self.currentPen)
|
||||||
|
# p.translate(r.left(), r.top())
|
||||||
|
# p.scale(r.width(), r.height())
|
||||||
|
# p.drawRect(0, 0, 1, 1)
|
||||||
|
p.drawRect(r)
|
||||||
|
tr=p.worldTransform()
|
||||||
|
obj_info(tr)
|
||||||
|
tr.setMatrix(tr.m11(), tr.m12(), tr.m13(), tr.m21(), -tr.m22(), tr.m23(), tr.m31(), tr.m32(), tr.m33())
|
||||||
|
p.setWorldTransform(tr)
|
||||||
|
obj_info(tr)
|
||||||
|
obj_info(p.transform())
|
||||||
|
obj_info(p.worldTransform())
|
||||||
|
f=p.font();
|
||||||
|
f.setPixelSize(15)
|
||||||
|
p.setFont(f)
|
||||||
|
p.drawText(0, 5, 'Thierry')
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
#(h, t)=os.path.split(sys.argv[0]);cmd='\n '+(t if len(h)>20 else sys.argv[0])+' '
|
#(h, t)=os.path.split(sys.argv[0]);cmd='\n '+(t if len(h)>20 else sys.argv[0])+' '
|
||||||
@@ -638,6 +662,7 @@ if __name__=='__main__':
|
|||||||
w.setWindowTitle('pyqtgraph example: ROI Examples')
|
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)
|
||||||
|
vb.enableAutoRange(enable=False)
|
||||||
try:
|
try:
|
||||||
g=pg.GridItem(pen=(0, 255, 0), textPen=(0, 255, 0)) # green grid and labels
|
g=pg.GridItem(pen=(0, 255, 0), textPen=(0, 255, 0)) # green grid and labels
|
||||||
except:
|
except:
|
||||||
|
|||||||
24
swissmx.py
24
swissmx.py
@@ -85,7 +85,7 @@ ts.log('Import part 3/8:')
|
|||||||
import qtawesome
|
import qtawesome
|
||||||
import qutilities
|
import qutilities
|
||||||
from PyQt5 import QtCore, QtGui
|
from PyQt5 import QtCore, QtGui
|
||||||
from PyQt5.QtCore import Qt, pyqtSlot, QSize, QRegExp, pyqtSignal, QObject, QThread
|
from PyQt5.QtCore import Qt, pyqtSlot, QSize, QRegExp, pyqtSignal, QObject, QThread, QRectF
|
||||||
from PyQt5.QtGui import QKeySequence, QPixmap, QRegExpValidator, QFont
|
from PyQt5.QtGui import QKeySequence, QPixmap, QRegExpValidator, QFont
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAction, QApplication, QDoubleSpinBox, QFileDialog, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLineEdit,
|
QAction, QApplication, QDoubleSpinBox, QFileDialog, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLineEdit,
|
||||||
@@ -388,8 +388,12 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
self.glw.scene().sigMouseClicked.connect(self.cb_mouse_click)
|
self.glw.scene().sigMouseClicked.connect(self.cb_mouse_click)
|
||||||
|
|
||||||
#--- viewbox ---
|
#--- viewbox ---
|
||||||
#self.vb=vb=self.glw.addViewBox(invertY=False,border='r',enableMenu=False)
|
self.vb=vb=self.glw.addViewBox(invertY=False,border='r',enableMenu=True)
|
||||||
self.vb=vb=self.glw.addViewBox(invertY=False,border='r',enableMenu=False)
|
#TODO: vb.enableAutoRange(enable=True), vb.autoRange() does not work for ItemGroups
|
||||||
|
#therefore set the vieweRange manually
|
||||||
|
pad=10
|
||||||
|
vb.setRange(QRectF(-1200-pad,-1000-pad,1200+2*pad,1000+2*pad))
|
||||||
|
|
||||||
vb.setAspectLocked(True)
|
vb.setAspectLocked(True)
|
||||||
vb.setBackgroundColor((120, 90, 90))
|
vb.setBackgroundColor((120, 90, 90))
|
||||||
|
|
||||||
@@ -728,6 +732,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
app=QApplication.instance()
|
app=QApplication.instance()
|
||||||
cam=app._camera
|
cam=app._camera
|
||||||
self._goImg.setImage(cam._pic)
|
self._goImg.setImage(cam._pic)
|
||||||
|
#vb.setRange(QRectF(-1300,-1100,1400,1200))
|
||||||
|
|
||||||
def cb_new_frame_sim(self, **kwargs):
|
def cb_new_frame_sim(self, **kwargs):
|
||||||
app=QApplication.instance()
|
app=QApplication.instance()
|
||||||
@@ -1122,6 +1127,14 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
fy_motor.move_rel(pFix[1])
|
fy_motor.move_rel(pFix[1])
|
||||||
#fx_motor.move_abs(fx_motor.get_val()+pFix[0])
|
#fx_motor.move_abs(fx_motor.get_val()+pFix[0])
|
||||||
#fy_motor.move_abs(fy_motor.get_val()+pFix[1])
|
#fy_motor.move_abs(fy_motor.get_val()+pFix[1])
|
||||||
|
|
||||||
|
#if none of the image is visible, recenter it
|
||||||
|
r1=self.vb.viewRect()
|
||||||
|
#r2=self.vb.itemBoundingRect(self._goImg)
|
||||||
|
r2=self.vb.itemBoundingRect(self._goBeamMarker)
|
||||||
|
if not r1.intersects(r2):
|
||||||
|
self.vb.autoRange(items=(self._goImg,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pln=geo._fitPlane
|
pln=geo._fitPlane
|
||||||
except AttributeError: pass
|
except AttributeError: pass
|
||||||
@@ -1540,6 +1553,8 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
self._testCode=tc={'idx':0}
|
self._testCode=tc={'idx':0}
|
||||||
step=tc['idx']
|
step=tc['idx']
|
||||||
vb=self.vb
|
vb=self.vb
|
||||||
|
vb.autoRange(items=(self._goImg,))
|
||||||
|
return
|
||||||
|
|
||||||
if step==0:
|
if step==0:
|
||||||
grp=pg.ItemGroup()
|
grp=pg.ItemGroup()
|
||||||
@@ -1551,6 +1566,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
obj=UsrGO.Marker((200, 100), (100, 100), mode=1)
|
obj=UsrGO.Marker((200, 100), (100, 100), mode=1)
|
||||||
grp.addItem(obj)
|
grp.addItem(obj)
|
||||||
tc['grp']=grp
|
tc['grp']=grp
|
||||||
|
vb.autoRange(items=(obj,))
|
||||||
elif step==1:
|
elif step==1:
|
||||||
grp=tc['grp']
|
grp=tc['grp']
|
||||||
tr=grp.transform()
|
tr=grp.transform()
|
||||||
@@ -1901,7 +1917,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
grp=self._goTracked
|
grp=self._goTracked
|
||||||
for go in grp.childItems():
|
for go in grp.childItems():
|
||||||
vb.removeItem(go)
|
vb.removeItem(go)
|
||||||
#grp.clear()
|
grp.setFlag(grp.ItemHasNoContents)
|
||||||
mft._tree.setData(None)
|
mft._tree.setData(None)
|
||||||
|
|
||||||
def module_fix_target_fit_fiducial(self):
|
def module_fix_target_fit_fiducial(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user