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

Subversion Repositories phr

[/] [phr/] [trunk/] [codigo/] [gui/] [linux/] [phr-gui.py] - Blame information for rev 241

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

Line No. Rev Author Line
1 213 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 213 maximiq
 
11
#####################################
12
# Para que funcione mejor en Linux
13
#import os
14
 
15
abspath = os.path.abspath(__file__)
16
dname = os.path.dirname(abspath)
17
os.chdir(dname)
18
#####################################
19
 
20
# 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
 
118
Revision (SVN) 209.
119
"""
120
 
121
        licence = """
122
PHR GUI is free software; you can redistribute it and/or modify
123
it under the terms of the GNU General Public License as
124
published by the Free Software Foundation; either version 2
125
of the License, or (at your option) any later version.
126
 
127
PHR GUI is distributed in the hope that it will be useful,
128
but WITHOUT ANY WARRANTY; without even the implied warranty of
129
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
130
See the GNU General Public License for more details. You should have
131
received a copy of the GNU General Public License along with
132
PHR GUI; if not, write to the Free Software Foundation, Inc.,
133
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
134
"""
135
 
136
 
137
        info = wx.AboutDialogInfo()
138
 
139
        info.SetIcon(wx.Icon('grafica/phr-gui-96.png', wx.BITMAP_TYPE_PNG))
140
        info.SetName('PHR GUI')
141
        info.SetVersion('0.1')
142
        info.SetDescription(description)
143
        #info.SetCopyright('(C) 2014 CUDAR (UTN-FRC)')
144
        info.SetCopyright('Abril de 2014, CUDAR (UTN-FRC)')
145
        info.SetWebSite('http://opencores.org/project,phr')
146
        #info.SetLicence(licence)
147
        info.AddDeveloper('Luis Guanuco, Maximiliano Quinteros.')
148
 
149
 
150
        wx.AboutBox(info)
151
 
152
    def ShowHelpMessage(self):
153
        mensaje = """
154
Procedimiento para usar este programa:
155
 
156
Para configurar la FPGA:
157
1) Setear el jumper en la placa PHR en modo JTAG.
158
2) Elegir el archivo de configuracion (*.bit).
159
3) Presione el boton \"Configurar FPGA\".
160
4) Tras terminar el paso anterior la FPGA debe comenzar a funcionar.
161
 
162
Para programar la memoria PROM:
163
1) Setear el jumper en la placa PHR en modo \"Master Serial\".
164
2) Elegir el archivo de programacion (*.bit).
165
3) Presione el boton \"Programar PROM\".
166
4) Una vez terminado el paso anterior, presionar el boton de RESET.
167
 
168
Mas ayuda en los manuales que puede descargar desde el servidor de
169
OpenCores donde se aloja el proyecto: http://opencores.org/project,phr
170
"""
171
        wx.MessageBox(mensaje, 'Info',
172
            wx.OK | wx.ICON_INFORMATION)
173
 
174
    def boton_ayuda(self, event): # wxGlade: MyFrame.<event_handler>
175
        self.ShowHelpMessage()
176
        event.Skip()
177
 
178
    def boton_acerca_de(self, event): # wxGlade: MyFrame.<event_handler>
179
        self.OnAboutBox()
180
        event.Skip()
181
 
182
    def boton_elegir_fichero(self, event): # wxGlade: MyFrame.<event_handler>
183
        #funcion editada por maximiq
184
 
185
        wildcard = "Archivo BIT de Xilinx (*.bit)|*.bit|" \
186
                   "Todos los archivos (*.*)|*.*"
187
        dialog = wx.FileDialog(None, "Elija un archivo", os.getcwd(), "", wildcard, wx.OPEN)
188
        if dialog.ShowModal() == wx.ID_OK:
189
            self.text_ctrl_file.SetValue(dialog.GetPath())
190
 
191
        dialog.Destroy()
192
 
193
        event.Skip()
194
 
195 217 maximiq
    def before_run (self):
196
        ## preparar entorno para los eventos conf_fpga prog_prom comprobar_conexion
197 213 maximiq
        self.button_conf_fpga.Disable()
198
        self.button_prog_prom.Disable()
199
        self.button_conection.Disable()
200
        self.button_empty.Disable()
201
        self.frame_1_statusbar.SetFields(["Espere ..."])
202 217 maximiq
 
203
    def after_run (self):
204
        ## restaurar entorno 
205
        self.button_conf_fpga.Enable()
206
        self.button_prog_prom.Enable()
207
        self.button_conection.Enable()
208
        self.button_empty.Enable()
209
        self.frame_1_statusbar.SetFields(["Listo"])
210
 
211
    def boton_conf_fpga_thread(self):
212
        ## preparar entorno
213
        wx.CallAfter(self.before_run)
214 213 maximiq
 
215
        ## accion
216
        # se copia el fichero de programacion al directorio local
217
        #subprocess.call ("copy \"" + self.text_ctrl_file.GetValue() + "\" fpgaFile", shell=True)
218
 
219
        # se ejecuta el xc3sprog
220
        command = "./xc3sprog/xc3sprog -v -c ftdi -p 0 \""+ self.text_ctrl_file.GetValue() + "\":w:0:BIT"
221
 
222 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
223 213 maximiq
 
224
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
225
 
226
        for line in iter(process.stdout.readline, ''):
227 217 maximiq
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
228 213 maximiq
        process.stdout.close()
229
 
230 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
231 213 maximiq
 
232
        ## restaurar entorno 
233 217 maximiq
        wx.CallAfter(self.after_run)
234 213 maximiq
 
235 217 maximiq
 
236
    def boton_conf_fpga(self, event): # wxGlade: MyFrame.<event_handler>
237
        #funcion editada por maximiq
238
        thread.start_new_thread(self.boton_conf_fpga_thread, ())
239 213 maximiq
        event.Skip()
240
 
241 217 maximiq
    def boton_prog_prom_thread(self):
242 213 maximiq
        #funcion editada por maximiq
243
 
244
        ## preparar entorno
245 217 maximiq
        wx.CallAfter(self.before_run)
246 213 maximiq
 
247
        ## accion
248
        # se copia el fichero de programacion al directorio local
249
        #subprocess.call ("copy \"" + self.text_ctrl_file.GetValue() + "\" fpgaFile", shell=True)
250
 
251
        command = "./xc3sprog/xc3sprog -v -c ftdi -p 1 \"" + self.text_ctrl_file.GetValue() + "\":w:0:BIT"
252
 
253 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
254
 
255 213 maximiq
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
256
 
257
        for line in iter(process.stdout.readline, ''):
258 217 maximiq
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
259 213 maximiq
        process.stdout.close()
260
#        line = ''
261
#        while True:
262
#            out = process.stdout.read(1)
263
#            if out == '' and process.poll() != None:
264
#                break
265
#            if out != '' and out != '\x0a':
266
#                line = line + out
267
#                if out == '\x0d':
268
#                    self.text_ctrl_console.AppendText(line)
269
#                    line = ''
270
 
271 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
272 213 maximiq
 
273
        ## restaurar entorno 
274 217 maximiq
        wx.CallAfter(self.after_run)
275 213 maximiq
 
276 217 maximiq
 
277
    def boton_prog_prom(self, event): # wxGlade: MyFrame.<event_handler>
278 213 maximiq
        #funcion editada por maximiq
279 217 maximiq
        thread.start_new_thread(self.boton_prog_prom_thread, ())
280
        event.Skip()
281 213 maximiq
 
282 217 maximiq
    def boton_conexion_thread (self):
283 213 maximiq
        ## preparar entorno
284 217 maximiq
        wx.CallAfter(self.before_run, )
285 213 maximiq
 
286
        ## accion
287
        command = "./xc3sprog/xc3sprog -c ftdi"  # the shell command
288
 
289 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
290 213 maximiq
 
291
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
292
 
293
        for line in iter(process.stdout.readline, ''):
294 217 maximiq
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
295 213 maximiq
        process.stdout.close()
296
 
297 217 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
298 213 maximiq
 
299
        ## restaurar entorno 
300 217 maximiq
        wx.CallAfter(self.after_run, )
301
 
302
 
303
    def boton_conexion(self, event): # wxGlade: MyFrame.<event_handler>
304
        #funcion editada por maximiq
305
        thread.start_new_thread(self.boton_conexion_thread, ())
306 213 maximiq
        event.Skip()
307
 
308
    def boton_borrar(self, event): # wxGlade: MyFrame.<event_handler>
309
        #funcion editada por maximiq
310
 
311
        ## accion
312
        self.text_ctrl_console.SetValue("PHR>>> ") # borra todo el contenido
313
 
314
        event.Skip()
315
 
316
# end of class MyFrame
317
 
318
 
319
if __name__ == "__main__":
320
    app = wx.App(False)
321
    frame_1 = MyFrame(None, -1, "")
322
    app.SetTopWindow(frame_1)
323
    frame_1.Show()
324
    app.MainLoop()

powered by: WebSVN 2.1.0

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