Skip to content

Instantly share code, notes, and snippets.

@achristianson
Last active November 3, 2017 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achristianson/f429b5f44937572a5e6b7b166655befc to your computer and use it in GitHub Desktop.
Save achristianson/f429b5f44937572a5e6b7b166655befc to your computer and use it in GitHub Desktop.
import os,sys
import threading
from PyQt4 import QtGui
from PyQt4.QtCore import QObject, pyqtSignal, QTimer
content = None
content_lock = threading.Lock()
trigger = None
window = None
pic = None
pixmap = None
def update_img():
global pixmap
content_lock.acquire()
if content is not None:
if pixmap is None:
pixmap = QtGui.QPixmap()
pixmap.loadFromData(content, "PNG")
pic.setPixmap(pixmap)
pixmap.loadFromData(content, "PNG")
window.setFixedWidth(pixmap.width());
window.setFixedHeight(pixmap.height());
pic.setFixedWidth(pixmap.width());
pic.setFixedHeight(pixmap.height());
pic.repaint()
content_lock.release()
class GuiThread(threading.Thread):
def run(self):
global window
global pic
log.info('setting up ui')
app = QtGui.QApplication([])
window = QtGui.QMainWindow()
window.setGeometry(0, 0, 640, 480)
pic = QtGui.QLabel(window)
pic.setGeometry(0, 0, 640, 480)
#use full ABSOLUTE path to the image, not relative
window.show()
timer = QTimer()
timer.timeout.connect(update_img)
timer.start(15)
app.exec_()
if threading.current_thread().name == 'MainThread':
t = GuiThread()
t.start()
log.info('waiting for flow files')
class ReadCallback(object):
def process(self, input_stream):
global content
content_lock.acquire()
content = input_stream.read()
content_lock.release()
log.info('read %d bytes' % len(content))
return len(content)
def onTrigger(context, session):
log.info('triggered')
flow_file = session.get()
if flow_file is not None:
log.info('got flow file %s' % flow_file.getAttribute('filename'))
session.read(flow_file, ReadCallback())
session.transfer(flow_file, REL_SUCCESS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment