Skip to content

Commit

Permalink
fix issue with removing middle proximal/distal evoked inputs by downs…
Browse files Browse the repository at this point in the history
…hifting later evoked inputs
  • Loading branch information
samnemo committed Nov 15, 2018
1 parent 5f4d6b4 commit 773fba3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.9'
__version__ = '0.1.0'
69 changes: 69 additions & 0 deletions hnn_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 773fba3

Please sign in to comment.