473,385 Members | 1,588 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.

infinite loop + gui freezes the program

Alright guys, If someone could give me some ideas or examples if possible since I'm really stuck on this one without a clue how to proceed. I'm trying to write a little logging program for my scanner, but I'm stuck with infinite loop. Still new to programming, but I got myself to dead end. I want my program to have infinite loop when I press the toggle button and the info to display in labels in my gui. I got that by clicking a button, but whenever I try doing it with infinite loop, my gui freezes. What can I do so that the gui wont freeze?

Here's my code

Expand|Select|Wrap|Line Numbers
  1. def currentStatus():
  2.     ser.write("STS\r")
  3.     return ser.read(139).split(",")
  4.  
  5. class mainApp:
  6.     def __init__(self):
  7.  
  8.         # Set the Glade file
  9.         self.gladefile = "gladeSerialProject.glade"
  10.         self.wTree = gtk.glade.XML(self.gladefile)
  11.  
  12.         # Create dictionary
  13.         signals = { "on_mainWindow_destroy" : gtk.main_quit, \
  14.             "on_button1_clicked"        : self.labelTest, \
  15.             "on_togglebutton1_toggled"    : self.toggleButton }
  16.  
  17.         # connect to the dictionary
  18.         self.wTree.signal_autoconnect(signals)
  19.  
  20.     # Test withi label
  21.     def labelTest(self, widget):
  22.         self.wTree.get_widget("label1").set_text(currentStatus()[6])
  23.  
  24.     #-------------Freezes    
  25.     def toggleButton(self, widget):
  26.         if widget.get_active():
  27.             while True:
  28.                 self.wTree.get_widget("label1").set_text(currentStatus()[6])
  29.             else: print "Press to start"
  30.  
  31.  
  32. if __name__ == "__main__":
  33.     mainApp = mainApp()
  34.     gtk.main()
May 24 '07 #1
1 3042
bartonc
6,596 Expert 4TB
I'm not familiar with GTK, but all gui packages have something like Update() that forces an update event into the event queue. That's how you prevent "tight loops" from freezing the GUI parts of your program.
May 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
37
by: Protoman | last post by:
Hi!!! Protoman here, I need to write an infinite precision number class b/c I want to compute pi. Give me some sample code. Also, when I run my program and it computes pi, will my computer freeze...
6
by: RdR | last post by:
Hi, Has anyone encountered infinite looping in Q Replication? This happens when I have a source DB2 table A going to a target DB2 table B, it also happens that the samne target table B is...
7
by: vjay | last post by:
I want to just create a linklist.The program below goes into an endless loop.The srange behaviour is that i can exit from the program if i create only two nodes.After two goes into infinite loop. ...
10
by: Steven Woody | last post by:
i have a program which always run dead after one or two days, i think somewhere a piece of the code is suspicious of involving into a infinite loop. but for some reason, it is very hard to debug....
33
by: dmoran21 | last post by:
Hi all, I am a mathematician and I'm trying to write a program to try out a formula that I've derived. However, it seems that I've got an infinite loop and I don't quite understand why. I was...
13
by: Sunbags | last post by:
Hello, I'm a 2nd year Computer Engineering student and I have a problem with my VB6 code. I've just started learning VB6 for a project in which we have to create a form which displays the...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
5
by: Tinku | last post by:
I am sorry for asking this silly question, but i don't understand why it is happening please suggest me ================================= #include <stdio.h> int main() { static int i=1;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.