-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_frame.py
153 lines (122 loc) · 7.45 KB
/
first_frame.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import tkinter as tk
from settings import Settings
from settings_gui import Settings_GUI
from PIL import Image, ImageTk, ImageDraw
from easy_json import edit_value, get_value
from new_schedule import New
from sites import Web
from aboutus import Aboutus
from howtouse import Howtouse
class FirstFrame():
def __init__(self, frame, restart):
self.restart = restart
self.frame = frame
self.settings = Settings()
# set the frame's color
self.frame.config(bg=self.settings.bg_color)
self.image_path = self.settings.image_path
self.image_size = 100
self.username = self.settings.username
self.profile_frame = tk.Frame(frame, bg=self.settings.bg_color, width=self.settings.w1, height=self.settings.h1)
self.profile_frame.pack(pady=20)
self.profile_frame.pack_propagate(0)
# Making profile button
self.profile_image = self.create_profile_image() # I tried to directly pass it. It didn't work
self.profile_button = tk.Button(self.profile_frame, image=self.profile_image, text="", compound=tk.LEFT, bg=self.settings.bg_color, highlightthickness=0, bd=0, padx=5)
self.profile_name = tk.Label(self.profile_frame, text=self.username, fg=self.settings.fg_color, bg=self.settings.bg_color, padx=5, font='unicode')
# Grid in place
self.profile_button.grid(row=0, column=0)
self.profile_name.grid(row=0, column=1)
# Create a frame for navigation
self.nav_frame = tk.Frame(frame, bg=self.settings.bg_color, width=self.settings.w1, height=self.settings.h2)
self.nav_frame.pack()
self.nav_frame.pack_propagate(0)
# 4 buttons and 1 label in the nav frame
self.settings_bt = tk.Button(self.nav_frame, text='Settings', width=self.settings.w1, fg=self.settings.fg_color, bg=self.settings.button_color, highlightthickness=0, bd=0, height=2, command=self.create_settings_window).pack(pady=(0,2.5), padx=10)
self.howtouse = tk.Button(self.nav_frame, text='How to use?', width=self.settings.w1, fg=self.settings.fg_color, bg=self.settings.button_color, highlightthickness=0, bd=0, height=2, command=self.howtouse).pack(pady=2.5, padx=10)
self.create_new_schedule = tk.Button(self.nav_frame,text='My Schedules', width=self.settings.w1, bg=self.settings.button_color, highlightthickness=0, bd=0, fg=self.settings.fg_color, height=2, command=self.new_schedule).pack(pady=2.5, padx=10)
self.block_sites = tk.Button(self.nav_frame, text='Block websites', width=self.settings.w1, fg=self.settings.fg_color, bg=self.settings.button_color, highlightthickness=0, bd=0, height=2, command=self.site_window).pack(pady=2.5, padx=10)
self.aboutus = tk.Button(self.nav_frame, text='About us', width=self.settings.w1, fg=self.settings.fg_color, bg=self.settings.button_color, highlightthickness=0, bd=0, height=2, command=self.aboutus).pack(pady=2.5, padx=10)
self.copy_right = tk.Label(self.nav_frame, text="Copyright © WYH, AMM", width=self.settings.w1, fg="#fd971f", bg=self.settings.button_color).pack(side='bottom', padx=10)
# Initialize false to settings window
self.settings_window = None
self.schedule = None
self.site = None
self.aboutus_window = None
self.htu_window = None
def create_profile_image(self):
try:
if(get_value('pp_location', 'data/settings.json') == 'images/white/newuser.png' and get_value('theme', 'data/settings.json') != 'white'):
edit_value('pp_location', 'images/newuser.png', 'data/settings.json')
if(get_value('pp_location', 'data/settings.json') == 'images/newuser.png' and get_value('theme', 'data/settings.json') == 'white'):
edit_value('pp_location', 'images/white/newuser.png', 'data/settings.json')
# Open the image
img = Image.open(get_value('pp_location', 'data/settings.json'))
except FileNotFoundError: # if file not found, automatically set to new user image
if get_value('theme', 'data/settings.json') == 'white':
edit_value('pp_location', 'images/white/newuser.png', 'data/settings.json')
img = Image.open('images/white/newuser.png')
else:
edit_value('pp_location', 'images/newuser.png', 'data/settings.json')
img = Image.open('images/newuser.png')
if self.image_path == 'images/newuser.png' or self.image_path == 'images/white/newuser.png':
# Resize the image
img = img.resize((self.image_size, self.image_size), Image.LANCZOS)
# create a new image with the same size and fill it with white color
background = Image.new('RGBA', img.size)
draw = ImageDraw.Draw(background)
draw.rectangle((0, 0, img.size[0], img.size[1]), fill=self.settings.bg_color)
# merge the color-filled image with the original image
result = Image.alpha_composite(background, img)
# Create a Tkinter image object
tkimg = ImageTk.PhotoImage(result)
# now just return the image and create button inside the constructor method
return tkimg
else:
# Resize the image
img = img.resize((self.image_size, self.image_size), Image.LANCZOS)
# Create a Tkinter image object
tkimg = ImageTk.PhotoImage(img)
# now just return the image and create button inside the constructor method
return tkimg
def create_settings_window(self):
# check if there is existing settings window
# only false value will create a window
if self.settings_window is None or not self.settings_window.winfo_exists():
# create a toplevel window under the first frame
self.settings_window = tk.Toplevel(self.frame)
Settings_GUI(self.settings_window, self.restart)
else:
self.settings_window.lift()
def new_schedule(self):
# check if there is existing schedule window
# only false value will create a window
if self.schedule is None or not self.schedule.winfo_exists():
# create a toplevel window under the first frame
self.schedule = tk.Toplevel(self.frame)
Schedule = New(self.schedule, self.restart)
else:
self.schedule.lift()
def site_window(self):
# check if there is existing schedule window
# only false value will create a window
if self.site is None or not self.site.winfo_exists():
# create a toplevel window under the first frame
self.site = tk.Toplevel(self.frame)
Site = Web(self.site)
else:
self.site.lift()
def aboutus(self):
if self.aboutus_window is None or not self.aboutus_window.winfo_exists():
# create a toplevel window under the first frame
self.aboutus_window = tk.Toplevel(self.frame)
Aboutus(self.aboutus_window)
else:
self.aboutus_window.lift()
def howtouse(self):
if self.htu_window is None or not self.htu_window.winfo_exists():
# create a toplevel window under the first frame
self.htu_window = tk.Toplevel(self.frame)
Howtouse(self.htu_window)
else:
self.htu_window.lift()