@@ -962,42 +962,58 @@ class w_switch_table(Gtk.ApplicationWindow):
962962 def __init__ (self , switch ):
963963 self .link = switch
964964 builder = switch .builder
965- builder .get_object ("window_switch_hbox" ).override_background_color (Gtk .StateType .NORMAL , Gdk .RGBA (* hex_to_rgba ("#FF9800" )))
965+ # builder.get_object("window_switch_hbox").override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*hex_to_rgba("#FF9800")))
966966 builder .get_object ("window_switch-table_button" ).connect ("clicked" , self .hide )
967967 builder .get_object ("window_switch-table" ).connect ("delete-event" , self .hide )
968- self .labels = []
968+ self .store = Gtk .ListStore (str ,int ,int ,int )
969+
970+ self .view = builder .get_object ("window_switch-table-TreeView" )
971+ self .view .set_model (self .store )
972+ for i , column_title in enumerate (["MAC" , "Puerto" , "TTL (s)" ]):
973+ renderer = Gtk .CellRendererText ()
974+ column = Gtk .TreeViewColumn (column_title , renderer , text = i )
975+ self .view .append_column (column )
976+ self .ticking = False
977+ builder .get_object ("window_switch-table" ).set_keep_above (True )
969978
970979 def show (self , * a ):
971- self .link .builder .get_object ("window_switch-table" ).show_all ()
972980 self .ticking = True
973981 GObject .timeout_add (1001 , self .tick )
982+ for row in self .store :
983+ row [2 ] = row [3 ] - time .time ()
984+ self .link .builder .get_object ("window_switch-table" ).show_all ()
974985
975986 def hide (self , window , * event ):
976987 self .link .builder .get_object ("window_switch-table" ).hide ()
977988 self .ticking = False
978989 return True
979990 def append (self , lst ):
980- grid = self .link .builder .get_object ("window_switch-table_grid" )
981- grid .insert_row (0 )
982- for i in range (len (lst )):
983- if i == 0 :
984- readmac = str (hex (lst [i ])).upper ().replace ("0X" , "" )
985- readmac = ":" .join ([readmac [i * 2 :i * 2 + 2 ] for i ,bl in enumerate (readmac [::2 ])])
986- child = Gtk .Label .new (readmac )
987- elif i == 2 :
988- child = Gtk .Label .new (str (int (lst [i ]- time .time ())))
989- child .exp = lst [i ]
990- self .labels .append (child )
991- else :
992- child = Gtk .Label .new (str (lst [i ]))
993- grid .attach (child , i , 0 , 1 , 1 )
994- child .show ()
995- print ("Appending" , child )
991+ lst .append (lst [2 ])
992+ for row in self .store :
993+ row [2 ] = row [3 ] - time .time ()
994+ row = self .store .append (lst )
995+ print (self .view .get_property ("visible" ))
996+ if self .view .get_property ("visible" ) == True and self .ticking == False :
997+ self .ticking = True
998+ GObject .timeout_add (1001 , self .tick )
999+
9961000 def tick (self ):
997- for label in self .labels :
998- label .set_label (str (int (label .exp - time .time ())))
1001+ for row in self .store :
1002+ row [2 ] = row [3 ] - time .time ()
1003+ if row [2 ] <= 0 :
1004+ try :
1005+ self .store .remove (row .iter )
1006+ self .link .table .remove (row )
1007+ except :
1008+ pass
1009+ if len (self .store ) == 0 :
1010+ self .ticking = False
9991011 return self .ticking
10001012 def remove (self , lst ):
1013+ for row in self .store :
1014+ if row == lst :
1015+ self .store .remove (row .iter )
1016+ self .link .table
10011017 pass
10021018 #Get children, if children.get_label() == MAC, delete it.
10031019
@@ -1012,7 +1028,7 @@ def __init__(self, x, y, *args, name="Default", maxconnections=5, ip=None):
10121028 ObjetoBase .__init__ (self , x , y , self .objectype , name = name , maxconnections = maxconnections )
10131029 self .x = x
10141030 self .y = y
1015- self .timeout = 100 #Segundos
1031+ self .timeout = 20 #Segundos
10161032
10171033 for p in range (self .max_connections ):
10181034 self .Port (self )
@@ -1052,16 +1068,26 @@ def packet_received(self, pck, port=None):
10521068 macs = "{0:0112b}" .format (pck .frame )[6 * 8 + 1 :6 * 16 + 1 ]
10531069
10541070 #LO PRIMERO: AÑADIRLO A LA TABLA
1071+ readmac = str (hex (int (macs ,2 ))).upper ().replace ("0X" , "" )
1072+ readmac = ":" .join ([readmac [i * 2 :i * 2 + 2 ] for i ,bl in enumerate (readmac [::2 ])])
10551073
1056- if int (macs ,2 ) not in [x [0 ] for x in self .table ]:
1057- tmp = [int (macs ,2 ), port , int (time .time ()+ self .timeout )]
1058- self .table .append (tmp )
1059- self .wtable .append (tmp )
10601074 for tab in self .table :
10611075 if tab [2 ] <= time .time ():
10621076 print ("Ha llegado tu hora" )
10631077 self .table .remove (tab )
10641078 self .wtable .remove (tab )
1079+ if tab [0 ] == int (macd ,2 ):
1080+ print ("TAB[0] == mcd" )
1081+ tab [2 ] = int (time .time ()+ self .timeout )
1082+ for row in self .wtable .store :
1083+ print (row [0 ], tab [0 ])
1084+ if int (row [0 ].replace (":" ,"" ),16 ) == tab [0 ]:
1085+ row [3 ] = int (time .time ()+ self .timeout )
1086+ if int (macs ,2 ) not in [x [0 ] for x in self .table ]:
1087+ tmp = [int (macs ,2 ), port , int (time .time ()+ self .timeout )]
1088+ self .table .append (tmp )
1089+ tmp = [readmac , port , int (time .time ()+ self .timeout )]
1090+ self .wtable .append (tmp )
10651091
10661092 ################################
10671093
@@ -1120,6 +1146,8 @@ def debug(self, *args):
11201146 for row in self .table :
11211147 if row [1 ] == None :
11221148 row [1 ] = "None"
1149+ if int (row [2 ]- time .time ()) <= 0 :
1150+ self .table .remove (row )
11231151 print (row_format .format (row [0 ], row [1 ], int (row [2 ]- int (time .time ()))))
11241152
11251153#¿Tengo permisos de escritura?, no se si tendré permisos
@@ -1624,7 +1652,7 @@ def __init__(self):
16241652 pass
16251653
16261654 def create (r , sourceip , desti_ip , * n , payload = int ( 4.3 * 10 ** 19 ) << 6 | 42 , \
1627- flags = 0b010 , ttl = 10 ):
1655+ flags = 0b010 , ttl = 32 ):
16281656 self = Ping ()
16291657 if r == 0 :
16301658 Type = 8
0 commit comments