Commits

iorodeo  committed 0803074

Finished modificatinos to plot.py so that it works with the version c pcb.

  • Participants
  • Parent commits 41248c5

Comments (0)

Files changed (4)

File python/Colorimeter/colorimeter/gui/plot/plot.py

         dfltSolutionDict = import_export.loadDefaultTestSolutionDict(tag='D')
         solutionDict = dict(userSolutionDict.items() + dfltSolutionDict.items())
         data = TestSolutionDialog().importData(solutionDict)
+
         if data is not None:
-            if data['led'] in constants.COLOR2LED_DICT:     
-                self.setMode('standard')
-                self.setLEDColor(data['led'])
-            elif data['led'] == 'custom':
-                self.setMode('customLEDVerB')
-            elif data['led'] == 'custom1':
-                self.setMode('customLEDVerC')
-                # --------------------------------------------
-                # TODO
-                # --------------------------------------------
-            elif data['led'] == 'custom2':
-                self.setMode('customLEDVerC')
-                # --------------------------------------------
-                # TODO  
-                # -------------------------------------------
+
+            isNewStyle = True 
+            try:
+                sensorMode = data['mode']
+            except KeyError:
+                isNewStyle = False 
+
+            if isNewStyle:
+                ledText = data['led']
+            else:
+                if data['led'] == 'custom':
+                    sensorMode = 'CustomLEDVerB'
+                    ledText = 'D1'
+                else:
+                    sensorMode = 'StandardRGBLED'
+                    ledText = data['led']
+
+            self.setMode(sensorMode)
+            self.setLEDByText(ledText)
+
+            #if data['led'] in constants.COLOR2LED_DICT:     
+            #    self.setMode('standard')
+            #    self.setLEDColor(data['led'])
+            #elif data['led'] == 'custom':
+            #    self.setMode('customLEDVerB')
+            #elif data['led'] == 'custom1':
+            #    self.setMode('customLEDVerC')
+            #    # --------------------------------------------
+            #    # TODO
+            #    # --------------------------------------------
+            #elif data['led'] == 'custom2':
+            #    self.setMode('customLEDVerC')
+            #    # --------------------------------------------
+            #    # TODO  
+            #    # -------------------------------------------
+
             self.setTableData(data['values'])
             self.setFitType(data['fitType'],data['fitParams'])
             self.setConcentrationUnits(data['concentrationUnits'])
                 import_export.deleteTestSolution(self.userHome,solutionName)
 
         dateStr = time.strftime('%Y-%m-%d %H:%M:%S %Z')
-
-        if self.isStandardRgbLEDMode():
-            currentLED = self.currentColor
-        else:
-            currentLED = 'custom'
-
+        modeConfig = self.getModeConfig()
+        ledText = modeConfig['LED'][self.currentLED]['text']
         dataDict = { 
                 'name': solutionName,
                 'date': dateStr,
-                'led': currentLED,
+                'led':  ledText,
+                'mode': self.sensorMode, 
                 'values': [map(float,x) for x in dataList],
                 'fitType': fitType,
                 'concentrationUnits': self.getConcentrationUnits(),
         ax.grid('on')
         units = self.getConcentrationUnits()
         ax.set_xlabel('Concentration ({0})'.format(units))
-        ax.set_ylabel('Absorbance ('+self.currentColor+' led)')
+        currentLEDText = self.getLEDText()
+        ax.set_ylabel('Absorbance ('+currentLEDText+' led)')
         if haveSlope:
             self.fig.text(
                     constants.PLOT_SLOPE_TEXT_POS[0],
                     )
         plt.draw()
 
+    def getLEDText(self,num=None):
+        modeConfig = self.getModeConfig()
+        if num is None:
+            num = self.currentLED
+        return modeConfig['LED'][num]['text']
+
+
     def getMeasurement(self):
         if constants.DEVEL_FAKE_MEASURE:
             absorbance = random.random()
             modeConfig = self.getModeConfig()
             ledDict = modeConfig['LED'][self.currentLED] 
             dummy0, dummy1, absorbance = self.dev.getMeasurement(ledDict['devColor'])
-            print(absorbance)
         digits = self.getSignificantDigits()
         absorbanceStr = '{value:1.{digits}f}'.format(value=absorbance,digits=digits)
         self.measurePushButton.setFlat(False)
     def getSaveFileHeader(self):
         timeStr = time.strftime('%Y-%m-%d %H:%M:%S %Z') 
         if self.isStandardRgbLEDMode():
-            currentLed = self.currentColor
+            ledInfoStr = self.getLEDText()
+            
         else:
+            ledText = self.getLEDText()
+            ledInfoStr = '{0}, {1}'.format(ledText, self.sensorMode)
             currentLed = 'custom'
         headerList = [ 
                 '# {0}'.format(timeStr),
                 '# Colorimeter Data', 
-                '# LED {0}'.format(currentLed),
+                '# LED {0}'.format(ledInfoStr),
                 '# -----------------------------', 
                 '# Concentration | Absorbance', 
                 ]
             self.ledColorWidget.setEnabled(False)
         else:
             self.calibratePushButton.setEnabled(True)
-            if self.isStandardRgbLEDMode():
-                self.ledColorWidget.setEnabled(True)
-            else:
-                self.ledColorWidget.setEnabled(False)
+            self.ledColorWidget.setEnabled(True)
 
     def getFitTypeAndParams(self):
         if self.actionFitTypeLinear.isChecked():

File python/Colorimeter/colorimeter/gui/plot/plot.ui

    </property>
   </action>
   <action name="actionCustomLEDVerC">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
    <property name="text">
     <string>Two custom LEDs (Ver. C)</string>
    </property>

File python/Colorimeter/colorimeter/gui/plot/plot_ui.py

 
 # Form implementation generated from reading ui file 'plot.ui'
 #
-# Created: Fri Oct 25 17:24:10 2013
+# Created: Sat Oct 26 13:02:36 2013
 #      by: PyQt4 UI code generator 4.7.2
 #
 # WARNING! All changes made in this file will be lost!
         self.actionSignificantDigits4.setCheckable(True)
         self.actionSignificantDigits4.setObjectName("actionSignificantDigits4")
         self.actionCustomLEDVerC = QtGui.QAction(MainWindow)
+        self.actionCustomLEDVerC.setCheckable(True)
         self.actionCustomLEDVerC.setObjectName("actionCustomLEDVerC")
         self.menuFile.addAction(self.actionSave)
         self.menuFile.addAction(self.actionLoad)

File python/Colorimeter/colorimeter/main_window.py

             else:
                 self.sensorModeSetChecked(self.sensorMode)
 
-
     def sensorModeSetChecked(self,sensorMode):
         modeAction = getattr(self, 'action{0}'.format(sensorMode))
         modeAction.setChecked(True)
         self.actionEditTestSolutions.triggered.connect(self.editTestSolutions_Callback)
 
     def initialize(self):
-        self.setLED(0)
+        self.setLED(0) # default is first led 
         super(MainWindowWithTable,self).initialize()
         self.lastLoadDir = self.userHome
         self.tableWidget.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
                 QtGui.QMessageBox.warning(self,msgTitle, msgText)
 
     def setMode(self,value):
+        self.setLED(0)
         super(MainWindowWithTable,self).setMode(value)
-        if value == 'StandardRGBLED':
-            self.tableWidget.clean(True,'')
-            self.setLEDChecks()
-        elif value == 'custom':
-            self.tableWidget.clean(True,'')
-            self.setLEDChecks()
-        else:
-            raise ValueError, 'unkown LED mode {0}'.format(value)
+        self.tableWidget.clean(True,'')
+        self.setLEDChecks()
+        self.setLEDText()
+        self.setLEDVisible()
 
     def loadFile_Callback(self):
         """
         button.setChecked(True)
         self.currentLED = num
 
+    def setLEDByText(self,ledText):
+        modeConfig = self.getModeConfig()
+        text2Num = dict([(d['text'], n) for n, d in modeConfig['LED'].iteritems()])
+        ledNum = text2Num[ledText]
+        self.setLED(ledNum)
+
     def getData(self):
         return self.tableWidget.getData(noValueSymb=self.noValueSymbol)
 
             self.portLineEdit.setEnabled(False)
             self.statusbar.showMessage('Connected, Stopped')
 
-    def clearColorLEDChecks(self):
-        for color in constants.COLOR2LED_DICT:
-            button = getattr(self,'{0}RadioButton'.format(color))
-            button.setChecked(False)
-            button.setCheckable(False)
-
     def setLEDChecks(self):
         modeConfig = self.getModeConfig()
         for ledNum, ledDict in modeConfig['LED'].iteritems():
             button = getattr(self,'LED{0}RadioButton'.format(ledNum))
             button.setCheckable(True)
-            button.setText(ledDict['text'])
             if ledNum == self.currentLED:
                 button.setChecked(True)
             else:
                 button.setChecked(False)
 
+    def setLEDText(self):
+        modeConfig = self.getModeConfig()
+        for ledNum, ledDict in modeConfig['LED'].iteritems():
+            button = getattr(self,'LED{0}RadioButton'.format(ledNum))
+            button.setText(ledDict['text'])
+
+    def setLEDVisible(self):
+        modeConfig = self.getModeConfig()
+        for ledNum in constants.LED_NUMBERS:
+            button = getattr(self,'LED{0}RadioButton'.format(ledNum))
+            if ledNum in modeConfig['LED']:
+                button.setVisible(True)
+            else:
+                button.setVisible(False)
+
+
+
+
+               
+
+                
+