-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (77 loc) · 2.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
from kivy.support import install_twisted_reactor
install_twisted_reactor()
import os
import signal
import sys
import subprocess
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.factory import Factory
from leer_struct import buscar_estructura
from threading import Thread
TMensaje = buscar_estructura(
'./c/comm.h',
'TMensaje'
)
from twisted.internet import protocol, reactor
class EscuchaC(protocol.Protocol):
def __init__(self, app):
self.app = app
def datagramReceived(self, data, direccion):
print(len(data))
m = TMensaje()
m.unpack(data)
self.app.llego_mensaje(m)
print TMensaje
class Ventana(Widget):
pass
class VisualApp(App):
procesos = {}
def build(self):
reactor.listenUDP(2016, EscuchaC(self))
return Ventana()
def matar_a_todos(self):
area_visualizacion = self.root.ids.vis
for pid, grafico in self.procesos.iteritems():
try:
os.kill(pid, signal.SIGTERM)
except:
pass
area_visualizacion.remove_widget(grafico)
self.procesos = {}
def compilar(self):
subprocess.call(
'cd c && make clean', shell=True)
subprocess.call(
'cd c && make', shell=True)
def llego_mensaje(self, m):
'''
m es del tipo TMensaje o sea que tiene
todo lo que escibimos en c/comm.h adentro
del struct {} TMensaje
'''
area_visualizacion = self.root.ids.vis
if not m.pid in self.procesos:
grafico = Factory.Proceso(
# Agregar un elemento a la pantalla
x=area_visualizacion.x + m.x,
y=area_visualizacion.y + m.y,
source=m.imagen.strip('\x00')
)
area_visualizacion.add_widget(grafico)
self.procesos[m.pid] = grafico
else:
proceso = self.procesos[m.pid]
if m.estado == -1:
area_visualizacion.remove_widget(
proceso
)
del self.procesos[m.pid]
proceso.x = m.x + area_visualizacion.x
proceso.y = m.y + area_visualizacion.y
proceso.source = m.imagen.strip('\x00')
if __name__ == '__main__':
VisualApp().run()