Skip to content

Commit cb020a9

Browse files
committed
Creada GUI para la tabla del Switch (WIP)
1 parent fdbe9c7 commit cb020a9

File tree

2 files changed

+161
-3
lines changed

2 files changed

+161
-3
lines changed

Interface2.glade

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,4 +1244,111 @@ http://ddavo.me</property>
12441244
</object>
12451245
</child>
12461246
</object>
1247+
<object class="GtkApplicationWindow" id="window_switch-table">
1248+
<property name="can_focus">False</property>
1249+
<property name="window_position">center</property>
1250+
<child>
1251+
<object class="GtkBox" id="window_switch-table_box">
1252+
<property name="visible">True</property>
1253+
<property name="can_focus">False</property>
1254+
<property name="orientation">vertical</property>
1255+
<child>
1256+
<object class="GtkBox" id="window_switch_hbox">
1257+
<property name="visible">True</property>
1258+
<property name="can_focus">False</property>
1259+
<property name="margin_bottom">3</property>
1260+
<property name="homogeneous">True</property>
1261+
<child>
1262+
<object class="GtkLabel" id="window_switch_mac">
1263+
<property name="visible">True</property>
1264+
<property name="can_focus">False</property>
1265+
<property name="margin_left">5</property>
1266+
<property name="label" translatable="yes">MAC</property>
1267+
<attributes>
1268+
<attribute name="weight" value="ultraheavy"/>
1269+
</attributes>
1270+
</object>
1271+
<packing>
1272+
<property name="expand">False</property>
1273+
<property name="fill">True</property>
1274+
<property name="position">0</property>
1275+
</packing>
1276+
</child>
1277+
<child>
1278+
<object class="GtkLabel" id="window_switch_port">
1279+
<property name="visible">True</property>
1280+
<property name="can_focus">False</property>
1281+
<property name="margin_left">5</property>
1282+
<property name="margin_right">5</property>
1283+
<property name="label" translatable="yes">PORT</property>
1284+
<property name="justify">center</property>
1285+
<attributes>
1286+
<attribute name="weight" value="ultraheavy"/>
1287+
</attributes>
1288+
</object>
1289+
<packing>
1290+
<property name="expand">False</property>
1291+
<property name="fill">True</property>
1292+
<property name="position">1</property>
1293+
</packing>
1294+
</child>
1295+
<child>
1296+
<object class="GtkLabel" id="window_switch_ttl">
1297+
<property name="visible">True</property>
1298+
<property name="can_focus">False</property>
1299+
<property name="margin_right">5</property>
1300+
<property name="label" translatable="yes">TTL (s)</property>
1301+
<property name="justify">center</property>
1302+
<attributes>
1303+
<attribute name="weight" value="ultraheavy"/>
1304+
</attributes>
1305+
</object>
1306+
<packing>
1307+
<property name="expand">False</property>
1308+
<property name="fill">True</property>
1309+
<property name="position">2</property>
1310+
</packing>
1311+
</child>
1312+
</object>
1313+
<packing>
1314+
<property name="expand">False</property>
1315+
<property name="fill">True</property>
1316+
<property name="position">0</property>
1317+
</packing>
1318+
</child>
1319+
<child>
1320+
<object class="GtkGrid" id="window_switch-table_grid">
1321+
<property name="visible">True</property>
1322+
<property name="can_focus">False</property>
1323+
<property name="margin_left">5</property>
1324+
<property name="margin_right">5</property>
1325+
<property name="row_spacing">2</property>
1326+
<property name="column_homogeneous">True</property>
1327+
<child>
1328+
<placeholder/>
1329+
</child>
1330+
</object>
1331+
<packing>
1332+
<property name="expand">False</property>
1333+
<property name="fill">True</property>
1334+
<property name="position">1</property>
1335+
</packing>
1336+
</child>
1337+
<child>
1338+
<object class="GtkButton" id="window_switch-table_button">
1339+
<property name="label">gtk-close</property>
1340+
<property name="visible">True</property>
1341+
<property name="can_focus">True</property>
1342+
<property name="receives_default">True</property>
1343+
<property name="use_stock">True</property>
1344+
</object>
1345+
<packing>
1346+
<property name="expand">False</property>
1347+
<property name="fill">True</property>
1348+
<property name="position">2</property>
1349+
</packing>
1350+
</child>
1351+
</object>
1352+
</child>
1353+
</object>
12471354
</interface>

Main.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)