forked from NITDgpOS/PlotIt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_main.py
329 lines (282 loc) · 14.1 KB
/
gui_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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#! /usr/bin/env python
#
# GUI module generated by PAGE version 4.9
# In conjunction with Tcl version 8.6
# Oct 12, 2017 07:53:45 PM
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
import gui_support
def vp_start_gui():
"""Starting point when module is the main routine."""
global val, w, root
root = Tk()
top = New_Toplevel_1(root)
m = Menubar(root)
gui_support.init(root, top)
root.protocol('WM_DELETE_WINDOW', destroy_app)
root.mainloop()
# global colors variables for theme switch
_bgcolordark = '#000000'
_fgcolordark = '#d9d9d9'
_activebgcolordark = '#808080'
_bgcolorlight = '#ffffff'
_fgcolorlight = '#000000'
_darkwindowbackground = '#31363b'
_lightwindowbackground = '#f2f2f2'
w = None
def create_New_Toplevel_1(root, *args, **kwargs):
"""Starting point when module is imported by another program."""
global w, w_win, rt
rt = root
w = Toplevel(root)
top = New_Toplevel_1(w)
gui_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_New_Toplevel_1():
global w
w.destroy()
w = None
def destroy_app():
global root
root.destroy()
exit(0)
class Menubar:
def __init__(self, master):
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Quit", command=root.destroy)
helpmenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Help", menu=helpmenu)
root.config(menu=menubar)
class New_Toplevel_1:
def __init__(self, top=None):
"""This class configures and populates the toplevel window.
top is the toplevel containing window."""
top.geometry("555x398+408+185")
top.title("PlotIt")
self.theme = 'light'
self.line_style = '-'
self.file_path = ''
root.configure(background=_lightwindowbackground)
self.Canvas1 = Canvas(top)
self.Canvas1.place(relx=0.04, rely=0.05, relheight=0.75, relwidth=0.72)
self.Canvas1.configure(background=_bgcolorlight)
self.Canvas1.configure(borderwidth="2")
self.Canvas1.configure(relief=RIDGE)
self.Canvas1.configure(selectbackground="#c4c4c4")
self.Canvas1.configure(width=394)
self.Canvas1.bind('<Configure>', self.resize_plot)
self.fx = Entry(top)
self.fx.place(relx=0.11, rely=0.85, relheight=0.05, relwidth=0.53)
self.fx.configure(background=_bgcolorlight)
self.fx.configure(font="TkFixedFont")
self.fx.configure(width=296)
self.fx.bind('<Return>', lambda x: gui_support.Plot(self.fx.get(),
range(int(self.x_lower.get()),
int(self.x_upper.get())),
self.color_input.get(),
self.theme,
self.Canvas1, self.line_style, self.file_path))
self.fx.configure(fg=_fgcolorlight)
self.fx.configure(insertbackground=_fgcolorlight)
self.Label1 = Label(top)
self.Label1.place(relx=0.77, rely=0.08, height=18, width=47)
self.Label1.configure(text='''x lower''')
self.Label1.configure(fg=_fgcolorlight)
self.Label1.configure(background=_lightwindowbackground)
self.x_lower = Entry(top)
self.x_lower.place(relx=0.88, rely=0.08, relheight=0.05, relwidth=0.08)
self.x_lower.configure(background=_bgcolorlight)
self.x_lower.configure(font="TkFixedFont")
self.x_lower.configure(width=46)
self.x_lower.insert(0, '0')
self.x_lower.configure(fg=_fgcolorlight)
self.Label2 = Label(top)
self.Label2.place(relx=0.77, rely=0.13, height=18, width=51)
self.Label2.configure(text='''x upper''')
self.Label2.configure(fg=_fgcolorlight)
self.Label2.configure(background=_lightwindowbackground)
self.x_upper = Entry(top)
self.x_upper.place(relx=0.88, rely=0.13, relheight=0.05, relwidth=0.08)
self.x_upper.configure(background=_bgcolorlight)
self.x_upper.configure(font="TkFixedFont")
self.x_upper.configure(width=46)
self.x_upper.insert(0, '100')
self.x_upper.configure(fg=_fgcolorlight)
self.Label3 = Label(top)
self.Label3.place(relx=0.04, rely=0.85, height=18, width=35)
self.Label3.configure(text='''f(x)=''')
self.Label3.configure(fg=_fgcolorlight)
self.Label3.configure(background=_lightwindowbackground)
self.bt_plot = Button(top)
self.bt_plot.place(relx=0.67, rely=0.85, height=26, width=47)
self.bt_plot.configure(activebackground=_activebgcolordark)
self.bt_plot.configure(command=lambda: gui_support.Plot(self.fx.get(),
range(int(self.x_lower.get()),
int(self.x_upper.get())),
self.color_input.get(),
self.theme,
self.Canvas1, self.line_style, self.file_path))
self.bt_plot.configure(cursor="left_ptr")
self.bt_plot.configure(text='''Plot''')
self.bt_plot.configure(width=47)
self.bt_plot.configure(background=_bgcolorlight)
self.bt_plot.configure(fg=_fgcolorlight)
self.Label4 = Label(top)
self.Label4.place(relx=0.78, rely=0.34, height=18, width=100)
self.Label4.configure(text=" Choose the Color ")
self.Label4.configure(fg=_fgcolorlight)
self.Label4.configure(background=_lightwindowbackground)
self.current_color = StringVar(top)
self.current_color.set('Red')
self.colors = {'Red', 'Blue', 'Cyan', 'Black', 'Green'}
self.dropdown_menu = OptionMenu(top, self.current_color,
*self.colors, command=self.Dropdown_Changed)
self.dropdown_menu.pack(side='top', anchor='w')
self.dropdown_menu.place(relx=0.78, rely=0.40, height=18, width=100)
self.dropdown_menu.configure(activebackground=_activebgcolordark)
self.dropdown_menu.configure(background=_bgcolorlight)
self.dropdown_menu.configure(fg=_fgcolorlight)
self.dropdown_menu['menu'].configure(activebackground=_activebgcolordark)
self.dropdown_menu['menu'].configure(background=_bgcolorlight)
self.dropdown_menu['menu'].configure(fg=_fgcolorlight)
self.color_input = Entry(top)
self.color_input.place(relx=0.78, rely=0.47,
relheight=0.05, relwidth=0.10)
self.color_input.configure(background=_bgcolorlight)
self.color_input.configure(font="TkFixedFont")
self.color_input.insert(0, '#FF0000')
self.color_input.configure(fg=_fgcolorlight)
self.bt_go = Button(top)
self.bt_go.place(relx=0.90, rely=0.47, height=20, width=40)
self.bt_go.configure(activebackground=_activebgcolordark)
self.bt_go.configure(command=lambda: gui_support.Plot(self.fx.get(),
range(int(self.x_lower.get()),
int(self.x_upper.get())),
self.color_input.get(),
self.theme,
self.Canvas1, self.line_style, self.file_path))
self.bt_go.configure(cursor="left_ptr")
self.bt_go.configure(text='''Go''')
self.bt_go.configure(width=47)
self.bt_go.configure(background=_bgcolorlight)
self.bt_go.configure(fg=_fgcolorlight)
self.bt_themeswitch = Button(top)
self.bt_themeswitch.place(relx=0.8, rely=0.85, height=26, width=100)
self.bt_themeswitch.configure(activebackground=_activebgcolordark)
self.bt_themeswitch.configure(background=_bgcolorlight)
self.bt_themeswitch.configure(cursor="left_ptr")
self.bt_themeswitch.configure(text='Dark Theme')
self.bt_themeswitch.configure(command=self.changeTheme)
self.bt_themeswitch.configure(fg=_fgcolorlight)
def Dropdown_Changed(self, current_color):
color = '#000000'
if current_color == 'Red':
color = '#FF0000'
elif current_color == 'Blue':
color = '#0000FF'
elif current_color == 'Cyan':
color = '#00FFFF'
elif current_color == 'Black':
color = '#000000'
elif current_color == 'Green':
color = '#008000'
self.color_input.delete(0, 100)
self.color_input.insert(0, color)
def changeTheme(self):
if self.bt_themeswitch['text'] == "Light Theme":
self.bt_themeswitch.configure(text="Dark Theme")
self.Canvas1.configure(background=_bgcolorlight)
self.fx.configure(background=_bgcolorlight)
self.fx.configure(fg=_fgcolorlight)
self.fx.configure(insertbackground=_fgcolorlight)
self.x_lower.configure(background=_bgcolorlight)
self.x_lower.configure(fg=_fgcolorlight)
self.x_upper.configure(background=_bgcolorlight)
self.x_upper.configure(fg=_fgcolorlight)
self.bt_plot.configure(activebackground=_activebgcolordark)
self.dropdown_menu.configure(activebackground=_activebgcolordark)
self.color_input.configure(background=_bgcolorlight)
self.color_input.configure(fg=_fgcolorlight)
self.bt_go.configure(activebackground=_activebgcolordark)
self.bt_themeswitch.configure(activebackground=_activebgcolordark)
self.Label1.configure(background=_lightwindowbackground)
self.Label1.configure(fg=_fgcolorlight)
self.Label2.configure(background=_lightwindowbackground)
self.Label2.configure(fg=_fgcolorlight)
self.Label3.configure(background=_lightwindowbackground)
self.Label3.configure(fg=_fgcolorlight)
self.Label4.configure(background=_lightwindowbackground)
self.Label4.configure(fg=_fgcolorlight)
self.bt_go.configure(background=_bgcolorlight)
self.bt_go.configure(fg=_fgcolorlight)
self.bt_plot.configure(background=_bgcolorlight)
self.bt_plot.configure(fg=_fgcolorlight)
self.bt_themeswitch.configure(background=_bgcolorlight)
self.bt_themeswitch.configure(fg=_fgcolorlight)
self.dropdown_menu.configure(background=_bgcolorlight)
self.dropdown_menu.configure(fg=_fgcolorlight)
self.dropdown_menu['menu'].configure(fg=_fgcolorlight)
self.dropdown_menu['menu'].configure(background=_bgcolorlight)
self.dropdown_menu['menu'].configure(activebackground=_activebgcolordark)
self.theme = 'light'
root.configure(background=_lightwindowbackground)
else:
self.bt_themeswitch.configure(text="Light Theme")
self.Canvas1.configure(background=_bgcolordark)
self.fx.configure(background=_bgcolordark)
self.fx.configure(fg=_fgcolordark)
self.fx.configure(insertbackground=_fgcolordark)
self.x_lower.configure(background=_bgcolordark)
self.x_lower.configure(fg=_fgcolordark)
self.x_upper.configure(background=_bgcolordark)
self.x_upper.configure(fg=_fgcolordark)
self.bt_plot.configure(activebackground=_activebgcolordark)
self.dropdown_menu.configure(activebackground=_activebgcolordark)
self.color_input.configure(background=_bgcolordark)
self.color_input.configure(fg=_fgcolordark)
self.bt_go.configure(activebackground=_activebgcolordark)
self.bt_themeswitch.configure(activebackground=_activebgcolordark)
self.Label1.configure(background=_darkwindowbackground)
self.Label1.configure(fg=_fgcolordark)
self.Label2.configure(background=_darkwindowbackground)
self.Label2.configure(fg=_fgcolordark)
self.Label3.configure(background=_darkwindowbackground)
self.Label3.configure(fg=_fgcolordark)
self.Label4.configure(background=_darkwindowbackground)
self.Label4.configure(fg=_fgcolordark)
self.bt_go.configure(background=_bgcolordark)
self.bt_go.configure(fg=_fgcolordark)
self.bt_plot.configure(background=_bgcolordark)
self.bt_plot.configure(fg=_fgcolordark)
self.bt_themeswitch.configure(background=_bgcolordark)
self.bt_themeswitch.configure(fg=_fgcolordark)
self.dropdown_menu.configure(background=_bgcolordark)
self.dropdown_menu.configure(fg=_fgcolordark)
self.dropdown_menu['menu'].configure(fg=_fgcolordark)
self.dropdown_menu['menu'].configure(background=_bgcolordark)
self.theme = 'dark'
root.configure(background=_darkwindowbackground)
gui_support.Plot(self.fx.get(), range(int(self.x_lower.get()), int(self.x_upper.get())),
self.color_input.get(), self.theme, self.Canvas1, self.line_style, self.file_path)
def resize_plot(self, event):
if gui_support.plotted:
gui_support.Plot(self.fx.get(), range(int(self.x_lower.get()),
int(self.x_upper.get())), self.color_input.get(),
self.theme, self.Canvas1, self.line_style, self.file_path)
@staticmethod
def popup1(event):
Popupmenu1 = Menu(root, tearoff=0)
Popupmenu1.configure(activebackground="#f9f9f9")
Popupmenu1.post(event.x_root, event.y_root)
if __name__ == "__main__":
vp_start_gui()