Advertisement
Guest User

Untitled

a guest
Feb 8th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import linuxcnc
  4. import os
  5. import hal
  6. import hal_glib
  7. from gladevcp.persistence import IniFile,widget_defaults,set_debug,select_widgets
  8.  
  9. class HandlerClass:
  10.  
  11. def __init__(self, halcomp,builder,useropts):
  12. self.halcomp = halcomp
  13. self.builder = builder
  14. self.useropts = useropts
  15. self.defaults = {
  16. # the following names will be saved/restored as method attributes
  17. # the save/restore mechanism is strongly typed - the variables type will be derived from the type of the
  18. # initialization value. Currently supported types are: int, float, bool, string
  19. IniFile.vars : { 'Travel_Offset' : 1.11, 'ArcOK_Timeout' : 1.22, 'Gap_Distance' : 0.333 },
  20. # Retains all HAL output widgets' state:
  21. IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(), hal_only=True,output_only = True)),
  22. }
  23.  
  24. #self.defaults = { # these will be saved/restored as method attributes
  25. #IniFile.vars: { 'nhits' : 0, 'lifetime_ticks': 0, 'a': 1.67, 'd': True, 'c' : "a string"},
  26. # we're interested restoring state to output HAL widgets only
  27. # NB: this does NOT restore state pf plain gtk objects - set hal_only to False to do this
  28. #IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(), hal_only=True,output_only = True)),
  29. #}
  30.  
  31.  
  32. self.ini_filename = __name__ + '.ini'
  33. print self.ini_filename
  34. self.ini = IniFile(self.ini_filename,self.defaults,self.builder)
  35. self.ini.restore_state(self)
  36.  
  37. self.builder.get_object('hal_spinbutton1').set_value(self.Travel_Offset)
  38. self.builder.get_object('hal_spinbutton2').set_value(self.ArcOK_Timeout)
  39. self.builder.get_object('hal_spinbutton3').set_value(self.Gap_Distance)
  40.  
  41. def on_window1_destroy(self,obj,data=None):
  42. self.set_value(self.Travel_Offset,self.ArcOK_Timeout,self.Gap_Distance)
  43. print "on_destroy() - saving state)"
  44. self.ini.save_state(self)
  45.  
  46. def on_hal_led1_realize(self,widget):
  47. widget.set_blink_rate(150)
  48.  
  49. def on_hal_led7_realize(self,widget):
  50. widget.set_blink_rate(300)
  51.  
  52. def get_handlers(halcomp,builder,useropts):
  53. print "get_handlers"
  54. return [HandlerClass(halcomp,builder,useropts)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement