-
Notifications
You must be signed in to change notification settings - Fork 2
/
gladevcp-jwp.py
70 lines (54 loc) · 2.74 KB
/
gladevcp-jwp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# demo interface to motion jog-while-paused features
import os,sys
from gladevcp.persistence import IniFile,widget_defaults,set_debug,select_widgets
import hal
import hal_glib
import gtk
import glib
import linuxcnc
# see enum pause_state in src/emc/motion/mot_priv.h
states = ("running", "pausing", "paused", "paused/offset","jogging","returning", "pause/step","stepping")
# see src/emc/nml_intf/motion_types.h
motions = ("none", "traverse", "feed", "arc", "toolchange", "probing", "indexrotary")
class HandlerClass:
def _on_state_changed(self,hal_pin,data=None):
state = hal_pin.get()
self.builder.get_object("state").set_text(states[state])
def _on_motion_type_changed(self,hal_pin,data=None):
self.builder.get_object("motion_type_label").set_text(motions[hal_pin.get()])
def on_in_position_changed(self,hal_led,data=None):
if self.state.get() and hal_led.hal_pin.get():
self.s.poll()
posfmt = " ".join(["%-8.4f"] * self.s.axes)
posn = posfmt % self.s.position[:self.s.axes]
print "new_position: ", posn, "motion type=",motions[self.motion_type.get()]
def on_unix_signal(self,signum,stack_frame):
print "on_unix_signal(): signal %d received, saving state" % (signum)
self.ini.save_state(self)
gtk.main_quit()
self.halcomp.exit()
def on_destroy(self,obj,data=None):
print "on_destroy() - saving state"
self.ini.save_state(self)
def __init__(self, halcomp,builder,useropts):
self.halcomp = halcomp
self.builder = builder
(directory,filename) = os.path.split(__file__)
(basename,extension) = os.path.splitext(filename)
self.ini_filename = os.path.join(directory,basename + '.ini')
self.defaults = { IniFile.vars: { },
IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(),
hal_only=True,output_only = True)),
}
self.ini = IniFile(self.ini_filename,self.defaults, self.builder)
self.ini.restore_state(self)
self.c = linuxcnc.command()
self.e = linuxcnc.error_channel()
self.s = linuxcnc.stat()
self.state = hal_glib.GPin(halcomp.newpin('state', hal.HAL_S32, hal.HAL_IN))
self.state.connect('value-changed', self._on_state_changed)
self.motion_type = hal_glib.GPin(halcomp.newpin('motion_type', hal.HAL_S32, hal.HAL_IN))
self.motion_type.connect('value-changed', self._on_motion_type_changed)
def get_handlers(halcomp,builder,useropts, compname):
return [HandlerClass(halcomp,builder,useropts)]