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

Subversion Repositories phr

[/] [phr/] [trunk/] [codigo/] [gui/] [linux/] [phr-gui.py] - Rev 298

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

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Wed Mar 26 16:29:14 2014
 
import wx
# imports by maximiq
import os          # se usa para el dialogo de abrir fichero
import subprocess  # para interactuar con el shell
import thread      # to prevent gui blocking
 
#####################################
# Para que funcione mejor en Linux
#import os
 
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
#####################################
 
# begin wxGlade: extracode
# end wxGlade
 
 
 
class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.frame_1_statusbar = self.CreateStatusBar(1, 0)
        self.bitmap_1 = wx.StaticBitmap(self, -1, wx.Bitmap("grafica/banner.jpg", wx.BITMAP_TYPE_ANY))
        self.button_help = wx.Button(self, -1, "  Ayuda  ")
        self.button_about = wx.Button(self, -1, "  Acerca de  ")
        self.text_ctrl_file = wx.TextCtrl(self, -1, "")
        self.button_choose_file = wx.Button(self, -1, "Elegir fichero")
        self.button_conf_fpga = wx.Button(self, -1, "Configurar FPGA")
        self.button_prog_prom = wx.Button(self, -1, "Programar PROM")
        self.text_ctrl_console = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
        self.button_conection = wx.Button(self, -1, u"  Comprobar conexión  ")
        self.button_empty = wx.Button(self, -1, "  Borrar salida  ")
 
        self.__set_properties()
        self.__do_layout()
 
        self.Bind(wx.EVT_BUTTON, self.boton_ayuda, self.button_help)
        self.Bind(wx.EVT_BUTTON, self.boton_acerca_de, self.button_about)
        self.Bind(wx.EVT_BUTTON, self.boton_elegir_fichero, self.button_choose_file)
        self.Bind(wx.EVT_BUTTON, self.boton_conf_fpga, self.button_conf_fpga)
        self.Bind(wx.EVT_BUTTON, self.boton_prog_prom, self.button_prog_prom)
        self.Bind(wx.EVT_BUTTON, self.boton_conexion, self.button_conection)
        self.Bind(wx.EVT_BUTTON, self.boton_borrar, self.button_empty)
        # end wxGlade
 
    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("PHR GUI")
        _icon = wx.EmptyIcon()
        _icon.CopyFromBitmap(wx.Bitmap("grafica/phr-gui.ico", wx.BITMAP_TYPE_ANY))
        self.SetIcon(_icon)
        self.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
        self.frame_1_statusbar.SetStatusWidths([-1])
        # statusbar fields
        frame_1_statusbar_fields = ["Listo"]
        for i in range(len(frame_1_statusbar_fields)):
            self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)
        self.text_ctrl_console.SetMinSize((-1, 150))
        # end wxGlade
        # start maximiq
        font1 = self.text_ctrl_console.GetFont()
        font1 = wx.Font(font1.GetPointSize(), wx.TELETYPE,
                       font1.GetStyle(),
                       font1.GetWeight(), font1.GetUnderlined())
        self.text_ctrl_console.SetFont(font1)
        #font1 = wx.Font(9, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')
        #self.text_ctrl_console.SetFont(font1)
        self.text_ctrl_console.SetValue("PHR>>> ") 
 
    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        grid_sizer_1 = wx.FlexGridSizer(5, 1, 0, 0)
        grid_sizer_2 = wx.GridSizer(1, 2, 0, 0)
        grid_sizer_4 = wx.GridSizer(1, 2, 0, 0)
        grid_sizer_5 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_6 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_7 = wx.FlexGridSizer(2, 1, 0, 0)
        grid_sizer_6.Add(self.bitmap_1, 0, wx.ALL, 5)
        grid_sizer_7.Add(self.button_help, 0, wx.RIGHT|wx.TOP|wx.BOTTOM|wx.EXPAND, 5)
        grid_sizer_7.Add(self.button_about, 0, wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
        grid_sizer_6.Add(grid_sizer_7, 1, wx.EXPAND, 0)
        grid_sizer_6.AddGrowableCol(1)
        grid_sizer_1.Add(grid_sizer_6, 1, wx.EXPAND, 0)
        grid_sizer_5.Add(self.text_ctrl_file, 0, wx.ALL|wx.EXPAND, 5)
        grid_sizer_5.Add(self.button_choose_file, 0, wx.RIGHT|wx.TOP|wx.BOTTOM, 5)
        grid_sizer_5.AddGrowableCol(0)
        grid_sizer_1.Add(grid_sizer_5, 1, wx.EXPAND, 0)
        grid_sizer_4.Add(self.button_conf_fpga, 1, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
        grid_sizer_4.Add(self.button_prog_prom, 0, wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
        grid_sizer_1.Add(grid_sizer_4, 1, wx.EXPAND, 0)
        grid_sizer_1.Add(self.text_ctrl_console, 0, wx.ALL|wx.EXPAND, 5)
        grid_sizer_2.Add(self.button_conection, 0, wx.LEFT|wx.BOTTOM, 5)
        grid_sizer_2.Add(self.button_empty, 0, wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT, 5)
        grid_sizer_1.Add(grid_sizer_2, 1, wx.EXPAND, 0)
        self.SetSizer(grid_sizer_1)
        grid_sizer_1.Fit(self)
        grid_sizer_1.SetSizeHints(self)
        grid_sizer_1.AddGrowableRow(3)
        grid_sizer_1.AddGrowableCol(0)
        self.Layout()
        # end wxGlade
 
    def OnAboutBox(self):
 
        description = """
PHR GUI es una interfaz grafica que permite interactuar con 
la Plataforma de Hardware Reconfigurable (desarrollada en el
CUDAR) a traves del software xc3sprog.
 
Revision (SVN) 209.
"""
 
        licence = """
PHR GUI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
PHR GUI is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the GNU General Public License for more details. You should have 
received a copy of the GNU General Public License along with
PHR GUI; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""
 
 
        info = wx.AboutDialogInfo()
 
        info.SetIcon(wx.Icon('grafica/phr-gui-96.png', wx.BITMAP_TYPE_PNG))
        info.SetName('PHR GUI')
        info.SetVersion('0.1')
        info.SetDescription(description)
        #info.SetCopyright('(C) 2014 CUDAR (UTN-FRC)')
        info.SetCopyright('Abril de 2014, CUDAR (UTN-FRC)')
        info.SetWebSite('http://opencores.org/project,phr')
        #info.SetLicence(licence)
        info.AddDeveloper('Luis Guanuco, Maximiliano Quinteros.')
 
 
        wx.AboutBox(info)
 
    def ShowHelpMessage(self):
        mensaje = """
Procedimiento para usar este programa:
 
Para configurar la FPGA:
1) Setear el jumper en la placa PHR en modo JTAG.
2) Elegir el archivo de configuracion (*.bit).
3) Presione el boton \"Configurar FPGA\".
4) Tras terminar el paso anterior la FPGA debe comenzar a funcionar.
 
Para programar la memoria PROM:
1) Setear el jumper en la placa PHR en modo \"Master Serial\".
2) Elegir el archivo de programacion (*.bit).
3) Presione el boton \"Programar PROM\".
4) Una vez terminado el paso anterior, presionar el boton de RESET.
 
Mas ayuda en los manuales que puede descargar desde el servidor de
OpenCores donde se aloja el proyecto: http://opencores.org/project,phr
"""
        wx.MessageBox(mensaje, 'Info', 
            wx.OK | wx.ICON_INFORMATION)
 
    def boton_ayuda(self, event): # wxGlade: MyFrame.<event_handler>
        self.ShowHelpMessage()
        event.Skip()
 
    def boton_acerca_de(self, event): # wxGlade: MyFrame.<event_handler>
        self.OnAboutBox()
        event.Skip()
 
    def boton_elegir_fichero(self, event): # wxGlade: MyFrame.<event_handler>
        #funcion editada por maximiq
 
        wildcard = "Archivo BIT de Xilinx (*.bit)|*.bit|" \
                   "Todos los archivos (*.*)|*.*"
        dialog = wx.FileDialog(None, "Elija un archivo", os.getcwd(), "", wildcard, wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
            self.text_ctrl_file.SetValue(dialog.GetPath())
 
        dialog.Destroy()
 
        event.Skip()
 
    def before_run (self):
        ## preparar entorno para los eventos conf_fpga prog_prom comprobar_conexion
        self.button_conf_fpga.Disable()
        self.button_prog_prom.Disable()
        self.button_conection.Disable()
        self.button_empty.Disable()
        self.frame_1_statusbar.SetFields(["Espere ..."])
 
    def after_run (self):
        ## restaurar entorno 
        self.button_conf_fpga.Enable()
        self.button_prog_prom.Enable()
        self.button_conection.Enable()
        self.button_empty.Enable()
        self.frame_1_statusbar.SetFields(["Listo"])
 
    def boton_conf_fpga_thread(self):
        ## preparar entorno
        wx.CallAfter(self.before_run)
 
        ## accion
        # se copia el fichero de programacion al directorio local
        #subprocess.call ("copy \"" + self.text_ctrl_file.GetValue() + "\" fpgaFile", shell=True)
 
        # se ejecuta el xc3sprog
        command = "./xc3sprog/xc3sprog -v -c ftdi -p 0 \""+ self.text_ctrl_file.GetValue() + "\":w:0:BIT"  
 
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
 
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
 
        for line in iter(process.stdout.readline, ''):
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
        process.stdout.close()
 
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
 
        ## restaurar entorno 
        wx.CallAfter(self.after_run)
 
 
    def boton_conf_fpga(self, event): # wxGlade: MyFrame.<event_handler>
        #funcion editada por maximiq
        thread.start_new_thread(self.boton_conf_fpga_thread, ())
        event.Skip()
 
    def boton_prog_prom_thread(self):
        #funcion editada por maximiq
 
        ## preparar entorno
        wx.CallAfter(self.before_run)
 
        ## accion
        # se copia el fichero de programacion al directorio local
        #subprocess.call ("copy \"" + self.text_ctrl_file.GetValue() + "\" fpgaFile", shell=True)
 
        command = "./xc3sprog/xc3sprog -v -c ftdi -p 1 \"" + self.text_ctrl_file.GetValue() + "\":w:0:BIT"
 
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
 
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
 
        for line in iter(process.stdout.readline, ''):
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
        process.stdout.close()
#        line = ''
#        while True:
#            out = process.stdout.read(1)
#            if out == '' and process.poll() != None:
#                break
#            if out != '' and out != '\x0a':
#                line = line + out
#                if out == '\x0d':
#                    self.text_ctrl_console.AppendText(line)
#                    line = ''
 
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
 
        ## restaurar entorno 
        wx.CallAfter(self.after_run)
 
 
    def boton_prog_prom(self, event): # wxGlade: MyFrame.<event_handler>
        #funcion editada por maximiq
        thread.start_new_thread(self.boton_prog_prom_thread, ())
        event.Skip()
 
    def boton_conexion_thread (self):
        ## preparar entorno
        wx.CallAfter(self.before_run, )
 
        ## accion
        command = "./xc3sprog/xc3sprog -c ftdi"  # the shell command
 
        wx.CallAfter(self.text_ctrl_console.AppendText, command + "\n")
 
        process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
 
        for line in iter(process.stdout.readline, ''):
            wx.CallAfter(self.text_ctrl_console.AppendText, line)
        process.stdout.close()
 
        wx.CallAfter(self.text_ctrl_console.AppendText, "\nPHR>>> ")
 
        ## restaurar entorno 
        wx.CallAfter(self.after_run, )
 
 
    def boton_conexion(self, event): # wxGlade: MyFrame.<event_handler>
        #funcion editada por maximiq
        thread.start_new_thread(self.boton_conexion_thread, ())
        event.Skip()
 
    def boton_borrar(self, event): # wxGlade: MyFrame.<event_handler>
        #funcion editada por maximiq
 
        ## accion
        self.text_ctrl_console.SetValue("PHR>>> ") # borra todo el contenido
 
        event.Skip()
 
# end of class MyFrame
 
 
if __name__ == "__main__":
    app = wx.App(False)
    frame_1 = MyFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Show()
    app.MainLoop()
 

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

powered by: WebSVN 2.1.0

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