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

Subversion Repositories phr

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

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 337 maximiq
        description = u"""
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: 337 $
41 332 maximiq
$Date: 2014-06-13 04:58:39 +0200 (Fri, 13 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 337 maximiq
        mensaje = u"""
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 337 maximiq
    def boton_transferir_thread(self, position):
130 331 maximiq
        ## preparar entorno
131
        wx.CallAfter(self.before_run)
132 337 maximiq
 
133
        position = str (position)
134 331 maximiq
 
135 336 maximiq
        if _platform == "linux" or _platform == "linux2":
136
            # linux
137 337 maximiq
            command = "./xc3sprog/lin/xc3sprog -v -c ftdi -p " + position + " \""+ self.text_ctrl_fichero.GetValue() + "\""
138 336 maximiq
        else:
139
            # windows
140
            subprocess.call ("copy \"" + self.text_ctrl_fichero.GetValue() + "\" fpgaFile", shell=True)
141 337 maximiq
            command = "xc3sprog\\win\\xc3sprog -v -L -c ftdi -p " + position + " fpgaFile:w:0:BIT"
142 331 maximiq
 
143
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
144
 
145
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
146
 
147
 
148 336 maximiq
        if _platform == "linux" or _platform == "linux2":
149
            # linux
150
            for line in iter(process.stdout.readline, ''):
151
                wx.CallAfter(self.text_ctrl_console.AppendText, line)
152
            process.stdout.close()
153
        else:
154
            # Windows
155
            line = ''
156
            while True:
157
                out = process.stdout.read(1)
158
                if out == '' and process.poll() != None:
159
                    break
160
                if out != '' and out != '\x0a':
161
                    line = line + out
162
                    if out == '\x0d':
163
                        wx.CallAfter(self.text_ctrl_console.AppendText, line)
164
                        line = ''
165
 
166 331 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
167
 
168
        ## restaurar entorno 
169
        wx.CallAfter(self.after_run)
170
 
171
 
172
    def boton_transferir_handler(self, event):  # wxGlade: wg_parent_class.<event_handler>
173 337 maximiq
 
174
        device_list_selection = self.list_box_dispositivos_conectados.GetSelections()
175
 
176
        if len (device_list_selection) > 0:
177
            position = device_list_selection[0]
178
        else:
179
            position = 0
180
 
181
        thread.start_new_thread(self.boton_transferir_thread, (position,))
182 331 maximiq
        event.Skip()
183
 
184
 
185
    def boton_detectar_thread (self):
186
        ## preparar entorno
187
        wx.CallAfter(self.before_run, )
188
        wx.CallAfter(self.list_box_dispositivos_conectados.Clear)
189 337 maximiq
 
190 331 maximiq
        ## accion
191
 
192 336 maximiq
        if _platform == "linux" or _platform == "linux2":
193
            # linux
194 337 maximiq
                command = "./xc3sprog/lin/xc3sprog -c ftdi"
195 336 maximiq
        else:
196
            # windows
197 337 maximiq
            command = "xc3sprog\\win\\xc3sprog -c ftdi -L -j -v"
198 336 maximiq
 
199 331 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
200 337 maximiq
 
201 331 maximiq
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
202
 
203
        for line in iter(process.stdout.readline, ''):
204
            # Append output to console
205
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
206
 
207
            # If it is a JTAG device append it in list box as well
208
            if line.lower()[0:10] == "jtag loc.:":
209
                deviceStr = line.split ()
210
                appendStr = deviceStr[0] + " " + deviceStr[2] + ": "
211
 
212
                if deviceStr[5] == "Desc:":
213
                    appendStr += deviceStr[6] + " (ID:" + deviceStr[4] + ")"
214
                else:
215
                    appendStr += "Unknown" + " (ID:" + deviceStr[4] + ")"
216
 
217
                wx.CallAfter(self.list_box_dispositivos_conectados.Append, appendStr)
218
 
219
        process.stdout.close()
220
 
221 337 maximiq
        if self.list_box_dispositivos_conectados.GetCount() >= 1:
222
            wx.CallAfter(self.list_box_dispositivos_conectados.SetSelection, 0)
223
 
224 331 maximiq
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
225
 
226
        ## restaurar entorno 
227
        wx.CallAfter(self.after_run, )
228
 
229
 
230
    def boton_detectar_handler(self, event):  # wxGlade: wg_parent_class.<event_handler>
231
        thread.start_new_thread(self.boton_detectar_thread, ())
232
        event.Skip()
233
 
234
# end of class phrgui
235
 
236
if __name__ == "__main__":
237 337 maximiq
    app = wx.App(False)
238 331 maximiq
    frame = phrgui(None, -1, "")
239
    app.SetTopWindow(frame)
240
    frame.Show()
241
    app.MainLoop()

powered by: WebSVN 2.1.0

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