By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

infinite loop + gui freezes the program

P: 1
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
Share this Question
Share on Google+
1 Reply


bartonc
Expert 5K+
P: 6,596
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

Post your reply

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