-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.py
92 lines (74 loc) · 3.96 KB
/
program.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
from tkinter import *
from tkinter import messagebox
from report import excelReport
from PIL import ImageTk
from PIL import Image
import threading
from utils import *
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.initWindow()
def initWindow(self):
def onClick(event):
if event.widget.get() == self.filenameEntryExample:
event.widget.delete(0,END)
event.widget.insert(0,"")
event.widget.config(fg='black')
elif event.widget.get() == self.screenerEntryExample:
event.widget.delete(0,END)
event.widget.insert(0,"")
event.widget.config(fg='black')
self.master.title("The Passive Investor")
self.pack(fill=BOTH, expand=1)
image = ImageTk.PhotoImage(Image.open(resourcePath("images\ThePassiveInvestorPNG.png")))
panel = Label(self, image = image, bg=background)
panel.image = image
panel.grid(row=1,column=1, columnspan=2,sticky=W+E+N+S)
filenameLabel = Label(self, text="Filename",bg=background)
filenameLabel.grid(row=2, column=1, sticky=E)
screenerLabel = Label(self, text='Tickers URL/File',bg=background)
screenerLabel.grid(row=3, column=1, sticky=E)
self.filenameEntry = StringVar()
self.filenameEntryExample = "Example: C:\Documents\Investing\Output\S&P500_Output.xlsx"
filenameEntry = Entry(self, textvariable=self.filenameEntry, width=100, fg=entryTextColour)
filenameEntry.grid(row=2, column=2, sticky=W, pady=10, padx=10)
filenameEntry.insert(0, self.filenameEntryExample)
filenameEntry.bind('<FocusIn>', onClick)
self.screenerEntry = StringVar()
self.screenerEntryExample = "Example: https://finance.yahoo.com/etfs (or C:\Documents\Investing\Input\S&P500_Input.xlsx)"
screenerEntry = Entry(self, textvariable=self.screenerEntry, width=100, fg=entryTextColour)
screenerEntry.grid(row=3, column=2, sticky=W, pady=10, padx=10)
screenerEntry.insert(0, self.screenerEntryExample)
screenerEntry.bind('<FocusIn>', onClick)
excelReportButton = Button(self, text="Create Report", command=self.runProgram,bg=buttonColor,fg=buttonTextColour)
excelReportButton.grid(row=4,column=1, columnspan=2, sticky=W+E+N+S,padx=10, pady=10)
def generateReport(self):
try:
screenerURL = self.screenerEntry.get()
if self.filenameEntry.get()[-5:] == '.xlsx':
filename = self.filenameEntry.get()
else:
filename = self.filenameEntry.get() + '.xlsx'
progress = Label(self, text="Collecting tickers..",bg=buttonColor,fg=buttonTextColour)
progress.grid(row=4,column=1, columnspan=2, sticky=W+E+N+S,padx=10, pady=10)
tickers = symbolCollector(screenerURL)
excelReport.excelWriter(self, tickers, filename)
except Exception as error:
messagebox.showerror('Error', "The program has crashed with the following error: \n\n"
+ str(error) + "\n\nIf the problem persists, please create an Issue with the error "
+ "message on the project's GitHub page:"
+ "https://github.com/JerBouma/ThePassiveInvestor/issues. \n\n"
+ "You can copy this entire message with CTRL + C.")
excelReportButton = Button(self, text="Create Report", command=self.runProgram,bg=buttonColor,fg=buttonTextColour)
excelReportButton.grid(row=4,column=1, columnspan=2, sticky=W+E+N+S,padx=10, pady=10)
def runProgram(self):
threading.Thread(target=self.generateReport).start()
root = Tk()
app = Window(root)
app.configure(background=background)
root.geometry('725x200')
root.iconbitmap("images/iconICO.ico")
root.resizable(False, False)
root.mainloop()