diff --git a/__init__.py b/__init__.py index 10e1b1a44..f367567ac 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1 @@ -__version__ = '0.0.9' +__version__ = '0.1.0' diff --git a/hnn_qt5.py b/hnn_qt5.py index 8696c976f..7abcbc3e0 100644 --- a/hnn_qt5.py +++ b/hnn_qt5.py @@ -825,18 +825,87 @@ def removeAllInputs (self): for i in range(len(self.ltabs)): self.removeCurrentInput() self.nprox = self.ndist = 0 + def IsProx (self,idx): + # is this evoked input proximal (True) or distal (False) ? + try: + d = self.ld[idx] + for k in d.keys(): + if k.count('evprox'): + return True + except: + pass + return False + + def getInputID (self,idx): + # get evoked input number of the evoked input associated with idx + try: + d = self.ld[idx] + for k in d.keys(): + lk = k.split('_') + if len(lk) >= 3: + return int(lk[2]) + except: + pass + return -1 + + def downShift (self,idx): + # downshift the evoked input ID, keys, values + d = self.ld[idx] + dnew = {} # new dictionary + newidx = 0 # new evoked input ID + for k,v in d.items(): + lk = k.split('_') + if len(lk) >= 3: + if lk[0]=='sigma': + newidx = int(lk[3])-1 + lk[3] = str(newidx) + else: + newidx = int(lk[2])-1 + lk[2] = str(newidx) + newkey = '_'.join(lk) + dnew[newkey] = v + if k in self.dqline: + self.dqline[newkey] = self.dqline[k] + del self.dqline[k] + self.ld[idx] = dnew + currtxt = self.tabs.tabText(idx) + newtxt = currtxt.split(' ')[0] + ' ' + str(newidx) + self.tabs.setTabText(idx,newtxt) + # print('d original:',d, 'd new:',dnew) + def removeInput (self,idx): + # remove the evoked input specified by idx if idx < 0 or idx > len(self.ltabs): return # print('removing input at index', idx) self.tabs.removeTab(idx) tab = self.ltabs[idx] self.ltabs.remove(tab) d = self.ld[idx] + + isprox = self.IsProx(idx) # is it a proximal input? + isdist = not isprox # is it a distal input? + inputID = self.getInputID(idx) # wht's the proximal/distal input number? + + # print('isprox,isdist,inputid',isprox,isdist,inputID) + for k in d.keys(): if k in self.dqline: del self.dqline[k] self.ld.remove(d) tab.setParent(None) + + # now downshift the evoked inputs (only proximal or only distal) that came after this one + # first get the IDs of the evoked inputs to downshift + lds = [] # list of inputs to downshift + for jdx in range(len(self.ltabs)): + if isprox and self.IsProx(jdx) and self.getInputID(jdx) > inputID: + #print('downshift prox',self.getInputID(jdx)) + lds.append(jdx) + elif isdist and not self.IsProx(jdx) and self.getInputID(jdx) > inputID: + #print('downshift dist',self.getInputID(jdx)) + lds.append(jdx) + for jdx in lds: self.downShift(jdx) # then do the downshifting + # print(self) # for testing def removeCurrentInput (self): # removes currently selected input