def labler(lablename,signalname,self,num): #incoming signal names are local, must be global for use in exec global selfglobal global rightInfoHub selfglobal=self #boolean logic if lablename in self.booleanList: if signalname=='true': rightInfoHub['textBoxes'][lablename].setCurrentIndex(0) elif signalname=='false': rightInfoHub['textBoxes'][lablename].setCurrentIndex(1) if lablename in (x[0] for x in self.catelogList) and signalname!='': if lablename==self.catelogList[0][0]: stdList=getInfo.getStandardNames(fileName()) else: stdList=getInfo.getCategories(fileName()) rightInfoHub['textBoxes'][lablename].setCurrentIndex(stdList.index(signalname)) if lablename=='voltage_range': stdList=['','-10 10','-5 5','-2.5 2.5','0 10'] rightInfoHub['textBoxes'][lablename].setCurrentIndex(stdList.index(signalname)) #if lablename=='default_sample_rate': rightInfoHub['headers'][lablename].setText(lablename) rightInfoHub['headers'][lablename].setMinimumSize(rightInfoHub['headers'][lablename].sizeHint()) if lablename not in self.booleanList and lablename not in (x[0] for x in self.catelogList) and lablename not in ['voltage_range','default_sample_rate']: rightInfoHub['textBoxes'][lablename].setText(str(signalname)) #Connvects changes in text box to bools logic rightInfoHub['textBoxes'][lablename].textEdited.connect(lambda: textChange()) textChange() #global variable bools set False to indicate no changes have been made yet bools=False
def newSig(self): boolsTrue() #Deselect qlistwidget for entry in range(self.left.scrollAreaWidgetContents.count()): item=self.left.scrollAreaWidgetContents.item(entry) self.left.scrollAreaWidgetContents.setItemSelected(item,False) clearRightInfoHub() makeRightInfoHub(self,getDictionary(fileName())) i=0 for entry in getDictionary(fileName()): labler(entry,'',self,i) i+=1 self.saveButton.clicked.connect(lambda:saveChanges(self,headers,-1))
def delete(signame,self,num): entries=getInfo.getinfo(fileName()) quit_messge='Are you sure you want to delete '+signame reply=QtGui.QMessageBox.question(self, 'Warning: altering varDB', quit_messge, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: from addSignal import addsignal from radioClickEvent import lookingAt from radioClickEvent import clearRightInfoHub clearRightInfoHub() #lookingAt(-1,self) addsignal(signame,self,num,{'action':'delete'})
def clearRightInfoHub(): global rightInfoHub dictionary=getInfo.getDictionary(fileName()) i=0 while i<len(dictionary): try: rightInfoHub['headers'][dictionary[i]].close() rightInfoHub['textBoxes'][dictionary[i]].close() except: pass i+=1
def generateButtons(self,filtering,num): global rightInfoHub #removes buttons from left self.left.scrollAreaWidgetContents.clear() entries=getinfo(fileName()) i=0 while i<len(entries): #displayed buttons must start with filter phrase if filtering.upper() in str(entries[i][1]).upper() or filtering=='': self.left.scrollAreaWidgetContents.addItem(entries[i][1]) i+=1 if num>=0: self.left.scrollAreaWidgetContents.setItemSelected(self.left.scrollAreaWidgetContents.item(num),True) try:self.left.scrollAreaWidgetContents.scrollToItem(self.left.scrollAreaWidgetContents.selectedItems()[0]) except:pass
def saveChanges(self,headers,num): global bools global rightInfoHub if bools==True: from addSignal import addsignal bools=False reply=QtGui.QMessageBox.question(self, 'Save Changes?', 'Save these changes to '+rightInfoHub['textBoxes']['name'].text()+'?', QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply==QtGui.QMessageBox.Yes: i=1 headers=getInfo.getDictionary(fileName()) #Get new information from text boxes signalist=[[]] signalist[0]=['name',signalSet(self,'name')] while i<len(headers): #signalist is of the form [ [attribute name, attribute text] * N] signalist.append([headers[i],signalSet(self,headers[i])]) i+=1 #Uses new information to replace previous information. #If entry with desired name exists, new entry is created addsignal(signalist,self,num,{'action':'edit'})
def makeRightInfoHub(self,headers): global rightInfoHub global bools clearRightInfoHub() def onActivated(self,sig): global rightInfoHub global bools bools=True i=0 while i<len(headers): rightInfoHub['headers'][headers[i]]=QtGui.QLabel(headers[i],self.upright) self.upright.verticalLayoutScroll.addWidget(rightInfoHub['headers'][headers[i]],i,1) #Check for boolean variable if headers[i] in self.booleanList: rightInfoHub['textBoxes'][headers[i]]=QtGui.QComboBox(self.upright) #warning: preserve assignment order rightInfoHub['textBoxes'][headers[i]].addItem("true") rightInfoHub['textBoxes'][headers[i]].addItem("false") rightInfoHub['textBoxes'][headers[i]].setCurrentIndex(1) rightInfoHub['textBoxes'][headers[i]].activated.connect(partial(onActivated,self,headers[i])) rightInfoHub['textBoxes'][headers[i]].activated.connect(lambda:textChange()) #Check if variable is in catalog list elif headers[i] in (entry[0] for entry in self.catelogList): rightInfoHub['textBoxes'][headers[i]]=QtGui.QComboBox(self.upright) if headers[i]==self.catelogList[0][0]: stdList=getInfo.getStandardNames(fileName()) else: stdList=getInfo.getCategories(fileName()) for item in stdList: rightInfoHub['textBoxes'][headers[i]].addItem(item) rightInfoHub['textBoxes'][headers[i]].currentIndexChanged.connect(lambda:textChange()) elif headers[i]=='default_sample_rate': rightInfoHub['textBoxes'][headers[i]]=QtGui.QComboBox(self.upright) rightInfoHub['textBoxes'][headers[i]].addItem("") rightInfoHub['textBoxes'][headers[i]].addItem("500") rightInfoHub['textBoxes'][headers[i]].addItem("100") rightInfoHub['textBoxes'][headers[i]].addItem("50") rightInfoHub['textBoxes'][headers[i]].addItem("10") rightInfoHub['textBoxes'][headers[i]].setCurrentIndex(0) rightInfoHub['textBoxes'][headers[i]].activated.connect(partial(onActivated,self,headers[i])) rightInfoHub['textBoxes'][headers[i]].activated.connect(lambda:textChange()) elif headers[i]=='voltage_range': rightInfoHub['textBoxes'][headers[i]]=QtGui.QComboBox(self.upright) rightInfoHub['textBoxes'][headers[i]].addItem("") rightInfoHub['textBoxes'][headers[i]].addItem("-10 10") rightInfoHub['textBoxes'][headers[i]].addItem("-5 5") rightInfoHub['textBoxes'][headers[i]].addItem("-2.5 2.5") rightInfoHub['textBoxes'][headers[i]].addItem("0 10") rightInfoHub['textBoxes'][headers[i]].setCurrentIndex(0) rightInfoHub['textBoxes'][headers[i]].activated.connect(partial(onActivated,self,headers[i])) rightInfoHub['textBoxes'][headers[i]].activated.connect(lambda:textChange()) else: rightInfoHub['textBoxes'][headers[i]]=QtGui.QLineEdit(self.upright) rightInfoHub['textBoxes'][headers[i]].textChanged.connect(lambda:textChange()) self.upright.verticalLayoutScroll.addWidget(rightInfoHub['textBoxes'][headers[i]],i,2) rightInfoHub['textBoxes'][headers[i]].setFixedWidth(500) i+=1
def lookingAt(self): global previousnum global bools global reftex global headers entries=getInfo.getinfo(fileName()) dictionary=getInfo.getDictionary(fileName()) #Stiffle error message when no signal is selected try:text= str(self.left.scrollAreaWidgetContents.selectedItems()[0].text()) except:return #get current selection's position in vdb i=0 while i<len(entries): if entries[i][1]==text: num=i i+=1 #Checks for changes to text boxes with bool #num =-1 is a flag that a variable is being deleted, and not to save changes made if bools==True and num!=-1: bools=False saveChanges(self,headers,num) return #If num is set as flag -1, reset it to 0 #This indicates not to save changes, so bool is set to False if num==-1: bools=False num=0 #Get attributes #headers=entries[num][0] headers=getInfo.getDictionary(fileName()) #CLEAR RIGHT SIDE INFORMATION HUB clearRightInfoHub() #Create framework for upright side information hub makeRightInfoHub(self,headers) #Get signal's attribute info i=1 signals=[] while i<len(entries[num][0])+1: signals.append(entries[num][i]) i+=1 i=0 #write attribute info to screen while i<len(entries[num][0]): if entries[num][0][i] in headers: labler(entries[num][0][i],signals[i],self,i) headers.remove(entries[num][0][i]) else: labler(dictionary[0],'',self,i) i+=1 #Disconnect buttons try: self.deleteButton.clicked.disconnect() except Exception: pass try: self.saveButton.clicked.disconnect() except Exception: pass #Connect buttons self.deleteButton.clicked.connect(lambda: delete(str(rightInfoHub['textBoxes']['name'].text()),self,num)) self.saveButton.clicked.connect(lambda: saveChanges(self,headers,num)) clearRightInfoHub() previousnum=num bools=False
def addsignal(signals,self,num,instructions): parser = etree.XMLParser(remove_blank_text=True) doc=etree.parse(fileName(),parser) root=doc.getroot() #+++++++++++ if instructions['action']=='edit': #Expecting signals to be of form [ [attribute,new valie] * n ] #Edits existing attributes added=False newAtt=[] j=0 for elm in root.iter('variable'): if elm.attrib['name'] == signals[0][1].upper(): #variable is already in vardb added=True #edit exiting entries i=0 while i<len(elm): for sig in signals: if elm[i].tag == sig[0] and elm[i].text != sig[1]: elm[i].text=sig[1] print 'changed ', elm.attrib['name'],": ",elm[i].tag,' to ',elm[i].text i+=1 #Check for new entries for sig in signals: inThere=False wasRemoved=False i=0 while i<len(elm): if elm[i].tag==sig[0]: inThere=True i+=1 if not inThere and sig[0] != 'name' and sig[1]!='': newAtt.append(etree.SubElement(elm,sig[0])) newAtt[j].text=sig[1] for att in elm: if getDictionary(fileName()).index(att.tag)>getDictionary(fileName()).index(sig[0]): att.addnext(newAtt[j]) break j+=1 print 'Added ',sig[0],' to ',elm.attrib['name'],' set as ',sig[1] #check for blank entries, remove them for att in elm: if str(att.text)=='' and str(att.tag) not in [s[0] for s in self.catelogList]: print 'removed ',att.tag,' from ',elm.attrib['name'] elm.remove(att) if added==False: instructions['action']='new signal' print str(signals[0][1]).upper(),' not found in VDB. Creating new entry.' #++++++++++++ if instructions['action']=='delete': for elm in root.iter('variable'): if elm.attrib['name']==signals: elm.getparent().remove(elm) print 'removed ',signals #+++++++++++ if instructions['action']=='new signal': #Expecting signals to be list of for [ [attribute,value]*n] #Inserts a new signal into varDB in alphabetical order #Check for name input if signals[0][0]!='name' : print 'exit code 1 in addsignal.py: no name was input' quit() #Insert element elms=[] for elm in root.iter('variable'): elms.append(str(elm.attrib['name'])) elms.append(str(signals[0][1]).upper()) elms.sort() added=False i=0 for elm in root.iter('variable'): if str(elm.attrib['name'])!=elms[i] and added==False: new = etree.Element('variable',name=signals[0][1].upper()) l=1 while l<len(signals): if signals[l][1]!='': subtext = etree.SubElement(new, signals[l][0]) subtext.text = signals[l][1] l+=1 elm.addprevious(new) added=True num=i print 'added ',signals[0][1] i+=1 if added==False: new = etree.Element('variable',name=signals[0][1].upper()) l=1 while l<len(signals): subtext = etree.SubElement(new, signals[l][0]) subtext.text = signals[l][1] l+=1 elm.addnext(new) added=True num=i print 'appended ',signals[0][1] #============= doc.write('VDB.xml',pretty_print=True) generateButtons(self,str(self.searchText.text()),num) return