class CanvasWidget(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.lay = QtGui.QGridLayout() self.lay.setSpacing(0) self.setLayout(self.lay) self.addBtn = QtGui.QPushButton('Add Image') self.clearBtn = QtGui.QPushButton('Clear Images') self.autoBtn = QtGui.QPushButton('Auto Range') self.canvas = Canvas() self.lay.addWidget(self.addBtn, 0, 0) self.lay.addWidget(self.clearBtn, 0, 1) self.lay.addWidget(self.autoBtn, 0, 2) self.lay.addWidget(self.canvas, 1, 0, 1, 3) self.imageItems = [] self.z = -1000 self.canvas.view.setRange(QtCore.QRectF(-0.01, -0.01, 0.02, 0.02)) self.connect(self.addBtn, QtCore.SIGNAL('clicked()'), self.addImage) self.connect(self.clearBtn, QtCore.SIGNAL('clicked()'), self.clearImages) self.connect(self.autoBtn, QtCore.SIGNAL('clicked()'), self.autoRange) def autoRange(self): bounds = self.imageItems[0].sceneBoundingRect() self.canvas.view.setRange(bounds) def addItem(self, *args, **kargs): return self.canvas.addItem(*args, **kargs) def addImage(self): fd = getManager().currentFile img = fd.read() if 'imagePosition' in fd.info(): ps = fd.info()['pixelSize'] pos = fd.info()['imagePosition'] else: info = img.infoCopy()[-1] ps = info['pixelSize'] pos = info['imagePosition'] img = img.view(ndarray) if img.ndim == 3: img = img.max(axis=0) #print pos, ps, img.shape, img.dtype, img.max(), img.min() item = ImageItem(img) self.canvas.addItem(item, pos, scale=ps, z=self.z, name=fd.shortName()) self.z += 1 self.imageItems.append(item) def clearImages(self): for item in self.imageItems: self.canvas.removeItem(item) self.imageItems = []
def makeObject(self, host): typ = self.type() args = self.args() if typ == 'plot': obj = pg.PlotWidget(name=self.name(), **args) elif typ == 'imageView': obj = pg.ImageView(**args) elif typ == 'canvas': obj = Canvas.Canvas(**args) elif typ == 'fileInput': obj = FileLoader.FileLoader(host.dataManager(), **args) #elif typ == 'database': #obj = DatabaseGui.DatabaseGui(host.dataManager(), **args) elif typ == 'table': obj = pg.TableWidget(**args) elif typ == 'dataTree': obj = pg.DataTreeWidget(**args) elif typ == 'parameterTree': obj = pg.parametertree.ParameterTree(**args) elif typ == 'graphicsView': obj = pg.GraphicsView(**args) elif typ == 'graphicsLayout': obj = pg.GraphicsLayoutWidget(**args) elif typ == 'viewBox': obj = pg.GraphicsView() obj.setCentralItem(pg.ViewBox(**args)) else: raise Exception( "Cannot automatically create element '%s' (type=%s)" % (self.name, typ)) #self.setObject(obj) ## handled indirectly.. return obj
def canvasItem(self): if self._canvasItem is None: self._canvasItem = Canvas.ScanCanvasItem(handle=self.source(), subDirs=self.dirHandles, name=self.itemName) self._canvasItem.graphicsItem().scan = self ## mark the graphicsItem so that we can trace back to here when it is clicked self._canvasItem.sigVisibilityChanged.connect(self.itemVisibilityChanged) self.item = self._canvasItem.graphicsItem() ## graphics item return self._canvasItem
def __init__(self): Qt.QWidget.__init__(self) self.lay = Qt.QGridLayout() self.lay.setSpacing(0) self.setLayout(self.lay) self.addBtn = Qt.QPushButton('Add Image') self.clearBtn = Qt.QPushButton('Clear Images') self.autoBtn = Qt.QPushButton('Auto Range') self.canvas = Canvas() self.lay.addWidget(self.addBtn, 0, 0) self.lay.addWidget(self.clearBtn, 0, 1) self.lay.addWidget(self.autoBtn, 0, 2) self.lay.addWidget(self.canvas, 1, 0, 1, 3) self.imageItems = [] self.z = -1000 self.canvas.view.setRange(Qt.QRectF(-0.01, -0.01, 0.02, 0.02)) self.connect(self.addBtn, Qt.SIGNAL('clicked()'), self.addImage) self.connect(self.clearBtn, Qt.SIGNAL('clicked()'), self.clearImages) self.connect(self.autoBtn, Qt.SIGNAL('clicked()'), self.autoRange)
def __init__(self): QtGui.QWidget.__init__(self) self.lay = QtGui.QGridLayout() self.lay.setSpacing(0) self.setLayout(self.lay) self.addBtn = QtGui.QPushButton('Add Image') self.clearBtn = QtGui.QPushButton('Clear Images') self.autoBtn = QtGui.QPushButton('Auto Range') self.canvas = Canvas() self.lay.addWidget(self.addBtn, 0, 0) self.lay.addWidget(self.clearBtn, 0, 1) self.lay.addWidget(self.autoBtn, 0, 2) self.lay.addWidget(self.canvas, 1, 0, 1, 3) self.imageItems = [] self.z = -1000 self.canvas.view.setRange(QtCore.QRectF(-0.01, -0.01, 0.02, 0.02)) self.connect(self.addBtn, QtCore.SIGNAL('clicked()'), self.addImage) self.connect(self.clearBtn, QtCore.SIGNAL('clicked()'), self.clearImages) self.connect(self.autoBtn, QtCore.SIGNAL('clicked()'), self.autoRange)