473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

wxPython unexpected exit

Hi, wxPython is cool and easy to use, But I ran into a problem
recently when I try to write a GUI.
The thing is I want to periodically update the content of StatixText
object, so after create them, I pack them into a list...the problem
comes when I later try to extract them from the list! I don't know
why?
my code is as following:

import wx, socket
import thread

class MyFrame(wx.Frame):

firstrun = 0
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Notifier')
self.panel = wx.Panel(self, -1)
self.length = 50
self.scale = 0.6
self.count = 5
self.size = wx.Frame.GetSize(self)
self.distance = self.size[1] / self.count
self.labellist = []
self.gaugelist = []

def ParseAndDisplay(self, data):
print "Successful access to main Frame class"
print 'And receive data: ', data
if MyFrame.firstrun == 0:
print 'First time run'
items = 3
for i in range(items):
self.labellist.append(wx.StaticText(self.panel, -1, data+str(i),
(150, 50+i*20), (300,30)))
MyFrame.firstrun = 1
else:
self.labellist[0].SetLabel('AAA')//PROGRAM WILL ABORT HERE!!!
self.labellist[1].SetLabel("Guo")
self.labellist[2].SetLabel("Qiang")
class NetUdp:

def __init__(self):
self.port = 8081
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.bind(("", self.port))
print "Listening on port", self.port

def recvdata(self):
data, addr = self.s.recvfrom(1024)
return data
def netThread():
netudp = NetUdp()
while True:
data = netudp.recvdata()
frame.ParseAndDisplay(data)

if __name__ == '__main__':
firstrun = 0
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
# start network thread first
id = thread.start_new_thread(netThread, ())
# main wxpython loop begins
app.MainLoop()

I know the code is ugly, but can anyone really save me here!

Sep 7 '07 #1
4 1911

"Jimmy" <mc**********@gmail.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
Hi, wxPython is cool and easy to use, But I ran into a problem
recently when I try to write a GUI.
The thing is I want to periodically update the content of StatixText
object, so after create them, I pack them into a list...the problem
comes when I later try to extract them from the list! I don't know
why?
my code is as following:

import wx, socket
import thread

class MyFrame(wx.Frame):

firstrun = 0
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Notifier')
self.panel = wx.Panel(self, -1)
self.length = 50
self.scale = 0.6
self.count = 5
self.size = wx.Frame.GetSize(self)
self.distance = self.size[1] / self.count
self.labellist = []
self.gaugelist = []

def ParseAndDisplay(self, data):
print "Successful access to main Frame class"
print 'And receive data: ', data
if MyFrame.firstrun == 0:
print 'First time run'
items = 3
for i in range(items):
self.labellist.append(wx.StaticText(self.panel, -1, data+str(i),
(150, 50+i*20), (300,30)))
MyFrame.firstrun = 1
else:
self.labellist[0].SetLabel('AAA')//PROGRAM WILL ABORT HERE!!!
self.labellist[1].SetLabel("Guo")
self.labellist[2].SetLabel("Qiang")
class NetUdp:

def __init__(self):
self.port = 8081
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.bind(("", self.port))
print "Listening on port", self.port

def recvdata(self):
data, addr = self.s.recvfrom(1024)
return data
def netThread():
netudp = NetUdp()
while True:
data = netudp.recvdata()
frame.ParseAndDisplay(data)

if __name__ == '__main__':
firstrun = 0
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
# start network thread first
id = thread.start_new_thread(netThread, ())
# main wxpython loop begins
app.MainLoop()

I know the code is ugly, but can anyone really save me here!
Communication OS thread -wx has to be done in a certain way. You must not
do this directly, i.e. you must not call wx code from w/i an OS thread. See
the wxPython Demo for an example of what you want to do: Process and
Events -Threads.

Cheers
Thin
Sep 7 '07 #2
On Sep 7, 3:10 am, Jimmy <mcknight0...@gmail.comwrote:
Hi, wxPython is cool and easy to use, But I ran into a problem
recently when I try to write a GUI.
The thing is I want to periodically update the content of StatixText
object, so after create them, I pack them into a list...the problem
comes when I later try to extract them from the list! I don't know
why?
my code is as following:

import wx, socket
import thread

class MyFrame(wx.Frame):

firstrun = 0
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Notifier')
self.panel = wx.Panel(self, -1)
self.length = 50
self.scale = 0.6
self.count = 5
self.size = wx.Frame.GetSize(self)
self.distance = self.size[1] / self.count
self.labellist = []
self.gaugelist = []

def ParseAndDisplay(self, data):
print "Successful access to main Frame class"
print 'And receive data: ', data
if MyFrame.firstrun == 0:
print 'First time run'
items = 3
for i in range(items):
self.labellist.append(wx.StaticText(self.panel, -1, data+str(i),
(150, 50+i*20), (300,30)))
MyFrame.firstrun = 1
else:
self.labellist[0].SetLabel('AAA')//PROGRAM WILL ABORT HERE!!!
self.labellist[1].SetLabel("Guo")
self.labellist[2].SetLabel("Qiang")

class NetUdp:

def __init__(self):
self.port = 8081
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.bind(("", self.port))
print "Listening on port", self.port

def recvdata(self):
data, addr = self.s.recvfrom(1024)
return data

def netThread():
netudp = NetUdp()
while True:
data = netudp.recvdata()
frame.ParseAndDisplay(data)

if __name__ == '__main__':
firstrun = 0
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
# start network thread first
id = thread.start_new_thread(netThread, ())
# main wxpython loop begins
app.MainLoop()

I know the code is ugly, but can anyone really save me here!
If you use threads that update the GUI, you need to take a look at the
following wiki page:
http://wiki.wxpython.org/LongRunningTasks

I've used the techniques therein and they *just work*. I'm not sure if
you can set values on items in a list or not. I've tried that sort of
thing and sometimes it works and sometimes it doesn't.

The wxPython group is probably the best place to ask these questions
anyway: http://www.wxpython.org/maillist.php

Mike
Sep 7 '07 #3
On Sep 7, 9:42 pm, kyoso...@gmail.com wrote:
On Sep 7, 3:10 am, Jimmy <mcknight0...@gmail.comwrote:
Hi, wxPython is cool and easy to use, But I ran into a problem
recently when I try to write a GUI.
The thing is I want to periodically update the content of StatixText
object, so after create them, I pack them into a list...the problem
comes when I later try to extract them from the list! I don't know
why?
my code is as following:
import wx, socket
import thread
class MyFrame(wx.Frame):
firstrun = 0
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Notifier')
self.panel = wx.Panel(self, -1)
self.length = 50
self.scale = 0.6
self.count = 5
self.size = wx.Frame.GetSize(self)
self.distance = self.size[1] / self.count
self.labellist = []
self.gaugelist = []
def ParseAndDisplay(self, data):
print "Successful access to main Frame class"
print 'And receive data: ', data
if MyFrame.firstrun == 0:
print 'First time run'
items = 3
for i in range(items):
self.labellist.append(wx.StaticText(self.panel, -1, data+str(i),
(150, 50+i*20), (300,30)))
MyFrame.firstrun = 1
else:
self.labellist[0].SetLabel('AAA')//PROGRAM WILL ABORT HERE!!!
self.labellist[1].SetLabel("Guo")
self.labellist[2].SetLabel("Qiang")
class NetUdp:
def __init__(self):
self.port = 8081
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.bind(("", self.port))
print "Listening on port", self.port
def recvdata(self):
data, addr = self.s.recvfrom(1024)
return data
def netThread():
netudp = NetUdp()
while True:
data = netudp.recvdata()
frame.ParseAndDisplay(data)
if __name__ == '__main__':
firstrun = 0
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
# start network thread first
id = thread.start_new_thread(netThread, ())
# main wxpython loop begins
app.MainLoop()
I know the code is ugly, but can anyone really save me here!

If you use threads that update the GUI, you need to take a look at the
following wiki page:http://wiki.wxpython.org/LongRunningTasks

I've used the techniques therein and they *just work*. I'm not sure if
you can set values on items in a list or not. I've tried that sort of
thing and sometimes it works and sometimes it doesn't.

The wxPython group is probably the best place to ask these questions
anyway:http://www.wxpython.org/maillist.php

Mike
Thanks for your help! It seems work!
Another question: I create a progress bar, and on creation, it will be
displayed,
How can I invisualize it when later I no longer need it?

Sep 8 '07 #4
Hi,
Thanks for your help! It seems work!
Another question: I create a progress bar, and on creation, it will be
displayed,
How can I invisualize it when later I no longer need it?
I think this is also a good way to use threads. Take a look at the
wxPython demo for the ProgressDialog code. Basically, you run it in a
loop and communicate with it every so often to tell it your progress.
When you're done, you can set some sentinel type value which would
kill the dialog.

I've never used it, but that's how I understand its usage. As I
mentioned, you should consider posting these types of questions to the
wxPython group: http://www.wxpython.org/maillist.php

Mike

Sep 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Townsend | last post by:
I've been experimenting with passing a window handle from a wxPython app to a Tkinter app. The Tkinter app should embed a Toplevel window containing a Canvas widget in the wxPython app's Frame (see...
1
by: flupke | last post by:
Hi, i'm trying to convert my java console app to a python gui. Now, the only problem i seem to have at the moment are the resizers for the layout. It seems that for the purpose of what i'm...
6
by: OKB (not okblacke) | last post by:
I've started taking a look at wxPython, and, well, I've noticed that the syntax needed to code with it is extremely ugly. I am wondering if there exist any preprocessing tools or clever...
1
by: mdk.R | last post by:
Hello all: i'am installed wxPython 2.5 and Python2.3.4..i try execute script with wxPython but it show error: Traceback (most recent call last): File "E:\py\test.py", line 7, in ? import wx...
25
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
1
by: lotmr | last post by:
I have previously posted a simple app I am working on, and while I love python and wxWindows, after checking the memory usage on such a simple app (system try application launcher) I see that it...
3
by: Tian | last post by:
I have made a program in wxpython, but how could i exit the program? I am using wxFrame for my window, what is the function to close the program? Thanks!!
0
by: zjumty | last post by:
I want to install wxPython 2.6 on Solaris10 x86. I have passed "make install", and want to execute python setup.py install. but i got some problems. first i run "python setup.py install",and i...
3
by: nvr | last post by:
Hi all I am doing the socket programming for the client side. but the code is not compiling and i am getting the below error ./Clientsend.c: line 11: syntax error near unexpected token `('...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.