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

Subversion Repositories phr

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

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

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

powered by: WebSVN 2.1.0

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