Foros del Web » Programando para Internet » Python »

problema reflejar datos query en wx.textctrl

Estas en el tema de problema reflejar datos query en wx.textctrl en el foro de Python en Foros del Web. Hola, al fin pude hacer una consulta sqlite con interface wxpython pero mi problema actual es que la consulta me la refleja en un cuadro ...
  #1 (permalink)  
Antiguo 01/08/2011, 14:21
Avatar de bosterkill  
Fecha de Ingreso: mayo-2011
Mensajes: 56
Antigüedad: 13 años
Puntos: 0
Pregunta problema reflejar datos query en wx.textctrl

Hola, al fin pude hacer una consulta sqlite con interface wxpython pero mi problema actual es que la consulta me la refleja en un cuadro "wxpython: stdout/stderr" y yo lo unico que deseo es reflejar el dato de base de datos en una caja de texto.. me pueden ayudar??

supongo que es problema con el fetchall()

codigo

Código Python:
Ver original
  1. import wx
  2. import sqlite3 as lite
  3.  
  4. class InsertarDato(wx.Frame):
  5.     def __init__(self, parent, id, title):
  6.         self.con = lite.connect("MiBase.sqlite")
  7.         self.cur = self.con.cursor()
  8.        
  9.         wx.Frame.__init__(self, parent, id, title, size = (280, 200))
  10.        
  11.         panel = wx.Panel(self, -1)
  12.        
  13.                
  14.         gs = wx.FlexGridSizer(3, 2, 9, 9)
  15.         vbox = wx.BoxSizer(wx.VERTICAL)
  16.         hbox = wx.BoxSizer(wx.HORIZONTAL)
  17.        
  18.         codigo = wx.StaticText(panel, -1, "Codigo")
  19.         producto = wx.StaticText(panel, -1, "Producto")
  20.         costo = wx.StaticText(panel, -1, "Costo")
  21.         self.sp = wx.TextCtrl(panel, -1, "", size = (60, -1))
  22.         self.tc1 = wx.TextCtrl(panel, -1, size = (150, -1))
  23.         self.tc2 = wx.TextCtrl(panel, -1, size = (150, -1))
  24.        
  25.         gs.AddMany([(codigo), (self.tc1, 1, wx.LEFT, 10),
  26.                     (producto), (self.tc2, 1, wx.LEFT, 10),
  27.                     (costo), (self.sp, 0, wx.LEFT, 10)])
  28.        
  29.         vbox.Add(gs, 0, wx.ALL, 10)
  30.         vbox.Add((-1, 30))
  31.        
  32.         guardar = wx.Button(panel, -1, "Guardar", size = (-1, 30))
  33.         salir = wx.Button(panel, -1, "Salir", size = (-1, 30))
  34.         buscar = wx.Button(panel, -1, "Buscar", size = (-1, 30))
  35.         hbox.Add(guardar)
  36.         hbox.Add(salir, 0, wx.LEFT, 5)
  37.         hbox.Add(buscar, 0, wx.RIGHT, 5)
  38.         vbox.Add(hbox, 0, wx.ALIGN_CENTER | wx.BOTTOM, 10)
  39.        
  40.         self.Bind(wx.EVT_BUTTON, self.OnGuardar, id = guardar.GetId())
  41.         self.Bind(wx.EVT_BUTTON, self.OnSalir, id = salir.GetId())
  42.         self.Bind(wx.EVT_BUTTON, self.OnBuscar, id = buscar.GetId())
  43.        
  44.         panel.SetSizer(vbox)
  45.        
  46.         self.Centre()
  47.         self.Show(True)
  48.        
  49.                
  50.        
  51.     def OnGuardar(self, event):
  52.         try:
  53.             codigo = self.tc1.GetValue()
  54.             producto = self.tc2.GetValue()
  55.             costo = self.sp.GetValue()
  56.            
  57.             self.cur.execute("insert into inventario values (?, ?, ?)", (codigo, producto, costo))
  58.             self.con.commit()
  59.             self.tc1.Clear()
  60.             self.sp.Clear()
  61.             self.tc2.Clear()
  62.            
  63.         except lite.Error, error:
  64.             dlg = wx.MessageDialog(self, str(error), "Ha ocurrido un error")
  65.             dlg.ShowModal()
  66.            
  67.     def OnSalir(self, event):
  68.         self.Destroy()
  69.      
  70.     def OnBuscar(self, event):
  71.         self.tc1.GetValue()
  72.        
  73.         self.cur.execute("SELECT * FROM inventario WHERE codigo = %s" %self.tc1.GetValue())
  74.         self.tc1.Clear()
  75.         self.recs_list = self.cur.fetchall()
  76.         print self.recs_list
  77.        
  78.  
  79.        
  80.        
  81. app = wx.App()
  82. InsertarDato(None, -1, "Dialogo de Inventario")
  83. app.MainLoop()
  #2 (permalink)  
Antiguo 01/08/2011, 16:53
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: problema reflejar datos query en wx.textctrl

En la linea 76 de tu código de arriba. Estas imprimiendo la lista de resultados. Por eso te manda el dialogo de stdout/stderr.

Ahora, no se como planeas desplegar la información. Te sugiero que uses un ListCtrl y un TextCtrl para hacer una ventana de búsqueda. Algo mas o menos parecido a esto.

Código Python:
Ver original
  1. import wx
  2. import sqlite3
  3.  
  4. class MyFrame(wx.Frame):
  5.     def __init__(self, *args, **kwargs):
  6.         wx.Frame.__init__(self, *args, **kwargs)
  7.         self.panel = MyPanel(self)
  8.        
  9. class MyPanel(wx.Panel):
  10.     def __init__(self, *args, **kwargs):
  11.         wx.Panel.__init__(self, *args, **kwargs)
  12.        
  13.         self.con = sqlite3.connect("MiBase.sqlite")
  14.         self.cur = self.con.cursor()
  15.        
  16.         hbox = wx.BoxSizer(wx.HORIZONTAL)
  17.         box = wx.BoxSizer(wx.VERTICAL)
  18.        
  19.         self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
  20.         self.list.InsertColumn(0, "Codigo")
  21.         self.list.InsertColumn(1, "Producto")
  22.         self.list.InsertColumn(2, "Costo")
  23.        
  24.        
  25.         self.text = wx.TextCtrl(self, -1, size=wx.Size(300, -1))
  26.        
  27.         self.button = wx.Button(self, -1, "Buscar")
  28.         self.button.Bind(wx.EVT_BUTTON, self.onClick)
  29.        
  30.         hbox.Add(self.text, 0)
  31.         hbox.Add(self.button, 0)
  32.        
  33.         box.Add(hbox, 0)
  34.         box.Add(self.list, 1, wx.EXPAND)
  35.        
  36.         self.SetSizer(box)
  37.         self.Center()
  38.        
  39.         self.text.SetFocus()
  40.            
  41.     def onClick(self, event):
  42.         self.cur.execute("SELECT codigo, producto, costo FROM inventario WHERE codigo = ?" , (self.text.GetValue(), ))
  43.         recs_list = self.cur.fetchall()
  44.         self.list.DeleteAllItems()
  45.        
  46.         for row in recs_list:
  47.             pos = self.list.InsertStringItem(0, str(row[0]))
  48.             self.list.SetStringItem(pos, 1, str(row[1]))
  49.             self.list.SetStringItem(pos, 2, str(row[2]))
  50.        
  51. class MyApp(wx.App):
  52.     def OnInit(self):
  53.         frame = MyFrame(None, -1, "ListCtrl")
  54.         frame.Show(True)
  55.         self.SetTopWindow(frame)
  56.         return True
  57.  
  58. app = MyApp(0)
  59. app.MainLoop()
  #3 (permalink)  
Antiguo 01/08/2011, 17:15
Avatar de bosterkill  
Fecha de Ingreso: mayo-2011
Mensajes: 56
Antigüedad: 13 años
Puntos: 0
Respuesta: problema reflejar datos query en wx.textctrl

Hola muchas gracias por responder, me has salvado,

no sabia
Código Python:
Ver original
  1. for row in recs_list:
  2.             pos = self.list.InsertStringItem(0, str(row[0]))
  3.             self.list.SetStringItem(pos, 1, str(row[1]))
  4.             self.list.SetStringItem(pos, 2, str(row[2]))


muchas gracias estoy muy agradecido

Etiquetas: query, wxpython
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:52.