################ __init__#################################3 #Pins connected to the corresponding iocontrol pins self.halcomp.newpin("tool-prep-number", hal.HAL_S32, hal.HAL_IN) self.halcomp.newpin("tool-prepare", hal.HAL_BIT, hal.HAL_IN) #Get tooltable self.path_inifile = os.environ.get('INI_FILE_NAME', '/dev/null') self.tooltable = os.path.dirname(self.path_inifile) + "/tool.tbl" #Pop-up window "stolen" from hal_manualtoolchange self.app = Tkinter.Tk() self.app.wm_geometry("-60-60") self.app.wm_title(_("AXIS Manual Toolchanger")) rs274.options.install(self.app) nf.start(self.app); nf.makecommand(self.app, "_", _) self.app.wm_protocol("WM_DELETE_WINDOW", self.app.wm_withdraw) #I have it withdraw right away because i dont want to look at it self.app.wm_withdraw() self.app.bind("", lambda event: self.app.wm_withdraw()) #Load tool table, could be loaded every tool change if you want to be able to still edit tool table without restart. fd = open(self.tooltable,"r") self.tooltable_lines = fd.readlines() fd.close ############## Periodicly ################## if self.halcomp['tool-prepare'] == True: # Will be true if M6 is called with a valid tool number self.toolchange_popup() ###### Methods ############# def toolchange_popup(self): message = _("Please change to tool nr. %s :") % self.halcomp['tool-prep-number'] + "\n " + self.get_tool_remark() try: r = self.app.call("nf_dialog", ".tool_change", _("Tool change request"), message, "info", 0, _("Continue")) finally: self.app.update() def get_tool_remark(self): for l in self.tooltable_lines: if _("T%s ")%self.halcomp['tool-prep-number'] in l: tool_entry = l tool_remark = after(tool_entry,";") return tool_remark #credit: https://www.dotnetperls.com/between-before-after-python def after(value, a): # Find and validate first part. pos_a = value.rfind(a) if pos_a == -1: return "" # Returns chars after the found string. adjusted_pos_a = pos_a + len(a) if adjusted_pos_a >= len(value): return "" return value[adjusted_pos_a:]