-
Notifications
You must be signed in to change notification settings - Fork 1
/
addaccesskey.py
98 lines (77 loc) · 3.56 KB
/
addaccesskey.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
#v1.0
#v0.9 - All research graph via menu & mouse click
#v0.8 - Candlestick graphs
#v0.7 - Base version with all graphs and bug fixes
#v0.6
#0.5
#v0.4
from tkinter import *
from tkinter import ttk
from tkinter import messagebox as msgbx
from tkinter.filedialog import *
from datetime import date
from tkcalendar import Calendar, DateEntry
import os.path as ospath
class classAddKey(Toplevel):
def __init__(self, master=None):
Toplevel.__init__(self, master=master)
self.key = ''
self.datadir = ''
self.wm_title("Add Key")
self.wm_protocol("WM_DELETE_WINDOW", self.OnClose)
self.configure(padx=5, pady=10)
self.iscancel = False
if(ospath.isfile('key_folder.txt')):
with open('key_folder.txt', 'r') as f:
d = f.read().split(',')
f.close()
prev_key = d[0]
prev_folder = d[1]
else:
prev_key = ''
prev_folder = ''
self.frame1 = ttk.Frame(self, borderwidth=5, relief="sunken") #, width=200, height=100)
# Now create purchase price entry
self.key_label = ttk.Label(self.frame1, text='Enter your key: ')
self.key_text = StringVar(value=prev_key)
self.key_entry = ttk.Entry(self.frame1, textvariable=self.key_text, width=40)
self.datafolder_label = ttk.Label(self.frame1, text='Folder for source data: ')
self.datafolder_text = StringVar(value=prev_folder)
self.datafolder_entry = ttk.Entry(self.frame1, textvariable=self.datafolder_text, width=40, state='read')
self.btn_add_datafolder = ttk.Button(self.frame1, text="Browse & Select Folder", command=self.btnDataFolder)
self.btn_ok = ttk.Button(self.frame1, text="Ok", command=self.btnOk)
self.btn_cancel = ttk.Button(self.frame1, text="Cancel", command=self.btnCancel)
#put widgets on grid_configure
self.frame1.grid_configure(row=0, column=0, sticky=(N, S, E, W), padx=5, pady=5)
self.key_label.grid_configure(row=0, column=0, sticky=(N, S, E, W))
self.key_entry.grid_configure(row=0, column=1, sticky=(N, S, E, W))
self.datafolder_label.grid_configure(row=1, column=0, sticky=(N, S, E, W))
self.datafolder_entry.grid_configure(row=1, column=1, sticky=(N, S, E, W))
self.btn_add_datafolder.grid_configure(row=1, column=2, padx=5, pady=5, sticky=(N, S, E, W))
self.btn_ok.grid_configure(row=2, column=1, padx=5, pady=5, sticky=(E))#, sticky=(N, S, E, W))
self.btn_cancel.grid_configure(row=2, column=2, padx=5, pady=5)#, sticky=(N, S, E, W))
def OnClose(self):
self.destroy()
def btnOk(self):
self.iscancel = False
self.destroy()
def btnDataFolder(self):
self.datafolder_text.set(askdirectory(initialdir = "./scriptdata", title = "Select source folder for data files"))
self.btn_add_datafolder.focus_force()
def btnCancel(self):
self.iscancel = True
self.destroy()
def show(self):
self.wm_deiconify()
self.key_entry.focus_force()
self.wait_window()
if(self.iscancel == False):
with open('key_folder.txt', 'w') as f:
f.write(f'{self.key_text.get()},{self.datafolder_text.get()}')
f.close()
return {'key':self.key_text.get(), 'folder':self.datafolder_text.get(),}
return {}
if __name__ == "__main__":
obj = classAddKey()
key = obj.show()
print(key)