473,385 Members | 1,673 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,385 software developers and data experts.

wxPython: non-GUI thread launching new frame? Delegates?

In my wxPython app a non-GUI thread (that reads info from the network)
tries to open a frame to show the new info. This results in my app
hanging (which is not too surprising). Coming from a C# environment I
wonder if there is some sort of delegate mechanism in wxPython to do
this sort of thing.

2B

Feb 20 '07 #1
6 2089
cyberco wrote:
In my wxPython app a non-GUI thread (that reads info from the network)
tries to open a frame to show the new info. This results in my app
hanging (which is not too surprising). Coming from a C# environment I
wonder if there is some sort of delegate mechanism in wxPython to do
this sort of thing.
Not sure how wx deals with this, but one thing you might explore is the
possibility to add a timer in the GUI-thread, that polls a thread-filled
queue.

Other toolkits as Qt have means to insert an extra event in the event queue
of the gui-thread in a thread-agnostic way, maybe wx has that too.

Googling...
....
....
....

.... finished

http://mail.python.org/pipermail/pyt...st/335467.html

"""
You need another way to pass completion information between the downloader
thread and the main thread; the simplest way is to define a custom wx
Event, and wxPostEvent from the downloader thread when it completes (
and when the gauge should be updated). wxPostEvent is safe to call from
non-eventloop threads.
The main thread's wx event loop just spins, properly updating all other
parts of the GUI, and receiving events from the downloader thread.

ANother approach is to have a thread-safe Queue and have the main
thread/event loop
poll the queue with queue.get_nowait() periodically (typically 0.1-1 sec).
The downloader thread shares the queue object and puts data structures
(typically
class instances, strings, or ints) that indicate status updates.
"""

So - both options a viable. And read to the end, the twisted-approach
certainly is the most clean one.

Diez
Feb 20 '07 #2
On 2/20/07, Diez B. Roggisch <de***@nospam.web.dewrote:
cyberco wrote:
In my wxPython app a non-GUI thread (that reads info from the network)
tries to open a frame to show the new info. This results in my app
hanging (which is not too surprising). Coming from a C# environment I
wonder if there is some sort of delegate mechanism in wxPython to do
this sort of thing.

Not sure how wx deals with this, but one thing you might explore is the
possibility to add a timer in the GUI-thread, that polls a thread-filled
queue.

Other toolkits as Qt have means to insert an extra event in the event queue
of the gui-thread in a thread-agnostic way, maybe wx has that too.

Googling...
...
...
...

... finished

http://mail.python.org/pipermail/pyt...st/335467.html

"""
You need another way to pass completion information between the downloader
thread and the main thread; the simplest way is to define a custom wx
Event, and wxPostEvent from the downloader thread when it completes (
and when the gauge should be updated). wxPostEvent is safe to call from
non-eventloop threads.
The main thread's wx event loop just spins, properly updating all other
parts of the GUI, and receiving events from the downloader thread.

ANother approach is to have a thread-safe Queue and have the main
thread/event loop
poll the queue with queue.get_nowait() periodically (typically 0.1-1 sec).
The downloader thread shares the queue object and puts data structures
(typically
class instances, strings, or ints) that indicate status updates.
"""

So - both options a viable. And read to the end, the twisted-approach
certainly is the most clean one.
This is rather out of date. wxPython provides a wx.CallAfter function,
which will call the passed callable on the next spin through the event
loop. It's essentially a wrapper around the custom event mechanism
described above.
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Feb 20 '07 #3
Ah! Great tip, thanks!
Now instead of calling:

parent.onRequest(param)

I call:

wx.CallAfter(lambda x: parent.onRequest(x), param)

Way cool.
2B
This is rather out of date. wxPython provides a wx.CallAfter function,
which will call the passed callable on the next spin through the event
loop. It's essentially a wrapper around the custom event mechanism
described above.
Diez
Feb 20 '07 #4
On 2007-02-20, cyberco <cy*****@gmail.comwrote:
Ah! Great tip, thanks!
Now instead of calling:

parent.onRequest(param)

I call:

wx.CallAfter(lambda x: parent.onRequest(x), param)
How does that differ from this?

wx.CallAfter(parent.onRequest, param)

--
Grant Edwards grante Yow! .. Everything
at is....FLIPPING AROUND!!
visi.com
Feb 20 '07 #5
On 20 Feb 2007 12:01:02 -0800, cyberco <cy*****@gmail.comwrote:
Ah! Great tip, thanks!
Now instead of calling:

parent.onRequest(param)

I call:

wx.CallAfter(lambda x: parent.onRequest(x), param)
You don't need the lambda - you can use:

wx.CallAfter(parent.OnRequest, param)
Feb 20 '07 #6
Oh boy....I must have hit an all time programmers-low with this....
That was plain stupid.
2B
You don't need the lambda - you can use:

wx.CallAfter(parent.OnRequest, param)

Feb 21 '07 #7

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

Similar topics

16
by: mike420 | last post by:
Tayss wrote: > > app = wxPySimpleApp() > frame = MainWindow(None, -1, "A window") > frame.Show(True) > app.MainLoop() > Why do you need a macro for that? Why don't you just write
5
by: JamesW | last post by:
Dear All, I need to install wxPython to run some programs that interest me. I have had numerous problems, probably due to knowing little about the packages and python, and taking the computer...
21
by: j_mckitrick | last post by:
Just thought I'd play devil's advocate... I tried wxPython briefly, and it had some nice features. It has a huge list of dependencies. I don't like the fonts (but I'd love to know how to get...
15
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems...
14
by: Erik Bethke | last post by:
Hello All, I am getting an error of not well-formed at the beginning of the Korean text in the second example. I am doing something wrong with how I am encoding my Korean? Do I need more of a...
1
by: timothy.williams | last post by:
I'm trying to install wxPython 2.5.3.1 using Python 2.3.2 on a Fedora 2 machine. I have python in a non-standard place, but I'm using --prefix with the configure script to point to where I have...
25
by: TPJ | last post by:
GUI's etc: PyGtk on Windows "(...) So if someone develops mainly for X and just wants to make sure that it is not impossible to run on Windows, you can use PyGTK. (...)", July 2nd, 1999 pyGTK...
4
by: KvS | last post by:
Hi all, I'm pretty new to (wx)Python so plz. don't shoot me if I've missed something obvious ;). I have a panel inside a frame, on which a Button and a StaticText is placed: self.panel =...
8
by: Janwillem | last post by:
Is there a way to force the wx.FileDialog to show as default the thumbnails vie in stead of list view? thanks, janwillem
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.