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-05-27 04:06:17 -04:00
|
|
|
self.core.settings = parent.settings
|
2015-03-02 16:47:52 -05:00
|
|
|
|
|
|
|
|
2017-05-22 19:42:32 -04:00
|
|
|
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple)
|
|
|
|
def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize,\
|
|
|
|
alignment, xOffset, yOffset, textColor, visColor):
|
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,
|
2017-05-22 19:42:32 -04:00
|
|
|
"yoffset": yOffset,
|
|
|
|
"textColor" : textColor,
|
|
|
|
"visColor" : visColor
|
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
|
|
|
|
|
2017-05-18 19:14:27 -04:00
|
|
|
bgImage = self.core.parseBaseImage(\
|
|
|
|
nextPreviewInformation["backgroundImage"],
|
|
|
|
preview=True
|
|
|
|
)
|
|
|
|
if bgImage == []:
|
|
|
|
bgImage = ''
|
|
|
|
else:
|
|
|
|
bgImage = bgImage[0]
|
|
|
|
|
2015-03-02 16:47:52 -05:00
|
|
|
im = self.core.drawBaseImage(
|
2017-05-18 19:14:27 -04:00
|
|
|
bgImage,
|
2015-03-02 16:47:52 -05:00
|
|
|
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"],
|
2017-05-22 19:42:32 -04:00
|
|
|
nextPreviewInformation["yoffset"],
|
|
|
|
nextPreviewInformation["textColor"],
|
|
|
|
nextPreviewInformation["visColor"])
|
2015-03-02 16:47:52 -05:00
|
|
|
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
|
|
|
|
|
2017-05-22 19:42:32 -04:00
|
|
|
im = self.core.drawBars(spectrum, im, nextPreviewInformation["visColor"])
|
2015-03-02 16:47:52 -05:00
|
|
|
|
|
|
|
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
|