-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.py
More file actions
194 lines (159 loc) · 6.78 KB
/
tempCodeRunnerFile.py
File metadata and controls
194 lines (159 loc) · 6.78 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
import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
from PIL import Image, ImageTk
import webbrowser
import requests
from io import BytesIO
from yahoo_fin import news
import threading
import sys
import os
def show_page(page):
for frame in [content_frame, news_page]:
frame.pack_forget()
page.pack(fill=tk.BOTH, expand=True)
def button_clicked(name):
print(f"{name} button clicked")
if name == "Stock":
threading.Thread(target=launch_stock_dashboard, daemon=True).start()
elif name == "News":
show_page(news_page)
def launch_stock_dashboard():
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
try:
# Show a loading message first
loading_label = tk.Label(root, text="Loading Stock Dashboard...", font=("Arial", 18), bg='white')
loading_label.place(relx=0.5, rely=0.5, anchor='center')
root.update()
# Create a separate Python process to run the PyQt application
# This completely avoids the threading issues
import subprocess
script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'stock', 'run_stock_dashboard.py')
# If the file doesn't exist, create it
if not os.path.exists(script_path):
with open(script_path, 'w') as f:
f.write('''
import sys
import os
from PyQt6.QtWidgets import QApplication
from stock_page import StockDashboard
if __name__ == "__main__":
try:
app = QApplication(sys.argv)
app.setStyle("Fusion")
window = StockDashboard()
window.show()
sys.exit(app.exec())
except Exception as e:
print(f"ERROR: {e}")
''')
# Run the PyQt application in a separate process
subprocess.Popen([sys.executable, script_path])
# Remove the loading label after a short delay
root.after(2000, loading_label.destroy)
except Exception as e:
print(f"Error launching stock dashboard: {e}")
messagebox.showerror("Error", f"Failed to launch stock dashboard: {e}")
# Remove loading label if there's an error
for widget in root.winfo_children():
if isinstance(widget, tk.Label) and widget.cget("text") == "Loading Stock Dashboard...":
widget.destroy()
root = tk.Tk()
root.title("ABC Stock Advisor")
root.state('zoomed')
root.configure(bg='white')
header = tk.Frame(root, bg='gray', height=100)
header.pack(fill=tk.X)
app_name = tk.Label(header, text="ABC Stock Advisor", font=("Arial", 24, "bold"), bg='gray', fg='white')
app_name.pack(side=tk.LEFT, padx=20, pady=20)
button_frame = tk.Frame(header, bg='gray')
button_frame.pack(side=tk.RIGHT, padx=10)
icon_size = (40, 40)
icons = {
"Stock": "stock.png",
"Portfolio": "portfolio.png",
"News": "news.png",
"Notification": "notification.png",
"Profile": "profile.png"
}
for name, icon_path in icons.items():
try:
image = Image.open(icon_path).resize(icon_size)
icon = ImageTk.PhotoImage(image)
except:
icon = None
frame = tk.Frame(button_frame, bg='gray')
frame.pack(side=tk.LEFT, padx=10)
button = tk.Button(frame, image=icon, text=name, compound=tk.TOP, bg='gray', fg='white',
relief=tk.FLAT, font=("Arial", 14), command=lambda n=name: button_clicked(n))
button.image = icon
button.pack()
content_frame = tk.Frame(root, bg='white', padx=50, pady=50)
content_frame.pack(expand=True, fill=tk.BOTH)
title_label = tk.Label(content_frame, text="Grow Your Wealth\nThe Smart Way.", font=("Arial", 30, "bold"), bg='white', fg='black', justify=tk.LEFT)
title_label.pack(anchor='w', pady=10)
description_label = tk.Label(content_frame, text="We're revolutionizing the way investing works with data and AI-driven quantitative models.", font=("Arial", 14), bg='white', fg='gray', justify=tk.LEFT)
description_label.pack(anchor='w', pady=5)
invest_button = tk.Button(content_frame, text="Start Investing", font=("Arial", 16, "bold"), bg='black', fg='white', padx=20, pady=10)
invest_button.pack(anchor='w', pady=20)
news_page = tk.Frame(root, bg='white')
news_title = tk.Label(news_page, text="📈 Latest Stock News", font=("Arial", 24, "bold"), bg='white', fg='black', padx=20, pady=10)
news_title.pack()
news_content = tk.Frame(news_page, bg='white')
news_content.pack(fill=tk.BOTH, expand=True, padx=20, pady=10)
DEFAULT_IMAGE_URL = "https://www.publicdomainpictures.net/pictures/320000/velka/stock-market-chart.jpg"
def get_news_image(query):
try:
search_url = f"https://www.bing.com/images/search?q={query.replace(' ', '+')}+stock+news"
response = requests.get(search_url)
image_url = DEFAULT_IMAGE_URL
except:
image_url = DEFAULT_IMAGE_URL
return image_url
def fetch_stock_news():
stock_ticker = "AAPL"
articles = news.get_yf_rss(stock_ticker)
for widget in news_content.winfo_children():
widget.destroy()
if not articles:
tk.Label(news_content, text="No news available. Check Yahoo Finance.", fg="red", bg="white").pack()
return
for article in articles[:10]:
title = article["title"]
link = article["link"]
image_url = get_news_image(title)
try:
img_data = requests.get(image_url, stream=True).content
image = Image.open(BytesIO(img_data)).resize((120, 80))
img_tk = ImageTk.PhotoImage(image)
except:
img_tk = None
news_item = tk.Frame(news_content, bg="white", pady=10, relief="solid", borderwidth=1)
news_item.pack(fill=tk.X, padx=10, pady=5)
if img_tk:
img_label = tk.Label(news_item, image=img_tk, bg="white")
img_label.image = img_tk
img_label.pack(side=tk.LEFT, padx=10)
news_label = tk.Label(news_item, text=title, font=("Arial", 14, "bold"), fg="blue", cursor="hand2", bg="white", wraplength=600, justify="left")
news_label.pack(side=tk.LEFT, anchor="w", padx=10)
news_label.bind("<Button-1>", lambda e, url=link: webbrowser.open(url))
def auto_refresh_news():
fetch_stock_news()
root.after(60000, auto_refresh_news)
fetch_stock_news()
auto_refresh_news()
marquee_frame = tk.Frame(root, bg='black', height=30)
marquee_frame.pack(fill=tk.X, side=tk.BOTTOM)
canvas = tk.Canvas(marquee_frame, bg='black', height=30)
canvas.pack(fill=tk.BOTH, expand=True)
marquee_text = "Stock Market Updates: Stock A +1.2% | Stock B -0.5% | Stock C +2.3% "
text_id = canvas.create_text(1500, 15, text=marquee_text, font=("Arial", 14), fill='white', anchor='w')
def scroll_text():
canvas.move(text_id, -2, 0)
if canvas.coords(text_id)[0] < -len(marquee_text) * 7:
canvas.coords(text_id, 1500, 15)
canvas.after(50, scroll_text)
scroll_text()
show_page(content_frame)
root.mainloop()