@@ -33,23 +33,36 @@ def tabularize():
3333
3434 # get the column headers
3535 data_types = []
36+ data_types .append ('id' )
3637 for key in root .findall ('.//{http://graphml.graphdrawing.org/xmlns}key' ):
3738 data_types .append (key .get ('id' ))
3839
3940 # configure table window
4041 window = Tk ()
4142 window .geometry ("1200x680" )
4243
44+ # configure framing for edit frame and table frame
45+ editFrame = Frame (window , width = 300 )
46+ editFrame .pack (side = "left" , fill = "y" )
47+
4348 tFrame = Frame (window )
44- tFrame .pack (fill = "both" )
49+ tFrame .pack (side = "left" , fill = "both" , expand = True )
4550
46- scroll = Scrollbar (tFrame )
47- scroll .pack (side = "right" , fill = "y" )
48-
49- treeview = Treeview (tFrame , show = "headings" , columns = data_types , yscrollcommand = scroll .set , height = 60 )
51+ # vertical scrollbar
52+ y_scrollbar = Scrollbar (tFrame , orient = "vertical" )
53+ y_scrollbar .pack (side = "right" , fill = "y" )
54+
55+ # horizontal scrollbar
56+ x_scrollbar = Scrollbar (tFrame , orient = "horizontal" )
57+ x_scrollbar .pack (side = "bottom" , fill = "x" )
58+
59+ # treeview
60+ treeview = Treeview (tFrame , show = "headings" , columns = data_types , yscrollcommand = y_scrollbar .set , xscrollcommand = x_scrollbar .set , height = 60 )
5061 treeview .pack (fill = "both" )
51-
52- scroll .config (command = treeview .yview )
62+
63+ # scrollbar configs
64+ y_scrollbar .config (command = treeview .yview )
65+ x_scrollbar .config (command = treeview .xview )
5366
5467 # set headers
5568 for col_name in data_types :
@@ -60,9 +73,44 @@ def tabularize():
6073 # insert nodes and set node values
6174 for node in root .findall ('.//{http://graphml.graphdrawing.org/xmlns}node' ):
6275 treeview .insert ('' , END , values = data_values )
76+ # set the id value of the node
77+ treeview .set (item = treeview .get_children ()[- 1 ], column = 'id' , value = node .get ('id' ))
78+ # set the data values of the node
6379 for data in node .findall ('.//{http://graphml.graphdrawing.org/xmlns}data' ):
6480 treeview .set (item = treeview .get_children ()[- 1 ], column = data .get ('key' ), value = data .text )
6581
82+ # create entries for each data_type other than the node's id
83+ entries = []
84+ for data_type in data_types :
85+ if data_type != "id" :
86+ label = Label (editFrame , text = f"{ data_type } " )
87+ label .pack ()
88+ entry = Entry (editFrame , width = 40 )
89+ entry .pack (padx = 5 )
90+ entries .append (entry )
91+
92+ # save entries to the treeview
93+ def save_entries ():
94+ if treeview .selection ()[0 ] is not None :
95+ for entry in entries :
96+ # index + 1 to avoid the id column
97+ treeview .set (item = treeview .selection ()[0 ], column = entries .index (entry )+ 1 , value = entry .get ())
98+
99+ # submit button for saving entries
100+ submit = Button (editFrame , text = "Submit" , command = save_entries )
101+ submit .pack (pady = 5 )
102+
103+ # autofill entries with data from selection
104+ def on_treeview_select (event ):
105+ selected_item = treeview .selection ()[0 ]
106+ item_data = treeview .item (selected_item , 'values' )
107+ for entry in entries :
108+ entry .delete (0 , END )
109+ # index + 1 to avoid the id column
110+ entry .insert (0 , item_data [entries .index (entry )+ 1 ])
111+
112+ treeview .bind ('<<TreeviewSelect>>' , on_treeview_select )
113+
66114 window .mainloop ()
67115
68116# create plot from graphml file
0 commit comments