Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 4th, 2004, 07:58 AM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
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

Reply With Quote
  #2  
Old June 5th, 2004, 03:20 PM
sfb sfb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 447 sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level)sfb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 45 sec
Reputation Power: 10
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...

Reply With Quote
  #3  
Old June 5th, 2004, 03:47 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
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

Reply With Quote
  #4  
Old June 5th, 2004, 05:24 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
This link should get you started:

http://wiki.wxpython.org/index.cgi/LongRunningTasks

Dave - The Developers' Coach

Reply With Quote
  #5  
Old June 5th, 2004, 05:51 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Quote:
Originally Posted by DevCoach
This link should get you started:

http://wiki.wxpython.org/index.cgi/LongRunningTasks

Dave - The Developers' Coach


Ya im going to have to deal with this one then. thanx

Reply With Quote
  #6  
Old June 6th, 2004, 11:19 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #7  
Old June 6th, 2004, 12:14 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,553 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110977 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 h 36 m 8 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
Nah you will just get an error about wxYeild being called recursively

Reply With Quote
  #8  
Old June 6th, 2004, 01:27 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > loops in gui


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |