Commits

Richard Gerkin committed 5d85f8c

Merging

Comments (0)

Files changed (34)

.DS_Store

Binary file added.

Phase1.pyc

Binary file added.

Phase3.pyc

Binary file added.
+##Examples using ctypes to communicate with ACCES I/O products
+##Examples below are tested with USB-IIRO-16 and USB-IDIO-16 modules,
+##but can be modified to work with other USB modules using the ACCES AIOUSB driver
+##Chris Allen 2012
+
+import time
+from ctypes import *
+
+
+###############################################################################
+##This determines the device address/addresses
+def GET_DEVICES():
+    DEVICES=windll.AIOUSB.VBGetDevices()
+    print DEVICES
+    BIT=0
+    while 1 << BIT <= DEVICES:
+        STATE=(DEVICES & (1 << BIT)) >> BIT
+        if STATE==1:
+            print "Device present at address ", BIT
+        else:
+            pass
+        BIT += 1
+
+        
+###############################################################################
+##Initialise the USB IO Module and ensure all outputs are off
+def INITIALIZE():
+    global DEVICE
+    ##Set this value to our device ID- usually 0 if only one device is connected
+    DEVICE=0
+
+    resetall=c_long(65535)
+
+    DIO=windll.AIOUSB.VBDIO_WriteAll(DEVICE, pointer(resetall))
+    IO_ERROR(DIO)
+
+
+def IO_ERROR(value):
+    VALUE=value
+    if VALUE==0:
+        print "SUCCESS"
+        pass
+    else:
+        print "ERROR, DEVICE NOT FOUND. ERROR:",VALUE
+###############################################################################
+##GET THE IO STATUS FROM THE DEVICE using ReadAll
+def GET_IO_STATUS():
+
+    readback=c_long(0)
+    
+    DIO=windll.AIOUSB.VBDIO_ReadAll(DEVICE, pointer(readback))
+    IO_ERROR(DIO)
+    
+    ##OUTPUTS
+    ##NOTE: For some reason the outputs seem inverted-
+    ##for example an output returns 1 when the output is off, but 0 when the output is on
+    ##Likewise when you wish to turn an output on- 0 is on, 1 is off
+    OUT_0=(readback.value>>0)&1
+    OUT_1=(readback.value>>1)&1
+    OUT_2=(readback.value>>2)&1
+    OUT_3=(readback.value>>3)&1
+    OUT_4=(readback.value>>4)&1
+    OUT_5=(readback.value>>5)&1
+    OUT_6=(readback.value>>6)&1
+    OUT_7=(readback.value>>7)&1
+    OUT_8=(readback.value>>8)&1
+    OUT_9=(readback.value>>9)&1
+    OUT_10=(readback.value>>10)&1
+    OUT_11=(readback.value>>11)&1
+    OUT_12=(readback.value>>12)&1
+    OUT_13=(readback.value>>13)&1
+    OUT_14=(readback.value>>14)&1
+    OUT_15=(readback.value>>15)&1
+    ##print the value of out outputs
+    print "OUTPUTS: \t", OUT_0, OUT_1, OUT_2, OUT_3, OUT_4, OUT_5, OUT_6,\
+        OUT_7, OUT_8, OUT_9, OUT_10, OUT_11, OUT_12, OUT_13, OUT_14, OUT_15
+    ##INPUTS
+    IN_0=(readback.value>>16)&1
+    IN_1=(readback.value>>17)&1
+    IN_2=(readback.value>>18)&1
+    IN_3=(readback.value>>19)&1
+    IN_4=(readback.value>>20)&1
+    IN_5=(readback.value>>21)&1
+    IN_6=(readback.value>>22)&1
+    IN_7=(readback.value>>23)&1
+    IN_8=(readback.value>>24)&1
+    IN_9=(readback.value>>25)&1
+    IN_10=(readback.value>>26)&1
+    IN_11=(readback.value>>27)&1
+    IN_12=(readback.value>>28)&1
+    IN_13=(readback.value>>29)&1
+    IN_14=(readback.value>>30)&1
+    IN_15=(readback.value>>31)&1
+    ##print the value of our inputs
+    print "INPUTS: \t", IN_0, IN_1, IN_2, IN_3, IN_4, IN_5, IN_6,\
+        IN_7, IN_8 , IN_9, IN_10, IN_11, IN_12, IN_13, IN_14, IN_15
+
+
+###############################################################################
+##SETUP VARIABLES FOR OUTPUTS
+OUT0=0
+OUT1=1
+OUT2=2
+OUT3=3
+OUT4=4
+OUT5=5
+OUT6=6
+OUT7=7
+OUT8=8
+OUT9=9
+OUT10=10
+OUT11=11
+OUT12=12
+OUT13=13
+OUT14=14
+OUT15=15
+
+ON=0##Note to turn an output ON, the value must be 0
+OFF=1##Note to turn an output OFF, the value must be 1
+
+##Turns OUT_0 on for 5 seconds, then turns it off again using DIO_Write1
+def TOGGLE_OUT_0():
+    GET_IO_STATUS()
+    print "Lets turn OUT_0 ON for 5 seconds"
+    time.sleep(1)
+
+    DIO=windll.AIOUSB.VBDIO_Write1(DEVICE, OUT0, ON)
+    IO_ERROR(DIO)
+    print "Now check to see if it did indeed turn on..."
+    GET_IO_STATUS()
+    time.sleep(5)
+
+    DIO=windll.AIOUSB.VBDIO_Write1(DEVICE, OUT0, OFF)
+    IO_ERROR(DIO)
+
+    print "Now lets check the IO Status to see that OUT_0 is off..."
+    GET_IO_STATUS()
+    
+
+###############################################################################
+##Uses DIO_WriteAll to toggle all outputs on in sequence then switch them all off
+def TOGGLE_OUTPUTS_ON():
+    for i in xrange(0, 17):
+        thisbit=65535<<i
+        print "thisbit: ", thisbit
+        outputs=c_short(thisbit)
+        DIO=windll.AIOUSB.VBDIO_WriteAll(DEVICE, pointer(outputs))
+        IO_ERROR(DIO)
+        GET_IO_STATUS()
+        time.sleep(1)
+    print "Switch all outputs off again..."
+    outputs=c_short(65535)
+    DIO=windll.AIOUSB.VBDIO_WriteAll(DEVICE, pointer(outputs))
+    GET_IO_STATUS()
+
+    
+##############################################################################
+##Uses arguments to select the output and state to switch
+##for example SWITCH_OUTPUT(OUT1, ON) will turn output 1 on
+def SWITCH_OUTPUT(output, state):
+    OUT = output
+    STATUS = state
+    if STATUS==0:
+        TSTATE="ON"
+    else:
+        TSTATE="OFF"
+    print "Turning OUT_",OUT , TSTATE
+    DIO=windll.AIOUSB.VBDIO_Write1(DEVICE, OUT, STATUS)
+    IO_ERROR(DIO)
+    
+  
+

__init__.pyc

Binary file added.
+# -*- coding: utf-8 -*-
+"""
+Created on Sat Jun 22 14:04:17 2013
+
+@author: Ryan Brackney
+
+To do:
+Get it working QtDesigner
+Figure out python crash on exit
+Get input fields for mouse name/experiment info/ect
+Allow Phase 3 to start at different stages
+Implement microcontroller support (wrapper currently working)
+Implement the text file output (code written, just not integrated yet)
+
+"""
+
+import sys,os
+# Add this file's directory to the python path.  
+sys.path.append(os.path.abspath(os.path.dirname(__file__))) 
+import random
+import time
+from qt.gui import Ui_MainWindow
+# Eventually you will want to replace 'Primary' with the auto-generated 'Ui_MainWindow'
+from PyQt4 import QtCore, QtGui
+from __init__ import *
+import Phase1,Phase3
+
+USE_QT_DESIGNER = False
+
+class Communicate(QtCore.QObject):
+    '''
+    not used at the moment
+    '''
+    lickOn = QtCore.pyqtSignal()
+    headEntry = QtCore.pyqtSignal()
+    reinforce = QtCore.pyqtSignal()
+    
+class My_MainWindow(QtGui.QWidget):
+    def __init__(self):
+        super(My_MainWindow, self).__init__()        
+        #MainWindow = QtGui.QMainWindow()
+        #self.setupUi(MainWindow)
+
+        self.c = Communicate()
+        self.initUI()
+        self.initVars()
+        self.initConnect()        
+        
+    def initUI(self):
+        self.btnHead = QtGui.QPushButton('Sim Head Entry',self)
+        self.btnResp = QtGui.QPushButton('Sim Lick', self)
+        self.btnClose = QtGui.QPushButton('Close', self)
+        
+        self.btnStartPhase1 = QtGui.QPushButton('Start Phase 1')
+        self.btnStartPhase3 = QtGui.QPushButton('Start Phase 3')
+#     
+        self.lblTimeLabel = QtGui.QLabel(self)
+        self.lcdTimeCnt = QtGui.QLCDNumber(self)
+        for i in range(20):
+            setattr(self,'lblEct%d' % (i+1),QtGui.QLabel(self))
+        
+        vbox = QtGui.QVBoxLayout()
+        vbox.addWidget(self.lblTimeLabel)
+        vbox.addWidget(self.lcdTimeCnt)
+        vbox.addWidget(self.btnResp)
+        vbox.addWidget(self.btnHead)
+        vbox.addWidget(self.btnStartPhase1)
+        vbox.addWidget(self.btnStartPhase3)
+
+        for i in range(20):
+            vbox.addWidget(getattr(self,'lblEct%d' % (i+1)))
+        vbox.addWidget(self.btnClose)
+
+        self.lblTimeLabel.setText('Session Time (s)')
+        
+        self.btnHead.setEnabled(False)
+        self.btnResp.setEnabled(False)
+
+        #self.btnStartPhase1.setEnabled(False)
+        self.setLayout(vbox)
+        self.setGeometry(300, 300, 300, 300)
+        self.setWindowTitle('Main')
+    
+    def initConnect(self):
+        self.btnResp.clicked.connect(self.respBtnClicked)
+        self.btnClose.clicked.connect(QtCore.QCoreApplication.instance().quit)
+        self.btnHead.clicked.connect(self.headEntryBtnClicked)
+        self.btnStartPhase1.clicked.connect(self.startPhase1)
+        self.btnStartPhase3.clicked.connect(self.startPhase3)
+        
+    def initVars(self):
+        '''
+        start all variables here
+        '''
+        self.bSesStart = False
+        self.bPhase1 = False    
+        self.bPhase3 = False         
+
+    def timingInit(self):
+        self.timer = QtCore.QBasicTimer()
+        self.timer.start(10, self) #this should start the timer
+        self.iTime = RunInternalTimer()
+#        print(self.curTrialTime)
+
+    def respBtnClicked(self):
+        self.curPhase.lickOn()  
+    
+    def headEntryBtnClicked(self):
+        self.curPhase.toggleHeadEntry()
+    
+    def disableStartButtons(self):
+        self.btnStartPhase3.setEnabled(False)
+        self.btnStartPhase1.setEnabled(False)        
+    
+    def startPhase1(self):
+        self.startSession()
+        self.bPhase1 = True
+        self.curPhase = Phase1.Phase1(30) #start Phase 1 with 30 trials
+        self.disableStartButtons()
+        self.btnHead.setEnabled(True)
+        self.btnResp.setEnabled(True)
+    
+    def startPhase3(self):
+        self.startSession()
+        self.bPhase3 = True
+        self.curPhase = Phase3.Phase3()
+        self.disableStartButtons()
+        self.btnHead.setEnabled(True)
+        self.btnResp.setEnabled(True)
+
+    def startSession(self):
+        self.DataFile = OutputData()
+        self.timingInit()
+        print('ses start')   
+
+    def updateDisplay(self):      
+        if self.bPhase3 == True:
+            ect1Display = 'Head In: ' + str(self.curPhase.bHeadIn)
+            ect2Display = 'ITI On: ' + str(self.curPhase.bITI) 
+            ect3Display = 'Waiting for Lick to Reinforce: ' + str(self.curPhase.bReinforcementAvailable)
+            ect4Display = 'Current Block Number:' + str(self.curPhase.curBlock)
+            ect5Display = 'Current Block Misses: '  + str(self.curPhase.curBlockMisses)    
+            ect6Display = 'Current Block Abstains: ' + str(self.curPhase.curBlockAbstain)    
+            ect7Display = 'Current Block Hits: ' + str(self.curPhase.curBlockHits)
+            ect8Display = 'Current Block Hits Criterion' + str(self.curPhase.hitCriterion)
+            ect9Display = 'bTrialStart: ' + str(self.curPhase.bTrialStart)
+            ect10Display = 'bTrialFinished: ' + str(self.curPhase.bTrialFinished)
+            ect11Display = 'bContinuePhase: ' + str(self.curPhase.bContinuePhase)
+            ect12Display = 'Response Path: ' + str(self.curPhase.binRespList)
+            ect13Display = 'Current Response Criterion: ' + str(self.curPhase.trialLengthByBlock[self.curPhase.curBlock -1])
+            ect14Display = 'Current ITI: ' + str(self.curPhase.itiTime[self.curPhase.curBlock -1])
+            ect15Display = ''
+            ect16Display = ''
+            ect17Display = ''
+            ect18Display = ''
+            ect19Display = ''
+
+            
+            for i in range(19):
+                label = getattr(self,'lblEct%d' % (i+1))
+                label.setText(ect1Display) 
+            
+        self.ect20Display = 'Phase 3 On: ' + str(self.bPhase3)
+        self.lblEct20.setText(self.ect20Display)   
+        
+    def timerEvent(self,event):
+        '''
+        Main Loop. Runs the 'update' methods of Phase1/Phase3/ect
+        '''
+        self.curSestime = self.iTime.timeSince()
+        self.lcdTimeCnt.display(round(self.curSestime,2))       
+        ###
+        
+        if self.bPhase1 == True:
+            self.bPhase1, self.hits, self.misses = self.curPhase.update()
+        if self.bPhase3 == True:
+            self.bPhase3 = self.curPhase.update()
+        self.updateDisplay()
+            
+def main():
+    """The entry point to the application"""
+    app = QtGui.QApplication(sys.argv)
+    if USE_QT_DESIGNER:
+        #ui = My_MainWindow()
+        MainWindow = QtGui.QMainWindow()
+        ui = Ui_MainWindow()
+        ui.setupUi(MainWindow)
+    else:
+        MainWindow = My_MainWindow()
+    MainWindow.show()
+    sys.exit(app.exec_())
+
+if __name__ == '__main__':
+    main()
+Mon Jun 24 15:38:23 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:38:52 2013
+mouse
+experiment
+anonymous
+Trial Start
+Trial Start
+Trial Start
+Trial Start
+Trial Start
+Trial Start
+Trial Start
+new Session
+Mon Jun 24 15:41:05 2013
+mouse
+experiment
+anonymous
+Trial Start
+new Session
+Mon Jun 24 15:43:13 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:43:15 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:44:35 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:44:37 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:46:47 2013
+mouse
+experiment
+anonymous
+Trial Start
+Trial Start
+Trial Start
+Trial Start
+Trial Start
+Trial Start
+new Session
+Mon Jun 24 15:47:05 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:06 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:06 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:06 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:06 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:07 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:07 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:07 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:07 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:07 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:47:07 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:49:27 2013
+mouse
+experiment
+anonymous
+Trial Start
+new Session
+Mon Jun 24 15:50:51 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:52:00 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:55:06 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 15:55:12 2013
+mouse
+experiment
+anonymous
+new Session
+Mon Jun 24 16:32:31 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 14:56:29 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:00:03 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:01:19 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:19:29 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:20:17 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:20:43 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:21:51 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:22:31 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:23:04 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:24:45 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:26:14 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:26:34 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:30:55 2013
+mouse
+experiment
+anonymous
+H In
+H Out
+H In
+H Out
+H In
+H Out
+H In
+H Out
+new Session
+Tue Jun 25 15:31:05 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:32:58 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:41:17 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:42:59 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 15:56:49 2013
+mouse
+experiment
+anonymous
+new Session
+Tue Jun 25 16:37:16 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 16:44:12 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 16:45:20 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 16:54:50 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 16:55:22 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:00:32 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:01:12 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:02:13 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:03:36 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:13:56 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:15:51 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:17:47 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:21:27 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:29:10 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:31:53 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:33:04 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:34:38 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:36:35 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:37:36 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:37:53 2013
+mouse
+experiment
+anonymous
+new Session
+Thu Jun 27 17:39:20 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 11:00:48 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 11:01:52 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 11:03:50 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 11:03:58 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 12:58:44 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 12:59:39 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 13:49:47 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 13:50:35 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 14:06:17 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:39:43 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:40:26 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:41:08 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:43:01 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:43:47 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:47:41 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:49:46 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:50:51 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:51:16 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:53:47 2013
+mouse
+experiment
+anonymous
+new Session
+Fri Jun 28 15:54:52 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:00:37 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:01:51 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:02:26 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:03:48 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:05:00 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:05:19 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:06:48 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:08:16 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 17:53:25 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:05:54 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:10:18 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:12:40 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:14:09 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:17:13 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:22:00 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:23:22 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:26:20 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:27:44 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:30:11 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:32:35 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:34:43 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:39:39 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:42:55 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:44:00 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:47:39 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:47:43 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:47:44 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:47:44 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:47:45 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:48:28 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:48:35 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:48:36 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:48:36 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 18:48:37 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:22:29 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:23:01 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:24:04 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:24:28 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:32:09 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:33:49 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:37:28 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:37:47 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:40:08 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:43:02 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:44:10 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 19:50:32 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 20:38:42 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 20:39:14 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 20:39:36 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 20:40:07 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 20:40:46 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 20:42:48 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 20:59:39 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 21:05:12 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 21:07:03 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 21:09:40 2013
+mouse
+experiment
+anonymous
+new Session
+Sat Jun 29 21:10:42 2013
+mouse
+experiment
+anonymous
+#   Discrimination Training
+#   By Ryan Brackney
+#   04/20/2013
+
+import pygame, os.path, sys, time, random
+from pygame.locals import *
+
+FPS = 15 #Number of Window updates per second
+WINDOWWIDTH = 640
+WINDOWHEIGHT = 480
+CELLSIZE = 20
+assert WINDOWWIDTH % CELLSIZE == 0, "Window width must be a multiple of cell size."
+assert WINDOWHEIGHT % CELLSIZE == 0, "Window height must be a multiple of cell size."
+CELLWIDTH = int(WINDOWWIDTH / CELLSIZE)
+CELLHEIGHT = int(WINDOWHEIGHT / CELLSIZE)
+BLACK     = (  0,   0,   0)
+BGCOLOR = BLACK
+
+
+def main():
+    global gSessClock, DISPLAYSURF, BASICFONT, SESSTARTTIME, OUTDATAFILE, SESTIMER
+    pygame.init()
+    gSessClock = pygame.time.Clock() #need to decide the benefits of using the pygame clock over the python clock (if at all)
+    pygame.display.set_caption('MouseWatering')
+    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
+    BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
+    SESTIMER = time.clock() #SESTIMER will be used as the reference for all timing events
+    OUTDATAFILE = 'sample.txt' #Where the session data is written to. Need to add a function to ask for the name, location, ect later
+    
+    while True:
+        runSession()
+
+def runSession():
+
+    durationIti = 5; #ITI time in seconds
+
+    while True:
+        SESTIMER = time.clock()
+
+        if bITIstart == False:
+            endTimeIti = SESTIMER + durationIti
+            bITIstart = True
+
+        if sesTime > endTimeIti:
+            startTrial()
+
+
+
+
+
+
+def startTrial():
+    try:
+        trialNum = next(advanceTrial)
+    except:
+        trialOrder, trialNum = startNewTrialBlock()
+        
+    if trialNum > len(trialOrder):
+        trialOrder, trialNum = startNewTrialBlock()
+
+    trialType = int(trialOrder([trialNum-1]))
+    
+
+    
+    #something about the response mode here
+    
+        
+
+
+
+def startNewTrialBlock
+    trialNum = 1
+    trialOrder = determineTrialBlockOrder
+    advanceTrial(trialNum)
+    return trialOrder, trialNum
+
+
+
+def advanceTrial(curTrial):
+##    trialBlockSize = len(trialOrder)
+    while True:      
+        yield curTrial
+        curTrial += 1
+
+
+##def determineTrialType(trialOrder, curTrial, x):
+##    trialBlockSize = len(trialOrder)
+##    while True:      
+##        yield int(trialOrder([curTrial-1])
+##        curTrial += 1
+
+def determineTrialBlockOrder():
+    trialCount = 20
+    trialTypes = [1,2] * (trialCount // 2)
+    return trialOrder = random.sample(trialTypes, trialCount)
+# Stage 1
+# By Ryan Brackney
+
+#Todo: Make ITI interval end check function, make sure it works. Adjust wrappers
+
+import pygame, os.path, sys, time, random
+from pygame.locals import *
+
+FPS = 15 #Number of Window updates per second
+WINDOWWIDTH = 640
+WINDOWHEIGHT = 480
+CELLSIZE = 20
+assert WINDOWWIDTH % CELLSIZE == 0, "Window width must be a multiple of cell size."
+assert WINDOWHEIGHT % CELLSIZE == 0, "Window height must be a multiple of cell size."
+CELLWIDTH = int(WINDOWWIDTH / CELLSIZE)
+CELLHEIGHT = int(WINDOWHEIGHT / CELLSIZE)
+BLACK     = (  0,   0,   0)
+BGCOLOR = BLACK
+
+def main():
+    global gSessClock, DISPLAYSURF, BASICFONT, SESSTARTTIME, OUTDATAFILE, SESTIMER
+
+    pygame.init()
+    gSessClock = pygame.time.Clock() #need to decide the benefits of using the pygame clock over the python clock (if at all)
+    pygame.display.set_caption('MouseWatering')
+    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
+    BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
+    SESTIMER = time.clock() #SESTIMER will be used as the reference for all timing events
+    OUTDATAFILE = 'sample.txt' #Where the session data is written to. Need to add a function to ask for the name, location, ect later
+    
+    while True:
+        runSession()
+
+            
+
+
+def runSession():
+    lickCounter = 0
+    lickFont = BASICFONT
+    bItiElapsed = False
+    bReinforceOnLick = False
+    requiredLickInterval = 2
+        
+    while True:
+        SESTIMER = time.clock()
+        for event in pygame.event.get(): #event handling loop
+
+##            if bViStarted == False: #Determine if a the interval for the next reward delivery has been selected yet
+##                intervalStartTime = SESTIMER
+##                reinforcerIntervalEndTime = sampleFromVI(intervalStartTime)    #determine the next interval                       
+##                bViStarted = True
+##            elif bViStarted == True and SESTIMER >= reinforcerIntervalEndTime:  #when that interval has elapsed, allow reinforcement
+##                bReinforceOnLick = True
+            if bItiElapsed == False:
+                #just record responses
+                pass
+            elif bItiElapsed == True:
+                #check to se if responses complete            
+                #reinforce, deliver 
+                pass
+            if event.type == QUIT: #this isn't working yet
+                #save data
+                terminate()
+            elif event.type == KEYDOWN: #right now, responses are simulated by pressing "r" on the keyboard. This is a placeholder for the control board response
+                if (event.key == K_r):
+                    outText = 'respTime: ' + str(SESTIMER)
+                    writeData(OUTDATAFILE, outText)
+                    lickCounter += 1
+                    lickCountText = 'licks: ' + str(lickCounter) + ' at ' + str(SESTIMER) + '   next reinforcer at ' # + str(reinforcerIntervalEndTime)
+                    print(lickCountText)                    
+                    (withinLicks, bFinishedBlock) = lickContingencyManagement(requiredLickInterval)
+                    strFinishBlock = 'Block Complete?' + str(bFinishedBlock)
+                    print(strFinishBlock)
+                    if bFinishedBlock == True:  #right now there's an error with reseting the Variable interval. Needs to be tracked down
+                        bFinishedBlock = False
+                        bViStarted = False
+                elif (event.key == K_q and event.key == K_LCTRL):  #this isn't working yet
+                    print('Response Q')
+                    terminate()
+                    
+
+
+        pygame.display.update() #updates the display
+        gSessClock.tick(FPS)
+
+
+        if SESTIMER > 100: #terminate the session after 100 seconds have passed (will change later)
+            terminate()
+        
+
+
+
+
+
+def writeData(fileName = 'default.txt', inputText = ''):
+    if os.path.isfile(fileName) == False:
+        with open(fileName, 'w', encoding = 'utf-8') as dataOutFile:
+            dataOutFile.write(inputText)
+    else:
+        with open(fileName, 'a', encoding = 'utf-8') as dataOutFile:
+            dataOutFile.write('\n')
+            dataOutFile.write(inputText)
+
+def showScreen():
+    titleFont = pygame.font.Font('freesansbold.ttf', 100)
+    titleName = titleFont.render('Mouse', True, WHITE)
+    while True:
+        DISPLAYSURF.fill(BGCOLOR)
+        pygame.display.update()
+        gSessClock.tick(FPS)      
+
+##def sampleFromVI(intervalStartTime): 
+##    intervalList = [1,5,10,15,20,25,30] #placeholder interval list
+##    intervalTime = random.sample(intervalList,1)
+##    intervalEndTime = intervalStartTime + intervalTime[0]
+##    return intervalEndTime
+
+##def contingencyVI(bReinforceOnLick):
+##    if bReinforceOnLick == True:
+##        print('water delivery!')
+##        outText = 'reinfTime: ' + str(SESTIMER)
+##        writeData(OUTDATAFILE, outText)
+##        #code for water delivery here
+
+def deliverSr(): #deliver reinforcer stimulus (sr)
+    #placeholder for controller card activation
+    print('water delivery!')
+    outText = 'reinfTime: ' + str(SESTIMER)
+    writeData(OUTDATAFILE, outText)
+
+
+def getITI(stage):
+
+    
+    #as with the BBC code, creates an ITI which advances in length as stage 1 training progresses
+    stageItiAdd = [.1, 2,5, 8] #the base ITI value depending on the stage
+    
+    addToIti = float(stageItiAdd[stage-1])
+    #need code in here for a variable ITI type depending on part of stage 1 training we're in
+    listIti1 = [1, 2, 3, 4, 5] 
+    randomlySampledTime = random.sample(listIti1,1)
+    intervalTime = randomlySampledTime[0] + addToIti
+    return intervalTime
+
+
+
+
+def lickContingencyManagement(requiredLickInterval = 2): #requiredLickInterval is the number of seconds of straight licking required
+    withinLicks = 0 #number of licks emitted while in this loop
+    binCount = int(requiredLickInterval / 2 * 10 - 1) #space the bins by 0.2 s
+    startTime = time.clock() #or whatever function we need here for clock time
+    responseInBin = [0]*(binCount + 1);
+    responseInBin[0] = 1
+    bCompletedInterval = False
+    
+    while True:
+        curTime = time.clock()
+        curBin = int((curTime - startTime) / 2 * 10)
+        if curBin > 0:
+            if responseInBin[curBin - 1] == 0:
+                print('end bins')
+                break
+        if curBin > binCount:
+            bCompletedInterval = True
+            break
+        for event in pygame.event.get():
+            if event.type == KEYDOWN and event.key == K_r:
+                #right now, responses are simulated by pressing "r" on the keyboard. This is a placeholder for the control board response
+                    responseInBin[curBin] = 1
+                    strRespInBin = 'Binned Resps: ' + str(responseInBin)
+                    print(strRespInBin)
+        
+    withinLicks = sum(responseInBin)    
+    return withinLicks, bCompletedInterval 
+    
+
+def terminate():
+    pygame.quit()
+    sys.exit()
+
+##def drawSesInfo():
+
+
+

old/Stage1Kernel.py

+# -*- coding: utf-8 -*-
+"""
+Created on Fri May 31 21:42:26 2013
+
+@author: Ryan
+
+This is the main section of the Stage 1 Training Program.
+"""
+
+#Load Wrapper here. Wrapper should have a timer module and define how responses
+#are inputed and outputs are controlled
+import time
+
+class Stage1():
+    def __init__(self):
+        #do start up stuff
+        #wrapper stuff here?
+        self.setup()
+    
+    def setup(self):
+        #initialize microcontroller
+        #arrange board
+  #      mainDataFile = OutputData(user text here) #finish this
+        self.sesTimerIn = RunTimer()
+        self.operations = operationModule()
+    
+    def UpdateSession(self):
+        pass
+    
+
+
+
+class operationModule():
+    import win32ui
+    def __init__(self):    
+        self.lickCnt = 0
+        self.reinfCnt = 0
+               
+    def lickResp(self):
+        self.lickCnt += 1
+        win32ui.MessageBox("resp", "resp")
+
+    def reinf(self):
+        self.reinfCnt += 1
+        win32ui.MessageBox("reinforcement", "reinforcement")
+
+#class Block():
+#    
+#    def __init__(self,stage):
+#        self.srCount = 0
+#        self.hits = 0
+#        self.misses = 0
+#        self.falseAlarms = 0
+#        self.stage = stage
+#
+#    def recordResp(self)        
+#        pass
+##        
+#        self.itiList = getITIs(stage) #Gets all ITIs for that stage   
+#        
+#    def startTrial(self,iti):
+#        pass
+#        #run the ITI
+#        #then wait for licks
+#    
+#        
+#    
+    def lickContingencyManagement(requiredLickInterval = 2): #requiredLickInterval is the number of seconds of straight licking required
+    withinLicks = 0 #number of licks emitted while in this loop
+    binCount = int(requiredLickInterval / 2 * 10 - 1) #space the bins by 0.2 s
+    lickTimer = RunTimer() #or whatever function we need here for clock time
+    responseInBin = [0]*(binCount + 1);
+    responseInBin[0] = 1
+    bCompletedInterval = False
+    
+    while True:
+       # curTime = time.clock()
+       # curBin = int((curTime - startTime) / 2 * 10)
+        if curBin > 0:
+            if responseInBin[curBin - 1] == 0:
+                print('end bins')
+                break
+        if curBin > binCount:
+            bCompletedInterval = True
+            break
+        for event in pygame.event.get():
+            if event.type == KEYDOWN and event.key == K_r:
+                #right now, responses are simulated by pressing "r" on the keyboard. This is a placeholder for the control board response
+                    responseInBin[curBin] = 1
+                    strRespInBin = 'Binned Resps: ' + str(responseInBin)
+                    print(strRespInBin)
+        
+    withinLicks = sum(responseInBin)    
+    return withinLicks, bCompletedInterval 
+#        
+#    def trialDecide(self):
+#        pass
+#        #would use this to determine a + or - trial if stage 2
+#        
+#    
+#    def getITIs(stage):    
+#    #as with the BBC code, creates an ITI which advances in length as stage 1 training progresses
+#    #need to change this so that it creates the entire list of ITIs
+#        stageItiAdd = [.1, 2,5, 8] #the base ITI value depending on the stage
+#        addToIti = float(stageItiAdd[stage-1])
+#    #need code in here for a variable ITI type depending on part of stage 1 training we're in
+#        listIti1 = [1, 2, 3, 4, 5] 
+#        randomlySampledTime = random.sample(listIti1,1)
+#        intervalTime = randomlySampledTime[0] + addToIti
+#        return intervalTime
+        
+#class OutputData():
+#    import os.path
+#    #need to check to see whether self.fileName works
+#    def __init__(self, fileName):
+#        self.fileName = str(fileName),'.txt'
+#               
+#        with open(fileName, 'w', encoding = 'utf-8') as dataOutFile:
+#            dataOutFile.write(todaysDate) #needs to be defined
+#        writeData(startTime)
+#        writeData(subjectName)
+#        writeData(experimentName)
+#        writeData(technicianName)
+#            
+#    def writeData(self, inputText =''):
+#        with open(fileName, 'a', encoding = 'utf-8') as dataOutFile:
+#            dataOutFile.write('\n')
+#            dataOutFile.write(inputText)
+            
+#class TrialBlock():
+#    def __init__(self, itiList,)
+#        #get current clock time here
+#        self.blockTimer = RunTimer() #whatever call needs to be here
+
+
+class RunTimer:   
+    def __init__(self):
+        self.startTime = time.time()    
+    
+    def curTime(self):
+        return time.time()    
+    
+    def timeSince(self):
+        return self.curTime() - self.startTime
+        
+# -*- coding: utf-8 -*-
+"""
+Created on Sun Jun  9 08:24:50 2013
+
+@author: FedLab2
+"""
+
+import sys
+from PyQt4 import QtGui, QtCore
+
+from Stage1Kernel import *
+
+class Example(QtGui.QWidget):
+    
+    def __init__(self):
+        super(Example, self).__init__()
+        
+        self.session = Stage1()
+        self.beginTimer()
+        self.initUI()        
+        
+        
+    def beginTimer(self):
+        self.tmrSes = QtCore.QTimer(self)
+        self.tmrSes.start(10)
+#        self.startTime = 0
+    def initUI(self):            
+       
+         
+        btnResp = QtGui.QPushButton('Sim Response', self)
+#        btnResp.move(50, 50)
+        btnClose = QtGui.QPushButton('Close', self)
+        btnStartTimer = QtGui.QPushButton('StartTimer',self)
+#        btnClose.move(50,100)        
+        self.lcdRespCnt = QtGui.QLCDNumber(self)
+        self.lcdSesTimer = QtGui.QLCDNumber(self)
+        
+#        self.lblRespCnt = QtGui.QLabel(self)
+        
+        
+        vbox = QtGui.QVBoxLayout()
+        vbox.addWidget(self.lcdRespCnt)
+        vbox.addWidget(self.lcdSesTimer)
+        
+  #      vbox.addWidget(self.lblRespCnt)
+        vbox.addWidget(btnResp)
+        vbox.addWidget(btnClose)
+        vbox.addWidget(btnStartTimer)
+
+        self.setLayout(vbox)
+        self.setGeometry(300, 300, 250, 150)
+        self.setWindowTitle('Response Whatever')
+        self.show()
+        
+        self.tmrSes.timeout.connect(self.updateTimerDisplay)
+     #   self.tmrSes.connect(self.lcdSesTimer.display)
+#        self.c = Communicate()
+        
+        btnResp.clicked.connect(self.respBtnClicked)
+#        btnStartTimer.clicked.connect(self.tmrSes.start)
+        btnClose.clicked.connect(QtCore.QCoreApplication.instance().quit)        
+        
+#        self.c = Communicate()
+#        self.c.
+        
+    def respBtnClicked(self):
+        self.session.operations.lickResp()      
+#        self.respCnt.add1()        
+#        curCount = self.respCnt.counter
+#        self.lcdRespCnt.display(curCount)
+    def updateTimerDisplay(self):
+        curTime =round(self.session.sesTimerIn.timeSince(),0)
+        self.lcdSesTimer.display(curTime)
+        
+def main():
+    
+    app = QtGui.QApplication(sys.argv)
+    ex = Example()
+    sys.exit(app.exec_())
+
+
+if __name__ == '__main__':
+    main()

old/adaptedFromTetris.py

+#!/usr/bin/python
+
+# tetris.py
+
+import sys
+import random
+import time
+from PyQt4 import QtCore, QtGui
+
+
+class Tetris(QtGui.QMainWindow):
+	def __init__(self):
+		QtGui.QMainWindow.__init__(self)
+
+		self.setGeometry(300, 300, 300, 380)
+		self.setWindowTitle('Program')
+		self.controlBoard = Board(self)
+
+		self.setCentralWidget(self.controlBoard)
+
+		self.statusbar = self.statusBar()
+		self.connect(self.controlBoard, 
+					 QtCore.SIGNAL("messageToStatusbar(QString)"), 
+					 self.statusbar, 
+					 QtCore.SLOT("showMessage(QString)"))
+
+		self.controlBoard.start()
+		self.center()
+
+	def center(self):
+		screen = QtGui.QDesktopWidget().screenGeometry()
+		size =  self.geometry()
+		self.move((screen.width()-size.width())/2, 
+		(screen.height()-size.height())/2)
+
+class Board(QtGui.QFrame):
+    BoardWidth = 10
+    BoardHeight = 22
+    Speed = 10
+
+    def __init__(self, parent):
+         QtGui.QFrame.__init__(self, parent)
+         self.timer = QtCore.QBasicTimer()
+         self.iTime = RunInternalTimer()
+         self.setFocusPolicy(QtCore.Qt.StrongFocus)
+         self.isStarted = False
+         self.bResp = False
+         self.curTime = 0
+         
+         
+    def initUI(self):
+        self.lcdTime = QtGui.QLCDNumber(self)
+        vbox = QtGui.QVBoxLayout()
+        vbox.addWidget(self.lcdTime)
+        
+#		self.setFocusPolicy(QtCore.Qt.StrongFocus)  #not sure what this does
+    def start(self):
+		self.isStarted = True
+		self.timer.start(Board.Speed, self)
+
+    def paintEvent(self, event):
+		painter = QtGui.QPainter(self)
+		rect = self.contentsRect()
+
+#		boardTop = rect.bottom() - Board.BoardHeight * self.squareHeight()
+
+
+
+    def keyPressEvent(self, event):
+		if not self.isStarted:
+			QtGui.QWidget.keyPressEvent(self, event)
+			return
+		key = event.key()
+		if key == QtCore.Qt.Key_P:
+			self.pause()
+			return
+
+    def timerEvent(self, event):
+         self.curTime = self.iTime.curTime()
+         if event.timerId() == self.timer.timerId():
+             pass
+         else:
+             QtGui.QFrame.timerEvent(self, event)
+
+
+
+
+class RunInternalTimer:   
+    def __init__(self):
+        self.startTime = time.time()    
+    
+    def curTime(self):
+        return time.time()    
+    
+    def timeSince(self):
+        return self.curTime() - self.startTime
+        
+app = QtGui.QApplication(sys.argv)
+tetris = Tetris()
+tetris.show()
+sys.exit(app.exec_())
+        

old/inheritanceScratch.py

+# -*- coding: utf-8 -*-
+"""
+Created on Tue Jun 18 17:13:33 2013
+
+@author: Dar
+"""
+
+class SuperParent:
+    def __init__(self):
+        self.Zeus = 'Greek'
+        self.Thor = 'Norse'
+        self.down = Parent(self)
+    
+    def hail(self, god):
+        print('all hail',god)
+        
+        
+        
+class Parent(SuperParent):
+    def __init__(self,parent):
+        SuperParent.__init__(self)
+        self.Cthulu = 'Lovecraft'
+        
+        
+# -*- coding: utf-8 -*-
+"""
+Created on Sat Jun 22 14:04:17 2013
+
+@author: Dar
+"""
+
+import sys
+import random
+import time
+import os.path
+from PyQt4 import QtCore, QtGui
+
+class Communicate(QtCore.QObject):
+    respMade = QtCore.pyqtSignal()
+    reinforce = QtCore.pyqtSignal()
+    
+    
+class Primary(QtGui.QWidget):
+    def __init__(self):
+        super(Primary, self).__init__()        
+      
+        self.c = Communicate()
+        self.initUI()
+        self.initVars()
+        
+    def initUI(self):
+        btnHead = QtGui.QPushButton('Head Entry',self)
+        btnResp = QtGui.QPushButton('Sim Lick', self)
+        btnStartSession = QtGui.QPushButton('Start Session', self)
+        btnClose = QtGui.QPushButton('Close', self)
+        btnStartIti = QtGui.QPushButton('StartITI', self)
+#     
+        self.lcdRespCnt = QtGui.QLCDNumber(self)
+        self.lcdTimeCnt = QtGui.QLCDNumber(self)
+        self.lcdItiTime = QtGui.QLCDNumber(self)
+        self.lblReinfCnt = QtGui.QLabel(self)
+        self.lblHeadIn = QtGui.QLabel(self)
+        self.lblLickinTrialCnt = QtGui.QLabel(self)
+        self.lblEct1 = QtGui.QLabel(self)
+        self.lblEct2 = QtGui.QLabel(self)
+        self.lblEct3 = QtGui.QLabel(self)
+        self.lblEct4 = QtGui.QLabel(self)
+        self.lblEct5 = QtGui.QLabel(self)
+        
+        vbox = QtGui.QVBoxLayout()
+        
+        vbox.addWidget(btnHead)
+        vbox.addWidget(self.lblHeadIn)
+        vbox.addWidget(btnResp)
+        vbox.addWidget(btnClose)
+        vbox.addWidget(btnStartSession)
+        vbox.addWidget(btnStartIti)
+        vbox.addWidget(self.lcdTimeCnt)
+        vbox.addWidget(self.lcdRespCnt)
+        vbox.addWidget(self.lcdItiTime)
+        vbox.addWidget(self.lblReinfCnt)
+        vbox.addWidget(self.lblLickinTrialCnt)
+        vbox.addWidget(self.lblEct1)
+        vbox.addWidget(self.lblEct2)
+        vbox.addWidget(self.lblEct3)
+        vbox.addWidget(self.lblEct4)
+        vbox.addWidget(self.lblEct5)
+
+        self.setLayout(vbox)
+        self.setGeometry(300, 300, 300, 300)
+        self.setWindowTitle('Main')
+        self.show()
+        
+        btnResp.clicked.connect(self.respBtnClicked)
+        btnStartSession.clicked.connect(self.startSession)
+        btnClose.clicked.connect(QtCore.QCoreApplication.instance().quit)
+        btnStartIti.clicked.connect(self.startTrial) 
+        btnHead.clicked.connect(self.toggleHeadEntry)
+        
+        self.c.respMade.connect(self.lickOn)         
+        
+    def initVars(self):
+        self.bHeadIn = False
+        self.bHeadTimer = False
+        self.bITI = False
+        self.bRespPhase = False
+        self.bLickOn = False
+        self.bReinfOn = False
+        self.respCount = 0
+        self.trialCountTotal = 0
+        self.trialWithinBlockCount = 0
+        self.trialBlockCount = 0
+        self.reinforcerCount = 0
+         
+        
+        #this is meant to be changed in and out, just so long as it has the same class structure
+        self.outsideController = OutsideEvent()
+           
+        
+    def startSession(self):
+        self.timingInit()
+        #this will need to be changed to accept inputs     
+        self.DataFile = OutputData()
+        print('ses start')
+    
+    def timingInit(self):
+        self.timer = QtCore.QBasicTimer()
+        self.timer.start(10, self) #this should start the timer
+        self.iTime = RunInternalTimer()
+
+#        print(self.curTrialTime)
+    def startTrial(self):
+        self.startIti(2)
+        self.DataFile.writeData('Trial Start')
+        
+    def toggleHeadEntry(self):
+        if self.bHeadIn == False:
+           self.headIn()
+        else:
+            self.headOut()
+
+    
+    def headIn(self):
+        self.bHeadIn = True
+        self.DataFile.writeData('H In')
+        print 'head in'
+        
+        
+        
+    def headOut(self):
+        self.bHeadIn = False
+        self.DataFile.writeData('H Out')
+        print 'head out'
+                
+        
+    def headTimerOn(self, waitTime = 0.2):
+        #activates a timer that waits for a lick after a head entry
+        self.headTimerDuration = waitTime
+        self.headTimerRun = RunInternalTimer()
+        self.bHeadTimer = True
+        print('head timer on')        
+        
+    def headTimerOff(self):
+        self.bHeadTimer = False
+        del self.headTimerRun
+        print('head timer off')
+    
+    def startIti(self, ItiDuration):        
+        self.ItiDuration = ItiDuration
+        self.ItiTimerRun = RunInternalTimer()
+        self.bITI = True
+        print('startIti')
+        
+    def endIti(self):
+        self.bITI = False
+        del self.ItiTimerRun
+        print('itiEnd')
+        self.DataFile.writeData('ITI End')
+        self.startRespPhase()
+        
+    def startRespPhase(self, duration = 9999999):
+        self.respPhaseDuration = duration
+        self.respPhaseTimerRun = RunInternalTimer()
+        self.bRespPhase = True
+        self.outsideController.lightOn()
+
+    def endRespPhase(self):
+        self.bRespPhase = False
+        self.outsideController.lightOff()
+        del self.respPhaseTimerRun
+
+    def respBtnClicked(self):
+        self.respCount += 1
+        self.lcdRespCnt.display(self.respCount)
+        self.lickMade()
+    
+    def lickMade(self):
+        self.c.respMade.emit()
+        self.DataFile.writeData('Lick')
+    
+    def reinforceOn(self, duration = 0.5):
+        self.reinforcerCount +=1
+        reinfDisplay = 'Reinforcer Count: ' + str(self.reinforcerCount)
+        self.lblReinfCnt.setText(reinfDisplay)
+        self.bReinfOn = True
+        self.reinfDuration = duration
+        self.reinfTimerRun = RunInternalTimer()
+        self.outsideController.reinforceOn()
+        self.DataFile.writeData('Reinf On')
+        
+
+    def reinforceOff(self):
+        self.bReinfOn = False
+        self.outsideController.reinforceOff()
+        self.DataFile.writeData('Reinf Off')
+
+    def updateDisplay(self):
+        headDisplay = 'Head Beam Break?: ' + str(self.bHeadIn)
+        self.lblHeadIn.setText(headDisplay)
+
+        ect1Display = 'bHeadTimer : ' + str(self.bHeadTimer)
+        self.lblEct1.setText(ect1Display)
+        
+        ect2Display = 'bRespPhase : ' + str(self.bRespPhase)
+        self.lblEct2.setText(ect2Display)
+        
+    def timerEvent(self,event):
+        self.updateDisplay()
+        self.curSestime = self.iTime.timeSince()
+        self.lcdTimeCnt.display(round(self.curSestime,2))       
+        ###
+        if self.bITI == True:            
+            if self.countDownCheck(self.ItiDuration,self.ItiTimerRun):
+                self.endIti()
+            else:
+                self.ItiTime = self.ItiTimerRun.timeSince()
+                itiCountDown = self.ItiDuration - round(self.ItiTime,2)
+                self.lcdItiTime.display(itiCountDown)
+        
+        ###
+        if self.bRespPhase == True:
+            if self.countDownCheck(self.respPhaseDuration,self.respPhaseTimerRun):
+                self.endRespPhase()
+                
+            if self.bHeadIn == True:
+                if self.bHeadTimer == False:                
+                    print(self.bHeadIn)
+                    self.headTimerOn(10)    #set to 10 just for test purposes, change to normal after
+            if self.bHeadTimer == True:
+                if self.countDownCheck(self.headTimerDuration,self.headTimerRun):
+                    self.endRespPhase()
+                    self.headTimerOff()
+                if self.bHeadIn == False:
+                    self.headTimerOff()
+                    self.endRespPhase()
+                if self.bLickOn == True:
+                    self.endRespPhase()                
+                    self.reinforceOn()
+                    self.headTimerOff()
+                    
+    
+        ###
+        if self.bReinfOn == True:
+            if self.countDownCheck(self.reinfDuration, self.reinfTimerRun):
+                self.reinforceOff()                
+        ###
+               
+        
+        ###
+        self.bLickOn = False
+        
+        
+        
+    def countDownCheck(self,duration, internalTimer):
+        counterTime = internalTimer.timeSince()
+        countDown = duration - counterTime
+        if countDown <= 0:
+            return True
+        else:
+            return False
+                
+            
+    def lickOn(self):
+        self.bLickOn = True
+        
+class lickInterval(Primary):
+    def __init__(self,intervalLength =2, binDuration = 0.2):
+        self.curBin = 0
+        self.interLength = intervalLength
+        self.binDuration = binDuration
+        self.binCountTotal = int(self.interLength / self.binDuration)
+        self.binList = [0]*self.binCountTotal
+        self.newBin(self.binDuration)
+        self.bResp = False
+        self.bContinue = True
+        self.lickDuration = 0
+        
+    def takeResp(self):
+        self.binList[self.curBin - 1] = 1
+        
+    def newBin(self):
+        self.curBin += 1
+        if self.curBin > self.binCountTotal        
+            self.endInterval()
+        self.binTimer =RunInternalTimer()
+    
+    def endOfBin(self):        
+        if self.binList[self.curBin - 1] == 1:
+            self.newBin()
+        else:
+            self.endInterval()
+            
+    def endInterval(self):
+        self.lickDuration = self.binList.count(1) * self.binDuration
+        self.bContinue = False:        
+
+        
+    def update(self):
+        self.curBinTime = self.binTimer.timeSince()
+        countDown = self.binDuration - self.curBinTime
+        Primary.lblLickinTrialCnt.setText(self.binDuration)        
+        if countDown <= 0:
+            self.endOfBin()
+            
+        if self.bContinue == False:
+            return self.lickDuration
+        else:
+            return False
+
+class RunInternalTimer:   
+    def __init__(self):
+        self.startTime = time.time()    
+    
+    def curTime(self):
+        return time.time()    
+    
+    def timeSince(self):
+        return self.curTime() - self.startTime
+
+
+class OutsideEvent: #this should eventually go into another file that's imported
+    def lightOn(self):
+        print('light on')
+    
+    def lightOff(self):
+        print('light off')
+        
+    def reinforceOn(self):
+        print('reinforcer on')        
+
+    def reinforceOff(self):
+        print('reinforcer off')     
+
+    def valveOn(self, valveNum):
+        print('valve',str(valveNum), 'on')
+
+    def valveOff(self, valveNum):
+        print('valve',str(valveNum), 'off')
+
+
+
+class OutputData():
+    def __init__(self, fileName = 'default',subjectName = 'mouse' ,experimentName = 'experiment',techName = 'anonymous'):
+        self.fileName = str(fileName) + '.txt'
+        startTime = time.asctime(time.localtime(time.time()))
+        
+        if os.path.isfile(self.fileName) == False:
+            self.file = open(self.fileName,'w')
+            self.file.write(startTime)
+            self.file.close()
+        else:
+            self.writeData('new Session')
+            self.writeData(startTime)
+            
+        self.writeData(subjectName)
+        self.writeData(experimentName)
+        self.writeData(techName)        
+
+    def writeData(self, inputText =''):
+        self.file = open(self.fileName, 'a')
+        self.file.write('\n')
+        self.file.write(inputText)
+        self.file.close()
+
+def main():
+    
+    app = QtGui.QApplication(sys.argv)
+    ex = Primary()
+    sys.exit(app.exec_())
+
+
+if __name__ == '__main__':
+    main()

old/respTestGUI.py

+# -*- coding: utf-8 -*-
+"""
+Created on Sun Jun  9 08:24:50 2013
+
+@author: FedLab2
+"""
+
+import sys
+import time
+from PyQt4 import QtGui, QtCore
+
+
+class Communicate(QtCore.QObject):
+    respMade = QtCore.pyqtSignal()
+    reinforce = QtCore.pyqtSignal()
+
+class Example(QtGui.QWidget):    
+    def __init__(self):
+        super(Example, self).__init__()        
+        self.initUI()
+        self.timingInit()
+        self.respCount = 0
+        self.c = Communicate()
+        
+#    def testBits(self):
+#        self.respCnt = quickAdd.respCounter()
+       # return respCnt       
+    
+    def timingInit(self):
+        self.timer = QtCore.QBasicTimer()
+
+        
+    def initUI(self):        
+
+        btnResp = QtGui.QPushButton('Sim Response', self)
+        btnStartTrial = QtGui.QPushButton('Start Trial', self)
+#        btnResp.move(50, 50)
+        btnClose = QtGui.QPushButton('Close', self)
+#     
+        self.lcdRespCnt = QtGui.QLCDNumber(self)
+        self.lcdTimeCnt = QtGui.QLCDNumber(self)
+        self.lblRespCnt = QtGui.QLabel(self)
+        
+        
+        vbox = QtGui.QVBoxLayout()
+        vbox.addWidget(self.lcdRespCnt)
+        vbox.addWidget(self.lblRespCnt)
+        vbox.addWidget(btnResp)
+        vbox.addWidget(btnClose)
+        vbox.addWidget(self.lcdTimeCnt)
+        vbox.addWidget(btnStartTrial)
+
+
+        self.setLayout(vbox)
+        self.setGeometry(300, 300, 250, 150)
+        self.setWindowTitle('Main')
+        self.show()
+        
+        btnResp.clicked.connect(self.respBtnClicked)
+        btnStartTrial.clicked.connect(self.startTrial)
+        btnClose.clicked.connect(QtCore.QCoreApplication.instance().quit)
+    
+    def initSesVars(self):
+        self.bITI = False
+        self.bTrial = False
+    
+    def startTrial(self):
+        print 352352
+        newTrial = Trial(100) 
+        
+#    def timerEvent(self, event):
+#        pass
+#         self.curTime = self.iTime.timeSince()
+#         self.lcdTimeCnt.display(round(self.curTime,2))
+         
+#        self.c = Communicate()
+#        self.c.
+        
+    def respBtnClicked(self):
+        self.respCount += 1
+        self.lcdRespCnt.display(self.respCount)
+        self.c.respMade.emit()
+        
+        
+#class BinnedTrial:
+#    def __init__(self,parent):
+#        self.trialTime = 0
+#        self.itiTime = 0
+#        self.bITI
+#        self.bStartTrial
+#            
+#    def timerEvent(self,event):
+#        if event.timerId() == self.timer.timerId():
+#            self.dostuff
+#        else:
+#            QtGui.QFrame.timerEvent(self, event)
+
+class Trial(Example):
+    def __init__(self,ITI):
+        Example.__init__(self)
+
+        self.bItiOn = True
+        self.itiTime = ITI
+        self.bLickLook = False
+        self.curBin = 0
+        self.binCount = 10
+        self.binInterval = 0.2
+        self.bRespOn = False
+        self.c.respMade.connect(self.respOnNow)
+        self.c.reinforce.connect(self.reinforce)
+        print('trial started')
+
+
+    def timingInit(self):
+        self.timer = QtCore.QBasicTimer()
+        self.timer.start(10, self) #this should start the timer
+        self.iTime = RunInternalTimer()
+        
+    def initUI(self):
+        btnResp = QtGui.QPushButton('Sim Response', self)
+#        btnClose.move(50,100)        
+        self.lcdRespCnt = QtGui.QLCDNumber(self)
+        self.lcdTimeCnt = QtGui.QLCDNumber(self)        
+        
+        vbox = QtGui.QVBoxLayout()
+        vbox.addWidget(self.lcdRespCnt)
+        vbox.addWidget(btnResp)
+        vbox.addWidget(self.lcdTimeCnt)
+
+        self.setLayout(vbox)
+        self.setGeometry(300, 300, 250, 150)
+        self.setWindowTitle('Trial')
+        self.show()
+        print('UI on')