Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import linuxcnc
- import os
- import hal
- import hal_glib
- from gladevcp.persistence import IniFile,widget_defaults,set_debug,select_widgets
- class HandlerClass:
- def __init__(self, halcomp,builder,useropts):
- self.halcomp = halcomp
- self.builder = builder
- self.useropts = useropts
- self.defaults = {
- # the following names will be saved/restored as method attributes
- # the save/restore mechanism is strongly typed - the variables type will be derived from the type of the
- # initialization value. Currently supported types are: int, float, bool, string
- IniFile.vars : { 'Travel_Offset' : 1.10, 'ArcOK_Timeout' : 1.20, 'Gap_Distance' : 0.150 },
- # Retains all HAL output widgets' state:
- IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(), hal_only=True,output_only = True)),
- }
- #self.defaults = { # these will be saved/restored as method attributes
- #IniFile.vars: { 'nhits' : 0, 'lifetime_ticks': 0, 'a': 1.67, 'd': True, 'c' : "a string"},
- # we're interested restoring state to output HAL widgets only
- # NB: this does NOT restore state pf plain gtk objects - set hal_only to False to do this
- #IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(), hal_only=True,output_only = True)),
- #}
- self.ini_filename = __name__ + '.ini'
- print self.ini_filename
- self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
- self.ini.restore_state(self)
- def on_window1_destroy(self,obj,data=None):
- print "on_destroy() - saving state)"
- self.ini.save_state(self)
- def on_hal_spinbutton1_realize(self,widget):
- widget.set_value(self.Travel_Offset)
- def on_hal_spinbutton1_destroy(self,widget,data=None):
- self.Travel_Offset = widget.get_value()
- def on_hal_spinbutton2_realize(self,widget):
- widget.set_value(self.ArcOK_Timeout)
- def on_hal_spinbutton2_destroy(self,widget,data=None):
- self.ArcOK_Timeout = widget.get_value()
- def on_hal_spinbutton3_realize(self,widget):
- widget.set_value(self.Gap_Distance)
- def on_hal_spinbutton3_destroy(self,widget,data=None):
- self.Gap_Distance = widget.get_value()
- def on_hal_led1_realize(self,widget):
- widget.set_blink_rate(150)
- def on_hal_led7_realize(self,widget):
- widget.set_blink_rate(300)
- def get_handlers(halcomp,builder,useropts):
- print "get_handlers"
- return [HandlerClass(halcomp,builder,useropts)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement