def pushTrayToDB(self,event):
     print 'pushing tray'
     [trayId]=event.argBundle
     mbs=event.myRobotScript
     tList=X_ROBOT_X02DA_database.xGetTrayList()
     gAhead=1
     if sum([trayId.upper()==tEle for tEle in tList])>0:
         gAhead=wx.GetSingleChoiceIndex('Tray Already Exists, Overwrite?','UserGUI_Robot',['No','Yes'])
     if gAhead:
         X_ROBOT_X02DA_database.xCreateTray(trayId,self.mainPtr.CurTray,mbs.sequenceText)
 def pullTrayFromDB(self,event):
     print 'pulling tray'
     # let user select TrayId
     #[trayId]=event.argBundle
     tList=X_ROBOT_X02DA_database.xGetTrayList()
     tIndex=wx.GetSingleChoiceIndex('Select Tray to Load:','UserGUI_Robot',tList)
     if tIndex>=0:
         trayId=tList[tIndex]
         [self.mainPtr.CurTray,event.myRobotScript.sequenceText]=X_ROBOT_X02DA_database.xGetWholeTray(trayId)
         self.mainPtr.kPostEvent('gsInit',[])
         self.createGrid()
     else:
         print 'User Cancelled Loading!'
 def __init__(self, parent,mainPtr=''):
     self._init_ctrls(parent)
     self.mainPtr=mainPtr
     try:
         tList=X_ROBOT_X02DA_database.xGetTrayList()
     except:
         print 'Tray List Empty!!!'
         tList=[]
     #
     #self.trayList.AppendItems(['Bob','The','Cat','Makes'])
     self.trayList.AppendItems(tList)
 def OnTrayListListbox(self, event):
     
     try:
         [cTray,scriptText]=X_ROBOT_X02DA_database.xGetWholeTray(event.GetString())
     except:
         print 'Tray '+event.GetString()+' Empty!!!!'
         scriptText=''
     cList=scriptText.split('\n')
     self.writeColorSequence(cList)
     #self.sequenceList.AppendItems([event.GetString()+'-'+str(j) for j in range(1,50)])
     #self.sequenceList.SetChecked(range(0,39))
     #print self.sequenceList
     event.Skip()
 def OnButDBLoadPosButton(self, event):
     cCol=self.trayPosSelect.GetGridCursorCol()
     cRow=self.trayPosSelect.GetGridCursorRow()
     self.mainPtr.CurTray[cRow][cCol][3]=[]
     print 'pulling tray'
     # let user select TrayId
     #[trayId]=event.argBundle
     sList=X_ROBOT_X02DA_database.xdGetAllSamplesInTrays()
     sList.sort()
     sIndex=wx.GetSingleChoiceIndex('Select Sample to Load:','UserGUI_Robot',sList)
     if sIndex>=0:
         sampleName=sList[sIndex]
         unsereSampleIst=X_ROBOT_X02DA_database.xdGetSample(sampleName)
         print 'Before'
         print self.mainPtr.CurTray[cRow][cCol]
         print 'After'
         print unsereSampleIst
         self.mainPtr.CurTray[cRow][cCol]=unsereSampleIst
         self.OnRefreshGridDisplay()
     else:
         print 'User Cancelled Loading!'
     
     event.Skip()
    def writeColorSequence(self,cList):
        
        self.sequenceList.Clear()
        
        alreadyScanned=[]
        sampleList=[]
        self.sequenceList.SetDoubleBuffered(False)
        for i in range(0,len(cList)):
            item = wx.ListItem() 

            #item.SetData(id) 
            #item.SetWidth(200) 
            cLine=cList[i]
            cStat=1
            if cLine.upper().find('IMSAMPLE')>-1:
                
                cSample=cLine.split('"')
                cSample=cSample[1]
                cStat=X_ROBOT_X02DA_database.xGetSampleStatus(cSample)
                print (cSample,cStat)
                sampleList+=[(cSample,cStat)]
                #if cStat==0: cLine='*NOPOS*'+cLine
                #if cStat==2: cLine='*MEASE*'+cLine
                #if cStat==3: cLine='*RECON*'+cLine
                
                #self.sequenceList.SetItemBackgroundColour(i,bgcolor[cStat])
                #print self.sequenceList.GetItemBackgroundColour(i)
                #self.sequenceList.SetItemForegroundColour(i,bgcolor[cStat])
                #self.sequenceList.DefaultAttributes.colBg=bgcolor[cStat]
                self.sequenceList.Refresh()
                #self.sequenceList.Show()
            item.SetText(cLine)
            #dir(item) 
            #self.sequenceList.Insert(i,item)
            self.sequenceList.Append(cLine)
            if cStat>1: alreadyScanned+=[i]
            
            #self.sequenceList.SetItemBackgroundColour(i,bgcolor[cStat])
        self.sequenceList.SetChecked(alreadyScanned)
        self.writeSampleStatus(sampleList)
    globals()["sys"].stderr = newPipe
if dbEnabled == 0:
    opt.usedb = False
else:
    logbookText += "User Id:" + X_ROBOT_X02DA_database.UserId + "\n"
    logbookName += X_ROBOT_X02DA_database.UserId
if opt.showpanel:
    thread.start_new_thread(os.system, ("medm -x /work/sls/config/medm/X_ROBOT_X02DA_robotSequencer.adl",))
if opt.debug:
    debugMode = 1
    logbookText += "DEBUG RUN\n"
else:
    debugMode = 0
if opt.usedb:
    if opt.name is None:
        tList = X_ROBOT_X02DA_database.xGetTrayList()
        import SimpleDialog

        root = SimpleDialog.Tk()
        cDlg = SimpleDialog.SimpleDialog(root, text="Which tray?", buttons=tList)
        tIndex = cDlg.go()
        cDlg.wm_delete_window()
        del (cDlg)
        root.destroy()
        del (root)
        if tIndex >= 0:
            trayId = tList[tIndex]
        else:
            sys.exit(-1)
    else:
        trayId = opt.name