2015-03-02 16:47:52 -05:00
|
|
|
from PyQt4 import QtCore, QtGui, uic
|
|
|
|
from PyQt4.QtCore import pyqtSignal, pyqtSlot
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
from PIL.ImageQt import ImageQt
|
|
|
|
import core
|
|
|
|
import time
|
|
|
|
from queue import Queue, Empty
|
|
|
|
import numpy
|
|
|
|
|
|
|
|
class Worker(QtCore.QObject):
|
|
|
|
|
|
|
|
imageCreated = pyqtSignal(['QImage'])
|
|
|
|
|
|
|
|
def __init__(self, parent=None, queue=None):
|
|
|
|
QtCore.QObject.__init__(self)
|
|
|
|
parent.newTask.connect(self.createPreviewImage)
|
|
|
|
parent.processTask.connect(self.process)
|
|
|
|
self.core = core.Core()
|
|
|
|
self.queue = queue
|
|
|
|
|
|
|
|
|
2017-04-20 19:00:17 -04:00
|
|
|
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int)
|
2017-04-20 13:01:19 -04:00
|
|
|
def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset):
|
2015-03-02 16:47:52 -05:00
|
|
|
# print('worker thread id: {}'.format(QtCore.QThread.currentThreadId()))
|
|
|
|
dic = {
|
|
|
|
"backgroundImage": backgroundImage,
|
|
|
|
"titleText": titleText,
|
2017-04-18 07:35:29 -04:00
|
|
|
"titleFont": titleFont,
|
2017-04-20 13:01:19 -04:00
|
|
|
"fontSize": fontSize,
|
2017-04-20 12:47:14 -04:00
|
|
|
"alignment": alignment,
|
|
|
|
"xoffset": xOffset,
|
|
|
|
"yoffset": yOffset
|
2015-03-02 16:47:52 -05:00
|
|
|
}
|
|
|
|
self.queue.put(dic)
|
|
|
|
|
|
|
|
@pyqtSlot()
|
|
|
|
def process(self):
|
|
|
|
try:
|
|
|
|
nextPreviewInformation = self.queue.get(block=False)
|
|
|
|
while self.queue.qsize() >= 2:
|
|
|
|
try:
|
|
|
|
self.queue.get(block=False)
|
|
|
|
except Empty:
|
|
|
|
continue
|
|
|
|
|
|
|
|
im = self.core.drawBaseImage(
|
|
|
|
nextPreviewInformation["backgroundImage"],
|
|
|
|
nextPreviewInformation["titleText"],
|
2017-04-18 07:35:29 -04:00
|
|
|
nextPreviewInformation["titleFont"],
|
2017-04-20 13:01:19 -04:00
|
|
|
nextPreviewInformation["fontSize"],
|
2017-04-20 12:47:14 -04:00
|
|
|
nextPreviewInformation["alignment"],
|
|
|
|
nextPreviewInformation["xoffset"],
|
|
|
|
nextPreviewInformation["yoffset"])
|
2015-03-02 16:47:52 -05:00
|
|
|
|
|
|
|
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
|
|
|
|
|
|
|
|
im = self.core.drawBars(spectrum, im)
|
|
|
|
|
|
|
|
self._image = ImageQt(im)
|
|
|
|
self._previewImage = QtGui.QImage(self._image)
|
|
|
|
|
|
|
|
self._scaledPreviewImage = self._previewImage.scaled(320, 180, QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation)
|
|
|
|
|
|
|
|
self.imageCreated.emit(self._scaledPreviewImage)
|
|
|
|
except Empty:
|
|
|
|
True
|