Pasar valores entre Frames

Mario Lacunza mlacunza en gmail.com
Mar Dic 13 21:09:24 CET 2005


OK, te envio un extracto del codigo:

frmMain.py:

import frmGeo
ab=frmGeo.create(None)
ab.Show()
rr=ab.GeneraUbigeo()
print rr

-------------------------------------------------------------------------------------------------------------------------
frmGeo.py:

#Boa:Frame:Frame1

import wx
import Conexion

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BTNOK, wxID_FRAME1CBODEPA, wxID_FRAME1CBODIST,
 wxID_FRAME1CBOPROV, wxID_FRAME1PANEL1, wxID_FRAME1STATICTEXT1,
 wxID_FRAME1STATICTEXT2, wxID_FRAME1STATICTEXT3,
] = [wx.NewId() for _init_ctrls in range(9)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(151, 298), size=wx.Size(743, 90),
              style=wx.DEFAULT_FRAME_STYLE,
              title=u'Ubicaci\xf3n Geogr\xe1fica')
        self.SetClientSize(wx.Size(743, 90))

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1',
parent=self,
              pos=wx.Point(0, 0), size=wx.Size(743, 90),
              style=wx.TAB_TRAVERSAL)

        self.cboDepa = wx.ComboBox(choices=[], id=wxID_FRAME1CBODEPA,
              name=u'cboDepa', parent=self.panel1, pos=wx.Point(24, 46),
              size=wx.Size(150, 25), style=0, value=u'')
        self.cboDepa.SetLabel(u'')
        self.cboDepa.SetToolTipString(u'Departamentos')
        self.cboDepa.Bind(wx.EVT_TEXT_ENTER, self.OnCboDepaTextEnter,
              id=wxID_FRAME1CBODEPA)
        self.cboDepa.Bind(wx.EVT_COMBOBOX, self.OnCboDepaCombobox,
              id=wxID_FRAME1CBODEPA)

        self.cboProv = wx.ComboBox(choices=[], id=wxID_FRAME1CBOPROV,
              name=u'cboProv', parent=self.panel1, pos=wx.Point(240, 46),
              size=wx.Size(192, 25), style=0, value=u'')
        self.cboProv.SetLabel(u'')
        self.cboProv.Enable(True)
        self.cboProv.SetToolTipString(u'Provincias')
        self.cboProv.Bind(wx.EVT_TEXT_ENTER, self.OnCboProvTextEnter,
              id=wxID_FRAME1CBOPROV)
        self.cboProv.Bind(wx.EVT_COMBOBOX, self.OnCboProvCombobox,
              id=wxID_FRAME1CBOPROV)

        self.cboDist = wx.ComboBox(choices=[], id=wxID_FRAME1CBODIST,
              name=u'cboDist', parent=self.panel1, pos=wx.Point(448, 46),
              size=wx.Size(184, 25), style=0, value=u'')
        self.cboDist.SetLabel(u'')
        self.cboDist.SetToolTipString(u'Distritos')
        self.cboDist.Bind(wx.EVT_TEXT_ENTER, self.OnCboDistTextEnter,
              id=wxID_FRAME1CBODIST)
        self.cboDist.Bind(wx.EVT_COMBOBOX, self.OnCboDistCombobox,
              id=wxID_FRAME1CBODIST)

        self.btnOk = wx.Button(id=wxID_FRAME1BTNOK, label=u'Aceptar',
              name=u'btnOk', parent=self.panel1, pos=wx.Point(654, 38),
              size=wx.Size(85, 30), style=0)
        self.btnOk.SetToolTipString(u'Seleccionar')
        self.btnOk.Bind(wx.EVT_BUTTON, self.OnBtnOkButton,
id=wxID_FRAME1BTNOK)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label=u'Departamento', name='staticText1', parent=self.panel1,
              pos=wx.Point(96, 22), size=wx.Size(70, 12), style=0)
        self.staticText1.SetForegroundColour(wx.Colour(0, 0, 255))

        self.staticText2 = wx.StaticText(id=wxID_FRAME1STATICTEXT2,
              label=u'Provincia', name='staticText2', parent=self.panel1,
              pos=wx.Point(300, 22), size=wx.Size(52, 12), style=0)
        self.staticText2.SetForegroundColour(wx.Colour(0, 0, 255))

        self.staticText3 = wx.StaticText(id=wxID_FRAME1STATICTEXT3,
              label=u'Distrito', name='staticText3', parent=self.panel1,
              pos=wx.Point(512, 22), size=wx.Size(52, 12), style=0)
        self.staticText3.SetForegroundColour(wx.Colour(0, 0, 255))

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.oGeo=GeoData()

        self.CargarDepa()

    def CargarDepa(self):
        rs=self.oGeo.CargarDpto()
        i=0

        for it in rs:
            x=unicode(rs[i][1],'iso-8859-15')
            self.cboDepa.Append(x,rs[i][0])
            i+=1


    def GeneraUbigeo(self):
        """Genera el codigo de Ubigeo obtenido."""
        ubigeo=self.keyDepa+self.keyProv+self.keyDist
        return ubigeo


    def OnBtnOkButton(self, event):
        self.GeneraUbigeo()

        self.Close(True)

    def OnCboDepaTextEnter(self, event):
        event.Skip()

    def OnCboDepaCombobox(self, event):

        self.cboProv.Clear()

        cb = event.GetEventObject()
        #Obtengo el Key
        kDepa = cb.GetClientData(cb.GetSelection())
        self.keyDepa=kDepa

        rs=self.oGeo.CargarProv(kDepa)
        i=0

        for it in rs:
            x=unicode(rs[i][1],'iso-8859-15')
            self.cboProv.Append(x,rs[i][0])
            i+=1


    def OnCboProvTextEnter(self, event):
        event.Skip()

    def OnCboProvCombobox(self, event):

        self.cboDist.Clear()

        cb = event.GetEventObject()
        #Obtengo el Key
        kProv = cb.GetClientData(cb.GetSelection())
        self.keyProv=kProv

        rs=self.oGeo.CargarDist(self.keyDepa,kProv)
        i=0

        for it in rs:
            x=unicode(rs[i][1],'iso-8859-15')
            self.cboDist.Append(x,rs[i][0])
            i+=1

    def OnCboDistTextEnter(self, event):
        event.Skip()

    def OnCboDistCombobox(self, event):
        cb = event.GetEventObject()
        #Obtengo el Key
        kDist = cb.GetClientData(cb.GetSelection())
        self.keyDist=kDist


class GeoData:

    def CargarDpto(self):
        """Obtiene los datos de los Departamentos del Peru."""

        sql="Select CO_DEPA, DE_DEPA From A_DEPA"

        cnn=Conexion.Conectar()
        rs=cnn.EjecutarSQL(sql)
        return rs

    def CargarProv(self,mCodDepa):
        """Obtiene los datos de las Provincias del Peru."""

        sql="Select CO_PROV, DE_PROV From A_PROV Where
CO_DEPA='%s'"%(mCodDepa)

        cnn=Conexion.Conectar()
        rs=cnn.EjecutarSQL(sql)
        return rs

    def CargarDist(self,mCodDepas,mCodProv):
        """Obtiene los datos de los Distritos del Peru."""

        sql="Select CO_DIST, DE_DIST From A_DIST Where CO_DEPA='%s' AND
CO_PROV='%s'" %(mCodDepas,mCodProv)

        cnn=Conexion.Conectar()
        rs=cnn.EjecutarSQL(sql)
        return rs
-------------------------------------------------------------------------------------------------------------------------

El error es:

Traceback (most recent call last):
  File "D:\Enlace\src\frmMain.py", line 278, in
OnMnuOperacionesMnuitemcajaMenu
    rr=ab.GeneraUbigeo()
  File "D:\Enlace\src\frmGeo.py", line 98, in GeneraUbigeo
    ubigeo=self.keyDepa+self.keyProv+self.keyDist
AttributeError: 'Frame1' object has no attribute 'keyDepa'

Te agradezco tu tiempo!!

--
Saludos / Best regards

Mario Lacunza
Desarrollador de Sistemas - Webmaster
Desarrollador 2 Estrellas  VS2005

Email: mlacunza [AT] gmail [DOT] com
Website: http://mlacunzav.cogia.net
Blog: http://mlacunza.blogspot.com/
Lima - Peru




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