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
|
import hal
# standard handler call - This will always be required
def get_handlers(linuxcnc_stat, linucnc_cmd, commands, master):
return [HandlerClass(linuxcnc_stat, linucnc_cmd, commands, master)]
# Also required - handler class
class HandlerClass:
# This will be pretty standard to gain access to everything
# linuxcnc_stat: is the python status instance of linuxcnc
# linuxcnc_cmd: is the python command instance of linuxcnc
# commands: is the command instance so one can call the internal routines
# master: give access to the master functions/data
def __init__(self, linuxcnc_stat, linuxcnc_cmd, commands, master):
self.parent = commands
self.current_mode = 0
# command functions are expected to have this layout:
# def some_name(self, widget_instance, arguments from widget):
# widget_instance gives access to the calling widget's function/data
# arguments can be a list of arguments, a single argument, or None
# depending on what was given in the configuration file.
def hello_world(self, wname, m):
# print to terminal so we know it worked
print('\nHello world\n')
# print the argument(s)
print(m)
# Print the calling widgets internal metadata (from config file)
print(wname.metadata)
# call a mdi command to print a msg in linuxcnc
# parent commands expect a widget_instance - None is substituted
self.parent.mdi(None,'(MSG, Hello Linuxcnc World!)')
def cycle_mode(self, wname, m):
if self.current_mode == 0:
self.current_mode = 1
self.parent.set_mdi_mode()
elif self.current_mode == 1:
self.current_mode = 2
self.parent.set_auto_mode()
else:
self.current_mode = 0
self.parent.set_manual_mode()
print(self.current_mode)
# Boiler code, often required
def __getitem__(self, item):
return getattr(self, item)
def __setitem__(self, item, value):
return setattr(self, item, value)
|