Hello
I am trying to work with threads and wxPython, but i have one problem.
In my application i open main Window and i then i am trying to open another window in thread, but the second window does not work. Take look on my code, please:
#-*- coding: utf-8 -*-
import re, time
import thread,threading, socket,wx
DEFAULT_HOST='localhost'
DEFAULT_PORT=1991
class ReceiveEmail:
def __init__(self):
while 1:
self.send_warning("some warning")
time.sleep(15)
def send_warning(self,what):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((DEFAULT_HOST, DEFAULT_PORT))
s.send(what)
s.close()
class Server(threading.Thread):
def __init__(self,prijimaci_funkce):
self.prijimaci_funkce=prijimaci_funkce
self.S = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.S.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.S.bind((DEFAULT_HOST,DEFAULT_PORT))
self.S.listen(5)
threading.Thread.__init__(self)
self.start()
#Start thread:
thread.start_new_thread(ReceiveEmail, ())
def run(self):
while True:
try:
newS, address = self.S.accept()
receivedData = newS.recv(1024)
self.prijimaci_funkce(receivedData)
newS.close()
finally: pass
self.S.close()
class EmailWarningWindow:
def __init__(self):
self.okno=wx.Frame(None,title="Second Window",id=1987,size=(490,340),style =wx.SIMPLE_BORDER|wx.STAY_ON_TOP)
wx.StaticText(self.okno, label="some text")
wx.Yield()
self.okno.SetAutoLayout(True)
self.okno.Show(True)
class App:
def __init__(self):
okno = wx.App(0)
self.okno=wx.Frame(None,title="First window",id=-1,size=(490,340))
Server(accept)
self.okno.Show(True)
okno.MainLoop()
def accept(data):
#Run the second window;
EmailWarningWindow()
if __name__ == "__main__":
App()
The first window (called "first window") does work normall, but the second window (called "second window") does not work:(
I tryied to solve it for several hours, but i didnt solve it; please help me
Thanks