Ah thanks, I wasn't aware that we could use GladeVCP panels with the axis gui.
Here is a custom mcode using python that works on it's own. Calling it will open a popup for XYZ values (includes value checking) and a click on the 'Set' button will set the current work offsets to the entered values, so there are no halpins involved.
Code:
#!/usr/bin/python3
import linuxcnc
import tkinter as tk
from tkinter import Tk, X, BOTH, LEFT
from tkinter import ttk
from tkinter.ttk import Frame, Label, Entry, Button
# add/remove the entries needed
entry_list = ('X','Y','Z')
class SimpleDialog(Frame):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.master.title("Enter Offset ")
self.pack(fill=BOTH, expand=True)
self.entries = []
for entry in entry_list:
self.e = self.createEntry(entry)
self.entries.append(self.e)
self.label_error = ttk.Label(self, foreground='red')
self.label_error.pack(fill=X, padx=5, expand=True)
frame_last = Frame(self)
frame_last.pack(fill=X)
self.btn = Button(frame_last, text="Set", command=self.onSubmit)
self.btn.pack(padx=5, pady=5)
self.btn.bind('<Return>', self.onSubmit)
def createEntry(self, entry):
frame = Frame(self)
frame.pack(fill=X)
lbl = Label(frame, text=entry+":", width=4)
lbl.pack(side=LEFT, padx=5, pady=2)
self.vcmd = (self.register(self.validate), '%P', '%W')
self.entry = Entry(frame)
self.entry.insert(0, '0')
self.entry.config(validate='focusout', validatecommand=self.vcmd)
self.entry.pack(fill=X, padx=5, expand=True)
return self.entry
def show_message(self, w, error='', color='black'):
color_state = []
self.label_error['text'] = error
for i in range(len(self.entries)):
if w == str(self.entries[i]):
self.entries[i]['foreground'] = color
color_state.append(str(self.entries[i].cget('foreground')))
if 'red' in color_state:
self.btn.configure(state="disabled")
else:
self.btn.configure(state="normal")
def validate(self, value, w):
try:
result = float(value)
self.show_message(w)
return True
except ValueError:
self.show_message(w, 'Invalid entry.', 'red')
return False
def onSubmit(self, *args):
value1 = float(self.entries[0].get())
value2 = float(self.entries[1].get())
value3 = float(self.entries[2].get())
# Get rid of the error message if the user clicks the
# close icon instead of the submit button
try:
root.destroy()
except:
pass
c = linuxcnc.command()
c.mdi('G10 L2 P0 X%f Y%f Z%f ' % (value1, value2, value3))
self.quit()
# This part triggers the dialog
root = Tk()
# the more entries in the list the longer the window needs to be
l = len(entry_list)
root.geometry("250x" + str(l*22+60) + "+300+300")
app = SimpleDialog()
root.mainloop()