-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadtrail.pyw
82 lines (60 loc) · 1.56 KB
/
readtrail.pyw
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
import tkinter as tk
import os, glob
import re
def sortBy(f):
s=re.findall("(\\w+)$",f)
return (int(s[0]) if s else -1,f)
def copyToClip():
myInt = 0
filename = "trail.txt"
folder = "c:/PTC/work/"
latestFile = glob.glob(folder+filename+".*")
useThis = max(latestFile, key=sortBy)
#print(useThis)
try:
myFile = open(useThis, "r")
fileOpened = True
except IOError:
fileOpened = False
print("File "+useThis+" Not found!")
for line in reversed(list(myFile)):
mystring = line.rstrip()
suffix1 = ".PRT"
suffix2 = ".ASM"
latestFile = glob.glob(folder+filename+".*")
#print(latestFile)
if mystring.endswith(suffix1):
#print(line[1:], end = '')
putToClip(line[1:])
break
if mystring.endswith(suffix2):
#print(line[1:], end = '')
putToClip(line[1:])
break
if myInt > 20:
break
myInt+=1
if( fileOpened ):
myFile.close()
fileOpened = False
def putToClip( mystring ):
# r = Tk()
# r.withdraw()
frame.clipboard_clear()
frame.clipboard_append(mystring)
# this.update() # now it stays on the clipboard after the window is closed
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
button.pack(side=tk.LEFT)
slogan = tk.Button(frame,
text="CopyToClipboard",
command=copyToClip)
slogan.pack(side=tk.LEFT)
root.attributes("-topmost", True)
#root.withdraw()
root.mainloop()