/
ScriptGui.py
160 lines (136 loc) · 5.06 KB
/
ScriptGui.py
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
#----------------------------------------------------------------
# !!!OUTDATED!!!
#----------------------------------------------------------------
#----------------------------------------------------------------
# Script for GUI to run Automation
#----------------------------------------------------------------
##### Import Modules #####
import tkinter as tk
from tkinter import *
from datetime import date
import ctypes, threading, sys, re, os
from ENTRY_FILE import *
from Settings import *
from PIL import Image, ImageTk
#Get list of jobs from text file
def find_jobs():
today = date.today()
tdate = today.strftime("%m-%d-%y")
try:
text_file = open(text_path + '\\' + tdate + '.txt', 'r')
except:
for i in range(11):
if i%11 == 0:
popup = ctypes.windll.user32.MessageBoxW
threading.Thread(target = lambda :popup(None, ' No task file exists', 'Error', 0)).start()
list = text_file.read().split()
#Create lists for jobs
list_o_jobs = []
scene_jobs = []
pix4d_jobs = []
for job in list:
job2 = job.split(',')
list_o_jobs.append(job2)
for job in list_o_jobs:
job[0] = job[0].upper()
for job in list_o_jobs:
if job[1] == 'CLT':
job[1] = CLT
elif job[1] == 'DEN':
job[1] = DEN
elif job[1] == 'ATL':
job[1] = ATL
elif job[1] == 'NAS':
job[1] = NAS
for job in list_o_jobs:
job[2] = job[2].lower()
for job in list_o_jobs:
if job[3] == 'Scene':
scene_jobs.append(job)
if job[3] == 'Pix4D':
pix4d_jobs.append(job)
if job[3] == 'Both':
scene_jobs.append(job)
pix4d_jobs.append(job)
return list_o_jobs, scene_jobs, pix4d_jobs
#Passes list of jobs that are checked by user
def confirmList():
fullRunList = []
for n in range(len(jobs)):
if (var[n].get() == 1):
fullRunList.append(jobs[n])
automate(fullRunList)
#Update scrollregion after starting 'mainloop' when all widgets are in gui
def on_configure(event):
gui.configure(scrollregion=gui.bbox('all'))
#Various declarations
job_list, scene_list, pix4d_list = find_jobs()
check = []
var = []
jobs = []
i = 0
z = 50
#create GUI
gui = Tk()
gui.title('Automation Script')
gui.geometry('803x730')
gui.configure(bg='#292d34')
windowWidth = gui.winfo_reqwidth()
windowHeight = gui.winfo_reqheight()
positionRight = int(gui.winfo_screenwidth()/2 - windowWidth/2)
positionDown = int(gui.winfo_screenheight()/3 - windowHeight/2)
gui.geometry("+{}+{}".format(positionRight, positionDown))
gui.resizable(False, False)
#Logo Image
img = ImageTk.PhotoImage(Image.open('img\\DeltaV_logo.png'))
panel = tk.Label(gui, image = img)
panel.pack(side = 'top')
#Title for program
programLabel = Label(gui, text='Automation Script')
programLabel.configure(bg='#292d34', fg='#fafafa', font=('Aerial', 20, 'bold'), pady=20)
programLabel.pack()
#Start Script Button
addFileButton = tk.Button(gui, text='Start', padx=10, pady=5, fg='black', bg='#889099', command=confirmList, font=('Aerial', 14, 'bold'))
addFileButton.pack()
#Frame in GUI that is scrollable
class ScrollableFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
#Create a canvas object and a vertical scrollbar for scrolling it
self.vscrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
self.vscrollbar.pack(side='right', fill="y", expand="false")
self.canvas = tk.Canvas(self,bg='#292d34', bd=0, height=350, highlightthickness=0, yscrollcommand=self.vscrollbar.set)
self.canvas.pack(side="left", fill="both", expand="true")
self.canvas.place(x=290,y=20)
self.canvas.bind_all("<MouseWheel>", self._on_mousewheel)
self.vscrollbar.config(command=self.canvas.yview)
#Reset the view
self.canvas.xview_moveto(0)
self.canvas.yview_moveto(0)
#Create a frame inside the canvas which will be scrolled with it
self.interior = tk.Frame(self.canvas, **kwargs)
self.canvas.create_window(0, 0, window=self.interior, anchor="nw")
self.bind('<Configure>', self.set_scrollregion)
#Allow mouse wheel to scroll in region
def _on_mousewheel(self, event):
self.canvas.yview_scroll(int(-1*(event.delta/120)), "units")
#Set the scroll region on the canvas
def set_scrollregion(self, event=None):
self.canvas.configure(scrollregion=self.canvas.bbox('all'))
checkbox_pane = ScrollableFrame(gui, bg='#292d34')
checkbox_pane.pack(expand="true", fill="both")
job_list, scene_list, pix4d_list = find_jobs()
check = []
var = []
jobs = []
i = 0
z = 50
for job in job_list:
jobs.append(job)
var.append(str(i))
var[i] = tk.IntVar(value=1)
box = tk.Checkbutton(checkbox_pane.interior, text=job[0] + ' ' + job[2] + ' ' + job[3], variable=var[i], onvalue=1, offvalue=0)
box.configure(bg='#292d34', fg='#fafafa', font=('Aerial', 12, 'bold'), selectcolor='black')
box.pack()
i+=1
gui.mainloop()