Files
linuxcncAllWasm/configs/sim/axis/panelui-demo/panelui_handler.py
2026-08-20 06:17:39 +08:00

51 lines
2.0 KiB
Python

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 m # print the argument(s)
#print wname.metadata # Print the calling widgets internal metadata (from config file)
# call a mdi command to print a msg in linuxcnc
# parent commands expect a widget_instance - None is substituted
self.parent.mdi_and_return(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)