Skip to content

Commit

Permalink
Try another method to show row numbers in treeview:
Browse files Browse the repository at this point in the history
+    treeviewA.heading(columns[0], text="SN")
     for i in range(len(agents[0])): #np.shape(arr1D_2D(agents))[1]):  # bind function: enable sorting in table headings
-        treeviewA.heading(columns[i], text=agents[0][i])
+        treeviewA.heading(columns[i+1], text=agents[0][i])
     for i in range(1, len(agents)): #
-        agents[i][0]=str(i)+"# "+agents[i][0]
+        #agents[i][0]=str(i)+"# "+agents[i][0]
         try:
-            treeviewA.insert('', i, values=tuple(agents[i])) #[0], agents[i][1], agents[i][2], agents[i][3], agents[i][4], agents[i][5],  agents[i][6], agents[i][7], agents[i][8], agents[i][9], agents[i][10]))
+            treeviewA.insert('', i, values=tuple(["#"+str(i-1)]+agents[i])) #[0], agents[i][1], agents[i][2], agents[i][3], agents[i][4], agents[i][5],  agents[i][6], agents[i][7], agents[i][8], agents[i][9], agents[i][10]))
         except:
             treeviewA.insert('', i, values=(i))

Add functions of add_agent() and del_agent().
Remove functions of newrow_A() and deleterow_A().

Signed-off-by: godisreal <[email protected]>
  • Loading branch information
godisreal committed Oct 24, 2024
1 parent e2bacbc commit f70eb7f
Showing 1 changed file with 122 additions and 83 deletions.
205 changes: 122 additions & 83 deletions treeviewCSV_crowdEgress.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def readCrowdEgressCSV(FileName, debug=True, marginTitle=1):
agent2exitFeatures, lowerIndex, upperIndex = getData(FileName, '&agent2exit')
Num_Agent2Exit=len(agent2exitFeatures)-marginTitle
if Num_Agent2Exit <= 0:
agent2exitFeatures, lowerIndex, upperIndex = getData(FileName, '&ped2exit')
agent2exitFeatures, lowerIndex, upperIndex = getData(FileName, '&Agent2Exit')
Num_Agent2Exit=len(agent2exitFeatures)-marginTitle
if Num_Agent2Exit <= 0:
agent2exitFeatures, lowerIndex, upperIndex = getData(FileName, '&Ped2Exit')
Expand Down Expand Up @@ -241,15 +241,15 @@ def file_new(event=None):
try:
treeviewA2E.insert('', i, values=tuple(agent2exit[i])) #[0], agent2exit[i][1], agent2exit[i][2], agent2exit[i][3], agent2exit[i][4], agent2exit[i][5], agent2exit[i][6], agent2exit[i][7], agent2exit[i][8], agent2exit[i][9], agent2exit[i][10]))
except:
treeviewA.insert('', i, values=(i))
treeviewA2E.insert('', i, values=(i))

for i in range(len(agentgroup[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewAG.heading(columns[i], text=agentgroup[0][i])
for i in range(1, len(agentgroup)): #
try:
treeviewAG.insert('', i, values=tuple(agentgroup[i])) #[0], agentgroup[i][1], agentgroup[i][2], agentgroup[i][3], agentgroup[i][4], agentgroup[i][5], agentgroup[i][6], agentgroup[i][7], agentgroup[i][8], agentgroup[i][9], agentgroup[i][10]))
except:
treeviewA.insert('', i, values=(i))
treeviewAG.insert('', i, values=(i))

for i in range(len(walls[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewW.heading(columns[i], text=walls[0][i])
Expand Down Expand Up @@ -319,66 +319,73 @@ def file_open(event=None):
treeviewW.update()
treeviewE2D.update()

treeviewA.column(chr(65), width=130, anchor='center')
treeviewA2E.column(chr(65), width=130, anchor='center')
treeviewAG.column(chr(65), width=130, anchor='center')

#treeviewA.column(chr(66), width=130, anchor='center')
#treeviewA2E.column(chr(66), width=130, anchor='center')
#treeviewAG.column(chr(66), width=130, anchor='center')

treeviewA.heading(columns[0], text="SN")
for i in range(len(agents[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewA.heading(columns[i], text=agents[0][i])
treeviewA.heading(columns[i+1], text=agents[0][i])
for i in range(1, len(agents)): #
agents[i][0]=str(i)+"# "+agents[i][0]
#agents[i][0]=str(i)+"# "+agents[i][0]
try:
treeviewA.insert('', i, values=tuple(agents[i])) #[0], agents[i][1], agents[i][2], agents[i][3], agents[i][4], agents[i][5], agents[i][6], agents[i][7], agents[i][8], agents[i][9], agents[i][10]))
treeviewA.insert('', i, values=tuple(["#"+str(i-1)]+agents[i])) #[0], agents[i][1], agents[i][2], agents[i][3], agents[i][4], agents[i][5], agents[i][6], agents[i][7], agents[i][8], agents[i][9], agents[i][10]))
except:
treeviewA.insert('', i, values=(i))

treeviewA.heading(columns[0], text="SN")
for i in range(len(agent2exit[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewA2E.heading(columns[i], text=agent2exit[0][i])
treeviewA2E.heading(columns[i+1], text=agent2exit[0][i])
for i in range(1, len(agent2exit)): #
agent2exit[i][0]=str(i)+"# "+agent2exit[i][0]
#agent2exit[i][0]=str(i)+"# "+agent2exit[i][0]
try:
treeviewA2E.insert('', i, values=tuple(agent2exit[i])) #[0], agent2exit[i][1], agent2exit[i][2], agent2exit[i][3], agent2exit[i][4], agent2exit[i][5], agent2exit[i][6], agent2exit[i][7], agent2exit[i][8], agent2exit[i][9], agent2exit[i][10]))
treeviewA2E.insert('', i, values=tuple(["#"+str(i-1)]+agent2exit[i])) #[0], agent2exit[i][1], agent2exit[i][2], agent2exit[i][3], agent2exit[i][4], agent2exit[i][5], agent2exit[i][6], agent2exit[i][7], agent2exit[i][8], agent2exit[i][9], agent2exit[i][10]))
except:
treeviewA.insert('', i, values=(i))

treeviewA.heading(columns[0], text="SN")
for i in range(len(agentgroup[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewAG.heading(columns[i], text=agentgroup[0][i])
treeviewAG.heading(columns[i+1], text=agentgroup[0][i])
for i in range(1, len(agentgroup)): #
agentgroup[i][0]=str(i)+"# "+agentgroup[i][0]
#agentgroup[i][0]=str(i)+"# "+agentgroup[i][0]
try:
treeviewAG.insert('', i, values=tuple(agentgroup[i])) #[0], agentgroup[i][1], agentgroup[i][2], agentgroup[i][3], agentgroup[i][4], agentgroup[i][5], agentgroup[i][6], agentgroup[i][7], agentgroup[i][8], agentgroup[i][9], agentgroup[i][10]))
treeviewAG.insert('', i, values=tuple(["#"+str(i-1)]+agentgroup[i])) #[0], agentgroup[i][1], agentgroup[i][2], agentgroup[i][3], agentgroup[i][4], agentgroup[i][5], agentgroup[i][6], agentgroup[i][7], agentgroup[i][8], agentgroup[i][9], agentgroup[i][10]))
except:
treeviewA.insert('', i, values=(i))

treeviewA.heading(columns[0], text="SN")
for i in range(len(walls[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewW.heading(columns[i], text=walls[0][i])
treeviewW.heading(columns[i+1], text=walls[0][i])
for i in range(1, len(walls)): #
try:
treeviewW.insert('', i, values=tuple(walls[i])) #[0], walls[i][1], walls[i][2], walls[i][3], walls[i][4], walls[i][5], walls[i][6], walls[i][7], walls[i][8]))
treeviewW.insert('', i, values=tuple(["#"+str(i-1)]+walls[i])) #[0], walls[i][1], walls[i][2], walls[i][3], walls[i][4], walls[i][5], walls[i][6], walls[i][7], walls[i][8]))
except:
treeviewW.insert('', i, values=(i))


treeviewA.heading(columns[0], text="SN")
for i in range(len(exits[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewE.heading(columns[i], text=exits[0][i])
treeviewE.heading(columns[i+1], text=exits[0][i])
for i in range(1, len(exits)): #
try:
treeviewE.insert('', i, values=tuple(exits[i])) #[0], exits[i][1], exits[i][2], exits[i][3], exits[i][4], exits[i][5], exits[i][6], exits[i][7], exits[i][8]))
treeviewE.insert('', i, values=tuple(["#"+str(i-1)]+exits[i])) #[0], exits[i][1], exits[i][2], exits[i][3], exits[i][4], exits[i][5], exits[i][6], exits[i][7], exits[i][8]))
except:
treeviewE.insert('', i, values=(i))


treeviewA.heading(columns[0], text="SN")
for i in range(len(doors[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewD.heading(columns[i], text=doors[0][i])
treeviewD.heading(columns[i+1], text=doors[0][i])
for i in range(1, len(doors)): #
try:
treeviewD.insert('', i, values=tuple(doors[i])) #[0], doors[i][1], doors[i][2], doors[i][3], doors[i][4], doors[i][5], doors[i][6], doors[i][7], doors[i][8]))
treeviewD.insert('', i, values=tuple(["#"+str(i-1)]+doors[i])) #[0], doors[i][1], doors[i][2], doors[i][3], doors[i][4], doors[i][5], doors[i][6], doors[i][7], doors[i][8]))
except:
treeviewD.insert('', i, values=(i))

treeviewA.heading(columns[0], text="SN")
for i in range(len(exit2door[0])): #np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewE2D.heading(columns[i], text=exit2door[0][i])
treeviewE2D.heading(columns[i+1], text=exit2door[0][i])
for i in range(1, len(exit2door)): #
try:
treeviewE2D.insert('', i, values=tuple(exit2door[i])) #[0], exit2door[i][1], exit2door[i][2], exit2door[i][3], exit2door[i][4], exit2door[i][5], exit2door[i][6], exit2door[i][7], exit2door[i][8]))
treeviewE2D.insert('', i, values=tuple(["#"+str(i-1)]+exit2door[i])) #[0], exit2door[i][1], exit2door[i][2], exit2door[i][3], exit2door[i][4], exit2door[i][5], exit2door[i][6], exit2door[i][7], exit2door[i][8]))
except:
treeviewE2D.insert('', i, values=(i))

Expand Down Expand Up @@ -742,63 +749,95 @@ def saveedit():
okb = Button(root, text=str(item_text[0])+'|'+agents[0][cn-1]+': <Save Changes>', width=56, command=saveedit)
okb.pack() #place(x=90+(cn-1)*242,y=2+rn*20)

def newrow_A():

def add_agent(event):
global agents
for item in treeviewA.selection():

#item = I001
item_text = treeviewA.item(item, "values")
print(item_text)
print(item)
#print(item_text[0:2]) # Output the column number selected by users
#column= treeviewA.identify_column(event.x)# column
#row = treeviewA.identify_row(item) # row

#cn = int(str(column).replace('#',''))
#rn = int(str(item).replace('I',''), base=16)
try:
treeviewA.insert('', len(agents), values=(item_text[0], item_text[1], item_text[2],item_text[3], item_text[4], item_text[5],item_text[6], item_text[7], item_text[8], item_text[9], item_text[10])) #dataCSV[i][3], dataCSV[i][4], dataCSV[i][5], dataCSV[i][6], dataCSV[i][7], dataCSV[i][8], dataCSV[i][9], dataCSV[i][10]))
agents.append([item_text[0], item_text[1], item_text[2],item_text[3], item_text[4], item_text[5],item_text[6], item_text[7], item_text[8], item_text[9], item_text[10]])
#npzVE = np.concatenate((npzVE, tempVE), axis=0)
except:
if len(agents)==1:
treeviewA.insert('', len(agents), values=(tuple(['agent'+str(len(agents)-1), '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']))) #['agent'+str(len(agents))]+agents[-1]))
agents.append(['agent'+str(len(agents)-1), '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'])
else:
treeviewA.insert('', len(agents), values=(tuple(agents[-1])))
agents.append(agents[-1])

#treeviewA.insert('', len(name)-1, values=(name[len(name)-1], pos[len(name)-1], vel[len(name)-1]))
print("len(agents)")
treeviewA.update()
column= treeviewA.identify_column(event.x)# column
row = treeviewA.identify_row(event.y) # row

cn = int(str(column).replace('#',''))
rn = int(str(row).replace('I',''), base=16)
temp = item_text[0].split(" ")
rn = int(temp[0].strip("#"))

#name.append('NoName')
#pos.append('IP')
#vel.append('Trial')
#treeviewA.insert('', len(name)-1, values=(name[len(name)-1], pos[len(name)-1], vel[len(name)-1]))
#treeviewA.update()
print("cn:", cn)
print("rn:", rn)

agents.insert(rn, agents[rn])
agent2exit.insert(rn, agent2exit[rn])
agentgroup.insert(rn, agentgroup[rn])

#newb.place(x=120, y=20) #y=(len(name)-1)*20+45)
#newb.update()
treeviewA.delete(*treeviewA.get_children())
treeviewA2E.delete(*treeviewA2E.get_children())
treeviewAG.delete(*treeviewAG.get_children())
treeviewA.update()
treeviewA2E.update()
treeviewAG.update()



def deleterow_A():
def del_agent():

global agents
for item in treeviewA.selection():

#item = I001
item_text = treeviewA.item(item, "values")
print(item_text)
print(item)
#print(item_text[0:2]) # Output the column number selected by users

#column= treeviewA.identify_column(event.x)# column
#row = treeviewA.identify_row(event.y) # row

#cn = int(str(column).replace('#',''))
rn = int(str(item).replace('I',''), base=16)
try:
treeviewA.delete(item) #dataCSV[i][3], dataCSV[i][4], dataCSV[i][5], dataCSV[i][6], dataCSV[i][7], dataCSV[i][8], dataCSV[i][9], dataCSV[i][10]))
except:
treeviewA.delete(item)
#treeviewA.insert('', len(name)-1, values=(name[len(name)-1], pos[len(name)-1], vel[len(name)-1]))
treeviewA.update()
#rn = int(str(row).replace('I',''), base=16)
temp = item_text[0].split(" ")
rn = int(temp[0].strip("#"))

#print("cn:", cn)
print("rn:", rn)

del agents[rn]
del agent2exit[rn]
del agentgroup[rn]

treeviewA.delete(*treeviewA.get_children())
treeviewA2E.delete(*treeviewA2E.get_children())
treeviewAG.delete(*treeviewAG.get_children())
treeviewA.update()
treeviewA2E.update()
treeviewAG.update()

for i in range(1, len(agents)): #
agents[i][0]=str(i)+"# "+agents[i][0]
try:
treeviewA.insert('', i, values=tuple(agents[i])) #[0], agents[i][1], agents[i][2], agents[i][3], agents[i][4], agents[i][5], agents[i][6], agents[i][7], agents[i][8], agents[i][9], agents[i][10]))
except:
treeviewA.insert('', i, values=(i))

for i in range(1, len(agent2exit)): #
agent2exit[i][0]=str(i)+"# "+agent2exit[i][0]
try:
treeviewA2E.insert('', i, values=tuple(agent2exit[i])) #[0], agent2exit[i][1], agent2exit[i][2], agent2exit[i][3], agent2exit[i][4], agent2exit[i][5], agent2exit[i][6], agent2exit[i][7], agent2exit[i][8], agent2exit[i][9], agent2exit[i][10]))
except:
treeviewA2E.insert('', i, values=(i))

for i in range(len(agentgroup[0])):
#np.shape(arr1D_2D(agents))[1]): # bind function: enable sorting in table headings
treeviewAG.heading(columns[i], text=agentgroup[0][i])
for i in range(1, len(agentgroup)): #
agentgroup[i][0]=str(i)+"# "+agentgroup[i][0]
try:
treeviewAG.insert('', i, values=tuple(agentgroup[i])) #[0], agentgroup[i][1], agentgroup[i][2], agentgroup[i][3], agentgroup[i][4], agentgroup[i][5], agentgroup[i][6], agentgroup[i][7], agentgroup[i][8], agentgroup[i][9], agentgroup[i][10]))
except:
treeviewAG.insert('', i, values=(i))


def set_cell_value_W(event):
global walls
pass
Expand Down Expand Up @@ -827,50 +866,50 @@ def set_cell_value_W(event):
menubar.add_cascade(label="File", menu=file_menu)

add_menu = Menu(menubar, tearoff=0, bg="lightgrey", fg="black")
add_menu.add_command(label="Add Agent", command=newrow_A, accelerator="Ctrl+A")
add_menu.add_command(label="Add Wall", command=newrow_A)
add_menu.add_command(label="Add Exit", command=newrow_A)
add_menu.add_command(label="Add Door", command=newrow_A)
add_menu.add_command(label="Add Agent", command=add_agent, accelerator="Ctrl+A")
add_menu.add_command(label="Add Wall", command=add_agent)
add_menu.add_command(label="Add Exit", command=add_agent)
add_menu.add_command(label="Add Door", command=add_agent)
menubar.add_cascade(label="Add", menu=add_menu)

delete_menu = Menu(menubar, tearoff=0, bg="lightgrey", fg="black")
delete_menu.add_command(label="Delete Agent", command=deleterow_A, accelerator="Ctrl+D")
delete_menu.add_command(label="Delete Agent", command=del_agent, accelerator="Ctrl+D")
menubar.add_cascade(label="Delete", menu=delete_menu)

newA = Button(frameAgent, text='New Agent', width=20, command=newrow_A)
newA = Button(frameAgent, text='New Agent', width=20, command=add_agent)
newA.pack() #place(x=120,y=20 ) #(len(name)-1)*20+45)

delA = Button(frameAgent, text='Delete Agent', width=20, command=deleterow_A)
delA = Button(frameAgent, text='Delete Agent', width=20, command=del_agent)
delA.pack() #place(x=120,y=20 )

newA2E = Button(frameAgent2Exit, text='New Agent2Exit', width=20, command=newrow_A)
newA2E = Button(frameAgent2Exit, text='New Agent2Exit', width=20, command=add_agent)
newA2E.pack() #place(x=120,y=20 ) #(len(name)-1)*20+45)

delA2E = Button(frameAgent2Exit, text='Delete Agent2Exit', width=20, command=deleterow_A)
delA2E = Button(frameAgent2Exit, text='Delete Agent2Exit', width=20, command=del_agent)
delA2E.pack() #place(x=120,y=20 )

newAG = Button(frameAgentGroup, text='New AgentGroup', width=20, command=newrow_A)
newAG = Button(frameAgentGroup, text='New AgentGroup', width=20, command=add_agent)
newAG.pack() #place(x=120,y=20 ) #(len(name)-1)*20+45)

delAG = Button(frameAgentGroup, text='Delete AgentGroup', width=20, command=deleterow_A)
delAG = Button(frameAgentGroup, text='Delete AgentGroup', width=20, command=del_agent)
delAG.pack() #place(x=120,y=20 )

newW = Button(frameWall, text='New Wall', width=20, command=newrow_A)
newW = Button(frameWall, text='New Wall', width=20, command=add_agent)
newW.pack() #place(x=120,y=20 ) #(len(name)-1)*20+45)

delW = Button(frameWall, text='Delete Wall', width=20, command=deleterow_A)
delW = Button(frameWall, text='Delete Wall', width=20, command=del_agent)
delW.pack() #place(x=120,y=20 )

newE = Button(frameExit, text='New Exit', width=20, command=newrow_A)
newE = Button(frameExit, text='New Exit', width=20, command=add_agent)
newE.pack() #place(x=120,y=20 ) #(len(name)-1)*20+45)

delE = Button(frameExit, text='Delete Exit', width=20, command=deleterow_A)
delE = Button(frameExit, text='Delete Exit', width=20, command=del_agent)
delE.pack() #place(x=120,y=20 )

newD = Button(frameDoor, text='New Door', width=20, command=newrow_A)
newD = Button(frameDoor, text='New Door', width=20, command=add_agent)
newD.pack() #place(x=120,y=20 ) #(len(name)-1)*20+45)

delD = Button(frameDoor, text='Delete Door', width=20, command=deleterow_A)
delD = Button(frameDoor, text='Delete Door', width=20, command=del_agent)
delD.pack() #place(x=120,y=20 )

root.mainloop()

0 comments on commit f70eb7f

Please sign in to comment.