#!/usr/bin/env python
from PyQt4 import QtCore
from PyQt4 import QtGui
""" Canvas for drawing"""
def __init__(self, parent=None):
QtGui.
QPixmap.__init__
(self,
64,
64) self.parent = parent
self.imH = 64
self.imW = 64
self.
fill(QtGui.
QColor(0,
255,
255)) self.
color = QtGui.
QColor(0,
0,
0)
def paintEvent(self, point=False):
if point:
p.
setPen(QtGui.
QPen(self.
color,
1, QtCore.
Qt.
SolidLine)) p.drawPoints(point)
def clic(self, mouseX, mouseY):
self.
paintEvent(QtCore.
QPoint(mouseX, mouseY
))
""" Display, zoom, pan..."""
def __init__(self):
self.im = Canvas(self)
self.imH = self.im.height()
self.imW = self.im.width()
self.zoomN = 1
self.scene.setSceneRect(0, 0, self.imW, self.imH)
self.scene.addPixmap(self.im)
self.setScene(self.scene)
self.
setTransformationAnchor(QtGui.
QGraphicsView.
AnchorUnderMouse) self.setMinimumSize(400, 400)
self.setWindowTitle("pix")
def mousePressEvent(self, event):
if event.buttons() == QtCore.Qt.LeftButton:
pos = self.mapToScene(event.pos())
self.im.clic(pos.x(), pos.y())
#~ self.scene.update(0,0,64,64)
#~ self.updateScene([QtCore.QRectF(0,0,64,64)])
self.scene.addPixmap(self.im)
print('items')
print(self.scene.items())
else:
def wheelEvent(self, event):
if event.delta() > 0:
self.scaleView(2)
elif event.delta() < 0:
self.scaleView(0.5)
def scaleView(self, factor):
n = self.zoomN * factor
if n < 1 or n > 16:
return
self.zoomN = n
self.scale(factor, factor)
if __name__ == '__main__':
import sys
widget = GraphWidget()
widget.show()
sys.exit(app.exec_())
#!/usr/bin/env python
from PyQt4 import QtCore
from PyQt4 import QtGui
class Canvas(QtGui.QPixmap):
""" Canvas for drawing"""
def __init__(self, parent=None):
QtGui.QPixmap.__init__(self, 64, 64)
self.parent = parent
self.imH = 64
self.imW = 64
self.fill(QtGui.QColor(0, 255, 255))
self.color = QtGui.QColor(0, 0, 0)
def paintEvent(self, point=False):
if point:
p = QtGui.QPainter(self)
p.setPen(QtGui.QPen(self.color, 1, QtCore.Qt.SolidLine))
p.drawPoints(point)
def clic(self, mouseX, mouseY):
self.paintEvent(QtCore.QPoint(mouseX, mouseY))
class GraphWidget(QtGui.QGraphicsView):
""" Display, zoom, pan..."""
def __init__(self):
QtGui.QGraphicsView.__init__(self)
self.im = Canvas(self)
self.imH = self.im.height()
self.imW = self.im.width()
self.zoomN = 1
self.scene = QtGui.QGraphicsScene(self)
self.scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
self.scene.setSceneRect(0, 0, self.imW, self.imH)
self.scene.addPixmap(self.im)
self.setScene(self.scene)
self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter)
self.setMinimumSize(400, 400)
self.setWindowTitle("pix")
def mousePressEvent(self, event):
if event.buttons() == QtCore.Qt.LeftButton:
pos = self.mapToScene(event.pos())
self.im.clic(pos.x(), pos.y())
#~ self.scene.update(0,0,64,64)
#~ self.updateScene([QtCore.QRectF(0,0,64,64)])
self.scene.addPixmap(self.im)
print('items')
print(self.scene.items())
else:
return QtGui.QGraphicsView.mousePressEvent(self, event)
def wheelEvent(self, event):
if event.delta() > 0:
self.scaleView(2)
elif event.delta() < 0:
self.scaleView(0.5)
def scaleView(self, factor):
n = self.zoomN * factor
if n < 1 or n > 16:
return
self.zoomN = n
self.scale(factor, factor)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
widget = GraphWidget()
widget.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Modified it as this:
#!/usr/bin/env python
from PyQt4 import QtCore
from PyQt4 import QtGui
import h5py
import numpy
""" Canvas for drawing"""
def __init__(self, parent=None):
QtGui.
QPixmap.__init__
(self,
1000,
1000) self.parent = parent
self.imH = 1000
self.imW = 1000
self.
fill(QtGui.
QColor(0,
255,
255)) self.
color = QtGui.
QColor(0,
0,
0)
def paintEvent(self, c, point=False):
if point:
p.
setPen(QtGui.
QPen(QtGui.
QColor(c, c, c
),
1, QtCore.
Qt.
SolidLine)) p.drawPoints(point)
def clic(self, mouseX, mouseY, c):
self.
paintEvent(c, QtCore.
QPoint(mouseX, mouseY
))
""" Display, zoom, pan..."""
def __init__(self):
self.im = Canvas(self)
self.imH = self.im.height()
self.imW = self.im.width()
self.zoomN = 1
self.scene.setSceneRect(0, 0, self.imW, self.imH)
self.scene.addPixmap(self.im)
self.setScene(self.scene)
self.
setTransformationAnchor(QtGui.
QGraphicsView.
AnchorUnderMouse) self.setMinimumSize(400, 400)
self.setWindowTitle("pix")
f = h5py.File('MSG3_201303312045.H5','r')
g=f['image4/image_data']
for i in range(50,3000):
for u in range(50,3000):
print(str(i) + " - " + str(u))
#self.im.setPen(QPen(QColor(qRgb(g[i,u],g[i,u],g[i,u])),1,Qt.SolidLine))
self.im.clic(i-50,u-50, g[i,u])
#self.fill(QtGui.QColor(g[i,u], g[i,u], g[i,u]))
self.scene.addPixmap(self.im)
def mousePressEvent(self, event):
if event.buttons() == QtCore.Qt.LeftButton:
pos = self.mapToScene(event.pos())
self.im.clic(pos.x(), pos.y())
#~ self.scene.update(0,0,64,64)
#~ self.updateScene([QtCore.QRectF(0,0,64,64)])
self.scene.addPixmap(self.im)
print('items')
else:
def wheelEvent(self, event):
if event.delta() > 0:
self.scaleView(2)
elif event.delta() < 0:
self.scaleView(0.5)
def scaleView(self, factor):
n = self.zoomN * factor
if n < 1 or n > 16:
return
self.zoomN = n
self.scale(factor, factor)
if __name__ == '__main__':
import sys
widget = GraphWidget()
widget.show()
sys.exit(app.exec_())
#!/usr/bin/env python
from PyQt4 import QtCore
from PyQt4 import QtGui
import h5py
import numpy
class Canvas(QtGui.QPixmap):
""" Canvas for drawing"""
def __init__(self, parent=None):
QtGui.QPixmap.__init__(self, 1000, 1000)
self.parent = parent
self.imH = 1000
self.imW = 1000
self.fill(QtGui.QColor(0, 255, 255))
self.color = QtGui.QColor(0, 0, 0)
def paintEvent(self, c, point=False):
if point:
p = QtGui.QPainter(self)
p.setPen(QtGui.QPen(QtGui.QColor(c, c, c), 1, QtCore.Qt.SolidLine))
p.drawPoints(point)
def clic(self, mouseX, mouseY, c):
self.paintEvent(c, QtCore.QPoint(mouseX, mouseY))
class GraphWidget(QtGui.QGraphicsView):
""" Display, zoom, pan..."""
def __init__(self):
QtGui.QGraphicsView.__init__(self)
self.im = Canvas(self)
self.imH = self.im.height()
self.imW = self.im.width()
self.zoomN = 1
self.scene = QtGui.QGraphicsScene(self)
self.scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
self.scene.setSceneRect(0, 0, self.imW, self.imH)
self.scene.addPixmap(self.im)
self.setScene(self.scene)
self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter)
self.setMinimumSize(400, 400)
self.setWindowTitle("pix")
f = h5py.File('MSG3_201303312045.H5','r')
g=f['image4/image_data']
for i in range(50,3000):
for u in range(50,3000):
print(str(i) + " - " + str(u))
#self.im.setPen(QPen(QColor(qRgb(g[i,u],g[i,u],g[i,u])),1,Qt.SolidLine))
self.im.clic(i-50,u-50, g[i,u])
#self.fill(QtGui.QColor(g[i,u], g[i,u], g[i,u]))
self.scene.addPixmap(self.im)
def mousePressEvent(self, event):
if event.buttons() == QtCore.Qt.LeftButton:
pos = self.mapToScene(event.pos())
self.im.clic(pos.x(), pos.y())
#~ self.scene.update(0,0,64,64)
#~ self.updateScene([QtCore.QRectF(0,0,64,64)])
self.scene.addPixmap(self.im)
print('items')
else:
return QtGui.QGraphicsView.mousePressEvent(self, event)
def wheelEvent(self, event):
if event.delta() > 0:
self.scaleView(2)
elif event.delta() < 0:
self.scaleView(0.5)
def scaleView(self, factor):
n = self.zoomN * factor
if n < 1 or n > 16:
return
self.zoomN = n
self.scale(factor, factor)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
widget = GraphWidget()
widget.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks