LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2008, 04:02 PM   #1
HaydenLovett
LQ Newbie
 
Registered: Dec 2008
Posts: 1

Rep: Reputation: 0
Looping action while button is pushed in Glade


I have written a script that runs with a glade gui. When a button in glade is pushed I need it to run a piece of code, pause for 3 seconds and run it again in an on going loop until the button is pushed again. So the button is just an on/off control.

I can get it to run the code with out any problems but i cannot get it to stop when the button is pushed again.

I have simplified the code for here,

Code:
from pylab import *
import sys
import datetime
import os
import time

import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade


###############################################################################
# End of Imports 



record = 0
view = 0

class gui:

	def __init__(self):
		global record
		global view
				
               

		
                #Set the Glade file
                self.gladefile = "graph4a.glade"  
                self.wTree = gtk.glade.XML(self.gladefile) 
              
                #Create our dictionay and connect it
                dic = { "on_record_toggled" : self.record_toggle,
                        "on_window1_destroy" : gtk.main_quit }
                
		self.wTree.signal_autoconnect(dic)



		
        def record_toggle(self, widget):
		global record
		if (record == 1):
			print "Record is turned off"
			record = 0                        
						    
                else:
                        print "Record is turned on" 
			record = 1
			os.system("perl modbus3c.pl")   #These 2 lines need to be continually looped
			time.sleep(3)			#whenever the record button is toggled on
							#until it is toggled off again
	

if __name__ == "__main__":
        hwg = gui()
        gtk.main()
 
Old 12-18-2008, 01:23 AM   #2
scheidel21
Senior Member
 
Registered: Feb 2003
Location: CT
Distribution: Debian 6+, CentOS 5+
Posts: 1,323

Rep: Reputation: 100Reputation: 100
I have not really used glade and this may be grasping at straws but is the process that is started backgrounded because is it possible the execution time of the application going a lot longer than you think? Also are you by chance creating an endless loop. really the code to exit the loop needs to be in the loop itself. i.e.

Code:
While btnToggleTXT = "Record On"
   run(process)
   wait 3
   if btnToggleTXT = "Record Off" then
      exit while
   end if
End while
This isn't in any real programming language, but you get the logic behind it. The loop continues forever unless the exit criteria is met. In your scenario you might put a test in after the pause to test if the variable record is still 1 and if it is no longer 1 then you can exit your loop., However, does the application you are calling exit after it finishes too, if it continues to run then you may have to call code to kill the application or exit it. Just some ideas I may be wrong, as a matter of fact I don't see a loop in your code anywhere so it would seem to me you start execution but never end it. I wish I could help you more, but I don't know that much about perl or glade. Let us know if you get it figured out.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python, Glade, using number keys to press button donnied Programming 0 01-20-2008 06:58 PM
Glade GUI :: Cancel Button Code nomb Programming 1 03-15-2007 08:06 AM
Does default middle button action in Firefox 1.5 annoy you? KimVette Linux - Software 2 12-08-2005 02:30 PM
Middle mouse button action TheJkWhoSaysNi Linux - Software 1 03-25-2005 08:38 PM
How to make a window opens when clicking a button with Glade-2 Claus Programming 0 09-24-2003 05:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration