-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
119 lines (100 loc) · 4.93 KB
/
main.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
# main.py - a rudimentary exchange interface using Binance API to trade, by Mc_Snurtle
# imports
import os
import time
import sys
import json
import customtkinter as ctk
from dotenv import load_dotenv
from pages.meme import Meme
from pages.tickers import TickerSearch
from pages.welcome import Welcome
from pages.settings import Settings
from pages.base_frame import BaseFrame, BaseScrollableFrame
from bars.fav_tickers import FavTickers
from bars.navigation import NavigationBar
from popup import popup
from dotenv import load_dotenv
class App(ctk.CTk):
def __init__(self, title: str, geometry: tuple[int, int], *args, **kwargs):
self.width, self.height = geometry
super(App, self).__init__(*args, **kwargs)
self.geometry(f"{self.width}x{self.height}")
self.iconbitmap(os.path.join(proj_dir, 'assets', 'icons', 'icon.ico'))
self.title(title)
self.minsize(self.width, self.height)
self.frame_id = 'meme'
# TEMP SECURITY WARNING
warning = popup('Critical Security Alert',
"BitBuyBit is currently using plain text .env files to store credential data.\n"
"This is very unsecure and is not recommended. Use any account / wallet\n"
"linking at your own risk. BitBuyBit will use much safer encrypted files to\n"
"store documents in the near future, and it is not recommended to link your\n"
"TradingView / Wallets at this time. Please be advised!\n"
"\n"
"Would you like to proceed?", [('Proceed', 1), ('Abort', 0)], self)
# warning.mainloop()
if warning == 0:
sys.exit(0)
self.welcome_frame = Welcome(self, theme)
self.welcome_frame.pack(side=ctk.BOTTOM, padx=theme['pad'][2], pady=theme['pad'][2], fill=ctk.BOTH, expand=True)
self.meme_frame = Meme(master=self.welcome_frame, proj_dir=proj_dir,
parent_geometry=(self.height * 0.5, self.height * 0.5))
self.meme_frame.pack(side=ctk.BOTTOM, padx=theme['pad'][2], pady=theme['pad'][2], fill=ctk.BOTH, expand=True)
self.ticker_frame = TickerSearch(self, theme, charting_opt, fav_tickers)
self.settings_frame = Settings(master=self, theme=theme, fav_tickers=fav_tickers, charting_opt=charting_opt, exit_func=self.exit_gracefully)
# layout
pages_list = [('Tickers', lambda frame=self.ticker_frame: self.sel_frame(frame=frame)),
('Settings', lambda frame=self.settings_frame: self.sel_frame(frame=frame))]
self.nav_bar = NavigationBar(self, pages_list, bg_color=theme['color']['bg2'], theme=theme, quotes=quotes)
self.nav_bar.pack(anchor=ctk.NW, side=ctk.TOP, fill=ctk.X)
if len(fav_tickers) > 0:
self.fav_tickers = FavTickers(
open_settings=lambda frame=self.settings_frame: self.sel_frame(frame=frame),
exit_func=self.exit_gracefully, fav_tickers=fav_tickers, theme=theme, master=self)
self.fav_tickers.pack(anchor=ctk.NW, side=ctk.TOP, fill=ctk.X)
self.frames: list[BaseFrame | BaseScrollableFrame] = [self.welcome_frame, self.ticker_frame,
self.settings_frame]
self.update_time()
def exit_gracefully(self):
self.fav_tickers.updating = False
self.destroy()
exit(0)
def update_time(self):
self.nav_bar.time_label.configure(text=f"{time.strftime('%H:%M:%S')}")
self.nav_bar.time_label.after(1000, self.update_time) # after 1 second...
def sel_frame(self, frame: ctk.CTkFrame):
[frame.pack_forget() for frame in self.frames]
if self.frame_id == frame.id:
frame = self.welcome_frame
frame.pack(padx=theme['pad'][2], pady=theme['pad'][2], fill=ctk.BOTH, expand=True)
self.frame_id = frame.id
def exit_gracefully():
window.fav_tickers.updating = False
window.destroy()
exit(0)
if __name__ == '__main__':
proj_dir = os.path.abspath(os.path.dirname(__file__))
charting_opt = {'async': True,
'legacy': False,
'rounding': True,
'live': 30}
load_dotenv('.env') # supplies COLOR, TV_USER, TV_PASS, etc,..
with open('assets/theme.json', 'r') as fp:
theme = json.load(fp)
theme['font'] = {
"title": ("Helvetica", 34),
"subtitle": ("Helvetica", 18),
"normal": ("Helvetica", 12)
}
with open('assets/quotes.json', 'r') as fp:
quotes = json.load(fp)
with open('./fav_tick.json', 'r') as fp:
fav_tickers: list[str] = json.load(fp)
try:
ctk.set_default_color_theme(theme['cur_color'])
ctk.set_appearance_mode(theme['cur_theme'])
except FileNotFoundError:
pass
window = App(geometry=(1280, 720), title="SellBitBuyBit - Mc_Snurtle")
window.mainloop()