-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifietecsa.py
147 lines (127 loc) · 6.45 KB
/
wifietecsa.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# coding=UTF-8
import configparser
import os
import threading
import raywifietecsaclass
import usuarios
import __about__
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
from os.path import dirname as updir
directorio = updir(os.path.abspath(__file__))
UI_FILE = directorio+"/ventana.glade"
os.environ["__version__"] = __about__.__version__
class WifiEtecsa:
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file(UI_FILE)
self.builder.connect_signals(self)
self._window = self.builder.get_object('window')
self._window.show_all()
self._ventanaUsuarios = usuarios.Ventana(self, Gtk, GLib, self.builder)
self._loginLogout = self.builder.get_object('loginLogout')
self._comboUsuarios = self.builder.get_object('comboUsuarios')
self._labelEstado = self.builder.get_object('labelEstado')
self._labelTiempo = self.builder.get_object('labelTiempo')
self._botonTiempo = self.builder.get_object('botonTiempo')
self._botonEstado = self.builder.get_object('botonEstado')
self._botonEstadoIcon = self.builder.get_object('image2')
self.cargarConfiguracion()
self._raywifi = raywifietecsaclass.RayWifiEtecsa()
self._cargandoConfig = False
self._saldo = ""
try:
usuario = self._config['USERS']["USER"+self._comboUsuarios.get_active_id()]
contrasena = self._config['USERS']["PASS"+self._comboUsuarios.get_active_id()]
except:
self._comboUsuarios.set_active_id("0")
usuario = self._config['USERS']["USER0"]
contrasena = self._config['USERS']["PASS0"]
threading.Thread(target=self.actualizarSaldo, args=(usuario,contrasena, )).start()
def on_loginLogout_button_press_event(self, loginLogout, gparam):
usuario = self._config['USERS']["USER"+self._comboUsuarios.get_active_id()]
contrasena = self._config['USERS']["PASS"+self._comboUsuarios.get_active_id()]
if loginLogout.get_active():
cerrarSesion = self._raywifi.logout()
if cerrarSesion == "Cerrado con éxito":
self._botonEstadoIcon.set_from_icon_name("network-wired-disconnected-symbolic", Gtk.IconSize.BUTTON)
else:
self._botonEstadoIcon.set_from_icon_name("network-wired-error-symbolic", Gtk.IconSize.BUTTON)
self._labelEstado.set_text(cerrarSesion)
threading.Thread(target=self.actualizarSaldo, args=(usuario,contrasena, "dimgray", )).start()
else:
self._labelEstado.set_text("Iniciando...")
textConexion = self._raywifi.login(usuario, contrasena)
self._labelEstado.set_text(textConexion)
if textConexion == "Usted está conectado":
self._botonEstadoIcon.set_from_icon_name("network-wired-symbolic", Gtk.IconSize.BUTTON)
else:
self._botonEstadoIcon.set_from_icon_name("network-wired-disconnected-symbolic", Gtk.IconSize.BUTTON)
self._labelTiempo.set_text("")
threading.Thread(target=self.actualizarSaldo, args=(usuario,contrasena, )).start()
def actualizarSaldo(self, usuario, contrasena, color_font=""):
GLib.idle_add(self._labelTiempo.set_markup, f'<b><span color=\"goldenrod\">--:--:--</span></b>')
saldo = self._raywifi.saldo(usuario, contrasena)
horas, minutos = saldo.split(":")[0:2]
color = "darkgreen"
minutos = int(minutos) + int(horas)*60
if minutos <= 5:
color = "red"
if minutos == 0:
color = "black"
if color_font:
color = color_font
GLib.idle_add(self._labelTiempo.set_markup, f'<b><span color=\"{color}\">{saldo}</span></b>')
def actualizarEstado(self):
estado = self._raywifi.status()
if estado == "Conectado":
GLib.idle_add(self._botonEstadoIcon.set_from_icon_name, "network-wired-symbolic", Gtk.IconSize.BUTTON)
else:
GLib.idle_add(self._botonEstadoIcon.set_from_icon_name, "network-wired-disconnected-symbolic", Gtk.IconSize.BUTTON)
GLib.idle_add(self._labelEstado.set_text, estado)
def on_botonTiempo_clicked(self, gparam):
usuario = self._config['USERS']["USER"+self._comboUsuarios.get_active_id()]
contrasena = self._config['USERS']["PASS"+self._comboUsuarios.get_active_id()]
threading.Thread(target=self.actualizarSaldo, args=(usuario,contrasena, )).start()
def on_botonEstado_clicked(self, gparam):
self._botonEstadoIcon.set_from_icon_name("network-wired-acquiring-symbolic", Gtk.IconSize.BUTTON)
threading.Thread(target=self.actualizarEstado, args=( )).start()
def on_botonUsuarios_clicked(self, gparam):
self._ventanaUsuarios.mostrarVentana()
def mostrar(self):
# self._window.show_all()
pass
def on_comboUsuarios_changed(self, gparam):
usuario = self._config['USERS']["USER"+self._comboUsuarios.get_active_id()]
contrasena = self._config['USERS']["PASS"+self._comboUsuarios.get_active_id()]
threading.Thread(target=self.actualizarSaldo, args=(usuario,contrasena, )).start()
if not self._cargandoConfig:
self._config['SETTINGS']['last_user_id'] = self._comboUsuarios.get_active_id()
with open(directorio+'/config.ini', 'w') as configfile:
self._config.write(configfile)
def on_window_destroy(self, window):
print("destruyendo")
self._config = configparser.ConfigParser()
self._config.read(directorio+'/config.ini')
self._config['SETTINGS']['last_user_id'] = self._comboUsuarios.get_active_id()
with open(directorio+'/config.ini', 'w') as configfile:
self._config.write(configfile)
Gtk.main_quit()
def cargarConfiguracion(self):
self._cargandoConfig = True
self._config = configparser.ConfigParser()
self._config.read(directorio+'/config.ini')
self._comboUsuarios.remove_all()
for key in self._config['USERS']:
if key.count("user"):
self._comboUsuarios.append(key[4:], self._config["USERS"][key])
self._comboUsuarios.set_active_id(self._config['SETTINGS']['last_user_id'])
self._labelEstado.set_text(f'Actualización: {os.environ["__version__"]}')
self._cargandoConfig = False
def main(argv):
wifiEtecsa = WifiEtecsa()
Gtk.main()
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))