-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
256 lines (195 loc) · 9.48 KB
/
Copy pathmain.py
File metadata and controls
256 lines (195 loc) · 9.48 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
import subprocess
from pathlib import Path
import csv
def main():
app = Application()
app.mainloop()
def call_handler_in_file(script_path, handler_name, *args):
python_script_dir = Path(__file__).parent
absolute_path = (python_script_dir / script_path).resolve()
if args:
formatted_args = ', '.join(f'"{arg}"' for arg in args)
handler_call = f'{handler_name}({formatted_args})'
else:
handler_call = f'{handler_name}()'
applescript = f'''
set scriptPath to "{absolute_path}"
set scriptAlias to POSIX file scriptPath as alias
set myScript to load script scriptAlias
tell myScript to {handler_call}
'''
result = subprocess.run(['osascript', '-e', applescript],
capture_output=True,
text=True)
class Application(tk.Tk):
def __init__(self):
super().__init__()
self.title("CueBilt")
### VARIABLES ###
self.QVers = tk.StringVar(value='QLab 5')
self.pgNumOpt = tk.BooleanVar(master=self, value=False)
### CONFIGURE APP ###
self.withdraw()
self.columnconfigure(0, weight=1)
self.QLabVersion_frame = qlabOpts(self)
self.QLabVersion_frame.grid(row=0, column=0, sticky="nsew", padx=10)
self.fileBrowser_frame = fileBrowser(self)
self.fileBrowser_frame.grid(row=2, column=0, sticky="nsew", padx=10)
self.chooseCols_frame = chooseCols(self)
self.chooseCols_frame.grid(row=3, column=0, sticky="nsew", padx=10)
auxOptions_frame = auxOptions(self)
auxOptions_frame.grid(row=4, column=0, padx=10)
self.transportOpts_frame = transportOpts(self, self.QLabVersion_frame, self.fileBrowser_frame, self.chooseCols_frame)
self.transportOpts_frame.grid(row=5, column=0, padx=10, pady=(0,20))
self.focus()
self.update_idletasks()
# Set window size
window_width = self.winfo_reqwidth()
window_height = self.winfo_reqheight()
# Get screen dimensions
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
# Calculate position coordinates
center_x = int((screen_width - window_width) / 2)
center_y = int((screen_height - window_height) / 2)
# Set the position and size of the window
self.geometry(f'+{center_x}+{center_y}')
self.deiconify()
# self.geometry("")
class fileBrowser(ttk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.fileBrowserframe = ttk.LabelFrame(self, text="Select '.tsv' or '.txt' file:")
self.fileBrowserframe.pack(fill="x", expand=True, side=tk.LEFT, padx=10, pady=10)
self.path_label = ttk.Label(self.fileBrowserframe, text="No file selected", wraplength=150)
self.path_label.pack(side=tk.LEFT, expand=True)
self.browseButton = ttk.Button(self.fileBrowserframe, text="Browse...", command=self.browse_file)
self.browseButton.pack(side=tk.RIGHT, expand=True)
def browse_file(self):
filepath = filedialog.askopenfilename(
title="Select a .tsv file",
defaultextension=".tsv",
filetypes=(
("Tab Separated Values", "*.tsv"),
("TXT Tab Separated", "*.txt"),
("All filetypes", "*.*")
)
)
if filepath:
self.path_label.config(text=filepath)
class qlabOpts(ttk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.QLabOptsFrame = ttk.Labelframe(self, text="Select QLab Version:")
self.QLabOptsFrame.pack(padx=10, pady=10, fill="x", expand=True)
qlab_versions = [
'QLab 3',
'QLab 4',
'QLab 5'
]
### self.QVers = tk.StringVar(value='QLab 5') ### NOW LIVES IN MAIN APP CLASS
for index in range(len(qlab_versions)):
self.qlabradioButtons = ttk.Radiobutton(self.QLabOptsFrame, text=qlab_versions[index], variable=parent.QVers, value=qlab_versions[index], takefocus=0)
self.qlabradioButtons.pack(side=tk.LEFT, expand=True, padx=10, pady=10)
self.QLabCmmds_frame = ttk.Frame(self)
self.QLabCmmds_frame.pack(fill="x", expand=True, side=tk.TOP)
self.qcommdbutton1 = ttk.Button(self.QLabCmmds_frame, text="Open QLab", command=lambda: call_handler_in_file('./scripts/openQLab.scpt', 'openQLab', parent.QVers.get())).pack(side=tk.LEFT, expand=True)
self.qcommdbutton2 = ttk.Button(self.QLabCmmds_frame, text="New Workspace", command=lambda: call_handler_in_file('./scripts/openQLab.scpt', 'newQLabWorkspace', parent.QVers.get())).pack(side=tk.LEFT, expand=True)
class chooseCols(ttk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.colInputFrame = ttk.Labelframe(self, text="Choose column letters from cue sheet.\nIf left blank, parameter will remain blank in QLab.")
self.colInputFrame.pack(padx=10, pady=10, fill="x", expand=True)
self.colInputFrame.columnconfigure(0, weight=1)
self.colInputFrame.columnconfigure(1, weight=1)
self.colInputFrame.columnconfigure(2, weight=1)
self.colInputFrame.columnconfigure(3, weight=1)
cue_sheet_cols = [
'Q Number',
'Q Name',
'Notes',
'Page #'
]
cueSheetAlpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
cueShtCols = tk.IntVar()
self.qlabel1 = ttk.Label(self.colInputFrame, text=cue_sheet_cols[0])
self.qlabel1.grid(row=0, column=0, padx=5, sticky="nsew")
self.colSpin1 = ttk.Spinbox(self.colInputFrame, values=cueSheetAlpha, width=6)
self.colSpin1.grid(row=1, column=0, padx=5, sticky="nsew")
self.qlabel2 = ttk.Label(self.colInputFrame, text=cue_sheet_cols[1])
self.qlabel2.grid(row=0, column=1, padx=5, sticky="nsew")
self.colSpin2 = ttk.Spinbox(self.colInputFrame, values=cueSheetAlpha, width=6)
self.colSpin2.grid(row=1, column=1, padx=5, sticky="nsew")
self.qlabel3 = ttk.Label(self.colInputFrame, text=cue_sheet_cols[2])
self.qlabel3.grid(row=0, column=2, padx=5, sticky="nsew")
self.colSpin3 = ttk.Spinbox(self.colInputFrame, values=cueSheetAlpha, width=6)
self.colSpin3.grid(row=1, column=2, padx=5, sticky="nsew")
self.qlabel4 = ttk.Label(self.colInputFrame, text=cue_sheet_cols[3])
self.qlabel4.grid(row=0, column=3, padx=5, sticky="nsew")
self.colSpin4 = ttk.Spinbox(self.colInputFrame, values=cueSheetAlpha, width=6)
self.colSpin4.grid(row=1, column=3, padx=5, sticky="nsew")
class auxOptions(ttk.Frame):
def __init__(self, parent):
super().__init__(parent)
# self.label_text = tk.StringVar()
# def update_label():
# if parent.pgNumOpt.get() == True:
# self.label_text.set("Ex: (p. 56) - Door Knock")
# else:
# self.label_text.set("Unchecked: page numbers will be included in Q Notes")
self.pgcheck = ttk.Checkbutton(self, text="Include page numbers in Q Name", variable=parent.pgNumOpt).pack(expand=True)
self.pgcheckLabel1 = ttk.Label(self, text="Ex: (p. 56) - Door Knock", font=('TkDefaultFont', 9)).pack(expand=True)
self.pgcheckLabel2 = ttk.Label(self, text="If unchecked, page numbers will be included in Q Notes", font=('TkDefaultFont', 9)).pack(expand=True)
class transportOpts(ttk.Frame):
def __init__(self, parent, QLabVersion_frame, fileBrowser_frame, chooseCols_frame):
super().__init__(parent)
self.QLabVersion_frame = QLabVersion_frame
self.fileBrowser_frame = fileBrowser_frame
self.chooseCols_frame = chooseCols_frame
self.parent = parent
self.clearwkspcButton = ttk.Button(self, text="Clear Workspace", command=lambda: call_handler_in_file('./scripts/resetQLabWorkspace.scpt', 'reset', parent.QVers.get())).pack(side=tk.TOP, expand=True, pady=20)
self.runButton = ttk.Button(
self,
text="Run",
command=self.run_qlab,
default="active"
)
self.runButton.pack(side=tk.TOP, expand=True)
def run_qlab(self):
col1 = self.chooseCols_frame.colSpin1.get()
col2 = self.chooseCols_frame.colSpin2.get()
col3 = self.chooseCols_frame.colSpin3.get()
col4 = self.chooseCols_frame.colSpin4.get()
pgsTog = self.parent.pgNumOpt.get()
qlab_version = self.parent.QVers.get()
filepath = self.fileBrowser_frame.path_label.cget("text")
call_handler_in_file(
'./scripts/cuebiltMain.scpt',
'startQLab',
col1,
col2,
col3,
col4,
pgsTog,
qlab_version,
filepath
)
# print("PYTHON MONITOR IS ON. ARGS PASSED:")
# print("QName Column = " + col1)
# print("QNum = " + col2)
# print("QNotes = " + col3)
# print("QPages = " + col4)
# print("Include Pages = " + str(pgsTog))
# print("Version = " + qlab_version)
# print("Filepath = " + filepath)
def run_qlab_test(self):
call_handler_in_file(
'./scripts/cuebiltMain.scpt',
'startQLabtest',
5
)
if __name__ == "__main__":
main()