Hola a todos como estan, me pueden ayudar con un problemilla

Mark Tavera mark.private.007 en gmail.com
Mar Mar 27 00:38:42 CEST 2007


soy nuevo en este lenguaje de programacion, estoy usando en postgres 8.1 y
python 2.4 con wx.python y la herramienta que estoy utilizando para
programar es Ulipad, y estoy utilizando el wx.grid para cargar datos de una
tabla el problema es que no se como recuperar  los datos del wx.grid  les
mando mi codigo .

# -*- coding: utf-8 -*-#
import wx
import wx.grid            as grid
import gridXML
import conecta

class Producto(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self,parent,id,title, (-1, -1), wx.Size(800,450))

        self.grid=grid.Grid(self,-1, pos=(10,80), size=(730,320), style=
wx.DD_DEFAULT_STYLE)
        self.grid.headers = ["codigo","nombre"]

        self.log = ''
        self.moveTo = None
        self.Bind(wx.EVT_IDLE, self.OnIdle)

        consulta1="select * from ingproducto"
        #print consulta1
        odat1=conecta.Postgres()
        odat1.Conexion()
        res1=odat1.Consultar(consulta1)
        #odat1.CerraConexion()
        self.grid.data=res1
        self.grid.SetTable(gridXML.XmlTableModel (self.grid.headers,
self.grid.data),True)
        self.grid.SetColSize(0,100)
        self.grid.SetColSize(1,150)




# test all the events

        self.Bind(grid.EVT_GRID_CELL_LEFT_CLICK , self.OnCellLeftClick)
        self.Bind(grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnCellRightClick)
        self.Bind(grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnCellLeftDClick)
        self.Bind(grid.EVT_GRID_CELL_RIGHT_DCLICK , self.OnCellRightDClick)

        self.Bind(grid.EVT_GRID_LABEL_LEFT_CLICK, self.OnLabelLeftClick)
        self.Bind(grid.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClick)
        self.Bind(grid.EVT_GRID_LABEL_LEFT_DCLICK , self.OnLabelLeftDClick)
        self.Bind(grid.EVT_GRID_LABEL_RIGHT_DCLICK, self.OnLabelRightDClick)

        self.Bind(grid.EVT_GRID_ROW_SIZE, self.OnRowSize)
        self.Bind(grid.EVT_GRID_COL_SIZE, self.OnColSize )

        self.Bind(grid.EVT_GRID_RANGE_SELECT, self.OnRangeSelect)
        self.Bind(grid.EVT_GRID_CELL_CHANGE, self.OnCellChange)
        self.Bind(grid.EVT_GRID_SELECT_CELL, self.OnSelectCell)

        self.Bind(grid.EVT_GRID_EDITOR_SHOWN, self.OnEditorShown)
        self.Bind(grid.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden)
        self.Bind(grid.EVT_GRID_EDITOR_CREATED, self.OnEditorCreated)


    def OnCellLeftClick(self, evt):
        self.log.write("OnCellLeftClick: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
        evt.Skip()

    def OnCellRightClick(self, evt):
        self.log.write("OnCellRightClick: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
        evt.Skip()

    def OnCellLeftDClick(self, evt):
        self.log.write ("OnCellLeftDClick: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
        evt.Skip()

    def OnCellRightDClick(self, evt):
        self.log.write("OnCellRightDClick: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
        evt.Skip()

    def OnLabelLeftClick(self, evt):
        self.log.write("OnLabelLeftClick: (%d,%d) %s\n" %
                       ( evt.GetRow(), evt.GetCol(), evt.GetPosition()))
        evt.Skip()

    def OnLabelRightClick(self, evt):
        self.log.write("OnLabelRightClick: (%d,%d) %s\n" %
                       (evt.GetRow (), evt.GetCol(), evt.GetPosition()))
        evt.Skip()

    def OnLabelLeftDClick(self, evt):
        self.log.write("OnLabelLeftDClick: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol (), evt.GetPosition()))
        evt.Skip()

    def OnLabelRightDClick(self, evt):
        self.log.write("OnLabelRightDClick: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition ()))
        evt.Skip()

    def OnRowSize(self, evt):
        self.log.write("OnRowSize: row %d, %s\n" %
                       (evt.GetRowOrCol(), evt.GetPosition()))
        evt.Skip()

    def OnColSize(self, evt):
        self.log.write("OnColSize: col %d, %s\n" %
                       (evt.GetRowOrCol(), evt.GetPosition()))
        evt.Skip()

    def OnRangeSelect(self, evt):
        if evt.Selecting():
            self.log.write("OnRangeSelect: top-left %s, bottom-right %s\n" %
                           (evt.GetTopLeftCoords(), evt.GetBottomRightCoords
()))
        evt.Skip ()


    def OnCellChange(self, evt):
        self.log.write("OnCellChange: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition()))

        # Show how to stay in a cell that has bad data.  We can't just
        # call SetGridCursor here since we are nested inside one so it
        # won't have any effect.  Instead, set coordinates to move to in
        # idle time.
        value = self.GetCellValue(evt.GetRow (), evt.GetCol())

        if value == 'no good':
            self.moveTo = evt.GetRow(), evt.GetCol()


    def OnIdle(self, evt):
        if self.moveTo != None:
            self.SetGridCursor (self.moveTo[0], self.moveTo[1])
            self.moveTo = None

        evt.Skip()


    def OnSelectCell(self, evt):
        self.log.write("OnSelectCell: (%d,%d) %s\n" %
                       ( evt.GetRow(), evt.GetCol(), evt.GetPosition()))

        # Another way to stay in a cell that has a bad value...
        row = self.GetGridCursorRow()
        col = self.GetGridCursorCol()

        if self.IsCellEditControlEnabled ():
            self.HideCellEditControl()
            self.DisableCellEditControl()

        value = self.GetCellValue(row, col)

        if value == 'no good 2':
            return  # cancels the cell selection

        evt.Skip()


    def OnEditorShown(self, evt):
        if evt.GetRow() == 6 and evt.GetCol() == 3 and \
           wx.MessageBox("Are you sure you wish to edit this cell?",
                        "Checking", wx.YES_NO) == wx.NO:
            evt.Veto()
            return

        self.log.write("OnEditorShown: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
        evt.Skip()


    def OnEditorHidden(self, evt):
        if evt.GetRow() == 6 and evt.GetCol() == 3 and \
           wx.MessageBox("Are you sure you wish to  finish editing this
cell?",
                        "Checking", wx.YES_NO) == wx.NO:
            evt.Veto()
            return

        self.log.write("OnEditorHidden: (%d,%d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetPosition()))
        evt.Skip()


    def OnEditorCreated(self, evt):
        self.log.write("OnEditorCreated: (%d, %d) %s\n" %
                       (evt.GetRow(), evt.GetCol(), evt.GetControl()))


class MyApp( wx.App):
    def OnInit(self):
        frame = Producto(None, -1, 'Lista Personal')
        frame.SetIcon(wx.Icon('add-new-client.gif', wx.BITMAP_TYPE_GIF))

        frame.Show(True)
        return True


app = MyApp(0)
app.MainLoop()



Espero que me puedan ayudar Gracias


Att:   mark.private.007 en gmail.com




Más información sobre la lista de distribución Python-es