-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_gui.py
More file actions
126 lines (95 loc) · 3.96 KB
/
run_gui.py
File metadata and controls
126 lines (95 loc) · 3.96 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
import json
import gtjt
import tkinter as tk
from tkinter import filedialog, Text
import os.path
import sys
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def getOutputDirectory():
#Creates OutputDirectory
out_directory = "output"
os.makedirs(resource_path(out_directory), exist_ok=True)
return resource_path(out_directory)
app = {
'title':"ConvertFile - Google Taks JSON to TXT",
'width':600,
'height':400,
'background_color':"#373a40",
'foreground_color':"#ffffff",
'font_color':"#ffffff",
'font':["Helvetica", 16],
'button_color':"#686d76",
'output_directory': getOutputDirectory()
}
root = tk.Tk()
root.title(app['title'])
root.iconbitmap(resource_path('icon.ico'))
gtask_file = tk.StringVar()
gtask_file.set("<not selected>")
def printOutput(string,append=True):
if append:
txt_Output.insert(tk.END, string + "\n")
else:
txt_Output.delete('1.0', tk.END)
txt_Output.insert(tk.END, string + "\n")
def buttonConvertFile_click(file):
if os.path.isfile(file):
printOutput('Processing Files ...')
if gtjt.ConvertFile(file,app['output_directory']):
printOutput('Done.')
printOutput('The lists have been extracted to the default Output directory')
else:
printOutput('Unable to process file. File is either invalid or inacessible.')
else:
printOutput('Invalid File')
def buttonOpenFile_click():
filename = filedialog.askopenfilename(initialdir="/", title="Selecte Gtask JSON File",
filetype=(("JSON Object","*.JSON"),("all files","*.*")))
gtask_file.set(filename)
printOutput(filename)
def buttonOpenOutputFolder_click():
path = os.path.realpath(app['output_directory'])
os.startfile(path)
canvas = tk.Canvas(root,height=app['height'],width=app['width'],bg=app['background_color'])
canvas.pack()
topFrame = tk.Frame(root,bg=app['background_color'])
topFrame.place(relwidth=0.94,relheight=0.6,relx=0.03,rely=0.03)
bottomFrame = tk.Frame(root)
bottomFrame.pack(side='bottom')
label_GTaskFile = tk.Label(topFrame, text="Google Tasks JSON to TXT Parser",
font=app['font'],bg=app['background_color'],
fg=app["font_color"],
justify="left")
txt_Output = tk.Text(topFrame, height=30, width=400, wrap='word')
label_GTaskFile.grid(row=0,column=0)
txt_Output.grid(row=2,column=0,columnspan=10,pady=4)
buttonOpenFile = tk.Button(root, text="Select JSON File",
padx=10,
pady=5,
fg=app['foreground_color'],
bg=app['button_color'],
command=buttonOpenFile_click)
buttonConvertFile = tk.Button(root, text="Extract Lists",
padx=10,
pady=5,
fg=app['foreground_color'],
bg=app['button_color'],
command=lambda: buttonConvertFile_click(gtask_file.get()))
buttonOpenOutputFolder = tk.Button(root, text="Open Output Folder",
padx=10,
pady=5,
fg=app['foreground_color'],
bg=app['button_color'],
command=buttonOpenOutputFolder_click)
buttonOpenOutputFolder.pack(side="right",padx=1,pady=1)
buttonConvertFile.pack(side="right",padx=1,pady=1)
buttonOpenFile.pack(side="right",padx=1,pady=1)
printOutput("To begin, please select the Google Tasks JSON file obtained trough Google TakeOut")
root.mainloop()