# Path: acquisition.py
# class UDPThread(QtCore.QThread):
#   newPacket = QtCore.pyqtSignal(object)
#   
#   def __init__(self, port=8888):
#     super(UDPThread, self).__init__()
# 
#     self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#     self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
#     self.socket.bind(('127.0.0.1', port))
# 
#     self.buffer = []
# 
#   def run(self):
#     while True:
#       data, addr = self.socket.recvfrom(1024)
#       data = eval(data)
#       
#       self.newPacket.emit(eval(str(data)))
#       #QtGui.QApplication.instance().processEvents()


from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import *
from PyQt5.QtQuick import *
from PyQt5.QtQuickWidgets import *
from PyQt5.QtQml import *
from acquisition import UDPThread
from flow import *
import sys
import signal as _signal

	reward = Averager(reward)
	inhibit1 = Averager(inhibit1)
	inhibit2 = Averager(inhibit2)
	

	def update_qml(reward, inhibit1, inhibit2, total):
		brightness = (reward * 0.4 + inhibit1 * 0.3 + inhibit2 * 0.3)

		#volume = float(reward / inhibit1) / 0.045 - 1.0


		videoPlayer.setProperty('brightness', brightness)
		#videoPlayer.setProperty('volume', volume)

	foo = Expression(update_qml, reward, inhibit1, inhibit2, total)



	return layout

context = Context()
context.register_channel('Channel 1')
context.register_channel('Channel 2')
layout = setup_flow(context)

analysisWindow = QWidget()
analysisWindow.setLayout(layout)
analysisWindow.show()


# Path: acquisition.py
# class UDPThread(QtCore.QThread):
#   newPacket = QtCore.pyqtSignal(object)
#   
#   def __init__(self, port=8888):
#     super(UDPThread, self).__init__()
# 
#     self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#     self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
#     self.socket.bind(('127.0.0.1', port))
# 
#     self.buffer = []
# 
#   def run(self):
#     while True:
#       data, addr = self.socket.recvfrom(1024)
#       data = eval(data)
#       
#       self.newPacket.emit(eval(str(data)))
#       #QtGui.QApplication.instance().processEvents()


# Path: qml.py
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import *
from PyQt5.QtQuick import *
from PyQt5.QtQuickWidgets import *
from PyQt5.QtQml import *
from acquisition import UDPThread
from flow import *
import sys
import signal as _signal


	reward = Averager(reward)
	inhibit1 = Averager(inhibit1)
	inhibit2 = Averager(inhibit2)
	

	def update_qml(reward, inhibit1, inhibit2, total):
		brightness = (reward * 0.4 + inhibit1 * 0.3 + inhibit2 * 0.3)

		#volume = float(reward / inhibit1) / 0.045 - 1.0


		videoPlayer.setProperty('brightness', brightness)
		#videoPlayer.setProperty('volume', volume)

	foo = Expression(update_qml, reward, inhibit1, inhibit2, total)



	return layout

context = Context()
context.register_channel('Channel 1')
context.register_channel('Channel 2')
layout = setup_flow(context)

analysisWindow = QWidget()
analysisWindow.setLayout(layout)
analysisWindow.show()


sourceThread = UDPThread()