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

Subversion Repositories phr

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

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

powered by: WebSVN 2.1.0

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