-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphicsTransform.py
90 lines (79 loc) · 3.48 KB
/
graphicsTransform.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
"""
This File is part of bLUe software.
Copyright (C) 2017 Bernard Virot <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Lesser Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import weakref
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QSizePolicy, QVBoxLayout, QPushButton, QHBoxLayout
from bLUeGui.graphicsForm import baseForm
from bLUeGui.memory import weakProxy
from utils import optionsWidget, UDict
class transForm (baseForm):
"""
Geometric transformation form
"""
@classmethod
def getNewWindow(cls, targetImage=None, axeSize=200, layer=None, parent=None, mainForm=None):
wdgt = transForm(targetImage=targetImage, axeSize=axeSize, layer=layer, parent=parent, mainForm=mainForm)
wdgt.setWindowTitle(layer.name)
return wdgt
def __init__(self, targetImage=None, axeSize=500, layer=None, parent=None, mainForm=None):
super(transForm, self).__init__(parent=parent)
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.setMinimumSize(axeSize, axeSize)
self.setAttribute(Qt.WA_DeleteOnClose)
# back links to image
self.targetImage = weakProxy(targetImage)
self.img = weakProxy(targetImage)
self.layer = weakProxy(layer)
self.mainForm = mainForm
# options
optionList1, optionNames1 = ['Free', 'Rotation', 'Translation'], ['Free Transformation', 'Rotation', 'Translation']
self.listWidget1 = optionsWidget(options=optionList1, optionNames=optionNames1, exclusive=True)
optionList2, optionNames2 = ['Transparent'], ['Set Transparent Pixels To Black']
self.listWidget2 = optionsWidget(options=optionList2, optionNames=optionNames2, exclusive=False)
self.options = UDict((self.listWidget1.options, self.listWidget2.options))
# set initial selection to Perspective
self.listWidget1.checkOption(optionList1[0])
# option changed handler
def g(item):
l = self.layer
l.tool.setBaseTransform()
#self.layer.tool.setVisible(True)
l.applyToStack()
l.parentImage.onImageChanged()
self.listWidget1.onSelect = g
self.listWidget2.onSelect = g
pushButton1 = QPushButton(' Reset Transformation ')
pushButton1.adjustSize()
def f():
self.layer.tool.resetTrans()
pushButton1.clicked.connect(f)
# layout
l = QVBoxLayout()
l.setAlignment(Qt.AlignTop)
l.addWidget(self.listWidget1)
l.addWidget(self.listWidget2)
hl = QHBoxLayout()
hl.setAlignment(Qt.AlignHCenter)
hl.addWidget(pushButton1)
l.addLayout(hl)
self.setLayout(l)
self.adjustSize()
self.setWhatsThis(
"""
<b>Geometric transformation :</b><br>
Choose a transformation type and drag either corner of the image using the small square red buttons.<br>
Ctrl+Alt+Drag to change the <b>initial positions</b> of buttons.
""")
class imageForm(transForm):
pass