#!/usr/bin/python import sys, os import gettext BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")) gettext.install("linuxcnc", localedir=os.path.join(BASE, "share", "locale"), unicode=True) import linuxcnc, hal import rs274.options LOGFILE = open('/tmp/manualtoolchange.log', 'w') LOGFILE.write('Start\n') linuxcncStat = linuxcnc.stat(); linuxcncCmd = linuxcnc.command() def do_change(n): LOGFILE.write('in do_change - with tool '+str(n)+'\n') linuxcncStat.poll() curLine = linuxcncStat.current_line if n: message = _("Insert tool %d and click continue when ready") % n else: message = _("Remove the tool and click continue when ready") app.wm_withdraw() app.update() if curLine >=0: LOGFILE.write('in do_change - curLine more than 0 and is '+str(curLine)+'\n') linuxcncCmd.abort() h.changed = True LOGFILE.write('in do_change - h.changed is '+str(h.changed)+'\n') app.tk.call("nf_dialog", ".tool_change", _("Tool change"), message, "info", 0, _("Continue")) LOGFILE.write('in do_change - dialog raised\n') if curLine >=0: linuxcncCmd.mode(linuxcnc.MODE_AUTO) linuxcncCmd.auto(linuxcnc.AUTO_RUN, curLine + 1) LOGFILE.write('in do_change - in if - linuxcnc.MODE_AUTO\n') else: h.changed = True LOGFILE.write('in do_change - else if - set h.changed to True\n') LOGFILE.write('in do_change - h.changed is '+str(h.changed)+'\n') app.update() LOGFILE.write('in do_change - done\n') h = hal.component("hal_manualtoolchange") h.newpin("number", hal.HAL_S32, hal.HAL_IN) h.newpin("change", hal.HAL_BIT, hal.HAL_IN) h.newpin("changed", hal.HAL_BIT, hal.HAL_OUT) h.ready() LOGFILE.write('HAL Created\n') LOGFILE.write('h.number = ') LOGFILE.write(str(h.number)) LOGFILE.write('\n') LOGFILE.write('h.change = ') LOGFILE.write(str(h.change)) LOGFILE.write('\n') LOGFILE.write('h.changed = ') LOGFILE.write(str(h.changed)) LOGFILE.write('\n') import Tkinter, nf, rs274.options app = Tkinter.Tk(className="AxisToolChanger") app.wm_geometry("-60-60") app.wm_title(_("AXIS Manual Toolchanger")) rs274.options.install(app) nf.start(app); nf.makecommand(app, "_", _) app.wm_protocol("WM_DELETE_WINDOW", app.wm_withdraw) lab = Tkinter.Message(app, aspect=500, text = _("\ This window is part of the AXIS manual toolchanger. It is safe to close\ or iconify this window, or it will close automatically after a few seconds.")) lab.pack() def withdraw(): LOGFILE.write('in withdraw...\n') app.wm_withdraw() app.bind("", lambda event: app.wm_withdraw()) app.after(10 * 1000, withdraw) try: while 1: LOGFILE.write('in While...\n') change = h.change if change and not h.changed: LOGFILE.write('in While... do_change\n') do_change(h.number) elif not change: LOGFILE.write('in While... elif not change\n') h.changed = False app.after(100) app.update() LOGFILE.write('done While.\n') except KeyboardInterrupt: pass LOGFILE.write('Closing...\n') LOGFILE.close()