# 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



_signal.signal(_signal.SIGINT, _signal.SIG_DFL)
myApp = QApplication(sys.argv)
qmlEngine = QQmlEngine()

VideoPlayer = QQmlComponent(qmlEngine, QUrl('file:NeuroWidgets/video.qml'))


quickWindow = QQuickWindow()

videoPlayer = VideoPlayer.create()
videoPlayer.setParentItem(quickWindow.contentItem())

counter = 0

def setup_flow(context):
	global OSC1

	ch1_raw = context.get_channel('Channel 1')	

	ch1 = DCBlock(ch1_raw).ac

	ch1 = BandPass(0.01, 32.0, input=ch1)
	ch1 = BandPass(0.01, 32.0, input=ch1)
	#ch1 = BandPass(1.0, 32.0, input=ch1)




# 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




_signal.signal(_signal.SIGINT, _signal.SIG_DFL)
myApp = QApplication(sys.argv)
qmlEngine = QQmlEngine()

VideoPlayer = QQmlComponent(qmlEngine, QUrl('file:NeuroWidgets/video.qml'))


quickWindow = QQuickWindow()

videoPlayer = VideoPlayer.create()
videoPlayer.setParentItem(quickWindow.contentItem())

counter = 0

def setup_flow(context):
	global OSC1

	ch1_raw = context.get_channel('Channel 1')	

	ch1 = DCBlock(ch1_raw).ac

	ch1 = BandPass(0.01, 32.0, input=ch1)
	ch1 = BandPass(0.01, 32.0, input=ch1)
	#ch1 = BandPass(1.0, 32.0, input=ch1)




	OSC1 = Oscilloscope('Raw', channels=[ch1])