@@ -958,6 +958,49 @@ def is_available(self):
958958 return True
959959 return False
960960
961+ class w_switch_table (Gtk .ApplicationWindow ):
962+ def __init__ (self , switch ):
963+ self .link = switch
964+ builder = switch .builder
965+ builder .get_object ("window_switch_hbox" ).override_background_color (Gtk .StateType .NORMAL , Gdk .RGBA (* hex_to_rgba ("#FF9800" )))
966+ builder .get_object ("window_switch-table_button" ).connect ("clicked" , self .hide )
967+ builder .get_object ("window_switch-table" ).connect ("delete-event" , self .hide )
968+ self .labels = []
969+
970+ def show (self , * a ):
971+ self .link .builder .get_object ("window_switch-table" ).show_all ()
972+ self .ticking = True
973+ GObject .timeout_add (1001 , self .tick )
974+
975+ def hide (self , window , * event ):
976+ self .link .builder .get_object ("window_switch-table" ).hide ()
977+ self .ticking = False
978+ return True
979+ 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 )
996+ def tick (self ):
997+ for label in self .labels :
998+ label .set_label (str (int (label .exp - time .time ())))
999+ return self .ticking
1000+ def remove (self , lst ):
1001+ pass
1002+ #Get children, if children.get_label() == MAC, delete it.
1003+
9611004 def __init__ (self , x , y , * args , name = "Default" , maxconnections = 5 , ip = None ):
9621005 self .objectype = "Switch"
9631006 self .portid = 0
@@ -969,15 +1012,20 @@ def __init__(self, x, y, *args, name="Default", maxconnections=5, ip=None):
9691012 ObjetoBase .__init__ (self , x , y , self .objectype , name = name , maxconnections = maxconnections )
9701013 self .x = x
9711014 self .y = y
972- self .timeout = 900 #Segundos
1015+ self .timeout = 100 #Segundos
9731016
9741017 for p in range (self .max_connections ):
9751018 self .Port (self )
9761019 print (self .pall )
9771020
9781021 self .table = [
9791022 #[MAC, port, expiration]
980- ] #Ya se usará
1023+ ]
1024+ self .wtable = self .w_switch_table (self )
1025+ child = Gtk .MenuItem .new_with_label ("Routing Table" )
1026+ self .builder .get_object ("grid_rclick" ).append (child )
1027+ child .connect ("activate" , self .wtable .show )
1028+ child .show ()
9811029
9821030 def deleteobject (self , * jhafg ):
9831031 self .image .destroy ()
@@ -1006,11 +1054,14 @@ def packet_received(self, pck, port=None):
10061054 #LO PRIMERO: AÑADIRLO A LA TABLA
10071055
10081056 if int (macs ,2 ) not in [x [0 ] for x in self .table ]:
1009- self .table .append ([int (macs ,2 ), port , int (time .time ()+ self .timeout )])
1057+ tmp = [int (macs ,2 ), port , int (time .time ()+ self .timeout )]
1058+ self .table .append (tmp )
1059+ self .wtable .append (tmp )
10101060 for tab in self .table :
10111061 if tab [2 ] <= time .time ():
10121062 print ("Ha llegado tu hora" )
10131063 self .table .remove (tab )
1064+ self .wtable .remove (tab )
10141065
10151066 ################################
10161067
0 commit comments