code cleanup
This commit is contained in:
parent
1f77433755
commit
e88e3a4232
@ -32,7 +32,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
QtGui.QWidget.__init__(self, parent)
|
QtGui.QWidget.__init__(self, parent)
|
||||||
self.ui = Ui_Form()
|
self.ui = Ui_Form()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
#self.view = self.ui.view
|
|
||||||
self.view = ViewBox()
|
self.view = ViewBox()
|
||||||
self.ui.view.setCentralItem(self.view)
|
self.ui.view.setCentralItem(self.view)
|
||||||
self.itemList = self.ui.itemList
|
self.itemList = self.ui.itemList
|
||||||
@ -49,9 +48,7 @@ class Canvas(QtGui.QWidget):
|
|||||||
self.redirect = None ## which canvas to redirect items to
|
self.redirect = None ## which canvas to redirect items to
|
||||||
self.items = []
|
self.items = []
|
||||||
|
|
||||||
#self.view.enableMouse()
|
|
||||||
self.view.setAspectLocked(True)
|
self.view.setAspectLocked(True)
|
||||||
#self.view.invertY()
|
|
||||||
|
|
||||||
grid = GridItem()
|
grid = GridItem()
|
||||||
self.grid = CanvasItem(grid, name='Grid', movable=False)
|
self.grid = CanvasItem(grid, name='Grid', movable=False)
|
||||||
@ -69,8 +66,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
self.ui.itemList.sigItemMoved.connect(self.treeItemMoved)
|
self.ui.itemList.sigItemMoved.connect(self.treeItemMoved)
|
||||||
self.ui.itemList.itemSelectionChanged.connect(self.treeItemSelected)
|
self.ui.itemList.itemSelectionChanged.connect(self.treeItemSelected)
|
||||||
self.ui.autoRangeBtn.clicked.connect(self.autoRange)
|
self.ui.autoRangeBtn.clicked.connect(self.autoRange)
|
||||||
#self.ui.storeSvgBtn.clicked.connect(self.storeSvg)
|
|
||||||
#self.ui.storePngBtn.clicked.connect(self.storePng)
|
|
||||||
self.ui.redirectCheck.toggled.connect(self.updateRedirect)
|
self.ui.redirectCheck.toggled.connect(self.updateRedirect)
|
||||||
self.ui.redirectCombo.currentIndexChanged.connect(self.updateRedirect)
|
self.ui.redirectCombo.currentIndexChanged.connect(self.updateRedirect)
|
||||||
self.multiSelectBox.sigRegionChanged.connect(self.multiSelectBoxChanged)
|
self.multiSelectBox.sigRegionChanged.connect(self.multiSelectBoxChanged)
|
||||||
@ -88,21 +83,11 @@ class Canvas(QtGui.QWidget):
|
|||||||
self.ui.redirectCombo.setHostName(self.registeredName)
|
self.ui.redirectCombo.setHostName(self.registeredName)
|
||||||
|
|
||||||
self.menu = QtGui.QMenu()
|
self.menu = QtGui.QMenu()
|
||||||
#self.menu.setTitle("Image")
|
|
||||||
remAct = QtGui.QAction("Remove item", self.menu)
|
remAct = QtGui.QAction("Remove item", self.menu)
|
||||||
remAct.triggered.connect(self.removeClicked)
|
remAct.triggered.connect(self.removeClicked)
|
||||||
self.menu.addAction(remAct)
|
self.menu.addAction(remAct)
|
||||||
self.menu.remAct = remAct
|
self.menu.remAct = remAct
|
||||||
self.ui.itemList.contextMenuEvent = self.itemListContextMenuEvent
|
self.ui.itemList.contextMenuEvent = self.itemListContextMenuEvent
|
||||||
|
|
||||||
|
|
||||||
#def storeSvg(self):
|
|
||||||
#from pyqtgraph.GraphicsScene.exportDialog import ExportDialog
|
|
||||||
#ex = ExportDialog(self.ui.view)
|
|
||||||
#ex.show()
|
|
||||||
|
|
||||||
#def storePng(self):
|
|
||||||
#self.ui.view.writeImage()
|
|
||||||
|
|
||||||
def splitterMoved(self):
|
def splitterMoved(self):
|
||||||
self.resizeEvent()
|
self.resizeEvent()
|
||||||
@ -135,7 +120,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
s = min(self.width(), max(100, min(200, self.width()*0.25)))
|
s = min(self.width(), max(100, min(200, self.width()*0.25)))
|
||||||
s2 = self.width()-s
|
s2 = self.width()-s
|
||||||
self.ui.splitter.setSizes([s2, s])
|
self.ui.splitter.setSizes([s2, s])
|
||||||
|
|
||||||
|
|
||||||
def updateRedirect(self, *args):
|
def updateRedirect(self, *args):
|
||||||
### Decide whether/where to redirect items and make it so
|
### Decide whether/where to redirect items and make it so
|
||||||
@ -154,7 +138,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
self.reclaimItems()
|
self.reclaimItems()
|
||||||
else:
|
else:
|
||||||
self.redirectItems(redirect)
|
self.redirectItems(redirect)
|
||||||
|
|
||||||
|
|
||||||
def redirectItems(self, canvas):
|
def redirectItems(self, canvas):
|
||||||
for i in self.items:
|
for i in self.items:
|
||||||
@ -171,12 +154,9 @@ class Canvas(QtGui.QWidget):
|
|||||||
else:
|
else:
|
||||||
parent.removeChild(li)
|
parent.removeChild(li)
|
||||||
canvas.addItem(i)
|
canvas.addItem(i)
|
||||||
|
|
||||||
|
|
||||||
def reclaimItems(self):
|
def reclaimItems(self):
|
||||||
items = self.items
|
items = self.items
|
||||||
#self.items = {'Grid': items['Grid']}
|
|
||||||
#del items['Grid']
|
|
||||||
self.items = [self.grid]
|
self.items = [self.grid]
|
||||||
items.remove(self.grid)
|
items.remove(self.grid)
|
||||||
|
|
||||||
@ -185,9 +165,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
self.addItem(i)
|
self.addItem(i)
|
||||||
|
|
||||||
def treeItemChanged(self, item, col):
|
def treeItemChanged(self, item, col):
|
||||||
#gi = self.items.get(item.name, None)
|
|
||||||
#if gi is None:
|
|
||||||
#return
|
|
||||||
try:
|
try:
|
||||||
citem = item.canvasItem()
|
citem = item.canvasItem()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -203,25 +180,16 @@ class Canvas(QtGui.QWidget):
|
|||||||
|
|
||||||
def treeItemSelected(self):
|
def treeItemSelected(self):
|
||||||
sel = self.selectedItems()
|
sel = self.selectedItems()
|
||||||
#sel = []
|
|
||||||
#for listItem in self.itemList.selectedItems():
|
|
||||||
#if hasattr(listItem, 'canvasItem') and listItem.canvasItem is not None:
|
|
||||||
#sel.append(listItem.canvasItem)
|
|
||||||
#sel = [self.items[item.name] for item in sel]
|
|
||||||
|
|
||||||
if len(sel) == 0:
|
if len(sel) == 0:
|
||||||
#self.selectWidget.hide()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
multi = len(sel) > 1
|
multi = len(sel) > 1
|
||||||
for i in self.items:
|
for i in self.items:
|
||||||
#i.ctrlWidget().hide()
|
|
||||||
## updated the selected state of every item
|
## updated the selected state of every item
|
||||||
i.selectionChanged(i in sel, multi)
|
i.selectionChanged(i in sel, multi)
|
||||||
|
|
||||||
if len(sel)==1:
|
if len(sel)==1:
|
||||||
#item = sel[0]
|
|
||||||
#item.ctrlWidget().show()
|
|
||||||
self.multiSelectBox.hide()
|
self.multiSelectBox.hide()
|
||||||
self.ui.mirrorSelectionBtn.hide()
|
self.ui.mirrorSelectionBtn.hide()
|
||||||
self.ui.reflectSelectionBtn.hide()
|
self.ui.reflectSelectionBtn.hide()
|
||||||
@ -229,14 +197,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
elif len(sel) > 1:
|
elif len(sel) > 1:
|
||||||
self.showMultiSelectBox()
|
self.showMultiSelectBox()
|
||||||
|
|
||||||
#if item.isMovable():
|
|
||||||
#self.selectBox.setPos(item.item.pos())
|
|
||||||
#self.selectBox.setSize(item.item.sceneBoundingRect().size())
|
|
||||||
#self.selectBox.show()
|
|
||||||
#else:
|
|
||||||
#self.selectBox.hide()
|
|
||||||
|
|
||||||
#self.emit(QtCore.SIGNAL('itemSelected'), self, item)
|
|
||||||
self.sigSelectionChanged.emit(self, sel)
|
self.sigSelectionChanged.emit(self, sel)
|
||||||
|
|
||||||
def selectedItems(self):
|
def selectedItems(self):
|
||||||
@ -245,19 +205,9 @@ class Canvas(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
return [item.canvasItem() for item in self.itemList.selectedItems() if item.canvasItem() is not None]
|
return [item.canvasItem() for item in self.itemList.selectedItems() if item.canvasItem() is not None]
|
||||||
|
|
||||||
#def selectedItem(self):
|
|
||||||
#sel = self.itemList.selectedItems()
|
|
||||||
#if sel is None or len(sel) < 1:
|
|
||||||
#return
|
|
||||||
#return self.items.get(sel[0].name, None)
|
|
||||||
|
|
||||||
def selectItem(self, item):
|
def selectItem(self, item):
|
||||||
li = item.listItem
|
li = item.listItem
|
||||||
#li = self.getListItem(item.name())
|
|
||||||
#print "select", li
|
|
||||||
self.itemList.setCurrentItem(li)
|
self.itemList.setCurrentItem(li)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def showMultiSelectBox(self):
|
def showMultiSelectBox(self):
|
||||||
## Get list of selected canvas items
|
## Get list of selected canvas items
|
||||||
@ -281,7 +231,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
self.ui.mirrorSelectionBtn.show()
|
self.ui.mirrorSelectionBtn.show()
|
||||||
self.ui.reflectSelectionBtn.show()
|
self.ui.reflectSelectionBtn.show()
|
||||||
self.ui.resetTransformsBtn.show()
|
self.ui.resetTransformsBtn.show()
|
||||||
#self.multiSelectBoxBase = self.multiSelectBox.getState().copy()
|
|
||||||
|
|
||||||
def mirrorSelectionClicked(self):
|
def mirrorSelectionClicked(self):
|
||||||
for ci in self.selectedItems():
|
for ci in self.selectedItems():
|
||||||
@ -312,7 +261,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
ci.setTemporaryTransform(transform)
|
ci.setTemporaryTransform(transform)
|
||||||
ci.sigTransformChanged.emit(ci)
|
ci.sigTransformChanged.emit(ci)
|
||||||
|
|
||||||
|
|
||||||
def addGraphicsItem(self, item, **opts):
|
def addGraphicsItem(self, item, **opts):
|
||||||
"""Add a new GraphicsItem to the scene at pos.
|
"""Add a new GraphicsItem to the scene at pos.
|
||||||
Common options are name, pos, scale, and z
|
Common options are name, pos, scale, and z
|
||||||
@ -321,13 +269,11 @@ class Canvas(QtGui.QWidget):
|
|||||||
item._canvasItem = citem
|
item._canvasItem = citem
|
||||||
self.addItem(citem)
|
self.addItem(citem)
|
||||||
return citem
|
return citem
|
||||||
|
|
||||||
|
|
||||||
def addGroup(self, name, **kargs):
|
def addGroup(self, name, **kargs):
|
||||||
group = GroupCanvasItem(name=name)
|
group = GroupCanvasItem(name=name)
|
||||||
self.addItem(group, **kargs)
|
self.addItem(group, **kargs)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
def addItem(self, citem):
|
def addItem(self, citem):
|
||||||
"""
|
"""
|
||||||
@ -363,7 +309,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
#name = newname
|
#name = newname
|
||||||
|
|
||||||
## find parent and add item to tree
|
## find parent and add item to tree
|
||||||
#currentNode = self.itemList.invisibleRootItem()
|
|
||||||
insertLocation = 0
|
insertLocation = 0
|
||||||
#print "Inserting node:", name
|
#print "Inserting node:", name
|
||||||
|
|
||||||
@ -413,11 +358,7 @@ class Canvas(QtGui.QWidget):
|
|||||||
node.setCheckState(0, QtCore.Qt.Unchecked)
|
node.setCheckState(0, QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
node.name = name
|
node.name = name
|
||||||
#if citem.opts['parent'] != None:
|
|
||||||
## insertLocation is incorrect in this case
|
|
||||||
parent.insertChild(insertLocation, node)
|
parent.insertChild(insertLocation, node)
|
||||||
#else:
|
|
||||||
#root.insertChild(insertLocation, node)
|
|
||||||
|
|
||||||
citem.name = name
|
citem.name = name
|
||||||
citem.listItem = node
|
citem.listItem = node
|
||||||
@ -435,36 +376,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
if len(self.items) == 2:
|
if len(self.items) == 2:
|
||||||
self.autoRange()
|
self.autoRange()
|
||||||
|
|
||||||
|
|
||||||
#for n in name:
|
|
||||||
#nextnode = None
|
|
||||||
#for x in range(currentNode.childCount()):
|
|
||||||
#ch = currentNode.child(x)
|
|
||||||
#if hasattr(ch, 'name'): ## check Z-value of current item to determine insert location
|
|
||||||
#zval = ch.canvasItem.zValue()
|
|
||||||
#if zval > z:
|
|
||||||
###print " ->", x
|
|
||||||
#insertLocation = x+1
|
|
||||||
#if n == ch.text(0):
|
|
||||||
#nextnode = ch
|
|
||||||
#break
|
|
||||||
#if nextnode is None: ## If name doesn't exist, create it
|
|
||||||
#nextnode = QtGui.QTreeWidgetItem([n])
|
|
||||||
#nextnode.setFlags((nextnode.flags() | QtCore.Qt.ItemIsUserCheckable) & ~QtCore.Qt.ItemIsDropEnabled)
|
|
||||||
#nextnode.setCheckState(0, QtCore.Qt.Checked)
|
|
||||||
### Add node to correct position in list by Z-value
|
|
||||||
###print " ==>", insertLocation
|
|
||||||
#currentNode.insertChild(insertLocation, nextnode)
|
|
||||||
|
|
||||||
#if n == name[-1]: ## This is the leaf; add some extra properties.
|
|
||||||
#nextnode.name = name
|
|
||||||
|
|
||||||
#if n == name[0]: ## This is the root; make the item movable
|
|
||||||
#nextnode.setFlags(nextnode.flags() | QtCore.Qt.ItemIsDragEnabled)
|
|
||||||
#else:
|
|
||||||
#nextnode.setFlags(nextnode.flags() & ~QtCore.Qt.ItemIsDragEnabled)
|
|
||||||
|
|
||||||
#currentNode = nextnode
|
|
||||||
return citem
|
return citem
|
||||||
|
|
||||||
def treeItemMoved(self, item, parent, index):
|
def treeItemMoved(self, item, parent, index):
|
||||||
@ -481,31 +392,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
for i in range(len(siblings)):
|
for i in range(len(siblings)):
|
||||||
item = siblings[i]
|
item = siblings[i]
|
||||||
item.setZValue(zvals[i])
|
item.setZValue(zvals[i])
|
||||||
#item = self.itemList.topLevelItem(i)
|
|
||||||
|
|
||||||
##ci = self.items[item.name]
|
|
||||||
#ci = item.canvasItem
|
|
||||||
#if ci is None:
|
|
||||||
#continue
|
|
||||||
#if ci.zValue() != zvals[i]:
|
|
||||||
#ci.setZValue(zvals[i])
|
|
||||||
|
|
||||||
#if self.itemList.topLevelItemCount() < 2:
|
|
||||||
#return
|
|
||||||
#name = item.name
|
|
||||||
#gi = self.items[name]
|
|
||||||
#if index == 0:
|
|
||||||
#next = self.itemList.topLevelItem(1)
|
|
||||||
#z = self.items[next.name].zValue()+1
|
|
||||||
#else:
|
|
||||||
#prev = self.itemList.topLevelItem(index-1)
|
|
||||||
#z = self.items[prev.name].zValue()-1
|
|
||||||
#gi.setZValue(z)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def itemVisibilityChanged(self, item):
|
def itemVisibilityChanged(self, item):
|
||||||
listItem = item.listItem
|
listItem = item.listItem
|
||||||
@ -521,7 +407,6 @@ class Canvas(QtGui.QWidget):
|
|||||||
if isinstance(item, QtGui.QTreeWidgetItem):
|
if isinstance(item, QtGui.QTreeWidgetItem):
|
||||||
item = item.canvasItem()
|
item = item.canvasItem()
|
||||||
|
|
||||||
|
|
||||||
if isinstance(item, CanvasItem):
|
if isinstance(item, CanvasItem):
|
||||||
item.setCanvas(None)
|
item.setCanvas(None)
|
||||||
listItem = item.listItem
|
listItem = item.listItem
|
||||||
@ -559,15 +444,10 @@ class Canvas(QtGui.QWidget):
|
|||||||
def getListItem(self, name):
|
def getListItem(self, name):
|
||||||
return self.items[name]
|
return self.items[name]
|
||||||
|
|
||||||
#def scene(self):
|
|
||||||
#return self.view.scene()
|
|
||||||
|
|
||||||
def itemTransformChanged(self, item):
|
def itemTransformChanged(self, item):
|
||||||
#self.emit(QtCore.SIGNAL('itemTransformChanged'), self, item)
|
|
||||||
self.sigItemTransformChanged.emit(self, item)
|
self.sigItemTransformChanged.emit(self, item)
|
||||||
|
|
||||||
def itemTransformChangeFinished(self, item):
|
def itemTransformChangeFinished(self, item):
|
||||||
#self.emit(QtCore.SIGNAL('itemTransformChangeFinished'), self, item)
|
|
||||||
self.sigItemTransformChangeFinished.emit(self, item)
|
self.sigItemTransformChangeFinished.emit(self, item)
|
||||||
|
|
||||||
def itemListContextMenuEvent(self, ev):
|
def itemListContextMenuEvent(self, ev):
|
||||||
@ -575,13 +455,13 @@ class Canvas(QtGui.QWidget):
|
|||||||
self.menu.popup(ev.globalPos())
|
self.menu.popup(ev.globalPos())
|
||||||
|
|
||||||
def removeClicked(self):
|
def removeClicked(self):
|
||||||
#self.removeItem(self.menuItem)
|
|
||||||
for item in self.selectedItems():
|
for item in self.selectedItems():
|
||||||
self.removeItem(item)
|
self.removeItem(item)
|
||||||
self.menuItem = None
|
self.menuItem = None
|
||||||
import gc
|
import gc
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
class SelectBox(ROI):
|
class SelectBox(ROI):
|
||||||
def __init__(self, scalable=False):
|
def __init__(self, scalable=False):
|
||||||
#QtGui.QGraphicsRectItem.__init__(self, 0, 0, size[0], size[1])
|
#QtGui.QGraphicsRectItem.__init__(self, 0, 0, size[0], size[1])
|
||||||
@ -593,14 +473,3 @@ class SelectBox(ROI):
|
|||||||
self.addScaleHandle([0, 0], center, lockAspect=True)
|
self.addScaleHandle([0, 0], center, lockAspect=True)
|
||||||
self.addRotateHandle([0, 1], center)
|
self.addRotateHandle([0, 1], center)
|
||||||
self.addRotateHandle([1, 0], center)
|
self.addRotateHandle([1, 0], center)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,14 +87,12 @@ class CanvasItem(QtCore.QObject):
|
|||||||
self.alphaSlider.valueChanged.connect(self.alphaChanged)
|
self.alphaSlider.valueChanged.connect(self.alphaChanged)
|
||||||
self.alphaSlider.sliderPressed.connect(self.alphaPressed)
|
self.alphaSlider.sliderPressed.connect(self.alphaPressed)
|
||||||
self.alphaSlider.sliderReleased.connect(self.alphaReleased)
|
self.alphaSlider.sliderReleased.connect(self.alphaReleased)
|
||||||
#self.canvas.sigSelectionChanged.connect(self.selectionChanged)
|
|
||||||
self.resetTransformBtn.clicked.connect(self.resetTransformClicked)
|
self.resetTransformBtn.clicked.connect(self.resetTransformClicked)
|
||||||
self.copyBtn.clicked.connect(self.copyClicked)
|
self.copyBtn.clicked.connect(self.copyClicked)
|
||||||
self.pasteBtn.clicked.connect(self.pasteClicked)
|
self.pasteBtn.clicked.connect(self.pasteClicked)
|
||||||
|
|
||||||
self.setMovable(self.opts['movable']) ## update gui to reflect this option
|
self.setMovable(self.opts['movable']) ## update gui to reflect this option
|
||||||
|
|
||||||
|
|
||||||
if 'transform' in self.opts:
|
if 'transform' in self.opts:
|
||||||
self.baseTransform = self.opts['transform']
|
self.baseTransform = self.opts['transform']
|
||||||
else:
|
else:
|
||||||
@ -114,7 +112,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
## every CanvasItem implements its own individual selection box
|
## every CanvasItem implements its own individual selection box
|
||||||
## so that subclasses are free to make their own.
|
## so that subclasses are free to make their own.
|
||||||
self.selectBox = SelectBox(scalable=self.opts['scalable'], rotatable=self.opts['rotatable'])
|
self.selectBox = SelectBox(scalable=self.opts['scalable'], rotatable=self.opts['rotatable'])
|
||||||
#self.canvas.scene().addItem(self.selectBox)
|
|
||||||
self.selectBox.hide()
|
self.selectBox.hide()
|
||||||
self.selectBox.setZValue(1e6)
|
self.selectBox.setZValue(1e6)
|
||||||
self.selectBox.sigRegionChanged.connect(self.selectBoxChanged) ## calls selectBoxMoved
|
self.selectBox.sigRegionChanged.connect(self.selectBoxChanged) ## calls selectBoxMoved
|
||||||
@ -129,16 +126,7 @@ class CanvasItem(QtCore.QObject):
|
|||||||
self.tempTransform = SRTTransform() ## holds the additional transform that happens during a move - gets added to the userTransform when move is done.
|
self.tempTransform = SRTTransform() ## holds the additional transform that happens during a move - gets added to the userTransform when move is done.
|
||||||
self.userTransform = SRTTransform() ## stores the total transform of the object
|
self.userTransform = SRTTransform() ## stores the total transform of the object
|
||||||
self.resetUserTransform()
|
self.resetUserTransform()
|
||||||
|
|
||||||
## now happens inside resetUserTransform -> selectBoxToItem
|
|
||||||
# self.selectBoxBase = self.selectBox.getState().copy()
|
|
||||||
|
|
||||||
|
|
||||||
#print "Created canvas item", self
|
|
||||||
#print " base:", self.baseTransform
|
|
||||||
#print " user:", self.userTransform
|
|
||||||
#print " temp:", self.tempTransform
|
|
||||||
#print " bounds:", self.item.sceneBoundingRect()
|
|
||||||
|
|
||||||
def setMovable(self, m):
|
def setMovable(self, m):
|
||||||
self.opts['movable'] = m
|
self.opts['movable'] = m
|
||||||
@ -239,7 +227,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
# s=self.updateTransform()
|
# s=self.updateTransform()
|
||||||
# self.setTranslate(-2*s['pos'][0], -2*s['pos'][1])
|
# self.setTranslate(-2*s['pos'][0], -2*s['pos'][1])
|
||||||
# self.selectBoxFromUser()
|
# self.selectBoxFromUser()
|
||||||
|
|
||||||
|
|
||||||
def hasUserTransform(self):
|
def hasUserTransform(self):
|
||||||
#print self.userRotate, self.userTranslate
|
#print self.userRotate, self.userTranslate
|
||||||
@ -255,7 +242,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
def isMovable(self):
|
def isMovable(self):
|
||||||
return self.opts['movable']
|
return self.opts['movable']
|
||||||
|
|
||||||
|
|
||||||
def selectBoxMoved(self):
|
def selectBoxMoved(self):
|
||||||
"""The selection box has moved; get its transformation information and pass to the graphics item"""
|
"""The selection box has moved; get its transformation information and pass to the graphics item"""
|
||||||
self.userTransform = self.selectBox.getGlobalTransform(relativeTo=self.selectBoxBase)
|
self.userTransform = self.selectBox.getGlobalTransform(relativeTo=self.selectBoxBase)
|
||||||
@ -290,7 +276,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
self.userTransform.setScale(x, y)
|
self.userTransform.setScale(x, y)
|
||||||
self.selectBoxFromUser()
|
self.selectBoxFromUser()
|
||||||
self.updateTransform()
|
self.updateTransform()
|
||||||
|
|
||||||
|
|
||||||
def setTemporaryTransform(self, transform):
|
def setTemporaryTransform(self, transform):
|
||||||
self.tempTransform = transform
|
self.tempTransform = transform
|
||||||
@ -302,21 +287,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
self.resetTemporaryTransform()
|
self.resetTemporaryTransform()
|
||||||
self.selectBoxFromUser() ## update the selection box to match the new userTransform
|
self.selectBoxFromUser() ## update the selection box to match the new userTransform
|
||||||
|
|
||||||
#st = self.userTransform.saveState()
|
|
||||||
|
|
||||||
#self.userTransform = self.userTransform * self.tempTransform ## order is important!
|
|
||||||
|
|
||||||
#### matrix multiplication affects the scale factors, need to reset
|
|
||||||
#if st['scale'][0] < 0 or st['scale'][1] < 0:
|
|
||||||
#nst = self.userTransform.saveState()
|
|
||||||
#self.userTransform.setScale([-nst['scale'][0], -nst['scale'][1]])
|
|
||||||
|
|
||||||
#self.resetTemporaryTransform()
|
|
||||||
#self.selectBoxFromUser()
|
|
||||||
#self.selectBoxChangeFinished()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def resetTemporaryTransform(self):
|
def resetTemporaryTransform(self):
|
||||||
self.tempTransform = SRTTransform() ## don't use Transform.reset()--this transform might be used elsewhere.
|
self.tempTransform = SRTTransform() ## don't use Transform.reset()--this transform might be used elsewhere.
|
||||||
self.updateTransform()
|
self.updateTransform()
|
||||||
@ -339,20 +309,13 @@ class CanvasItem(QtCore.QObject):
|
|||||||
|
|
||||||
def displayTransform(self, transform):
|
def displayTransform(self, transform):
|
||||||
"""Updates transform numbers in the ctrl widget."""
|
"""Updates transform numbers in the ctrl widget."""
|
||||||
|
|
||||||
tr = transform.saveState()
|
tr = transform.saveState()
|
||||||
|
|
||||||
self.transformGui.translateLabel.setText("Translate: (%f, %f)" %(tr['pos'][0], tr['pos'][1]))
|
self.transformGui.translateLabel.setText("Translate: (%f, %f)" %(tr['pos'][0], tr['pos'][1]))
|
||||||
self.transformGui.rotateLabel.setText("Rotate: %f degrees" %tr['angle'])
|
self.transformGui.rotateLabel.setText("Rotate: %f degrees" %tr['angle'])
|
||||||
self.transformGui.scaleLabel.setText("Scale: (%f, %f)" %(tr['scale'][0], tr['scale'][1]))
|
self.transformGui.scaleLabel.setText("Scale: (%f, %f)" %(tr['scale'][0], tr['scale'][1]))
|
||||||
#self.transformGui.mirrorImageCheck.setChecked(False)
|
|
||||||
#if tr['scale'][0] < 0:
|
|
||||||
# self.transformGui.mirrorImageCheck.setChecked(True)
|
|
||||||
|
|
||||||
|
|
||||||
def resetUserTransform(self):
|
def resetUserTransform(self):
|
||||||
#self.userRotate = 0
|
|
||||||
#self.userTranslate = pg.Point(0,0)
|
|
||||||
self.userTransform.reset()
|
self.userTransform.reset()
|
||||||
self.updateTransform()
|
self.updateTransform()
|
||||||
|
|
||||||
@ -368,8 +331,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
|
|
||||||
def restoreTransform(self, tr):
|
def restoreTransform(self, tr):
|
||||||
try:
|
try:
|
||||||
#self.userTranslate = pg.Point(tr['trans'])
|
|
||||||
#self.userRotate = tr['rot']
|
|
||||||
self.userTransform = SRTTransform(tr)
|
self.userTransform = SRTTransform(tr)
|
||||||
self.updateTransform()
|
self.updateTransform()
|
||||||
|
|
||||||
@ -377,16 +338,11 @@ class CanvasItem(QtCore.QObject):
|
|||||||
self.sigTransformChanged.emit(self)
|
self.sigTransformChanged.emit(self)
|
||||||
self.sigTransformChangeFinished.emit(self)
|
self.sigTransformChangeFinished.emit(self)
|
||||||
except:
|
except:
|
||||||
#self.userTranslate = pg.Point([0,0])
|
|
||||||
#self.userRotate = 0
|
|
||||||
self.userTransform = SRTTransform()
|
self.userTransform = SRTTransform()
|
||||||
debug.printExc("Failed to load transform:")
|
debug.printExc("Failed to load transform:")
|
||||||
#print "set transform", self, self.userTranslate
|
|
||||||
|
|
||||||
def saveTransform(self):
|
def saveTransform(self):
|
||||||
"""Return a dict containing the current user transform"""
|
"""Return a dict containing the current user transform"""
|
||||||
#print "save transform", self, self.userTranslate
|
|
||||||
#return {'trans': list(self.userTranslate), 'rot': self.userRotate}
|
|
||||||
return self.userTransform.saveState()
|
return self.userTransform.saveState()
|
||||||
|
|
||||||
def selectBoxFromUser(self):
|
def selectBoxFromUser(self):
|
||||||
@ -404,7 +360,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
#self.selectBox.setAngle(self.userRotate)
|
#self.selectBox.setAngle(self.userRotate)
|
||||||
#self.selectBox.setPos([x2, y2])
|
#self.selectBox.setPos([x2, y2])
|
||||||
self.selectBox.blockSignals(False)
|
self.selectBox.blockSignals(False)
|
||||||
|
|
||||||
|
|
||||||
def selectBoxToItem(self):
|
def selectBoxToItem(self):
|
||||||
"""Move/scale the selection box so it fits the item's bounding rect. (assumes item is not rotated)"""
|
"""Move/scale the selection box so it fits the item's bounding rect. (assumes item is not rotated)"""
|
||||||
@ -424,11 +379,6 @@ class CanvasItem(QtCore.QObject):
|
|||||||
self.opts['z'] = z
|
self.opts['z'] = z
|
||||||
if z is not None:
|
if z is not None:
|
||||||
self._graphicsItem.setZValue(z)
|
self._graphicsItem.setZValue(z)
|
||||||
|
|
||||||
#def selectionChanged(self, canvas, items):
|
|
||||||
#self.selected = len(items) == 1 and (items[0] is self)
|
|
||||||
#self.showSelectBox()
|
|
||||||
|
|
||||||
|
|
||||||
def selectionChanged(self, sel, multi):
|
def selectionChanged(self, sel, multi):
|
||||||
"""
|
"""
|
||||||
@ -456,16 +406,12 @@ class CanvasItem(QtCore.QObject):
|
|||||||
|
|
||||||
def hideSelectBox(self):
|
def hideSelectBox(self):
|
||||||
self.selectBox.hide()
|
self.selectBox.hide()
|
||||||
|
|
||||||
|
|
||||||
def selectBoxChanged(self):
|
def selectBoxChanged(self):
|
||||||
self.selectBoxMoved()
|
self.selectBoxMoved()
|
||||||
#self.updateTransform(self.selectBox)
|
|
||||||
#self.emit(QtCore.SIGNAL('transformChanged'), self)
|
|
||||||
self.sigTransformChanged.emit(self)
|
self.sigTransformChanged.emit(self)
|
||||||
|
|
||||||
def selectBoxChangeFinished(self):
|
def selectBoxChangeFinished(self):
|
||||||
#self.emit(QtCore.SIGNAL('transformChangeFinished'), self)
|
|
||||||
self.sigTransformChangeFinished.emit(self)
|
self.sigTransformChangeFinished.emit(self)
|
||||||
|
|
||||||
def alphaPressed(self):
|
def alphaPressed(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user