The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
loops in gui
Discuss loops in gui in the Python Programming forum on Dev Shed. loops in gui Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 4th, 2004, 06:58 AM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
loops in gui
Can anyone show me an example of wxPython with a while loop in it? cause i have been tring to add a while loop in one of my programs using wxPython.. but it stops the gui from loading.... i tried using threading but every time i am about to read about it.. i get disturbed by something or someone 
|

June 5th, 2004, 02:20 PM
|
|
|
Where or why are you trying to use a while loop?
Generally, with GUI programs, they are event-driven, so you respond to button clicks, mouse movements, etc. If you put a while loop in one of these methods, it wouldn't stop the GUI from loading - it would stop it from updating for a ... while.
If you are trying to have something happen all the time while your GUI is running, make a method for the action, and set a timer to trigger the method every so often.
In other words, a While loop is probably not the best solution to whatever you are trying to do in a GUI environment...
|

June 5th, 2004, 02:47 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
Quote: | Originally Posted by sfb Where or why are you trying to use a while loop?
Generally, with GUI programs, they are event-driven, so you respond to button clicks, mouse movements, etc. If you put a while loop in one of these methods, it wouldn't stop the GUI from loading - it would stop it from updating for a ... while.
If you are trying to have something happen all the time while your GUI is running, make a method for the action, and set a timer to trigger the method every so often.
In other words, a While loop is probably not the best solution to whatever you are trying to do in a GUI environment... |
Not nececeraly.. i was using socket.recv( ) in a while loop to get socket data.. didnt know what was going on cause it didnt want to load anything.... then i search around and i find
Code:
wxSocketClient::Connect
bool Connect(wxSockAddress& address, bool wait = TRUE)
Connects to a server using the specified address.
If wait is TRUE, Connect will wait until the connection completes. Warning: This will block the GUI.
I whent in to wxwidget irc chan and as you can see this class funtion ( wxSocketclient:Connect ) is the same as using the low level socket module... The only option i got is using threaded socket.. ( but dont know how yet, this is why i asked for a sample ) or select, or twisted.. And at the moment i dont want to learn twisted... so if anyone has an example using threading.. i would like to see it if its kool
|

June 5th, 2004, 04:24 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|

June 5th, 2004, 04:51 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
Quote: | Originally Posted by DevCoach |
Ya im going to have to deal with this one then. thanx
|

June 6th, 2004, 10:19 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
Forget the threading, looking at the link Dave supplied it looks like all you have to di is call the wxYield() function inside your loop to force the window to refesh and it should work fine..
Mark.
__________________
programming language development: www.netytan.com – Hula
|

June 6th, 2004, 11:14 AM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
Nah you will just get an error about wxYeild being called recursively
|

June 6th, 2004, 12:27 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
Quote: | Originally Posted by xlordt Nah you will just get an error about wxYeild being called recursively |
You can get round this by calling wxGetApp().wxYield(True). Th global function wxGetApp returns the wxApp object, and the wxYield method takes a boolean parameter that makes it only yield when not called recursively.
From the docs:
Quote:
wxApp::Yield
bool Yield(bool onlyIfNeeded = FALSE)
Yields control to pending messages in the windowing system. This can be useful, for example, when a time-consuming process writes to a text window. Without an occasional yield, the text window will not be updated properly, and on systems with cooperative multitasking, such as Windows 3.1 other processes will not respond.
Caution should be exercised, however, since yielding may allow the user to perform actions which are not compatible with the current task. Disabling menu items or whole menus during processing can avoid unwanted reentrance of code: see ::wxSafeYield for a better function.
Note that Yield() will not flush the message logs. This is intentional as calling Yield() is usually done to quickly update the screen and popping up a message box dialog may be undesirable. If you do wish to flush the log messages immediately (otherwise it will be done during the next idle loop iteration), call wxLog::FlushActive.
Calling Yield() recursively is normally an error and an assert failure is raised in debug build if such situation is detected. However if the the onlyIfNeeded parameter is TRUE, the method will just silently return FALSE instead. |
Dave - The Developers' Coach
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|