1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
| import os
import subprocess
import shlex
import tkinter as tk
from tkinter import filedialog
from tkinter import Toplevel
from tkinter.ttk import *
import tkinter.scrolledtext as tkst
import datetime
import sys
class Dialog(tk.Frame):
def __init__(self, master):
self.master = master
self.file_opt = options = {}
options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
options['initialfile'] = 'Watt.txt'
options['parent'] = master
def export_result(self, Var1):
self.filename = filedialog.asksaveasfile(mode='w', defaultextension='.txt', **self.file_opt)
if self.filename is None:
return
self.filename.write(Var1)
self.filename.close()
def message(self):
self.newWindow = Toplevel(self.master)
self.newWindow.title('Warning - Empty Field')
class TextArea(tk.Frame):
def __init__(self, parent):
self.parent = parent
self.dial = Dialog(parent)
tk.Frame.__init__(self, parent)
self.bill = tkst.ScrolledText(width=150, height=40, bg='#ECECEC')
self.bill.grid(row=1, column=0)
def print_output(self, a):
self.bill.insert('end', a)
def clear_screen(self):
self.bill.delete('0.0', 'end')
def get_output(self):
self.Var0 = self.bill.get('1.0', 'end')
self.dial.export_result(self.Var0)
class RadioButton(tk.Frame):
def __init__(self, parent):
self.parent = parent
self.butt = MainFrame(parent)
self.dialo = Dialog(parent)
tk.Frame.__init__(self, parent)
LIST = [
('Order Type/Tote Location Check', 'OTC'),
('Tote Decoupling Check', 'TDC'),
('Tracking Tote Id', 'TTid'),
('List Pickers', 'LP'),
('Send Message To Picker(s)[csv]', 'SM'),
('Kill Pid(s)[csv]', 'Kid')
]
self.v = tk.StringVar()
self.v.set('OTC')
val = 0
for text, mode in LIST:
self.radio = tk.Radiobutton(parent, text=text, variable=self.v, value=mode, bg='#ECECEC')
self.radio.grid(row=0, column=val)
val += 1
def function_sel(self):
if self.v != None and self.butt.entry1_1.select_present:
if self.v == 'OTC':
self.butt.ordertype()
elif self.v == 'TDC':
self.butt.q_down_load()
elif self.v == 'TTid':
self.butt.adbridge2()
else:
self.dialo.message()
class MainFrame(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.master = master
self.frameH1 = Frame(self.master)
self.frameH1.grid(row=0, column=0)
self.radiobutton0_0 = RadioButton(self.frameH1)
self.radiobutton0_0.grid(row=0, column=0, sticky=tk.E + tk.W)
self.label1_0 = Label(self.frameH1, text='Tote Id')
self.label1_0.grid(row=1, column=0, sticky=tk.E, pady=5)
self.sep1_0 = Separator(self.frameH1, orient='horizontal')
self.sep1_0.grid(row=0, column=0, columnspan=6, sticky=tk.W + tk.E + tk.S)
self.entry1_1 = tk.StringVar()
self.entry1_1 = Entry(self.frameH1, textvariable=self.entry1_1.get())
self.entry1_1.grid(row=1, column=1)
self.label1_2 = Label(self.frameH1, text='Pid')
self.label1_2.grid(row=1, column=2, sticky=tk.E)
self.entry1_3 = Entry(self.frameH1)
self.entry1_3.grid(row=1, column=3)
self.label1_4 = Label(self.frameH1, text='Picker Id')
self.label1_4.grid(row=1, column=4, sticky=tk.E)
self.entry1_5 = Entry(self.frameH1)
self.entry1_5.grid(row=1, column=5)
self.sep2_0 = Separator(self.frameH1, orient='horizontal')
self.sep2_0.grid(row=1, column=0, columnspan=6, sticky=tk.W + tk.E + tk.S)
self.sep3_0 = Separator(self.frameH1, orient='horizontal')
self.sep3_0.grid(row=3, column=0, columnspan=6, sticky=tk.W + tk.E + tk.S)
self.button2_0 = Button(self.frameH1, text='Execute', command=self.radiobutton0_0.function_sel())
self.button2_0.grid(row=2, column=1, pady=5)
self.frameH2 = Frame(self.master)
self.frameH2.grid(row=1, column=0)
self.tex = TextArea(self.frameH2)
self.tex.grid(row=1, column=0)
self.button2_3 = Button(self.frameH1, text='Clear Screen')
self.button2_3.bind('<Button-1>', lambda e: self.tex.clear_screen(), add='+')
self.button2_3.bind('<Button-1>', lambda e: self.entry1_1.delete('0', 'end'), add='+')
self.button2_3.grid(row=2, column=3)
self.button2_5 = Button(self.frameH1, text='Quit', command=self.frameH1.quit)
self.button2_5.grid(row=2, column=5, padx=15)
self.frameH3 = Frame(master)
self.frameH3.grid(row=2, column=0)
self.label4_0 = Label(self.frameH3, text='PTL Server Network Status')
self.label4_0.grid(row=0, column=0, pady=5, padx='10')
self.c4_1 = tk.Checkbutton(self.frameH3, bg='#ECECEC')
self.c4_1.grid(row=0, column=1, padx='10')
self.label4_2 = Label(self.frameH3, text='Controller Network Status')
self.label4_2.grid(row=0, column=2, padx='10')
self.c4_3 = tk.Checkbutton(self.frameH3, bg='#ECECEC')
self.c4_3.grid(row=0, column=3, padx='10')
self.label4_4 = Label(self.frameH3, text='PLC Network Status')
self.label4_4.grid(row=0, column=4, padx='10')
self.c4_5 = tk.Checkbutton(self.frameH3, bg='#ECECEC')
self.c4_5.grid(row=0, column=5, padx='10')
self.button4_6 = Button(self.frameH3, text='Export Screen Result')
self.button4_6.bind('<Button-1>', lambda e: self.tex.get_output())
self.button4_6.grid(row=0, column=6, padx='90')
def ordertype(self):
filename = 'logptlcont'
filepath = os.path.abspath(filename)
command_line = '''awk -F, 'match ($0,toteID) {T=$4} END {print T}' filePath'''
argos = shlex.split(command_line)
argos[2] = 'match ($0, %s ) {T=$4} END {print T}' % self.entry1_1.get()
argos[3] = filepath
self.p = subprocess.check_output(argos)
self.output1 = self.p.decode(sys.stdout.encoding)
self.out = self.entry1_1.get() + str('-') + self.output1
self.tex.print_output(self.out)
def q_down_load(self):
fileName = 'q_down_load'
filePath = os.path.abspath(fileName)
self.cat = subprocess.Popen(['cat', filePath], stdout=subprocess.PIPE, )
self.grep1 = subprocess.Popen(['grep', '.'], stdin=self.cat.stdout, stdout=subprocess.PIPE, )
self.grep2 = subprocess.Popen(['grep', '-B1', self.entry1_1.get()], stdin=self.grep1.stdout,
stdout=subprocess.PIPE, universal_newlines=True)
self.out, err = self.grep2.communicate()
if self.out == '':
self.out = str('%s - %s - No Such Tote Found\n' % (datetime.date.today(), self.entry1_1.get()))
self.tex.print_output(self.out)
def adbridge2(self):
filename = 'logptlcont'
filePath = os.path.abspath(filename)
self.grep1 = subprocess.Popen(['grep', '-i', 'STAT1', filePath], stdout=subprocess.PIPE, )
self.grep2 = subprocess.Popen(['grep', self.entry1_1.get(), '--color=auto'], stdin=self.grep1.stdout,
stdout=subprocess.PIPE, universal_newlines=True)
self.out, err = self.grep2.communicate()
if self.out == '':
self.out = str('%s - %s - No Such Tote Found\n' % (datetime.date.today(), self.entry1_1.get()))
self.tex.print_output(self.out)
def main():
root = tk.Tk()
root.title('Watt v1.0 - Yves')
root.configure(background='#ECECEC')
MainFrame(root)
root.mainloop()
if __name__ == '__main__':
main() |
Partager