2 # -*- coding: utf-8 -*-
3 # vim: set expandtab tabstop=4 shiftwidth=4 :
4 #----------------------------------------------------------------------------
6 #----------------------------------------------------------------------------
7 # This file is part of etherled.
9 # etherled is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the Free
11 # Software Foundation; either version 2 of the License, or (at your option)
14 # etherled is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 # You should have received a copy of the GNU General Public License along
20 # with etherled; if not, write to the Free Software Foundation, Inc., 59
21 # Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #----------------------------------------------------------------------------
23 # Creado: vie oct 27 22:16:20 ART 2005
24 # Autores: Leandro Lucarella <llucare@fi.uba.ar>
25 #----------------------------------------------------------------------------
29 from simplegladeapp import SimpleGladeApp
30 from simplegladeapp import bindtextdomain
31 from optparse import OptionParser
32 #from dispatcher import Dispatcher
36 app_name = "cetherled"
41 bindtextdomain(app_name, locale_dir)
45 class MainWindow(SimpleGladeApp):
47 def __init__(self, path="cetherled.glade", root="main_window",
48 domain=app_name, **kwargs):
49 self.columns = kwargs.get('columns', 16)
50 self.host = kwargs.get('host', 'localhost')
51 self.port = kwargs.get('port', 9876)
52 #notificar = Dispatcher(self.actualizar)
53 self.device = etherled.NetworkedDevice(self.host, self.port)
54 path = os.path.join(glade_dir, path)
55 SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
59 for i in xrange(ROWS):
60 for j in xrange(self.columns):
62 self.table_leds.attach(led, j, j+1, i, i+1)
66 def on_btn_salir_clicked(self, widget, *args):
69 def on_btn_enviar_clicked(self, widget, *args):
70 self.device.matrix = self.leds2matrix()
72 def on_btn_recibir_clicked(self, widget, *args):
73 matrix = self.device.matrix
74 for row in xrange(ROWS):
75 for col in xrange(self.columns):
76 self.tabla[row,col].prendido = matrix[row,col]
77 self.tabla[row,col].queue_draw()
78 etherled.protocol._print_matrix(matrix)
80 def on_main_window_delete_event(self, widget, event, *args):
83 def leds2matrix(self):
85 for row in xrange(ROWS):
86 for col in xrange(self.columns):
87 matrix[row,col] = int(self.tabla[row,col].prendido)
88 etherled.protocol._print_matrix(matrix)
93 parser = OptionParser(description="Cliente de etherled",
94 version="%prog " + app_version, prog='cetherled')
95 parser.add_option("-s", "--server", default='localhost', dest="host",
96 metavar="HOSTNAME", help="Nombre/IP del host del dispositivo "
97 "[default: localhost]")
98 parser.add_option("-p", "--port", default=9876, metavar="PORT",
99 type="int", help="Puerto UDP del dispositivo [default: 9876].")
100 parser.add_option("-c", "--columns", default=16, metavar="COLS",
101 type="int", help="Cantidad de columnas de la matriz [default: 16].")
102 parser.add_option("-g", "--gui", default=False, action="store_true",
103 help="Levanta la interfaz gráfica para dibujar la matriz")
104 (opts, args) = parser.parse_args()
105 return (parser, opts, args)
109 (parser, opts, args) = parse_options()
110 if (opts.columns < 8) or (opts.columns > 32):
111 parser.error("El número de columnas debe estar entre 8 y 32.")
114 main_window = MainWindow(columns=opts.columns, host=opts.host,
121 parser.error("Debe especificarse un comando si no se usa la GUI.")
124 dev = etherled.NetworkedDevice(opts.host, opts.port)
127 parser.error("El comando get no puede llevar argumentos.")
129 etherled.protocol._print_matrix(dev.matrix)
135 parser.error("Variable desconocida, debe ser una de: "
136 "matrix, pause, delay.")
140 elif var == 'matrix':
141 parser.error("Use la GUI para enviar la matriz.")
144 elif var == 'continue':
148 parser.error("Delay lleva 1 argumento.")
149 dev.delay = int(args[2])
151 parser.error("Variable desconocida, debe ser una de: "
152 "off, pause, continue, delay.")
155 if __name__ == '__main__':