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

Subversion Repositories phr

[/] [phr/] [trunk/] [codigo/] [gui/] [xin/] [phrgui.py] - Blame information for rev 336

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

Line No. Rev Author Line
1 331 maximiq
#!/usr/bin/env python
2 332 maximiq
# -*- coding: utf-8 -*-
3 331 maximiq
 
4
import wx
5
import guiparent
6
 
7
import os           # se usa para el dialogo de abrir fichero
8
import subprocess   # para interactuar con el shell
9
import thread       # to prevent gui blocking
10 336 maximiq
from sys import platform as _platform  # para detectar el sistema operativo
11 331 maximiq
 
12
 
13
class phrgui (guiparent.guiParent):
14
    def __init__(self, *args, **kwds):
15
        guiparent.guiParent.__init__(self, *args, **kwds)
16
        self.__set_extra_properties()
17
 
18
 
19
    def __set_extra_properties(self):
20
        # Definicion de la fuente monospace
21
        font1 = self.text_ctrl_console.GetFont()
22
        font1 = wx.Font(font1.GetPointSize(), wx.TELETYPE,
23
                   font1.GetStyle(),
24
                   font1.GetWeight(), font1.GetUnderlined())
25
 
26
        # Propiedades de la consola
27
        self.text_ctrl_console.SetFont(font1)
28
        self.text_ctrl_console.SetValue("PHR>>> ")
29
 
30
        # Propiedades de la la lista de dispositivos detectados
31
        self.list_box_dispositivos_conectados.SetFont(font1)
32
 
33
 
34
    def menu_item_ayuda_acerca_de_handler(self, event):  # wxGlade: wg_parent_class.<event_handler>
35
        description = """
36 332 maximiq
PHR GUI es una interfaz gráfica que permite interactuar con
37
la Plataforma de Hardware Reconfigurable (CUDAR) a través
38
del software xc3sprog.
39 331 maximiq
 
40 333 maximiq
$Rev: 336 $
41 332 maximiq
$Date: 2014-06-11 03:58:02 +0200 (Wed, 11 Jun 2014) $
42 331 maximiq
"""
43
        licence = """
44
PHR GUI is free software; you can redistribute it and/or modify
45
it under the terms of the GNU General Public License as
46
published by the Free Software Foundation; either version 2
47
of the License, or (at your option) any later version.
48
 
49
PHR GUI is distributed in the hope that it will be useful,
50
but WITHOUT ANY WARRANTY; without even the implied warranty of
51
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
52
See the GNU General Public License for more details. You should have
53
received a copy of the GNU General Public License along with
54
PHR GUI; if not, write to the Free Software Foundation, Inc.,
55
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
56
"""
57
        info = wx.AboutDialogInfo()
58
 
59
        info.SetIcon(wx.Icon('grafica/phr-gui-96.png', wx.BITMAP_TYPE_PNG))
60
        info.SetName('PHR GUI')
61
        info.SetVersion('0.1.1')
62
        info.SetDescription(description)
63
        #info.SetCopyright('(C) 2014 CUDAR (UTN-FRC)')
64
        info.SetCopyright('2014, CUDAR (UTN-FRC)')
65
        info.SetWebSite('http://opencores.org/project,phr')
66
        #info.SetLicence(licence)
67
        info.AddDeveloper('Luis Guanuco, Maximiliano Quinteros.')
68
 
69
        wx.AboutBox(info)
70
        event.Skip()
71
 
72
 
73
    def menu_item_ayuda_hint_handler(self, event):  # wxGlade: guiParent.<event_handler>
74
        mensaje = """
75 332 maximiq
Procedimiento general para utilizar este programa:
76 331 maximiq
 
77 332 maximiq
1. Conecte el programador y presione en el botón \"Detectar\".
78
Se listaran los dispositivos encontrados en la cadena JTAG.
79
2. Seleccione el dispositivo que desea programar o configurar.
80
3. Elija un fichero de configuración/programación.
81
      *.BIT para FPGA
82
      *.JED para CPLD
83
4. Presione el botón \"Transferir\".
84
 
85
Considere las recomendaciones de la placa específica que esté
86
utilizando.
87 331 maximiq
"""
88
        wx.MessageBox(mensaje, 'Info', wx.OK | wx.ICON_INFORMATION)
89
        event.Skip()
90
 
91
 
92
    def boton_elegir_fichero_handler(self, event):  # wxGlade: wg_parent_class.<event_handler>
93
        wildcard = "Archivo BIT de Xilinx (*.bit)|*.bit|" \
94 332 maximiq
                   "Archivo JEDEC para CPLD (*.jed)|*.jed|" \
95 331 maximiq
                   "Todos los archivos (*.*)|*.*"
96
        dialog = wx.FileDialog(None, "Elija un archivo", os.getcwd(), "", wildcard, wx.OPEN)
97
        if dialog.ShowModal() == wx.ID_OK:
98
            self.text_ctrl_fichero.SetValue(dialog.GetPath())
99
            print "New file to transfer: " + dialog.GetPath()
100
 
101
        dialog.Destroy()
102
        event.Skip()
103
 
104
 
105
    def boton_borrar_salida_handler(self, event):  # wxGlade: wg_parent_class.<event_handler>
106
        self.text_ctrl_console.SetValue("PHR>>> ") # borra el contenido de la consola
107
        print "Console cleared"
108
        event.Skip()
109
 
110
 
111
    def before_run (self):
112
        # preparar entorno para los eventos de transferencia y deteccion de dispositivos
113
        self.boton_transferir.Disable()
114
        self.boton_elegir_fichero.Disable()
115
        self.boton_detectar.Disable()
116
        self.boton_borrar_salida.Disable()
117
        self.statusbar.SetFields(["Espere ..."])
118
 
119
 
120
    def after_run (self):
121
        # restaurar entorno 
122
        self.boton_transferir.Enable()
123
        self.boton_elegir_fichero.Enable()
124
        self.boton_detectar.Enable()
125
        self.boton_borrar_salida.Enable()
126
        self.statusbar.SetFields(["Listo"])
127
 
128
 
129
    def boton_transferir_thread(self):
130
        ## preparar entorno
131
        wx.CallAfter(self.before_run)
132
 
133
        device_list_selection = self.list_box_dispositivos_conectados.GetSelections()
134
        if len (device_list_selection) > 0:
135
            position = str(device_list_selection[0])
136
        else:
137
            position = ""
138
 
139 336 maximiq
        if _platform == "linux" or _platform == "linux2":
140
            # linux
141
                command = "./xc3sprog/xc3sprog -v -c ftdi -p " + position + " \""+ self.text_ctrl_fichero.GetValue() + "\""
142
        else:
143
            # windows
144
            subprocess.call ("copy \"" + self.text_ctrl_fichero.GetValue() + "\" fpgaFile", shell=True)
145
            command = "xc3sprog\\xc3sprog.exe -v -L -c ftdi -p " + position + " fpgaFile:w:0:BIT"
146 331 maximiq
 
147
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
148
 
149
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
150
 
151
 
152 336 maximiq
        if _platform == "linux" or _platform == "linux2":
153
            # linux
154
            for line in iter(process.stdout.readline, ''):
155
                wx.CallAfter(self.text_ctrl_console.AppendText, line)
156
            process.stdout.close()
157
        else:
158
            # Windows
159
            line = ''
160
            while True:
161
                out = process.stdout.read(1)
162
                if out == '' and process.poll() != None:
163
                    break
164
                if out != '' and out != '\x0a':
165
                    line = line + out
166
                    if out == '\x0d':
167
                        wx.CallAfter(self.text_ctrl_console.AppendText, line)
168
                        line = ''
169
 
170 331 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
171
 
172
        ## restaurar entorno 
173
        wx.CallAfter(self.after_run)
174
 
175
 
176
    def boton_transferir_handler(self, event):  # wxGlade: wg_parent_class.<event_handler>
177
        thread.start_new_thread(self.boton_transferir_thread, ())
178
        event.Skip()
179
 
180
 
181
    def boton_detectar_thread (self):
182
        ## preparar entorno
183
        wx.CallAfter(self.before_run, )
184
        wx.CallAfter(self.list_box_dispositivos_conectados.Clear)
185
 
186
        ## accion
187
 
188 336 maximiq
        if _platform == "linux" or _platform == "linux2":
189
            # linux
190
                command = "./xc3sprog/xc3sprog -c ftdi"
191
        else:
192
            # windows
193
            command = "xc3sprog\\xc3sprog -c ftdi -L -j -v"
194
 
195 331 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
196
 
197
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
198
 
199
        for line in iter(process.stdout.readline, ''):
200
            # Append output to console
201
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
202
 
203
            # If it is a JTAG device append it in list box as well
204
            if line.lower()[0:10] == "jtag loc.:":
205
                deviceStr = line.split ()
206
                appendStr = deviceStr[0] + " " + deviceStr[2] + ": "
207
 
208
                if deviceStr[5] == "Desc:":
209
                    appendStr += deviceStr[6] + " (ID:" + deviceStr[4] + ")"
210
                else:
211
                    appendStr += "Unknown" + " (ID:" + deviceStr[4] + ")"
212
 
213
                wx.CallAfter(self.list_box_dispositivos_conectados.Append, appendStr)
214
 
215
        process.stdout.close()
216
 
217
        wx.CallAfter(self.list_box_dispositivos_conectados.SetSelection, 0)
218
 
219
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
220
 
221
        ## restaurar entorno 
222
        wx.CallAfter(self.after_run, )
223
 
224
 
225
    def boton_detectar_handler(self, event):  # wxGlade: wg_parent_class.<event_handler>
226
        thread.start_new_thread(self.boton_detectar_thread, ())
227
        event.Skip()
228
 
229
# end of class phrgui
230
 
231
if __name__ == "__main__":
232
    app = wx.PySimpleApp(0)
233
    wx.InitAllImageHandlers()
234
    frame = phrgui(None, -1, "")
235
    app.SetTopWindow(frame)
236
    frame.Show()
237
    app.MainLoop()
238
 

powered by: WebSVN 2.1.0

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