-
Notifications
You must be signed in to change notification settings - Fork 9
/
CameraMosaicBrick.py
114 lines (87 loc) · 4.4 KB
/
CameraMosaicBrick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
CameraMosaicBrick
[Description]
This brick can display several images in mosaic
[Slots]
----------------------------------------------------------------------
| name | arguments | description
----------------------------------------------------------------------
| getView | a Dictionary | return a dictionnary whith 2 key : 'view' (QubPixmapDisplayView Object) to add external action and 'drawing' (QubPixmapDisplay Object) to add external drawing
----------------------------------------------------------------------
"""
import weakref
import logging
import qt
from BlissFramework.BaseComponents import BlissWidget
from Qub.Widget.QubActionSet import QubZoomListAction
from Qub.Widget.QubActionSet import QubZoomRectangle
from Qub.Widget.QubActionSet import QubZoomAction
from Qub.Widget.QubActionSet import QubForegroundColorAction
from Qub.Widget.QubActionSet import QubOpenDialogAction
from Qub.Widget.QubDialog import QubMeasureListDialog
from Qub.Objects.Mosaic.QubMosaicView import QubMosaicView
__category__ = "Camera"
class CameraMosaicBrick(BlissWidget) :
def __init__(self,*args) :
BlissWidget.__init__(self,*args)
actions = []
self.__zoomList = QubZoomListAction(place = "toolbar",
zoomValList = [0.1,.25,.5,1,1.5,2,2.5,3,3.5,4],
show = 1,group = "zoom")
actions.append(self.__zoomList)
self.__zoomFitOrFill = QubZoomAction(place = "toolbar",keepROI = True,group = "zoom")
self.__zoomFitOrFill.setList(self.__zoomList)
self.__zoomList.setActionZoomMode(self.__zoomFitOrFill)
actions.append(self.__zoomFitOrFill)
zoomAction = QubZoomRectangle(label='Zoom Crop',place="toolbar", show=1, group="zoom",
activate_click_drag = True,drawingObjectLayer = 2 ** 31,
unactiveActionWhenDub = True)
qt.QObject.connect(zoomAction,qt.PYSIGNAL('RectangleSelected'),self.__rectangleZoomChanged)
actions.append(zoomAction)
####### CHANGE FOREGROUND COLOR #######
fcoloraction = QubForegroundColorAction(name="color", group="image")
actions.append(fcoloraction)
####### MEASURE #######
measureAction = QubOpenDialogAction(parent=self,name='measure',iconName='measure',label='Measure',group="Tools")
measureAction.setConnectCallBack(self._measure_dialog_new)
actions.append(measureAction)
self.__mainView = QubMosaicView(self,actions = actions)
layout = qt.QHBoxLayout(self)
layout.addWidget(self.__mainView)
####### SLOT #######
self.defineSlot('getView',())
def getView(self,key) :
try:
key['drawing'] = self.__mainView.view()
key['view'] = self.__mainView
except:
pass
def __rectangleZoomChanged(self,drawingMgr) :
self.__zoomFitOrFill.setState(False)
rect = drawingMgr.rect()
canvas = self.__mainView.view()
matrix = canvas.matrix()
vp = canvas.viewport()
viewWidth,viewHeight = vp.width(),vp.height()
zoomX = float(viewWidth) / rect.width()
zoomY = float(viewHeight) / rect.height()
zoom = max(zoomX,zoomY)
newMatrix = qt.QWMatrix(zoom,0,0,zoom,matrix.dx(),matrix.dy())
rect = newMatrix.map(rect)
zoom = min(zoom,20)
canvas.setZoom(zoom,zoom)
canvas.setContentsPos(rect.x(),rect.y())
self.__zoomList.writeStrValue("%d%%" % (zoom * 100))
def _measure_dialog_new(self,openDialogAction,aQubImage) :
try :
self.__measureDialog = QubMeasureListDialog(self,
canvas=aQubImage.canvas(),
matrix=aQubImage.matrix(),
eventMgr=aQubImage,
drawingObjectLayer = 2 ** 31)
self.__measureDialog.connect(aQubImage, qt.PYSIGNAL("ForegroundColorChanged"),
self.__measureDialog.setDefaultColor)
openDialogAction.setDialog(self.__measureDialog)
except:
import traceback
traceback.print_exc()