Charset problem in a WxApp

Hi everybody. I'm deploying my first "big" aplication in wxPython and
I'm very glad with this great languaje. (yes, my English is terrible,
sorry, I'm workig on it too :slight_smile: )
My aplication is an school administrator and basically speaks with a
MySQL database through a Frame with menus. It grows day by day, when
its become serius, I'll publish it by GPL license. (The actual full
code is attached too).

Like an Spanish talker, I need some characters like ñ, á, é, í, ó, ú,
etc, that are bringing me some troubles. I need some help to fix some
errors. I'll try to explain these:

In my app, I have:

# -*- coding: UTF8 -*-

#### To use UTF-8 CHarset

...
import MySQLdb

####To connect to MySQL

...

#Clase Frame
class Frame(wx.Frame):
    def __init__(self, title, pos, size):
        wx.Frame.__init__(self, None, -1, title, pos, size)
        self.db = MySQLdb.connect("localhost", "javier", "javier", "escuela")

#### Make my connection
...

    def OnAltaAlumnos(self, evt):
        self.AA = wx.Frame(self, -1, "Alta de Alumnos", (40, 30), (750, 600))
        panelAA = wx.Panel (self.AA, -1 )
        tituloAA = wx.StaticText (panelAA , -1, 'Ingreso de Nuevo
Alumno: ', (15, 10))
        LblApellidoAA = wx.StaticText (panelAA, -1, 'Apellido: ', (15, 50))
        self.TxClApellidoAA = wx.TextCtrl(panelAA, -1, '', (115, 40), (100, -1))

#### Some wxTextCtrl in a form to input some data

...

    def OnAceptarAA(self, event):
        apellidos = unicode(self.TxClApellidoAA.GetValue())

#### Brings the data in the wx.TextCtrl
....

#### Put all the data from the form into the Database

c = self.db.cursor()
        c.execute("""INSERT INTO alumnos (apellidos) VALUES (%s) """,
(apellidos))

sancabase.py (41.4 KB)

···

####################
Ok, If I input "Tía" when I want to make a query (Select apellidos
from alumnos) I obtain an error msg like this:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/py/shell.py",
line 1144, in writeOut
    self.write(text)
  File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/py/shell.py",
line 934, in write
    self.AddText(text)
  File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/stc.py",
line 1425, in AddText
    return _stc.StyledTextCtrl_AddText(*args, **kwargs)
  File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-4:
invalid data

If I use PyCrust to view my variables I see: "Tr\xeda"

But............

If I use only PyCrust:

import wx
db=MySQLdb.connect('localhost', 'javier', 'javier', 'escuela')
c = db.cursor()
c.execute("""INSERT INTO alumnos (apellidos) VALUES ('Tía')""")
c.execute('''SELECT apellidos from alumnos''')

5L

d=c.fetchall()
print d

(('T\xc3\xada'),)

print d[0][0]

Tía

Note the difference between 'Tr\xeda' and 'T\xc3\xada' to represent 'Tía'

Why PyCrust insert my special caracters in a correct way buy my app don't ???

Thanks a lot. Regards

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Hi Javier,

Javier Castrillo wrote:

Hi everybody. I'm deploying my first "big" aplication in wxPython and
I'm very glad with this great languaje. (yes, my English is terrible,
sorry, I'm workig on it too :slight_smile: )
My aplication is an school administrator and basically speaks with a
MySQL database through a Frame with menus. It grows day by day, when
its become serius, I'll publish it by GPL license. (The actual full
code is attached too).

Like an Spanish talker, I need some characters like ñ, á, é, í, ó, ú,
etc, that are bringing me some troubles. I need some help to fix some
errors. I'll try to explain these:

Just a guess, on your database connect I don't see that you specify what character set you are working with.

Is the data stored in your SQL DB in utf-8 or in some other encoding? I am not using MySQL, but I would think that you can tell it what character set you want to work with, on mine (orm/kinterbasdb with Firebird) the connect string looks like:

                    self.ds = datasource(adapter="firebird", database=self.dbfilename,
                                user="userid", password="pw",
                                charset="ISO8859_1")

Hope this helps
Werner

Hi Javier,

Now, I don't use the unicode version of wxPython and I have no problem with accents character.
I'm not sure it is the best solution ...

Friendly.

Javier Castrillo a écrit :

···

Hi everybody. I'm deploying my first "big" aplication in wxPython and
I'm very glad with this great languaje. (yes, my English is terrible,
sorry, I'm workig on it too :slight_smile: )
My aplication is an school administrator and basically speaks with a
MySQL database through a Frame with menus. It grows day by day, when
its become serius, I'll publish it by GPL license. (The actual full
code is attached too).

Like an Spanish talker, I need some characters like ñ, á, é, í, ó, ú,
etc, that are bringing me some troubles. I need some help to fix some
errors. I'll try to explain these:

In my app, I have:

# -*- coding: UTF8 -*-

#### To use UTF-8 CHarset

...
import MySQLdb

####To connect to MySQL

...

#Clase Frame
class Frame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
self.db = MySQLdb.connect("localhost", "javier", "javier", "escuela")

#### Make my connection
...

def OnAltaAlumnos(self, evt):
self.AA = wx.Frame(self, -1, "Alta de Alumnos", (40, 30), (750, 600))
panelAA = wx.Panel (self.AA, -1 )
tituloAA = wx.StaticText (panelAA , -1, 'Ingreso de Nuevo
Alumno: ', (15, 10))
LblApellidoAA = wx.StaticText (panelAA, -1, 'Apellido: ', (15, 50))
self.TxClApellidoAA = wx.TextCtrl(panelAA, -1, '', (115, 40), (100, -1))

#### Some wxTextCtrl in a form to input some data

...

def OnAceptarAA(self, event):
apellidos = unicode(self.TxClApellidoAA.GetValue())

#### Brings the data in the wx.TextCtrl
....

#### Put all the data from the form into the Database

c = self.db.cursor()
c.execute("""INSERT INTO alumnos (apellidos) VALUES (%s) """,
(apellidos))

####################
Ok, If I input "Tía" when I want to make a query (Select apellidos
from alumnos) I obtain an error msg like this:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/py/shell.py",
line 1144, in writeOut
self.write(text)
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/py/shell.py",
line 934, in write
self.AddText(text)
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/stc.py",
line 1425, in AddText
return _stc.StyledTextCtrl_AddText(*args, **kwargs)
File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-4:
invalid data

If I use PyCrust to view my variables I see: "Tr\xeda"

But............

If I use only PyCrust:

import wx
db=MySQLdb.connect('localhost', 'javier', 'javier', 'escuela')
c = db.cursor()
c.execute("""INSERT INTO alumnos (apellidos) VALUES ('Tía')""")
c.execute('''SELECT apellidos from alumnos''')

5L

d=c.fetchall()
print d

(('T\xc3\xada'),)

print d[0][0]

Tía

Note the difference between 'Tr\xeda' and 'T\xc3\xada' to represent 'Tía'

Why PyCrust insert my special caracters in a correct way buy my app don't ???

Thanks a lot. Regards

------------------------------------------------------------------------

#!/usr/bin/python
# -*- coding: UTF8 -*-
#
# ---------------------------------------------------------------------------------------------------------------------#
#
# Sancabase - Administrador general para centros de Formación Profesional
# Copyright (c) 2007 Javier Castrillo // riverplatense at gmail dot com
#Este programa es software libre; usted puede redistruirlo y/o modificarlo bajo los términos de la Licencia Pública #General GNU, tal y como está publicada por la Free Software Foundation; ya sea la versión 2 de la Licencia, o (a su #elección) cualquier versión posterior.
#
#Este programa se distribuye con la intención de ser útil, pero SIN NINGUNA GARANT�A; incluso sin la garantía implícita #de USABILIDAD O UTILIDAD PARA UN FIN PARTICULAR. Vea la Licencia Pública General GNU para más detalles.
#
#Usted debería haber recibido una copia de la Licencia Pública General GNU junto a este programa; si no es así, escriba #a la Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, EEUU.
#
# ---------------------------------------------------------------------------------------------------------------------#

import wx
import sys
import MySQLdb

class App(wx.App):
    def OnInit(self):
        frame = Frame("SancaBase - Administrador general para Centros de Formación Profesional", (30, 30), (800, 600))
        frame.Show()
        self.SetTopWindow(frame)
        return True

#Clase Frame
class Frame(wx.Frame):
    def __init__(self, title, pos, size):
        wx.Frame.__init__(self, None, -1, title, pos, size)

        #Me conecto a la base de datos
        self.db = MySQLdb.connect("localhost", "javier", "javier", "escuela")

        #Creo la barra de menúes completa
        menuBar = wx.MenuBar()

        #Menú Archivo
        menuArchivo = wx.Menu()
        menuBar.Append(menuArchivo, "&Archivo")
        menuArchivo.Append(1, "&Salir", "Salir de Sancabase")

        #Menú ABM
        menuABM = wx.Menu()
        menuBar.Append(menuABM, "A&BM")
        submenuAltas = wx.Menu()
        submenuAltas.Append(11, "&Alumnos", "Altas de alumnos")
        submenuAltas.Append(12, "&Cursos", "Altas de cursos")
        submenuAltas.Append(13, "&Instructores", "Altas de instructores")
        submenuAltas.Append(14, "C&oordinadores", "Altas de coordinadores")
        submenuAltas.Append(15, "C&entros", "Altas de Centros")
        menuABM.AppendMenu(10, "Altas", submenuAltas)
        submenuModificaciones = wx.Menu()
        submenuModificaciones.Append(111, "&Alumnos", "Modificaciones de alumnos")
        submenuModificaciones.Append(112, "&Cursos", "Modificaciones de cursos")
        submenuModificaciones.Append(113, "&Instructores", "Modificaciones de instructores")
        submenuModificaciones.Append(114, "C&oordinadores", "Modificaciones de coordinadores")
        submenuModificaciones.Append(115, "C&entros de FP", "Modificaciones de centros de FP")
        menuABM.AppendMenu(110, "Modificaciones", submenuModificaciones)
        menuABM.AppendSeparator()
        menuABM.Append(120, "&Datos del Centro", "Datos de la institución")

        #Menú Listados
        menuListados = wx.Menu()
        menuBar.Append(menuListados, "&Listados")
        menuListados.Append(21, "&Alumnos", "Listado de alumnos")
        menuListados.Append(22, "&Cursos", "Listado de cursos")
        menuListados.Append(23, "&Instructores", "Listado de instructores")
        menuListados.Append(24, "C&oordinadores", "Listado de coordinadores")
        menuListados.Append(25, "C&entros", "Listado de centros de FP")
        menuListados.Append(26, "&Gastos", "Listado de gastos")
        menuListados.Append(27, "&Proyectos", "Listado de proyectos")

        #Menú Gastos
        menuGastos = wx.Menu()
        menuBar.Append(menuGastos, "&Gastos")
        menuGastos.Append(31, "&Nuevo por período", "Abre una planilla de gastos nueva por período")
        menuGastos.Append(32, "N&uevo por proyecto", "Abre una planilla de gastos nueva por proyecto")
        menuGastos.AppendSeparator()
        menuGastos.Append(33, "Abrir p&eríodo", 'Abre una planilla de gastos existente por período')
        menuGastos.Append(34, 'Abrir p&royecto', 'Abre una planilla de gastos existente por proyecto')

        #Menú Gestiones
        menuGestiones = wx.Menu()
        menuBar.Append(menuGestiones, "G&estiones")
        menuGestiones.Append(41, "Agen&da", "Calendario y agenda")
        menuGestiones.Append(42, "&Nueva gestión", "Abre un documento en blanco")
        menuGestiones.AppendSeparator()
        menuGestiones.Append(43, "&Abrir", "Abre un documento existente")

        #Menú Ayuda
        menuAyuda = wx.Menu()
        menuBar.Append(menuAyuda, "Ay&uda")
        menuAyuda.Append(51, "&Ayuda...", "Ayuda")
        menuAyuda.AppendSeparator()
        menuAyuda.Append(52, "A&cerca de...", "Info de esta aplicación")

        #Crear la barra de menúes y de Status
        self.SetMenuBar(menuBar)
        self.CreateStatusBar()
        self.SetStatusText("Sancabase - Administrador de alumnos para Centros de FP")

        #Bindeo de funciones
        self.Bind(wx.EVT_MENU, self.OnExit, id=1)
        self.Bind(wx.EVT_MENU, self.OnAltaAlumnos, id=11)
        self.Bind(wx.EVT_MENU, self.OnAltaCursos, id=12)
        self.Bind(wx.EVT_MENU, self.OnAltaInstructores, id=13)
        self.Bind(wx.EVT_MENU, self.OnAltaCoordinadores, id=14)
        self.Bind(wx.EVT_MENU, self.OnAltaColegios, id=15)
        self.Bind(wx.EVT_MENU, self.OnDatosInstitucion, id=120)
        self.Bind(wx.EVT_MENU, self.OnModAlumnos, id=111)
        self.Bind(wx.EVT_MENU, self.OnGastNuPer, id=31)
        #self.Bind(wx.EVT_MENU, self.OnGastNuProy, id=32)
        #self.Bind(wx.EVT_MENU, self.OnGastAbrPer, id=33)
        #self.Binb(wx.EVT_MENU, self.OnGastAbrProy, id=34)
        self.Bind(wx.EVT_MENU, self.OnAbout, id=52)

    #Función Salir - 1
    def OnExit(self, evt):
        self.Close()

    #Función AltaAlumnos -11
    def OnAltaAlumnos(self, evt):
        self.AA = wx.Frame(self, -1, "Alta de Alumnos", (40, 30), (750, 600))
        panelAA = wx.Panel (self.AA, -1 )
        tituloAA = wx.StaticText (panelAA , -1, 'Ingreso de Nuevo Alumno: ', (15, 10))
        LblApellidoAA = wx.StaticText (panelAA, -1, 'Apellido: ', (15, 50))
        self.TxClApellidoAA = wx.TextCtrl(panelAA, -1, '', (115, 40), (100, -1))
        self.TxClApellidoAA.SetFocus()
        LblNombresAA = wx.StaticText(panelAA, -1, 'Nombres: ', (15, 80))
        self.TxClNombresAA = wx.TextCtrl(panelAA, -1, '', (115, 70), (100, -1))
        LblSexoAA = wx.StaticText (panelAA, -1, 'Sexo: ', (15, 110))
        sexo = ['M', 'F']
        self.CombSexAA = wx.ComboBox(panelAA, -1, 'M', (115, 100), (100, -1), sexo, wx.CB_DROPDOWN)
        LblTipoDocAA = wx.StaticText (panelAA, -1, 'Tipo doc: ', (15, 140))
        tipoDNI = ['DNI', 'CI', 'LE', 'PAS', 'LC']
        self.CombTipoDocAA = wx.ComboBox(panelAA, -1, 'DNI', (115, 130), (100, -1), tipoDNI, wx.CB_DROPDOWN)
        LblNumDocAA = wx.StaticText(panelAA, -1, 'N° doc: ', (15, 170))
        self.TxClNumDocAA = wx.TextCtrl(panelAA, -1, '', (115, 160), (100, -1))
        LblNacAA = wx.StaticText(panelAA, -1, 'Nacionalidad: ', (15, 200))
        Nacionalidades = ['Ar', 'Py', 'Pe', 'Cl', 'Bo', 'Uy', 'Co', 'Es', 'It', 'Ve', 'Br']
        self.ListNacAA = wx.ComboBox(panelAA, -1, 'Ar',(115, 190), (100, -1), Nacionalidades, wx.CB_DROPDOWN)
        LblFechaNacAA = wx.StaticText (panelAA, -1, 'Fecha nac: ', (15, 230))
        self.DpcFechaNacAA = wx.DatePickerCtrl(panelAA, -1, size=(102,-1),pos=(115, 220), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        LblLugNacAA = wx.StaticText(panelAA, -1, 'Lugar nac: ', (15, 260))
        self.TxClLugNacAA = wx.TextCtrl(panelAA, -1, '', (115, 250), (100,-1))
        LblDomAA = wx.StaticText(panelAA, -1, 'Datos del domicilio ', (15, 290))
        LblDomCalleAA = wx.StaticText(panelAA, -1, 'Calle: ', (15, 320))
        self.TxClDomCalleAA = wx.TextCtrl(panelAA, -1, '', (115, 310), (100,-1))
        LblDomNumAA = wx.StaticText(panelAA, -1, 'Número: ', (15, 350))
        self.TxClDomNumAA = wx.TextCtrl(panelAA, -1, '', (115, 340), (100,-1))
        LblDomPisoAA = wx.StaticText(panelAA, -1, 'Piso: ', (15, 380))
        self.TxClDomPisoAA = wx.TextCtrl(panelAA, -1, '', (115, 370), (100,-1))
        LblDomDptoAA = wx.StaticText(panelAA, -1, 'Dpto: ', (15, 410))
        self.TxClDomDptoAA = wx.TextCtrl(panelAA, -1, '', (115, 400), (100,-1))
        LblDomCpAA = wx.StaticText(panelAA, -1, 'Cod. Postal: ', (15, 440))
        self.TxClDomCpAA = wx.TextCtrl(panelAA, -1, '', (115, 430), (100,-1))
        LblDomLocalidadAA = wx.StaticText(panelAA, -1, 'Localidad: ', (15, 470))
        self.TxClDomLocalidaAA = wx.TextCtrl(panelAA, -1, '', (115, 460), (100,-1))
        LblDomPciaAA = wx.StaticText(panelAA, -1, 'Provincia: ', (15, 500))
        self.TxClDomPciaAA = wx.TextCtrl(panelAA, -1, 'Bs As', (115, 490), (100,-1))
        LblTeAA = wx.StaticText(panelAA, -1, 'Teléfono: ', (15, 530))
        self.TxClTeAA = wx.TextCtrl(panelAA, -1, '', (115, 520), (100,-1))
        LblEstAA = wx.StaticText(panelAA, -1, 'Estudios: ', (280, 50))
        estudios = ['Primarios', 'Secundarios', 'Terciarios', 'Universitarios']
        self.CombEstAA = wx.ComboBox(panelAA, -1, 'Primarios', (370, 40), (100, 27), estudios, wx.CB_DROPDOWN)

        self.RadCompAA = wx.RadioButton(panelAA, -1, "Completo", (280, 70), style=wx.RB_GROUP)
        self.RadInCompAA = wx.RadioButton(panelAA, -1, "Hasta", (280, 100))
        self.TxClHastAA = wx.TextCtrl(panelAA, -1, "", (345, 96), (20, -1))
        textAnioAA = wx.StaticText (panelAA, -1, 'año', (370, 100))
        self.textAA = {"Hasta" : self.TxClHastAA}
        self.TxClHastAA.Enable(False)
        for eachRadio in [self.RadCompAA, self.RadInCompAA]:
            self.Bind (wx.EVT_RADIOBUTTON, self.OnEstComp, eachRadio)
        self.selectedText = self.TxClHastAA
        
        self.CorreoAA = wx.TextCtrl(panelAA, -1, '', (370, 130), (100, -1))
        LblTratMedAA = wx.StaticText(panelAA, -1, 'Trat. médico:', (530, 50))
        self.TxCtlTratMedAA = wx.TextCtrl(panelAA, -1, '', (625, 40), (100, 50), style=(wx.TE_MULTILINE))
        LblObsAA = wx.StaticText(panelAA, -1, 'Obs:', (530, 110))
        self.TxCtlObsAA = wx.TextCtrl(panelAA, -1, '', (625, 100), (100, 90), style=wx.TE_MULTILINE)

        # Madre
        textMadAA = wx.StaticText (panelAA, -1, 'Datos de la madre', (280, 230))
        self.checkMadAA = wx.CheckBox (panelAA, -1, "Vive", pos=(410, 225))
        textMadNomAA = wx.StaticText (panelAA, -1, 'Nombre: ', (280, 260))
        self.TxClMadNomAA = wx.TextCtrl(panelAA, -1, "",size=(100, -1), pos = (370, 250))
        LblMadTipoDocAA = wx.StaticText (panelAA, -1, 'Tipo doc: ', (280, 290))
        self.LisMadTipoDocAA = wx.ComboBox(panelAA, -1, 'DNI', (370, 280), (100, 27), tipoDNI, wx.CB_DROPDOWN)
        LblMadNumDocAA = wx.StaticText(panelAA, -1, 'N° doc: ', (280, 320))
        self.TxClMadNumDocAA = wx.TextCtrl(panelAA, -1, size=(100, -1), pos=(370, 310))
        LblMadNacAA = wx.StaticText(panelAA, -1, 'Nacionalidad: ', (280, 350))
        self.LisMadNacAA = wx.ComboBox(panelAA, -1, 'Ar', (370, 340), (100, 27), Nacionalidades, wx.CB_DROPDOWN)
        LblMadFechaNacAA = wx.StaticText (panelAA, -1, 'Fecha nac: ', (280, 380))
        self.DpcMadFechaNacAA = wx.DatePickerCtrl(panelAA, -1, size=(102,-1),pos=(370, 370), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        LblMadOcuAA = wx.StaticText(panelAA, -1, 'Ocupación: ', (280, 410))
        self.TxClMadOcuAA = wx.TextCtrl(panelAA, -1, '', (370, 400), (100, -1))
        LblMadTeAA = wx.StaticText(panelAA, -1, 'Teléfono: ', (280, 440))
        self.TxClMadTeAA = wx.TextCtrl(panelAA, -1, '', (370, 430), (100, -1))
        self.textRelMadAA = {"Vive" : self.TxClMadNomAA, "Vive" : self.LisMadTipoDocAA, "Vive" : self.TxClMadNumDocAA, "Vive" : self.LisMadNacAA, "Vive" : self.DpcMadFechaNacAA, "Vive" : self.TxClMadOcuAA, "Vive" : self.TxClMadTeAA}
        for cadaobj in [self.TxClMadNomAA, self.LisMadTipoDocAA, self.TxClMadNumDocAA, self.LisMadNacAA, self.DpcMadFechaNacAA, self.TxClMadOcuAA, self.TxClMadTeAA]:
            cadaobj.Enable(False)
        self.Bind(wx.EVT_CHECKBOX, self.OnviveMad, self.checkMadAA)

        # Padre
        textPadAA = wx.StaticText (panelAA, -1, 'Datos del Padre', (530, 230))
        self.checkPadAA = wx.CheckBox (panelAA, -1, "Vive", pos=(650, 225))
        textPadNomAA = wx.StaticText (panelAA, -1, 'Nombre: ', (530, 260))
        self.TxClPadNomAA = wx.TextCtrl(panelAA, -1, "", (625, 250), (100, -1))
        LblPadTipoDocAA = wx.StaticText (panelAA, -1, 'Tipo doc: ', (530, 290))
        self.LisPadTipoDocAA = wx.ComboBox(panelAA, -1, 'DNI', (625, 280), (100, 27), tipoDNI, wx.CB_DROPDOWN)
        LblPadNumDocAA = wx.StaticText(panelAA, -1, 'N° doc: ', (530, 320))
        self.TxClPadNumDocAA = wx.TextCtrl(panelAA, -1, '', (625, 310), (100, -1))
        LblPadNacAA = wx.StaticText(panelAA, -1, 'Nacionalidad: ', (530, 350))
        self.LisPadNacAA = wx.ComboBox(panelAA, -1, 'Ar', (625, 340), (100, 27), Nacionalidades, wx.CB_DROPDOWN)
        LblPadFechaNacAA = wx.StaticText (panelAA, -1, 'Fecha nac: ', (530, 380))
        self.DpcPadFechaNacAA = wx.DatePickerCtrl(panelAA, -1, size=(102,-1),pos=(625, 370), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        LblPadOcuAA = wx.StaticText(panelAA, -1, 'Ocupación: ', (530, 410))
        self.TxClPadOcuAA = wx.TextCtrl(panelAA, -1, '', (625, 400), (100, -1))
        LblPadTeAA = wx.StaticText(panelAA, -1, 'Teléfono: ', (530, 440))
        self.TxClPadTeAA = wx.TextCtrl(panelAA, -1, '', (625, 430), (100, -1))
        self.textRelPadAA = {"Vive" : self.TxClPadNomAA, "Vive" : self.LisPadTipoDocAA, "Vive" : self.TxClPadNumDocAA, "Vive" : self.LisPadNacAA, "Vive" : self.DpcPadFechaNacAA, "Vive" : self.TxClPadOcuAA, "Vive" : self.TxClPadTeAA}
        for cadaobj in [self.TxClPadNomAA, self.LisPadTipoDocAA, self.TxClPadNumDocAA, self.LisPadNacAA, self.DpcPadFechaNacAA, self.TxClPadOcuAA, self.TxClPadTeAA]:
            cadaobj.Enable(False)
        self.Bind(wx.EVT_CHECKBOX, self.OnvivePad, self.checkPadAA)

        # Botones AA
        BtnCancelarAA = wx.Button(panelAA, wx.ID_CANCEL,pos= (450, 520))
        self.Bind(wx.EVT_BUTTON, self.OnCloseAA, BtnCancelarAA)
        BtnAceptarAA = wx.Button(panelAA, wx.ID_OK, pos=(600, 520))
        self.Bind(wx.EVT_BUTTON, self.OnAceptarAA, BtnAceptarAA)
        self.AA.Show(True)

    # EstudiosCompletos
    def OnEstComp (self, event):
        if self.selectedText:
            self.selectedText.Enable(False)
        radioSelected = event.GetEventObject()
        text = self.textAA[radioSelected.GetLabel()]
        text.Enable(True)
        self.selectedText = text

    # Madre vive
    def OnviveMad(self, event):
        if self.checkMadAA.IsChecked():
            for cadaobj in [self.TxClMadNomAA, self.LisMadTipoDocAA, self.TxClMadNumDocAA, self.LisMadNacAA, self.DpcMadFechaNacAA, self.TxClMadOcuAA, self.TxClMadTeAA]:
                cadaobj.Enable(True)
        else:
            for cadaobj in [self.TxClMadNomAA, self.LisMadTipoDocAA, self.TxClMadNumDocAA, self.LisMadNacAA, self.DpcMadFechaNacAA, self.TxClMadOcuAA, self.TxClMadTeAA]:
                cadaobj.Enable(False)
    # Padre vive
    def OnvivePad(self, event):
        if self.checkPadAA.IsChecked():
            for cadaobj in [self.TxClPadNomAA, self.LisPadTipoDocAA, self.TxClPadNumDocAA, self.LisPadNacAA, self.DpcPadFechaNacAA, self.TxClPadOcuAA, self.TxClPadTeAA]:
                cadaobj.Enable(True)
        else:
            for cadaobj in [self.TxClPadNomAA, self.LisPadTipoDocAA, self.TxClPadNumDocAA, self.LisPadNacAA, self.DpcPadFechaNacAA, self.TxClPadOcuAA, self.TxClPadTeAA]:
                cadaobj.Enable(False)

    # Botones Alta de alumnos
    def OnCloseAA(self, event):
        self.AA.Destroy()

    def OnAceptarAA(self, event):
        apellidos = unicode(self.TxClApellidoAA.GetValue())
        print apellidos
        nombres = self.TxClNombresAA.GetValue()
        sexo = self.CombSexAA.GetValue()
        tipo_doc = self.CombTipoDocAA.GetValue()
        num_doc = self.TxClNumDocAA.GetValue()
        nacionalidad = self.ListNacAA.GetValue()
        dia = self.DpcFechaNacAA.GetValue()
        fecha_nac = ('%04d/%02d/%04d' % (dia.GetYear(),
                                         dia.GetMonth()+1,
                                         dia.GetDay()))
        lugar_nac = self.TxClLugNacAA.GetValue()
        calle_dom = self.TxClDomCalleAA.GetValue()
        num_dom = self.TxClDomNumAA.GetValue()
        piso_dom = self.TxClDomPisoAA.GetValue()
        dpto_dom = self.TxClDomDptoAA.GetValue()
        cp_dom = self.TxClDomCpAA.GetValue()
        localidad_dom = self.TxClDomLocalidaAA.GetValue()
        pcia_dom = self.TxClDomPciaAA.GetValue()
        tel_dom = self.TxClTeAA.GetValue()
        estudios = self.CombEstAA.GetValue()
        hasta_est = self.TxClHastAA.GetValue()
        correo = self.CorreoAA.GetValue()
        nombre_madre = self.TxClMadNomAA.GetValue()
        tipo_doc_madre = self.LisMadTipoDocAA.GetValue()
        num_doc_madre = self.TxClMadNumDocAA.GetValue()
        nac_madre = self.LisMadNacAA.GetValue()
        dia = self.DpcMadFechaNacAA.GetValue()
        fecha_nac_madre = ('%04d/%02d/%04d' % (dia.GetYear(),
                                               dia.GetMonth()+1,
                                               dia.GetDay()))
        ocupacion_madre = self.TxClMadOcuAA.GetValue()
        vive_madre = self.checkMadAA.IsChecked()
        tel_contacto_madre = self.TxClMadTeAA.GetValue()
        nombre_padre = self.TxClPadNomAA.GetValue()
        tipo_doc_padre = self.LisPadTipoDocAA.GetValue()
        num_doc_padre = self.TxClPadNumDocAA.GetValue()
        nac_padre = self.LisPadNacAA.GetValue()
        dia = self.DpcPadFechaNacAA.GetValue()
        fecha_nac_padre = ('%04d/%02d/%04d' % (dia.GetYear(),
                                               dia.GetMonth()+1,
                                               dia.GetDay()))
        ocupacion_padre = self.TxClPadOcuAA.GetValue()
        vive_padre = self.checkPadAA.IsChecked()
        tel_contacto_padre = self.TxClPadTeAA.GetValue()
        trat_medico = self.TxCtlTratMedAA.GetValue()
        observaciones = self.TxCtlObsAA.GetValue()
        c = self.db.cursor()
        c.execute("""INSERT INTO alumnos (apellidos, nombres, sexo, tipo_doc, num_doc, nacionalidad, fecha_nac, lugar_nac, calle_dom, num_dom, piso_dom, dpto_dom, cp_dom, localidad_dom, pcia_dom, tel_dom, estudios, hasta_est, correo, nombre_madre, tipo_doc_madre, num_doc_madre, nac_madre, fecha_nac_madre, ocupacion_madre, vive_madre, tel_contacto_madre, nombre_padre, tipo_doc_padre, num_doc_padre, nac_padre, fecha_nac_padre, ocupacion_padre, vive_padre, tel_contacto_padre, trat_medico, observaciones) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """, (apellidos, nombres, sexo, tipo_doc, num_doc, nacionalidad, fecha_nac, lugar_nac, calle_dom, num_dom, piso_dom, dpto_dom, cp_dom, localidad_dom, pcia_dom, tel_dom, estudios, hasta_est, correo, nombre_madre, tipo_doc_madre, num_doc_madre, nac_madre, fecha_nac_madre, ocupacion_madre, vive_madre, tel_contacto_madre, nombre_padre, tipo_doc_padre, num_doc_padre, nac_padre, fecha_nac_padre, ocupacion_padre, vive_padre, tel_contacto_padre, trat_medico, observaciones))
        wx.MessageBox("Operación realizada con éxito", "Alta de Alumno", wx.OK | wx.ICON_INFORMATION, self)
        self.AA.Destroy()

    #Función AltaCursos -12
    def OnAltaCursos(self, evt):
        self.AC = wx.Frame(self, -1, "Alta de Cursos", (80, 80), (600, 470))
        panelAC = wx.Panel (self.AC, -1 )
        tituloAC = wx.StaticText (panelAC , -1, 'Ingreso de Nuevo Curso: ', (50, 40))
        LblNumCurso = wx.StaticText (panelAC, -1, 'Curso número: ', (50, 80))
        self.TxClNumCurso = wx.TextCtrl(panelAC, -1, '', (180, 70), (120, -1))
        self.TxClNumCurso.SetFocus()
        tipo = ['FP', 'FPA']
        LblTipo = wx.StaticText (panelAC, -1, 'Tipo: ', (50, 110))
        self.CombTipo = wx.ComboBox(panelAC, -1, '', (180, 100), (120, -1), tipo, wx.CB_DROPDOWN)
        c = self.db.cursor()
        c.execute('''SELECT denominacion FROM especialidades ORDER BY id_especialidad ASC''')
        especialidades = c.fetchall()
        d = len(especialidades)
        StrEsp=
        for denominacion in range(0, d):
            StrEsp.append(especialidades[denominacion][0])
        LblEspecialidad = wx.StaticText (panelAC, -1, 'Especialidad: ', (50, 140))
        self.CombEspecialidad = wx.ComboBox(panelAC, -1, '', (180, 130), wx.DefaultSize, StrEsp, wx.CB_DROPDOWN)
        LblInstructor = wx.StaticText (panelAC, -1, 'Instructor: ', (50, 170))
        c.execute("""SELECT apellido FROM instructores ORDER BY apellido asc""")
        Instructores = c.fetchall()
        d = len(Instructores)
        StrIns=
        for instructor in range (0, d):
            StrIns.append(Instructores[instructor][0])
        self.CombInstructor = wx.ComboBox(panelAC, -1, '', (180, 160), wx.DefaultSize, StrIns, wx.CB_DROPDOWN)
        LblInicio = wx.StaticText (panelAC, -1, 'Fecha inicio: ', (50, 200))
        self.DpcComienzo = wx.DatePickerCtrl(panelAC, -1, size=(120,-1), pos=(180, 190), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        LblFin = wx.StaticText (panelAC, -1, 'Fecha final: ', (50, 230))
        self.DpcFin = wx.DatePickerCtrl(panelAC, -1, size=(120,-1), pos=(180, 220), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        LblHoras = wx.StaticText (panelAC , -1, 'Horas reloj: ', (50, 260))
        self.TxClHoras = wx.SpinCtrl(panelAC, -1, '', (180, 250), (120, -1))
        self.TxClHoras.SetRange(10, 900)
        self.TxClHoras.SetValue(100)
        c.execute("""SELECT nombre FROM establecimientos ORDER BY id_establecimiento asc""")
        Centros = c.fetchall()
        d = len(Centros)
        StrCentros=
        for centro in range (0, d):
            StrCentros.append(Centros[centro][0])
        LblCentros = wx.StaticText (panelAC , -1, 'Centro: ', (50, 290))
        self.CombEstablecimiento = wx.ComboBox(panelAC, -1, '', (180, 280), wx.DefaultSize, StrCentros, wx.CB_DROPDOWN)
        LblAsigAl=wx.StaticText(panelAC, -1, 'Asigna alumnos: ', (50, 320))
        self.ChkAsig = wx.CheckBox(panelAC, -1, '',(180, 315))
        BtnCancelarCu = wx.Button(panelAC, wx.ID_CANCEL, pos = (370, 390))
        self.Bind(wx.EVT_BUTTON, self.OnCloseCu, BtnCancelarCu)
        BtnAceptarCu = wx.Button(panelAC, wx.ID_OK, pos = (470, 390))
        self.Bind(wx.EVT_BUTTON, self.OnAceptarCu, BtnAceptarCu)
        self.AC.Show(True)

    def OnCloseCu(self, event):
        self.AC.Destroy()

    def OnAceptarCu(self, event):
        num_curso = self.TxClNumCurso.GetValue()
        tipo = self.CombTipo.GetValue()
        especialidad = self.CombEspecialidad.GetValue()
        instructor = self.CombInstructor.GetValue()
        #fecha_inicio = self.DpcComienzo.GetValue()
        dia = self.DpcComienzo.GetValue()
        fecha_inicio = ('%04d/%02d/%04d' % (dia.GetYear(),
                                            dia.GetMonth()+1,
                                            dia.GetDay()))
        dia = self.DpcFin.GetValue() fecha_final = ('%04d/%02d/%04d' % (dia.GetYear(),
                                           dia.GetMonth()+1,
                                           dia.GetDay()))
        horas = self.TxClHoras.GetValue()
        establecimiento = self.CombEstablecimiento.GetValue()
        c = self.db.cursor()
        c.execute("""INSERT INTO cursos (num_curso, tipo, especialidad, instructor, fecha_inicio, fecha_final, horas, establecimiento) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) """, (num_curso, tipo, especialidad, instructor, fecha_inicio, fecha_final, horas, establecimiento))
        if self.ChkAsig.IsChecked():
            self.AsA = wx.Frame(self, -1, 'Asignación de alumnos', (130, 130), (500, 360))
            self.panelAsA = wx.Panel(self.AsA, -1)
            tituloAsA = wx.StaticText(self.panelAsA, -1, 'Asignación de alumnos: ', (50, 40))
            LblNumeroAsA = wx.StaticText(self.panelAsA, -1, 'Curso N°: %s' % (num_curso), (50, 80))
            lista = wx.ListCtrl(self.panelAsA, -1, style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_VIRTUAL)

            self.AsA.Show(True)
        else:
            wx.MessageBox("Operación realizada con éxito", "Alta de Curso", wx.OK | wx.ICON_INFORMATION, self)
        self.AC.Destroy()

    #Función AltaInstructores -13°
    def OnAltaInstructores(self, evt):
        self.AI = wx.Frame(self, -1, "Alta de Instructor", (130, 130), (500, 360))
        self.panelAI = wx.Panel (self.AI, -1 )
        tituloAI = wx.StaticText (self.panelAI , -1, 'Ingreso de Instructores: ', (50, 40))
        LblApellidoAI = wx.StaticText (self.panelAI, -1, 'Apellido: ', (50, 80))
        self.TxClApellidoAI = wx.TextCtrl(self.panelAI, -1, '', (180, 70), (125, -1))
        self.TxClApellidoAI.SetFocus()
        LblNombreAI = wx.StaticText (self.panelAI, -1, 'Nombres: ', (50, 110))
        self.TxClNombreAI = wx.TextCtrl(self.panelAI, -1, '', (180, 100), (125, -1))
        LblTeContactoAI = wx.StaticText (self.panelAI, -1, 'TE de contacto: ', (50, 140))
        self.TxClTeContactoAI = wx.TextCtrl(self.panelAI, -1, '', (180, 130), (125, -1))
        LblDomicilioAI = wx.StaticText (self.panelAI, -1, 'Domicilio: ', (50, 170))
        self.TxClDomicilioAI = wx.TextCtrl(self.panelAI, -1, '', (180, 160), (125, -1))
        LblCorreoAI = wx.StaticText (self.panelAI, -1, 'Correo: ', (50, 200))
        self.TxClCorreoAI = wx.TextCtrl(self.panelAI, -1, '', (180, 190), (125, -1))
        BtnCancelarAI = wx.Button(self.panelAI, wx.ID_CANCEL,pos= (300, 300))
        self.Bind(wx.EVT_BUTTON, self.OnCloseAI, BtnCancelarAI)
        BtnAceptarAI = wx.Button(self.panelAI, wx.ID_OK, pos=(400, 300))
        self.Bind(wx.EVT_BUTTON, self.OnAceptarAI, BtnAceptarAI)
        self.AI.Show(True)

    def OnCloseAI(self, event):
        self.AI.Destroy()

    def OnAceptarAI(self, event):
        apellido = self.TxClApellidoAI.GetValue()
        nombres = self.TxClNombreAI.GetValue()
        te_contacto = self.TxClTeContactoAI.GetValue()
        domicilio = self.TxClDomicilioAI.GetValue()
        correo = self.TxClCorreoAI.GetValue()
        c = self.db.cursor()
        c.execute("""INSERT INTO instructores (apellido, nombres, te_contacto, domicilio, correo) VALUES (%s, %s, %s, %s, %s) """, (apellido, nombres, te_contacto, domicilio, correo))
        wx.MessageBox("Operación realizada con éxito", "Alta de Instructor", wx.OK | wx.ICON_INFORMATION, self)
        self.AI.Destroy()

    #Función AltaCoordinadores -14
    def OnAltaCoordinadores(self, evt):
        self.ACD = wx.Frame(self, -1, "Alta de Coordinador", (130, 130), (500, 360))
        self.panelACD = wx.Panel (self.ACD, -1 )
        tituloACD = wx.StaticText (self.panelACD, -1, 'Ingreso de Coordinadores: ', (50, 40))
        LblApellidoACD = wx.StaticText (self.panelACD, -1, 'Apellido: ', (50, 80))
        self.TxClApellidoACD = wx.TextCtrl(self.panelACD, -1, '', size=(125, -1), pos=(180, 70))
        self.TxClApellidoACD.SetFocus()
        LblNombreACD = wx.StaticText (self.panelACD, -1, 'Nombres: ', (50, 110))
        self.TxClNombreACD = wx.TextCtrl(self.panelACD, -1, '', size=(125, -1), pos=(180, 100))
        LblTeContactoACD = wx.StaticText (self.panelACD, -1, 'TE de contacto: ', (50, 140))
        self.TxClTeContactoACD = wx.TextCtrl(self.panelACD, -1, '', size=(125, -1), pos=(180, 130))
        LblDomicilioACD = wx.StaticText (self.panelACD, -1, 'Domicilio: ', (50, 170))
        self.TxClDomicilioACD = wx.TextCtrl(self.panelACD, -1, '', size=(125, -1), pos=(180, 160))
        LblCorreoACD = wx.StaticText (self.panelACD, -1, 'Correo: ', (50, 200) )
        self.TxClCorreoACD = wx.TextCtrl(self.panelACD, -1, '', size=(125, -1), pos=(180, 190))
        BtnCancelarACD = wx.Button(self.panelACD, wx.ID_CANCEL,pos= (300, 300))
        self.Bind(wx.EVT_BUTTON, self.OnCloseACD, BtnCancelarACD)
        BtnAceptarACD = wx.Button(self.panelACD, wx.ID_OK, pos=(400, 300))
        self.Bind(wx.EVT_BUTTON, self.OnAceptarACD, BtnAceptarACD)
        self.ACD.Show(True)

    def OnCloseACD(self, event):
        self.ACD.Destroy()

    def OnAceptarACD(self, event):
        apellido = self.TxClApellidoACD.GetValue()
        nombres = self.TxClNombreACD.GetValue()
        te_contacto = self.TxClTeContactoACD.GetValue()
        domicilio = self.TxClDomicilioACD.GetValue()
        correo = self.TxClCorreoACD.GetValue()
        c = self.db.cursor()
        c.execute("""INSERT INTO coordinadores (apellido, nombres, te_contacto, domicilio, correo) VALUES (%s, %s, %s, %s, %s) """, (apellido, nombres, te_contacto, domicilio, correo))
        wx.MessageBox("Operación realizada con éxito", "Alta de Coordinador", wx.OK | wx.ICON_INFORMATION, self)
        self.ACD.Destroy()

    #Función AltaColegios -15
    def OnAltaColegios(self, evt):
        self.ACG = wx.Frame(self, -1, "Alta de Centros", (100, 100), (600, 500))
        self.panelACG = wx.Panel (self.ACG, -1 )
        tituloACG = wx.StaticText (self.panelACG , -1, 'Datos de la Institución: ', (50, 40))
        LblTipoACG = wx.StaticText (self.panelACG, -1, 'Tipo de establecimiento: ', (50, 80))
        TiposCol= ['CFP', 'EPB', 'POL', 'SEC', 'EGB']
        self.CombACG = wx.ComboBox(self.panelACG, -1, 'CFP', (215, 70), (135, -1), TiposCol, wx.CB_DROPDOWN)
        self.CombACG.SetFocus()
        LblNumeroACG = wx.StaticText (self.panelACG , -1, 'Número (escuela): ', (50, 110))
        self.TxClNumeroACG = wx.TextCtrl(self.panelACG, -1, '', (215, 100), (135, -1))
        LblNombreACG = wx.StaticText (self.panelACG , -1, 'Nombre: ', (50, 140))
        self.TxClNombreACG = wx.TextCtrl(self.panelACG, -1, '', (215, 130), (135, -1))
        LblCalleACG = wx.StaticText (self.panelACG, -1, 'Calle: ', (50, 170))
        self.TxClCalleACG = wx.TextCtrl(self.panelACG, -1, '', (215, 160), (135, -1))
        LblNumPuertaACG = wx.StaticText (self.panelACG , -1, 'Número: (puerta) ', (50, 200))
        self.TxClNumPuertaACG = wx.TextCtrl(self.panelACG, -1, '', (215, 190), (135, -1))
        LblLocalidadACG = wx.StaticText (self.panelACG, -1, 'Localidad: ', (50, 230))
        self.TxClLocalidadACG = wx.TextCtrl(self.panelACG, -1, '', (215, 220), (135, -1))
        LblCPAACG = wx.StaticText (self.panelACG , -1, 'C. Postal: ', (50, 260))
        self.TxClCPAACG = wx.TextCtrl(self.panelACG, -1, '', (215, 250), (135, -1))
        LblTeACG = wx.StaticText (self.panelACG, -1, 'Teléfono: ', (50, 290))
        self.TxClTeACG = wx.TextCtrl(self.panelACG, -1, '', (215, 280), (135, -1))
        LblCorreoACG = wx.StaticText (self.panelACG , -1, 'Correo-e: ', (50, 320))
        self.TxClCorreoACG = wx.TextCtrl(self.panelACG, -1, '', (215, 310), (135, -1))
        LblDistritoACG = wx.StaticText (self.panelACG, -1, 'Distrito: ', (50, 350))
        distritos=['Malvinas Argentinas', 'Vicente López', 'San Isidro', 'San Fernando', 'Tigre', 'Avellaneda', 'Berazategui', 'San Martín', '3 de Febrero', 'Pilar', 'José C. Paz', 'San Miguel']
        self.TxClDistritoACG = wx.ComboBox(self.panelACG, -1, '', (215, 340), wx.DefaultSize, distritos, wx.CB_DROPDOWN)
        LblCoordinador = wx.StaticText(self.panelACG, -1, 'Coordinador: ', (50, 380))
        c = self.db.cursor()
        c.execute('''SELECT apellido FROM coordinadores ORDER BY id_coordinador ASC''')
        coordinadores = c.fetchall()
        d = len(coordinadores)
        StrCoord=
        for coordinador in range(0, d):
            StrCoord.append(coordinadores[coordinador][0])
        self.CombCoord = wx.ComboBox(self.panelACG, -1, '', (215, 370), wx.DefaultSize, StrCoord, wx.CB_DROPDOWN)
        BtnCancelarACG = wx.Button(self.panelACG, wx.ID_CANCEL,pos= (330, 430))
        self.Bind(wx.EVT_BUTTON, self.OnCloseACG, BtnCancelarACG)
        BtnAceptarACG = wx.Button(self.panelACG, wx.ID_OK, pos=(450, 430))
        self.Bind(wx.EVT_BUTTON, self.OnAceptarACG, BtnAceptarACG)
        self.ACG.Show(True)

    def OnCloseACG(self, event):
        self.ACG.Destroy()

    def OnAceptarACG(self, event):
        tipo = self.CombACG.GetValue()
        numero = self.TxClNumeroACG.GetValue()
        nombre = self.TxClNombreACG.GetValue()
        calle = self.TxClCalleACG.GetValue()
        numpuerta = self.TxClNumPuertaACG.GetValue()
        localidad = self.TxClLocalidadACG.GetValue()
        cpa = self.TxClCPAACG.GetValue()
        te = self.TxClTeACG.GetValue()
        correo = self.TxClCorreoACG.GetValue()
        distrito = self.TxClDistritoACG.GetValue()
        coordinador = self.CombCoord.GetValue()
        c = self.db.cursor()
        c.execute("""INSERT INTO establecimientos (tipo, numero, nombre, calle, num_puerta, localidad, cp, telefono, correo, distrito, coordinador) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """, (tipo, numero, nombre, calle, numpuerta, localidad, cpa, te, correo, distrito, coordinador))
        wx.MessageBox("Operación realizada con éxito", "Alta de Institución Educativa", wx.OK | wx.ICON_INFORMATION, self)
        self.ACG.Destroy()

    #Función Datos Institucion -120
    def OnDatosInstitucion(self, evt):
        self.DI = wx.Frame(self, -1, "Edición de datos de la institución educativa", (130, 100), (700, 460))
        self.panelDI = wx.Panel (self.DI, -1 )
        tituloDI = wx.StaticText (self.panelDI , -1, 'Datos de la Institución: ', (50, 40))
        LblTipoDI = wx.StaticText (self.panelDI, -1, 'Tipo: ', (50, 80))
        TiposCol= ['CFP', 'EPB', 'POL', 'SEC', 'EGB']
        self.CombDI = wx.ComboBox(self.panelDI, -1, 'CFP', (150, 70), (80, -1), TiposCol, wx.CB_DROPDOWN)
        self.CombDI.SetFocus()
        LblNumDI = wx.StaticText (self.panelDI , -1, 'Número: ', (50, 110))
        self.TxClNumDI = wx.TextCtrl(self.panelDI, -1, '401', (150, 100), (80, -1))
        LblNombreDI = wx.StaticText (self.panelDI , -1, 'Nombre: ', (50, 140))
        self.TxClNombreDI = wx.TextCtrl(self.panelDI, -1, '', (150, 130), (135, -1))
        LblCalleDI = wx.StaticText (self.panelDI, -1, 'Calle: ', (50, 170))
        self.TxClCalleDI = wx.TextCtrl(self.panelDI, -1, '', (150, 160), (135, -1))
        LblNumPuertaDI = wx.StaticText(self.panelDI, -1, 'N° (puerta): ', (50, 200))
        self.TxCNumPuertaDI = wx.TextCtrl(self.panelDI, -1, '', (150, 190), (80, -1))
        LblCPDI = wx.StaticText (self.panelDI, -1, 'C. Postal: ', (50, 230))
        self.TxClCPDI = wx.TextCtrl(self.panelDI, -1, '', (150, 220), (80, -1))
        LblLocalidadDI = wx.StaticText (self.panelDI, -1, 'Localidad: ', (50, 260))
        self.TxClLocalildadDI = wx.TextCtrl(self.panelDI, -1, '', (150, 250), (135, -1))
        LblTeDI = wx.StaticText (self.panelDI, -1, 'Teléfono: ', (50, 290))
        self.TxClTeDI = wx.TextCtrl(self.panelDI, -1, '', (150, 280), (135, -1))
        LblCorreoDI = wx.StaticText(self.panelDI, -1, 'Correo-e: ', (50, 320))
        self.TxCCorreoDI = wx.TextCtrl(self.panelDI, -1, '', (150, 310), (135, -1))
        distritos=['Malvinas Argentinas', 'Vicente López', 'San Isidro', 'San Fernando', 'Tigre', 'Avellaneda', 'Berazategui', 'San Martín', '3 de Febrero', 'Pilar', 'José C. Paz', 'San Miguel']
        LblDistritoDI = wx.StaticText(self.panelDI, -1, 'Distrito: ', (50, 350))
        self.TxClDistritoDI = wx.ComboBox(self.panelDI, -1, 'Vicente López', (150, 340), wx.DefaultSize, distritos, wx.CB_DROPDOWN)
        LblDirectorDI = wx.StaticText(self.panelDI, -1, 'Director: ', (400, 80))
        self.TxClDirectorDI = wx.TextCtrl(self.panelDI, -1, '', (500, 70), (135, -1))
        LblRegenteDI = wx.StaticText(self.panelDI, -1, 'Regente: ', (400, 110))
        self.TxClRegenteDI = wx.TextCtrl(self.panelDI, -1, '', (500, 100), (135, -1))
        LblSecretarioDI = wx.StaticText(self.panelDI, -1, 'Secretario: ', (400, 140))
        self.TxClSecretarioDI = wx.TextCtrl(self.panelDI, -1, '', (500, 130), (135, -1))
        LblURLDI = wx.StaticText(self.panelDI, -1, 'URL: ', (400, 170))
        self.TxClURLDI = wx.TextCtrl(self.panelDI, -1, '', (500, 160), (135, -1))
        BtnCancelarC = wx.Button(self.panelDI, wx.ID_CANCEL,pos= (430, 400))
        self.Bind(wx.EVT_BUTTON, self.OnCloseC, BtnCancelarC)
        BtnAceptarC = wx.Button(self.panelDI, wx.ID_OK, pos=(550, 400))
        self.Bind(wx.EVT_BUTTON, self.OnAceptarC, BtnAceptarC)
        self.DI.Show(True)

    def OnCloseC(self, event):
        self.DI.Destroy()

    def OnAceptarC(self, event):
        tipo = self.CombDI.GetValue()
        numero = self.TxClNumDI.GetValue()
        nombre = self.TxClNombreDI.GetValue()
        calle = self.TxClCalleDI.GetValue()
        numpuerta = self.TxCNumPuertaDI.GetValue()
        cp = self.TxClCPDI.GetValue()
        localidad = self.TxClLocalildadDI.GetValue()
        telefono = self.TxClTeDI.GetValue()
        ecorreo = self.TxCCorreoDI.GetValue()
        distrito = self.TxClDistritoDI.GetValue()
        director = self.TxClDirectorDI.GetValue()
        regente = self.TxClRegenteDI.GetValue()
        secretario = self.TxClSecretarioDI.GetValue()
        url = self.TxClURLDI.GetValue()
        c = self.db.cursor()
        c.execute("""INSERT INTO miescuela (tipo, numero, nombre, calle, numpuerta, cp, localidad, telefono, ecorreo, distrito, director, regente, secretario, url) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """, (tipo, numero, nombre, calle, numpuerta, cp, localidad, telefono, ecorreo, distrito, director, regente, secretario, url))
        wx.MessageBox("Operación realizada con éxito", "Alta de Mi Centro / Escuela", wx.OK | wx.ICON_INFORMATION, self)
        self.DI.Destroy()

# Modificaciones

    # Modificaciones de alumnos - 111
    def OnModAlumnos(self, event):
        self.dialogMA = wx.TextEntryDialog(None,
        "Ingrese el Apellido del alumno", "Modificación de alumnos", "", style=wx.OK|wx.CANCEL, pos=(300, 300))
        if self.dialogMA.ShowModal() == wx.ID_OK:
            self.apellido = self.dialogMA.GetValue()
        self.dialogMA.Destroy()
        self.MA = wx.Frame(self, -1, "Modificación de datos de alumno", (250, 120), (420, 420))
        panelMA = wx.Panel (self.MA, -1 )
        LblApellMA = wx.StaticText(panelMA, -1, 'Alumnos que cumplen el criterio de búsqueda:', (30, 20))
        LblApellMA = wx.StaticText(panelMA, -1, "Apellido : % s" % (self.apellido), (50, 50))
        c = self.db.cursor()
        c.execute("""SELECT nombres, num_doc FROM alumnos WHERE apellidos = %s""", (self.apellido,))
        q = c.fetchmany()
        print sys.getdefaultencoding()
        print sys.stdout.encoding
        LblQNMA = wx.StaticText(panelMA, -1, "Nombre: %s" % q[0][0], (50, 80))
        LblQDMA = wx.StaticText(panelMA, -1, "DNI: %s" % q[0][1], (50, 110))
        self.MA.Show(True)

    #Función Gastos nuevos por período - 31
    def OnGastNuPer(self, evt):
        self.GNPPreg=wx.Frame(self, -1, 'Gastos por período', (300, 200), (300, 200))
        panel = wx.Panel(self.GNPPreg, -1 )
        Lblsel = wx.StaticText(panel, -1, 'Seleccione el período: ', (20, 20))
        radio1 = wx.RadioButton(panel, -1, 'Anual', (20, 60), style=wx.RB_GROUP)
        radio2 = wx.RadioButton(panel, -1, 'Mensual', (20, 90))
        self.anual = wx.SpinCtrl(panel, -1, '', (120, 60), (120, -1))
        self.anual.SetRange(1990, 2100)
        self.anual.SetValue(2007)
        self.mensual = wx.DatePickerCtrl(panel, -1, size=(120,-1), pos=(121, 90), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        self.texts = {'Anual': self.anual, 'Mensual': self.mensual}
        self.mensual.Enable(False)
        for eachRadio in [radio1, radio2]:
            self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioGastos, eachRadio)
        self.selectedTextGastos = self.anual
        BtnCancelar = wx.Button(panel, wx.ID_CANCEL,pos= (100, 150))
        self.Bind(wx.EVT_BUTTON, self.OnCloseGastos, BtnCancelar)
        BtnAceptar = wx.Button(panel, wx.ID_OK, pos=(200, 150))
        self.Bind(wx.EVT_BUTTON, self.OnGastNuPerPrinc, BtnAceptar)
        self.GNPPreg.Show(True)

    def OnGastNuPerPrinc(self, event):
        import wx.grid
        GasNuPerPr = wx.Frame(self, -1, 'Gastos por período', (10, 10), (950, 700))
        grilla = wx.grid.Grid(GasNuPerPr, -1, (10,10), wx.DefaultSize, style=wx.WANTS_CHARS)
        grilla.CreateGrid(100, 10)
        colLabels = ['Ã?tem', 'Fecha', 'Descripción', 'Responsable', 'Monto', 'Observaciones']
        for col in range (6):
            grilla.SetColLabelValue(col, colLabels[col])
        self.GNPPreg.Destroy()
        GasNuPerPr.Show(True)

    def OnCloseGastos(self, event):
        self.GNPPreg.Destroy()

    # Función de selección de período a crear
    def OnRadioGastos(self, event):
        if self.selectedTextGastos:
            self.selectedTextGastos.Enable(False)
        radioSelected = event.GetEventObject()
        textGastos = self.texts[radioSelected.GetLabel()]
        textGastos.Enable(True)
        self.selectedTextGastos = textGastos

    #Función Acerca de - 52
    def OnAbout(self, evt):
        from wx.lib.wordwrap import wordwrap
        import gpl
        info = wx.AboutDialogInfo()
        #info.SetIcon(self, Vippy.png)
        info.Name = "Administrador SancaBase"
        info.Version = "0.0.5"
        info.Copyright = "Copyleft Javier Castrillo"
        info.Description = '''Esta aplicación está pensada desde el CFP 401
        de Vicente López hacia todos los centros
        de Formación Profesional que día a día ponen
        lo mejor de sí en pos de enriquecer a la siempre
        olvidada y rezagada educación de los pueblos.'''
        info.WebSite = ("http://www.sancayetano.esc.edu.ar", "Sitio de nuestro centro")
        info.Developers = [ "Javier Castrillo riverplatense at gmail dot com"]
        info.License = wordwrap(gpl.licenseText, 500, wx.ClientDC(self))
        wx.AboutBox(info)

#Loop principal
if __name__== '__main__':
    app = App()
    app.MainLoop()
------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--

Hugues JEAN-BAPTISTE (hjb@agorinfo.fr)
AGORINFO S.A.S. (http://www.agorinfo.fr)

Is the data stored in your SQL DB in utf-8 or in some other encoding? I

It's in UTF-8

···

On 07/06/07, Werner F. Bruhin <werner.bruhin@free.fr> wrote:

show variables like "%character%";

+--------------------------+----------------------------+

Variable_name | Value |

+--------------------------+----------------------------+

character_set_client | utf8 |
character_set_connection | utf8 |
character_set_database | utf8 |
character_set_filesystem | binary |
character_set_results | utf8 |
character_set_server | utf8 |
character_set_system | utf8 |
character_sets_dir | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+
8 rows in set (0.00 sec)

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Javier,

Javier Castrillo wrote:

···

On 07/06/07, Werner F. Bruhin <werner.bruhin@free.fr> wrote:

Is the data stored in your SQL DB in utf-8 or in some other encoding? I

It's in UTF-8

Is the problem only happening in an wx.stc control, does it work e.g. in a normal wx.textctrl?

You might also want to check the archive of this list there are some messages relating to Unicode and/or wx.stc.

Werner

Is the problem only happening in an wx.stc control, does it work e.g. in
a normal wx.textctrl?

Sorry, I don't understand. The problem is in a normal wx.TextCtrl. I
don't know what a wx.stc is.

You might also want to check the archive of this list there are some
messages relating to Unicode and/or wx.stc.

I'll do it rigth now. Thanks

···

On 07/06/07, Werner F. Bruhin <werner.bruhin@free.fr> wrote:

Werner

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Javier Castrillo wrote:

Like an Spanish talker, I need some characters like ñ, á, é, í, ó, ú,
etc, that are bringing me some troubles. I need some help to fix some
errors. I'll try to explain these:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/py/shell.py",
line 1144, in writeOut
   self.write(text)
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/py/shell.py",
line 934, in write
   self.AddText(text)
File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/stc.py",
line 1425, in AddText
   return _stc.StyledTextCtrl_AddText(*args, **kwargs)
File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-4:
invalid data

If I use PyCrust to view my variables I see: "Tr\xeda"

But............

If I use only PyCrust:

import wx
db=MySQLdb.connect('localhost', 'javier', 'javier', 'escuela')
c = db.cursor()
c.execute("""INSERT INTO alumnos (apellidos) VALUES ('Tía')""")
c.execute('''SELECT apellidos from alumnos''')

5L

d=c.fetchall()
print d

(('T\xc3\xada'),)

print d[0][0]

Tía

Note the difference between 'Tr\xeda' and 'T\xc3\xada' to represent 'Tía'

Why PyCrust insert my special caracters in a correct way buy my app don't ???

What is the return value of sys.getdefaultencoding()? What about wx.GetDefaultPyEncoding()? Are you using an unicode build or an ansi build of wxPython? Which platform? Can you provide a small runnable sample to show the problem that doesn't depend on having a database?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

What is the return value of sys.getdefaultencoding()?

'utf8'

What about
wx.GetDefaultPyEncoding()?

utf8

Are you using an unicode build or an ansi
build of wxPython?

I not sure, but I think thats an ANSI one. How could I check these???

Which platform?

Ubuntu Feisty

Can you provide a small runnable
sample to show the problem that doesn't depend on having a database?

That problems only appears when I get some results from these db, all
the wx.Static text looks great, with "á, é, ñ," etc !!!!
And if I run the SQL query from PyCrust... it's works fine!!

Thanks a lot

···

On 07/06/07, Robin Dunn <robin@alldunn.com> wrote:

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Javier,

Javier Castrillo wrote:

···

On 07/06/07, Werner F. Bruhin <werner.bruhin@free.fr> wrote:

Is the problem only happening in an wx.stc control, does it work e.g. in
a normal wx.textctrl?

Sorry, I don't understand. The problem is in a normal wx.TextCtrl. I
don't know what a wx.stc is.

I got to that conclusion looking at your traceback, have a look at the end

   return _stc.StyledTextCtrl_AddText(*args, **kwargs)
File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-4:
invalid data

Werner

Pos 2-4 are the unknown characters that "Tía" becomes (sometimes I
think that I write English like drunked Yoda would write)

Tr\xeda (not the rigth way T\xc3\xada)

Am I rigth?

···

On 07/06/07, Werner F. Bruhin <werner.bruhin@free.fr> wrote:

I got to that conclusion looking at your traceback, have a look at the end

File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-4:
invalid data

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Hi Javier,

I not sure, but I think thats an ANSI one. How could I check these???

        log("Running wxPython version %s" % (wx.version()))

or print should show you this.

---Phil

thanks,

the result is:

Running wxPython version 2.8.4.0 (gtk2-unicode)

···

On 07/06/07, Phillip Stevens <pmstevens@verizon.net> wrote:

        log("Running wxPython version %s" % (wx.version()))

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Javier Castrillo wrote:

That problems only appears when I get some results from these db, all
the wx.Static text looks great, with "á, é, ñ," etc !!!!
And if I run the SQL query from PyCrust... it's works fine!!

It may just be that the medium used for display is interpreting the values differently. (For example, printing to a terminal vs. printing to to PyShell vs. having a constant string value in the source code, etc. You can probably check programatically if the value is of the type you expect and if it compares equal to the values you expect.
When you get the value from the db what is the object's type, unicode or string? If it is a string does it decode to unicode correctly using the utf-8 codec?

  uniValue = dbValue.decode('utf-8')

You can then compare that with what you have in a textctrl or whatever. Since you are using a unicode build of wxPython their values will be unicode objects.

  if uniValue == textCtrl.GetValue():
    ...

BTW, I just noticed that in the two representations of 'Tía' that you've shown one is correct for unicode objects and one is correct for a string object using the utf-8 encoding.

  >>>
  >>> st = 'T\xc3\xada'
  >>> uni = s.decode('utf-8')
  >>> print st
  Tía
  >>> print uni
  Tía
  >>> st
  'T\xc3\xada'
  >>> uni
  u'T\xeda'
  >>>

Notice the 'u' in front of that last string?

···

On 07/06/07, Robin Dunn <robin@alldunn.com> wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks a lot Robin. I´ll try these in a few minutes. BTW, when you get
a SQL result from a db, it´s a tuple type object.

Regards, I´ll be there tomorrow with the results of this new stuff. Thak you!

···

On 08/06/07, Robin Dunn <robin@alldunn.com> wrote:

you expect and if it compares equal to the values you expect.
When you get the value from the db what is the object's type, unicode or
string? If it is a string does it decode to unicode correctly using
the utf-8 codec?

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Regards, I´ll be there tomorrow with the results of this new stuff. Thak you!

Here I am again...

etc. You can probably check programatically if the value is of the type
you expect and if it compares equal to the values you expect.
When you get the value from the db what is the object's type, unicode or
string? If it is a string does it decode to unicode correctly using
the utf-8 codec?

      uniValue = dbValue.decode('utf-8')

The value is a String. uniValue returns an error like this (the string
was "tío"):

Traceback (most recent call last):
  File "test.py", line 39, in OnInsert
    uniValue = value.decode('utf-8')
  File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-2:
unexpected end of data

You can then compare that with what you have in a textctrl or whatever.
Since you are using a unicode build of wxPython their values will be
unicode objects.

      if uniValue == textCtrl.GetValue():

Painfully, I can arrive to these point..

But,
I Hope It helps, I think so:
I made a test base (prueba) with only one field (test), a varchar.
Then I wrote a little wx.App with an wx.TextCtrl and a button, when I
press the button, I send the value of the wxTextCtrl to the db, then
It makes a single SQL select query and print some info.

The App code is:

#!/usr/bin/python
# -*- coding: UTF8 -*-

import wx
import sys
import MySQLdb

class App(wx.App):
    def OnInit(self):
        frame = Frame('Prueba Unicode', (30, 30), (300, 300))
        frame.Show()
        self.SetTopWindow(frame)
        return True

class Frame(wx.Frame):
    def __init__(self, title, pos, size):
        wx.Frame.__init__(self, None, -1, title, pos, size)
        self.db = MySQLdb.connect("localhost", "javier", "javier", "escuela")
        panel = wx.Panel(self, -1)
        text = wx.StaticText(panel, -1, 'Data to insert: ', (40, 40))
        self.datatodb = wx.TextCtrl(panel, -1, '', (150, 30), (120, -1))
        self.datatodb.SetFocus()
        BtnInsert = wx.Button(panel, -1, 'Insert',(120, 150))
        self.Bind(wx.EVT_BUTTON, self.OnInsert, BtnInsert)

    def OnInsert(self, event):
        datain = self.datatodb.GetValue()
        print 'Before to send: ', datain
        c = self.db.cursor()
        c.execute('''INSERT INTO prueba(test) VALUES (%s)''', (datain))
        self.datatodb.SetValue('')
        c.execute ('''SELECT test from prueba WHERE test = %s''', (datain))
        d=c.fetchall()
        print 'Tuple result of SQL', d
        value = d[0][0]
        print 'First element of tuple: ', value
        tipo = type(value)
        print 'Type : ', tipo
        uniValue = value.decode('utf-8')
        print 'string.decode: ', uniValue
        print
if __name__== '__main__':
    app = App()
    app.MainLoop()

               ...

Then I test my App two times, first with the word 'Yoda' and later
with the word 'Ví­a'. The result was:

Before to send: yoda
Tuple result of SQL (('yoda',),)
First element of tuple: yoda
Type : <type 'str'>
string.decode: yoda

Before to send: Ví­a
Tuple result of SQL (('V\xeda',),)
First element of tuple: V
Type : <type 'str'>
Traceback (most recent call last):
  File "test.py", line 39, in OnInsert
    uniValue = value.decode('utf-8')
  File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-2:
unexpected end of data

Like we say in Argentina: 'Hasta aquí­ llegó mi amor'
Literally: 'As far as here my love reaches' but now it means 'My
ability has finished, you are my only hope' :slight_smile:

Regards, thanks a lot!!!

···

On 08/06/07, Javier Castrillo <riverplatense@gmail.com> wrote:

On 08/06/07, Robin Dunn <robin@alldunn.com> wrote:

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Javier Castrillo wrote:

      uniValue = dbValue.decode('utf-8')

The value is a String. uniValue returns an error like this (the string
was "tío"):

Traceback (most recent call last):
File "test.py", line 39, in OnInsert
   uniValue = value.decode('utf-8')
File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-2:
unexpected end of data

Then it's not coming out of the DB as utf-8. You'll need to find out what encoding it is and use that one to convert to unicode.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Javier Castrillo wrote:

Hi everybody. I'm deploying my first "big" aplication in wxPython and
I'm very glad with this great languaje. (yes, my English is terrible,
sorry, I'm workig on it too :slight_smile: )
My aplication is an school administrator and basically speaks with a
MySQL database through a Frame with menus. It grows day by day, when
its become serius, I'll publish it by GPL license. (The actual full
code is attached too).

Like an Spanish talker, I need some characters like ñ, á, é, í, ó, ú,
etc, that are bringing me some troubles. I need some help to fix some
errors. I'll try to explain these:

In my app, I have:

# -*- coding: UTF8 -*-

#### To use UTF-8 CHarset

...
import MySQLdb

####To connect to MySQL

...

#Clase Frame
class Frame(wx.Frame):
   def __init__(self, title, pos, size):
       wx.Frame.__init__(self, None, -1, title, pos, size)
       self.db = MySQLdb.connect("localhost", "javier", "javier",
"escuela")

I remember that once I had a similar problem using perl. Even though the
database was set to store in utf-8 I had to explicitly set the charset when
opening a connection. Try:

self.db = MySQLdb.connect("localhost", "javier", "javier", "escuela",
charset='UTF8')

Maybe that helps.

Christian

It was really useful. Thank you!!!

It worked very well. Thanks a lot

···

On 09/06/07, Christian K <ckkart@hoc.net> wrote:

opening a connection. Try:

self.db = MySQLdb.connect("localhost", "javier", "javier", "escuela",
charset='UTF8')

Maybe that helps.

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre