OpenCores
URL https://opencores.org/ocsvn/phr/phr/trunk

Subversion Repositories phr

[/] [phr/] [trunk/] [codigo/] [gui/] [windows/] [gui/] [phr-gui.py] - Blame information for rev 242

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 182 maximiq
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# generated by wxGlade 0.6.3 on Wed Mar 26 16:29:14 2014
4
 
5
import wx
6
# imports by maximiq
7
import os          # se usa para el dialogo de abrir fichero
8
import subprocess  # para interactuar con el shell
9 217 maximiq
import thread      # to prevent gui blocking
10 182 maximiq
 
11 211 maximiq
#####################################
12
# Para que funcione mejor en Linux
13
#import os
14 182 maximiq
 
15 211 maximiq
#abspath = os.path.abspath(__file__)
16
#dname = os.path.dirname(abspath)
17
#os.chdir(dname)
18
#####################################
19
 
20 182 maximiq
# begin wxGlade: extracode
21
# end wxGlade
22
 
23
 
24
 
25
class MyFrame(wx.Frame):
26
    def __init__(self, *args, **kwds):
27
        # begin wxGlade: MyFrame.__init__
28
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
29
        wx.Frame.__init__(self, *args, **kwds)
30
        self.frame_1_statusbar = self.CreateStatusBar(1, 0)
31
        self.bitmap_1 = wx.StaticBitmap(self, -1, wx.Bitmap("grafica/banner.jpg", wx.BITMAP_TYPE_ANY))
32
        self.button_help = wx.Button(self, -1, "  Ayuda  ")
33
        self.button_about = wx.Button(self, -1, "  Acerca de  ")
34
        self.text_ctrl_file = wx.TextCtrl(self, -1, "")
35
        self.button_choose_file = wx.Button(self, -1, "Elegir fichero")
36
        self.button_conf_fpga = wx.Button(self, -1, "Configurar FPGA")
37
        self.button_prog_prom = wx.Button(self, -1, "Programar PROM")
38
        self.text_ctrl_console = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
39
        self.button_conection = wx.Button(self, -1, u"  Comprobar conexión  ")
40
        self.button_empty = wx.Button(self, -1, "  Borrar salida  ")
41
 
42
        self.__set_properties()
43
        self.__do_layout()
44
 
45
        self.Bind(wx.EVT_BUTTON, self.boton_ayuda, self.button_help)
46
        self.Bind(wx.EVT_BUTTON, self.boton_acerca_de, self.button_about)
47
        self.Bind(wx.EVT_BUTTON, self.boton_elegir_fichero, self.button_choose_file)
48
        self.Bind(wx.EVT_BUTTON, self.boton_conf_fpga, self.button_conf_fpga)
49
        self.Bind(wx.EVT_BUTTON, self.boton_prog_prom, self.button_prog_prom)
50
        self.Bind(wx.EVT_BUTTON, self.boton_conexion, self.button_conection)
51
        self.Bind(wx.EVT_BUTTON, self.boton_borrar, self.button_empty)
52
        # end wxGlade
53
 
54
    def __set_properties(self):
55
        # begin wxGlade: MyFrame.__set_properties
56
        self.SetTitle("PHR GUI")
57
        _icon = wx.EmptyIcon()
58
        _icon.CopyFromBitmap(wx.Bitmap("grafica/phr-gui.ico", wx.BITMAP_TYPE_ANY))
59
        self.SetIcon(_icon)
60
        self.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
61
        self.frame_1_statusbar.SetStatusWidths([-1])
62
        # statusbar fields
63
        frame_1_statusbar_fields = ["Listo"]
64
        for i in range(len(frame_1_statusbar_fields)):
65
            self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)
66
        self.text_ctrl_console.SetMinSize((-1, 150))
67
        # end wxGlade
68
        # start maximiq
69
        font1 = self.text_ctrl_console.GetFont()
70
        font1 = wx.Font(font1.GetPointSize(), wx.TELETYPE,
71
                       font1.GetStyle(),
72
                       font1.GetWeight(), font1.GetUnderlined())
73
        self.text_ctrl_console.SetFont(font1)
74
        #font1 = wx.Font(9, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')
75
        #self.text_ctrl_console.SetFont(font1)
76
        self.text_ctrl_console.SetValue("PHR>>> ")
77
 
78
    def __do_layout(self):
79
        # begin wxGlade: MyFrame.__do_layout
80
        grid_sizer_1 = wx.FlexGridSizer(5, 1, 0, 0)
81
        grid_sizer_2 = wx.GridSizer(1, 2, 0, 0)
82
        grid_sizer_4 = wx.GridSizer(1, 2, 0, 0)
83
        grid_sizer_5 = wx.FlexGridSizer(1, 2, 0, 0)
84
        grid_sizer_6 = wx.FlexGridSizer(1, 2, 0, 0)
85
        grid_sizer_7 = wx.FlexGridSizer(2, 1, 0, 0)
86
        grid_sizer_6.Add(self.bitmap_1, 0, wx.ALL, 5)
87
        grid_sizer_7.Add(self.button_help, 0, wx.RIGHT|wx.TOP|wx.BOTTOM|wx.EXPAND, 5)
88
        grid_sizer_7.Add(self.button_about, 0, wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
89
        grid_sizer_6.Add(grid_sizer_7, 1, wx.EXPAND, 0)
90
        grid_sizer_6.AddGrowableCol(1)
91
        grid_sizer_1.Add(grid_sizer_6, 1, wx.EXPAND, 0)
92
        grid_sizer_5.Add(self.text_ctrl_file, 0, wx.ALL|wx.EXPAND, 5)
93
        grid_sizer_5.Add(self.button_choose_file, 0, wx.RIGHT|wx.TOP|wx.BOTTOM, 5)
94
        grid_sizer_5.AddGrowableCol(0)
95
        grid_sizer_1.Add(grid_sizer_5, 1, wx.EXPAND, 0)
96
        grid_sizer_4.Add(self.button_conf_fpga, 1, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
97
        grid_sizer_4.Add(self.button_prog_prom, 0, wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
98
        grid_sizer_1.Add(grid_sizer_4, 1, wx.EXPAND, 0)
99
        grid_sizer_1.Add(self.text_ctrl_console, 0, wx.ALL|wx.EXPAND, 5)
100
        grid_sizer_2.Add(self.button_conection, 0, wx.LEFT|wx.BOTTOM, 5)
101
        grid_sizer_2.Add(self.button_empty, 0, wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT, 5)
102
        grid_sizer_1.Add(grid_sizer_2, 1, wx.EXPAND, 0)
103
        self.SetSizer(grid_sizer_1)
104
        grid_sizer_1.Fit(self)
105
        grid_sizer_1.SetSizeHints(self)
106
        grid_sizer_1.AddGrowableRow(3)
107
        grid_sizer_1.AddGrowableCol(0)
108
        self.Layout()
109
        # end wxGlade
110
 
111
    def OnAboutBox(self):
112
 
113
        description = """
114
PHR GUI es una interfaz grafica que permite interactuar con
115
la Plataforma de Hardware Reconfigurable (desarrollada en el
116
CUDAR) a traves del software xc3sprog.
117 211 maximiq
 
118 217 maximiq
Revision (SVN) 217.
119
(EN DESARROLLO)
120 182 maximiq
"""
121
 
122
        licence = """
123
PHR GUI is free software; you can redistribute it and/or modify
124
it under the terms of the GNU General Public License as
125
published by the Free Software Foundation; either version 2
126
of the License, or (at your option) any later version.
127
 
128
PHR GUI is distributed in the hope that it will be useful,
129
but WITHOUT ANY WARRANTY; without even the implied warranty of
130
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
131
See the GNU General Public License for more details. You should have
132
received a copy of the GNU General Public License along with
133
PHR GUI; if not, write to the Free Software Foundation, Inc.,
134
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
135
"""
136
 
137
 
138
        info = wx.AboutDialogInfo()
139
 
140
        info.SetIcon(wx.Icon('grafica/phr-gui-96.png', wx.BITMAP_TYPE_PNG))
141
        info.SetName('PHR GUI')
142 211 maximiq
        info.SetVersion('0.1')
143 182 maximiq
        info.SetDescription(description)
144
        #info.SetCopyright('(C) 2014 CUDAR (UTN-FRC)')
145
        info.SetCopyright('Abril de 2014, CUDAR (UTN-FRC)')
146
        info.SetWebSite('http://opencores.org/project,phr')
147
        #info.SetLicence(licence)
148
        info.AddDeveloper('Luis Guanuco, Maximiliano Quinteros.')
149
 
150
 
151
        wx.AboutBox(info)
152
 
153
    def ShowHelpMessage(self):
154
        mensaje = """
155
Procedimiento para usar este programa:
156
 
157
Para configurar la FPGA:
158
1) Setear el jumper en la placa PHR en modo JTAG.
159
2) Elegir el archivo de configuracion (*.bit).
160
3) Presione el boton \"Configurar FPGA\".
161
4) Tras terminar el paso anterior la FPGA debe comenzar a funcionar.
162
 
163
Para programar la memoria PROM:
164 211 maximiq
1) Setear el jumper en la placa PHR en modo \"Master Serial\".
165 182 maximiq
2) Elegir el archivo de programacion (*.bit).
166
3) Presione el boton \"Programar PROM\".
167 211 maximiq
4) Una vez terminado el paso anterior, presionar el boton de RESET.
168 182 maximiq
 
169
Mas ayuda en los manuales que puede descargar desde el servidor de
170
OpenCores donde se aloja el proyecto: http://opencores.org/project,phr
171
"""
172
        wx.MessageBox(mensaje, 'Info',
173
            wx.OK | wx.ICON_INFORMATION)
174
 
175
    def boton_ayuda(self, event): # wxGlade: MyFrame.<event_handler>
176
        self.ShowHelpMessage()
177
        event.Skip()
178
 
179
    def boton_acerca_de(self, event): # wxGlade: MyFrame.<event_handler>
180
        self.OnAboutBox()
181
        event.Skip()
182
 
183
    def boton_elegir_fichero(self, event): # wxGlade: MyFrame.<event_handler>
184
        #funcion editada por maximiq
185
 
186
        wildcard = "Archivo BIT de Xilinx (*.bit)|*.bit|" \
187
                   "Todos los archivos (*.*)|*.*"
188
        dialog = wx.FileDialog(None, "Elija un archivo", os.getcwd(), "", wildcard, wx.OPEN)
189
        if dialog.ShowModal() == wx.ID_OK:
190
            self.text_ctrl_file.SetValue(dialog.GetPath())
191
 
192
        dialog.Destroy()
193
 
194
        event.Skip()
195
 
196 217 maximiq
    def before_run (self):
197
        ## preparar entorno para los eventos conf_fpga prog_prom comprobar_conexion
198 182 maximiq
        self.button_conf_fpga.Disable()
199
        self.button_prog_prom.Disable()
200
        self.button_conection.Disable()
201
        self.button_empty.Disable()
202
        self.frame_1_statusbar.SetFields(["Espere ..."])
203 217 maximiq
 
204
    def after_run (self):
205
        ## restaurar entorno 
206
        self.button_conf_fpga.Enable()
207
        self.button_prog_prom.Enable()
208
        self.button_conection.Enable()
209
        self.button_empty.Enable()
210
        self.frame_1_statusbar.SetFields(["Listo"])
211
 
212
    def boton_conf_fpga_thread(self):
213
        ## preparar entorno
214
        wx.CallAfter(self.before_run)
215 182 maximiq
 
216
        ## accion
217
        # se copia el fichero de programacion al directorio local
218
        subprocess.call ("copy \"" + self.text_ctrl_file.GetValue() + "\" fpgaFile", shell=True)
219
 
220
        # se ejecuta el xc3sprog
221
        command = "xc3sprog\\xc3sprog -v -L -c ftdi -p 0 fpgaFile:w:0:BIT"
222
 
223 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
224
 
225 182 maximiq
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
226
 
227
        for line in iter(process.stdout.readline, ''):
228 217 maximiq
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
229 182 maximiq
        process.stdout.close()
230
 
231 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
232 182 maximiq
 
233
        ## restaurar entorno 
234 217 maximiq
        wx.CallAfter(self.after_run)
235
 
236 182 maximiq
 
237 217 maximiq
    def boton_conf_fpga(self, event): # wxGlade: MyFrame.<event_handler>
238
        #funcion editada por maximiq
239
        thread.start_new_thread(self.boton_conf_fpga_thread, ())
240 182 maximiq
        event.Skip()
241
 
242 217 maximiq
    def boton_prog_prom_thread(self):
243 182 maximiq
        #funcion editada por maximiq
244
 
245
        ## preparar entorno
246 217 maximiq
        wx.CallAfter(self.before_run)
247 182 maximiq
 
248
        ## accion
249
 
250
        # se copia el fichero de programacion al directorio local
251
        subprocess.call ("copy \"" + self.text_ctrl_file.GetValue() + "\" fpgaFile", shell=True)
252
 
253
        command = "xc3sprog\\xc3sprog.exe -v -L -c ftdi -p 1 fpgaFile:w:0:BIT"
254
 
255 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
256
 
257 182 maximiq
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
258
 
259 211 maximiq
        line = ''
260
        while True:
261
            out = process.stdout.read(1)
262
            if out == '' and process.poll() != None:
263
                break
264
            if out != '' and out != '\x0a':
265
                line = line + out
266
                if out == '\x0d':
267 217 maximiq
                    wx.CallAfter(self.text_ctrl_console.AppendText, line)
268 211 maximiq
                    line = ''
269
 
270 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
271 182 maximiq
 
272
        ## restaurar entorno 
273 217 maximiq
        wx.CallAfter(self.after_run)
274 182 maximiq
 
275 217 maximiq
    def boton_prog_prom(self, event): # wxGlade: MyFrame.<event_handler>
276 182 maximiq
        #funcion editada por maximiq
277 217 maximiq
        thread.start_new_thread(self.boton_prog_prom_thread, ())
278
        event.Skip()
279
 
280
    def boton_conexion_thread (self):
281 182 maximiq
        ## preparar entorno
282 217 maximiq
        wx.CallAfter(self.before_run, )
283 182 maximiq
 
284
        ## accion
285
        command = "xc3sprog\\xc3sprog -c ftdi -L -j -v"  # the shell command
286
 
287 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
288 182 maximiq
 
289
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
290
 
291
        for line in iter(process.stdout.readline, ''):
292 217 maximiq
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
293 182 maximiq
        process.stdout.close()
294
 
295 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
296 182 maximiq
 
297
        ## restaurar entorno 
298 217 maximiq
        wx.CallAfter(self.after_run, )
299
 
300
    def boton_conexion(self, event): # wxGlade: MyFrame.<event_handler>
301
        #funcion editada por maximiq
302
        thread.start_new_thread(self.boton_conexion_thread, ())
303 182 maximiq
        event.Skip()
304
 
305
    def boton_borrar(self, event): # wxGlade: MyFrame.<event_handler>
306
        #funcion editada por maximiq
307
 
308
        ## accion
309
        self.text_ctrl_console.SetValue("PHR>>> ") # borra todo el contenido
310
 
311
        event.Skip()
312
 
313
# end of class MyFrame
314
 
315
 
316
if __name__ == "__main__":
317
    app = wx.App(False)
318
    frame_1 = MyFrame(None, -1, "")
319
    app.SetTopWindow(frame_1)
320
    frame_1.Show()
321
    app.MainLoop()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.