#! /usr/bin/python
# DrawPoints.py
# Kelly Dwan
# Version 1.0; 5.6
import sys, random
from PyQt4 import QtGui, QtCore
# # # # #
# Points(textEdit, imgdir, scan)
# Set up for the scan image display
# -textEdit: the textbox of the GUI, used to display which scan you're currently working on.
# -imgdir: the directory holding the brain scans
# -scan: the specific scan to be displayed (filename only, directory taken care of by imgdir)
class Points(QtGui.QWidget):
def __init__(self, textEdit, imgdir, scan, parent=None):
QtGui.QWidget.__init__(self, parent)
self.textEdit = textEdit
self.imgdir = imgdir
self.scan = scan
self.textEdit.setAlignment(QtCore.Qt.AlignCenter)
self.textEdit.setText("Welcome! \nYou're currently viewing "+scan)
self.filename = imgdir + scan
self.scanImg = QtGui.QPixmap(self.filename)
self.setGeometry(0, 0, self.scanImg.size().width(),self.scanImg.size().height())
self.setWindowTitle('Points')
self.mouseLocations = []
self.i=0
# # #
# mousePressEvent(event)
# extends the default click-event action to append the click locations to mouseLocations
def mousePressEvent(self, event):
QtGui.QWidget.mousePressEvent(self, event)
x = event.x()
y = event.y()
self.mouseLocations.append( [x, y] )
self.i += 1
self.repaint()
# # #
# paintEvent(event)
# extends the default paint-event action to draw points at each location in mouseLocations.
def paintEvent(self, event):
paint = QtGui.QPainter()
paint.begin(self)
paint.drawPixmap(0,0,self.scanImg)
paint.setPen(QtGui.QPen(QtCore.Qt.red,5))
for pos in self.mouseLocations:
paint.drawPoint( pos[0], pos[1] )
paint.end()