#!/usr/bin/python #-*- coding: utf-8 -*- title="Pomiar Długośći Narzędzia" fontsize = 15 import sys import os import ConfigParser import Tkinter as tk import subprocess import time MessageFilePath = __file__ + "messages.ini" proceed = "Y" if not os.path.isfile(MessageFilePath): instruction = MessageFilePath + " does not exist" proceed = "N" else: if len(sys.argv) == 1: instruction = "M100 was called with no P value" proceed = "N" else: P=sys.argv[1] if len(P)<7: ps=P else: ps=P[0:len(P)-7] cfg = ConfigParser.ConfigParser() try: cfg.read(MessageFilePath) instruction = cfg.get("Messages", ps) instruction = instruction.decode("utf-8") except (ConfigParser.MissingSectionHeaderError), Argument: proceed = "N" instruction = "First line of\n" + MessageFilePath + "\nmust be:\n[Messages]" pass except (ConfigParser.MissingSectionHeaderError, ConfigParser.NoOptionError), Argument: proceed = "N" instruction = "There is no message for number\n" + P + "\n in the file\n" + MessageFilePath if instruction == "": instruction = "The message for P" + P + " is blank" proceed = "N" mess = os.linesep + instruction.replace("\n", os.linesep) + os.linesep window = tk.Tk() window.title(title) if P == "10.000000": window.geometry("320x240") else: window.geometry("320x180") msg = tk.Message(window, text = mess,width=1000) msg.config(fg="Black", font=("times", fontsize, "bold")) def close(event): exit(1) window.bind("",close) if proceed == "Y": def go_on(event): exit(0) window.bind("",go_on) def Przerwij_clicked(): cmd = "halcmd setp qtdragon.led-probe 1" subprocess.check_output(cmd, shell = True) exit(0) btnNoContinue = tk.Button(window,text="Cancel, Continue without\n measuring the tool",command=Przerwij_clicked,width=60,height=2,font=("Helvetica", "20")) btnNoContinue.configure(bg = "red") def Continue_clicked(): cmd = "halcmd setp qtdragon.led-probe 0" subprocess.check_output(cmd, shell = True) exit(0) btnContinue = tk.Button(window,text="Continue",command=Continue_clicked,width=60,height=1,font=("Helvetica", "22")) btnContinue.configure(bg = "yellow") def Stop_clicked(): exit(1) msg.pack() if proceed == "Y" and P == "10.000000": btnContinue.pack() btnNoContinue.pack() elif proceed == "Y": btnContinue.pack() window.mainloop()