ayuda, con classes
alvaro tovar
alvaro.tovar en gmail.com
Dom Jul 8 16:49:37 CEST 2007
hola, estoy tratando de hacer un programa con hilos, pero tengo un problema,
y no se como resolverlo,
wxPython
-----------------------
import wx
from threading import Thread
ID_ABOUT=101
ID_EXIT=110
class Dialogo(wx.Frame):
control=None
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY, title, size =
(200,100))
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.control.write('fdfda')
self.control.write('fdfda')
self.CreateStatusBar() # A Statusbar in the bottom of the window
# Setting up the menu.
filemenu= wx.Menu()
filemenu.Append(wx.ID_ABOUT, "&About"," Information about this
program")
filemenu.AppendSeparator()
filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame
content.
self.Show(True)
def escribir(self,tex):
self.control.write(tex)
class v(Thread):
frame=None
def run(self):
app = wx.PySimpleApp()
self.frame = Dialogo(None, -1, "Sample editor")
print 'corre',self.frame
print 'dialogo',self.frame.__class__
print dir(self)
print dir(self.frame)
app.MainLoop()
------------------------------
y
servidor
------------------------------
mport socket,thread
from wxPython import *
def leerYescribir(canal,*args):
print 'ller escribir'
ventana=v()
ventana.start()
# thread.start_new_thread(d.correr,())
# thread.start_new_thread(correr,())
print 'fdsf'
print ventana.__class__,dir(ventana)
print ventana.frame.__class__ ,dir(ventana.frame.__class__)
thread.start_new_thread(leer, (canal,ventana.frame))
thread.start_new_thread(escribir, (canal,ventana.frame))
def leer(canal,ventana):
while True:
print 'a escuchar\n'
print dir(ventana)
ventana.control.write('de: '+canal.recv(100)+'\n')
------------------------
corro el servidor
y me sale esto
Unhandled exception in thread started by <function leer at 0x018C3170>
Traceback (most recent call last):
File "E:\aat\eclipse-SDK-3.2-win32\eclipse\workspace\chat\src\servidor.py",
line 20, in leer
a enviar
escribe :
ventana.control.write('de: '+canal.recv(100)+'\n')
AttributeError: 'NoneType' object has no attribute 'control'
dice que ventana no tiene el atributo control y que es de tipo NoneType,
pero no deberia, ventana es de tipo diaogo. en leerYescribir ventana es de
tipo v, y v.frame es Dialogo.
gracias
Más información sobre la lista de distribución Python-es