Okienko zmiany narzędzia – dodawanie własnego GUI do Axisa
Plik //usr/bin/axis/ po funkcji parse_gcode_expression(e) a przed definicją
klasy _prompt_areyousure
wstawiamy nasą klasę:
class _prompt_tool:
""" Prompt for new tool number"""
def __init__(self, title, text):
t = self.t = Toplevel(root_window, padx=7, pady=7)
t.wm_title(title)
t.wm_transient(root_window)
t.wm_resizable(0, 0)
m = Message(t, text=text, aspect=500, anchor="w", justify="left")
self.w = w = StringVar(t)
l = Tkinter.Message(t, textvariable=w, justify="left", anchor="w", aspect=500)
self.inputs = fi = Tkinter.Frame(t)
self.v1 = v1 = StringVar(fi)
l1 = Label(fi, text=_("New tool:"))
self.e1 = e1 = Entry(fi, textvariable=v1)
#e1.configure(takefocus=1)
self.buttons = f = Tkinter.Frame(t)
self.ok = Tkinter.Button(f, text=_("Ok"), command=self.do_ok, width=10,height=1,padx=0,pady=.25, default="active")
self.cancel = Tkinter.Button(f, text=_("Cancel"), command=self.do_cancel, width=10,height=1,padx=0,pady=.25, default="normal")
m.pack(side="top", anchor="w")
l.pack(side="top", anchor="w", fill="x", expand=1)
l1.pack(side="top", anchor="w")
e1.pack(side="top", anchor="e")
fi.pack(side="top", anchor="e")
f.pack(side="bottom", anchor="e")
self.ok.pack(side="left", padx=3, pady=3)
self.cancel.pack(side="left", padx=3, pady=3)
t.wm_protocol("WM_DELETE_WINDOW", self.cancel.invoke)
t.bind("<Return>", lambda event: (self.ok.flash(), self.ok.invoke()))
t.bind("<KP_Enter>", lambda event: (self.ok.flash(), self.ok.invoke()))
t.bind("<Escape>", lambda event: (self.cancel.flash(), self.cancel.invoke()))
def do_ok(self):
self.status=True
self.t.destroy()
def do_cancel(self):
self.status=False
self.t.destroy()
def result(self):
return (self.v1.get())
def do_focus(self):
print("do focus")
if not self.e1.winfo_viewable():
self._after = self.t.after(10, self.do_focus)
else:
self.e1.focus()
self.e1.selection_range(0, "end")
self._after = None
def run(self):
self.t.grab_set()
self._after = self.t.after_idle(self.do_focus)
self.t.wait_window()
try:
self.t.destroy()
except Tkinter.TclError:
pass
return self.result()
def prompt_tool(title, text):
t = _prompt_tool(title, text)
return t.run()(tak, def prompt_tool(title, text) jest
już poza definicją klasy)
Niżej – po funkcji clear_offset a przed
touch_off wstawiamy naszą funkcję:
def select_tool(event=None, new_tool = None):
new_tool = prompt_tool(_("Select tool:"), _("Select tool:"))
ensure_mode(linuxcnc.MODE_MDI)
s.poll()
tool_command = "M6 T%s G43" % new_tool
c.mdi(tool_command)
c.wait_complete()
ensure_mode(linuxcnc.MODE_MANUAL)
s.poll()
o.tkRedraw() W pliku //usr/share/axis/tcl/axis.tcl/
po setup_widget_accel $_tabs_manual.jogf.zerohome.zero [_ „Touch Off”]
dodajemy nasz button:
button $_tabs_manual.jogf.zerohome.tool
-command select_tool
-padx 2m
-pady 0
setup_widget_accel $_tabs_manual.jogf.zerohome.tool [_ "Set tool"]
a niżej po bloku zaczynającym się od grid $_tabs_manual.jogf.zerohome.zero
dodajemy nasz blok:
grid $_tabs_manual.jogf.zerohome.tool
-column 1
-row 1
-ipadx 2
-pady 2
-sticky w
W ten sposób dodaliśmy do Axisa nowy przycisk wywołujący naszą funkcję prompttool
Teraz w ~.axisrc/ dodajemy sobie nasz skrót klawiszowy (u nas jest to Control-n)
root_window.bind("<Control-n>", commands.select_tool)
i już.
Napisaliśmy własną funkcję, dodaliśmy ją do GUI i podpięliśmy do skrótu klawiszowego. Jak to mówią amerykanie: 'nie próbujcie tego pod Machem’ 🙂