#!/usr/bin/python

import pygtk
pygtk.require("2.0")
import gtk
import gladevcp.makepins
from gladevcp.gladebuilder import GladeBuilder
import hal
import linuxcnc
import sys,os
xmlname = "mygui.glade"
s = linuxcnc.stat() 
c = linuxcnc.command()
class Mygui(object):
        def estop_clicked(self,widget):
        	s.poll()
        	print "!!!!!!!234"
        if s.task_state == linuxcnc.STATE_ESTOP:
                c.state(linuxcnc.STATE_ESTOP_RESET)
        else:
                c.state(linuxcnc.STATE_ESTOP)
	def on_window1_destroy(self, widget, data=None):
		print "quit++"
		gtk.main_quit()
	def __init__(self):
		self.builder = gtk.Builder()
		self.builder.add_from_file(xmlname)
		halcomp = hal.component("mygui")
		self.builder.connect_signals(self)
		self.window = self.builder.get_object("window1")
		self.window.show()
		#self.window.fullscreen()
		panel = gladevcp.makepins.GladePanel( halcomp, xmlname, self.builder, None)
		

if __name__ == "__main__":
	app = Mygui()
	res = os.spawnvp(os.P_WAIT, "halcmd", ["halcmd", "-f", "./mode.hal"])
	if res: raise SystemExit, res
	gtk.main()
