Commits

Richard Gerkin committed 801f3f8

Added scratch.py to separate UI and program logic

Comments (0)

Files changed (13)

Binary file modified.
-<<<<<<< local
 from __init__ import *
-=======
-# -*- coding: utf-8 -*-
-"""
-Created on Sat Jun 29 17:48:24 2013
-
-@author: Dar
-"""
-
-
-
-from olfSupport import *
->>>>>>> other
 
 class Phase1(InternalEvent):
     '''
         self.hits = 0
         self.itiTime = 1
 
-<<<<<<< local
-=======
-
->>>>>>> other
     def update(self):
         if self.bITI == True:
             #print self.ItiTimerRun.countDownTime()
     
         self.lickOff()
         return self.bContinuePhase, self.hits, self.misses    
-<<<<<<< local
-=======
-
->>>>>>> other
        
     def endTrial(self):
         self.bTrialStart = False

Phase1.pyc

Binary file removed.
-<<<<<<< local
 from __init__ import *
-=======
-from olfSupport import *
->>>>>>> other
 
 class Phase3(InternalEvent):
     '''

Phase3.pyc

Binary file removed.
-# -*- coding: utf-8 -*-
-"""
-Created on Sat Jun 29 17:45:39 2013
-
-@author: Dar
-"""
-
 import time
 import os
-import outside_events
-
-# Create the python template from the design file each time the program runs.  
-# This will only take few ms and make sure the design changes are reflected immediately.  
-os.chdir(os.path.dirname(__file__))
-#os.system('pyuic4 qt/gui.ui > qt/gui.py')
+import outside_events as outside_events
+# Change to "import outside_events.micro as outside_events" to use the microcontroller.  
 
 class InternalEvent(object):
     '''

__init__.pyc

Binary file removed.
-# -*- coding: utf-8 -*-
 """
 Created on Sat Jun 22 14:04:17 2013
 
-from ui import *
+import os
 
-def main():
-    import sys
-    app = QtGui.QApplication(sys.argv)
-    MainWindow = QtGui.QMainWindow()
-    ui = Ui_MainWindow()
-    ui.setupUi(MainWindow)
-    MainWindow.show()
-    sys.exit(app.exec_())
+AUTO_REGEN = False
 
-def TurnLickLightGreen():
-    ui.lickButton.changeColor('green')
-
+if AUTO_REGEN:
+	# Create the python template from the design file each time 
+	# the program runs. This will only take few ms and make sure 
+	# the design changes are reflected immediately.  
+	curr_dir = os.getcwd()
+	os.chdir(os.path.dirname(__file__))
+	os.system('pyuic4 gui.ui > gui.py')
+	os.chdir(curr_dir)

qt/__init__.pyc

Binary file removed.

qt/gui.pyc

Binary file removed.

qt/ui.pyc

Binary file removed.
+"""
+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 = True
+
+class Communicate(QtCore.QObject):
+    '''
+    not used at the moment
+    '''
+    lickOn = QtCore.pyqtSignal()
+    headEntry = QtCore.pyqtSignal()
+    reinforce = QtCore.pyqtSignal()
+    
+class Master(QtGui.QWidget):
+    def __init__(self,main_window):
+        super(Master, self).__init__(main_window)        
+        
+        self.main_window = main_window
+        self.c = Communicate()
+        self.initVars()
+        
+    def initVars(self):
+        """Initialize 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('Session start')   
+
+    def updateDisplay(self): 
+        """This should be text and numeric controls in Qt Designer."""     
+        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/etc."""
+        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 initUI(self):
+    """All of this should be moved into Qt Designer and auto generated."""
+    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,master):
+    self.btnResp.clicked.connect(master.respBtnClicked)
+    self.btnClose.clicked.connect(QtCore.QCoreApplication.instance().quit)
+    self.btnHead.clicked.connect(master.headEntryBtnClicked)
+    self.btnStartPhase1.clicked.connect(master.startPhase1)
+    self.btnStartPhase3.clicked.connect(master.startPhase3)
+            
+def main():
+    """The entry point to the application"""
+    app = QtGui.QApplication(sys.argv)
+    main_window = QtGui.QMainWindow()
+    ui = Ui_MainWindow()
+    ui.setupUi(main_window)
+    central_widget = main_window.centralWidget()
+    initUI(central_widget)
+    master = Master(main_window)
+    initConnect(central_widget,master)    
+    main_window.show()
+    sys.exit(app.exec_())
+
+if __name__ == '__main__':
+    main()