-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_interface.py
129 lines (109 loc) · 3.57 KB
/
user_interface.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
"""
Installing the tkinter library """
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
import sys
import os
import multiprocessing
from PIL import Image, ImageTk
from app.pages import (
net_income_page,
cash_to_earnings_page,
cash_flow_page,
debt_page,
homepage,
revenue_page,
)
# Add the project root directory to the Python path
if getattr(sys, 'frozen', False):
# If running as a PyInstaller bundle
# pylint: disable=protected-access
bundle_dir = sys._MEIPASS
else:
# If running in a normal Python environment
bundle_dir = os.path.abspath(os.path.dirname(__file__))
icon_path = os.path.join(bundle_dir, "assets/charticon2ICO.ico")
class UserInterFace(tk.Tk):
"""
User interface class
"""
def __init__(self):
tk.Tk.__init__(self)
self.window_title = self.title("Stock Analyzer")
container = tk.Frame(self)
self.icon_image = Image.open(icon_path)
self.icon_photo = ImageTk.PhotoImage(self.icon_image)
# Set the window icon
self.iconphoto(False, self.icon_photo)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
menu = tk.Menu(container)
home = tk.Menu(menu, tearoff=0)
menu.add_cascade(menu=home, label="Main")
home.add_command(
label="Home", command=lambda: self.show_frame(homepage.StartPage)
)
menu.add_separator()
charts = tk.Menu(menu, tearoff=0)
menu.add_cascade(menu=charts, label="Charts")
charts.add_command(
label="Cash Flow", command=lambda: self.show_frame(cash_flow_page.CashFlow)
)
charts.add_command(
label="Cash to Earnings",
command=lambda: self.show_frame(cash_to_earnings_page.CashToEarnings),
)
charts.add_command(
label="Long Term Debt", command=lambda: self.show_frame(debt_page.Debt)
)
charts.add_command(
label="Net Income", command=lambda: self.show_frame(net_income_page.NetIncome)
)
charts.add_command(
label="Revenue", command=lambda: self.show_frame(revenue_page.Revenue)
)
menu.add_separator()
tk.Tk.config(self, menu=menu)
for F in (
homepage.StartPage,
cash_flow_page.CashFlow,
debt_page.Debt,
net_income_page.NetIncome,
revenue_page.Revenue,
cash_to_earnings_page.CashToEarnings,
):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(homepage.StartPage)
def show_frame(self, cont):
"""
Shows frame
"""
frame = self.frames[cont]
frame.tkraise()
def get_page(self, page_class):
"""
gets the page
"""
return self.frames[page_class]
def on_closing(self):
"""
Perform any cleanup here before closing
"""
print("Cleaning up and closing the application...")
self.destroy()
sys.exit(0) # Ensure the application exits
if __name__ == "__main__":
multiprocessing.freeze_support() # This prevents double-execution
try:
app = UserInterFace()
app.geometry("1200x800")
app.protocol("WM_DELETE_WINDOW", app.on_closing)
app.mainloop()
except KeyboardInterrupt as e:
print("Closing app")