From dab216e726da89cde4c8f9c6077c77536cc84d14 Mon Sep 17 00:00:00 2001 From: Akshat Garg Date: Thu, 15 Feb 2018 21:39:01 +0530 Subject: [PATCH] Fixes #84: Create Drop down Menu in GUI for selecting different linestyles --- gui_main.py | 66 +++++++++++++++++++++++++++++++++---------------- lib/plotutil.py | 2 ++ 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/gui_main.py b/gui_main.py index bfb94be..0935d91 100644 --- a/gui_main.py +++ b/gui_main.py @@ -102,8 +102,8 @@ def __init__(self, top=None): top.title("PlotIt") self.theme = 'light' - self.line_style = '-' self.file_path = '' + self.line_style = '-' root.configure(background=_lightwindowbackground) self.Canvas1 = Canvas(top) @@ -187,16 +187,30 @@ def __init__(self, top=None): 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.dropdown_menu_color = 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.dropdown_menu_color.pack(side='top', anchor='w') + self.dropdown_menu_color.place(relx=0.78, rely=0.40, height=18, width=100) + self.dropdown_menu_color.configure(activebackground=_activebgcolordark) + self.dropdown_menu_color.configure(background=_bgcolorlight) + self.dropdown_menu_color.configure(fg=_fgcolorlight) + self.dropdown_menu_color['menu'].configure(activebackground=_activebgcolordark) + self.dropdown_menu_color['menu'].configure(background=_bgcolorlight) + self.dropdown_menu_color['menu'].configure(fg=_fgcolorlight) + + self.current_line_style = StringVar(top) + self.current_line_style.set('-') + self.line_styles = {'-', '--', '-.', ':'} + self.dropdown_menu_line_style = OptionMenu(top, self.current_line_style, + *self.line_styles, command=self.dropdown_changed_line_style) + self.dropdown_menu_line_style.pack(side='top', anchor='w') + self.dropdown_menu_line_style.place(relx=0.78, rely=0.60, height=18, width=100) + self.dropdown_menu_line_style.configure(activebackground=_activebgcolordark) + self.dropdown_menu_line_style.configure(background=_bgcolorlight) + self.dropdown_menu_line_style.configure(fg=_fgcolorlight) + self.dropdown_menu_line_style['menu'].configure(activebackground=_activebgcolordark) + self.dropdown_menu_line_style['menu'].configure(background=_bgcolorlight) + self.dropdown_menu_line_style['menu'].configure(fg=_fgcolorlight) self.color_input = Entry(top) self.color_input.place(relx=0.78, rely=0.47, @@ -245,6 +259,16 @@ def Dropdown_Changed(self, current_color): self.color_input.delete(0, 100) self.color_input.insert(0, color) + def dropdown_changed_line_style(self, current_line_style): + if current_line_style == '-': + self.line_style = '-' + elif current_line_style == '--': + self.line_style = '--' + elif current_line_style == '-.': + self.line_style = '-.' + elif current_line_style == ':': + self.line_style = ':' + def changeTheme(self): if self.bt_themeswitch['text'] == "Light Theme": self.bt_themeswitch.configure(text="Dark Theme") @@ -257,7 +281,7 @@ def changeTheme(self): 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.dropdown_menu_color.configure(activebackground=_activebgcolordark) self.color_input.configure(background=_bgcolorlight) self.color_input.configure(fg=_fgcolorlight) self.bt_go.configure(activebackground=_activebgcolordark) @@ -276,11 +300,11 @@ def changeTheme(self): 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.dropdown_menu_color.configure(background=_bgcolorlight) + self.dropdown_menu_color.configure(fg=_fgcolorlight) + self.dropdown_menu_color['menu'].configure(fg=_fgcolorlight) + self.dropdown_menu_color['menu'].configure(background=_bgcolorlight) + self.dropdown_menu_color['menu'].configure(activebackground=_activebgcolordark) self.theme = 'light' root.configure(background=_lightwindowbackground) else: @@ -294,7 +318,7 @@ def changeTheme(self): 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.dropdown_menu_color.configure(activebackground=_activebgcolordark) self.color_input.configure(background=_bgcolordark) self.color_input.configure(fg=_fgcolordark) self.bt_go.configure(activebackground=_activebgcolordark) @@ -313,10 +337,10 @@ def changeTheme(self): 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.dropdown_menu_color.configure(background=_bgcolordark) + self.dropdown_menu_color.configure(fg=_fgcolordark) + self.dropdown_menu_color['menu'].configure(fg=_fgcolordark) + self.dropdown_menu_color['menu'].configure(background=_bgcolordark) self.theme = 'dark' root.configure(background=_darkwindowbackground) diff --git a/lib/plotutil.py b/lib/plotutil.py index da6d53e..73547fe 100644 --- a/lib/plotutil.py +++ b/lib/plotutil.py @@ -4,6 +4,7 @@ import matplotlib.pyplot as plt import matplotlib.style as mplstyle from matplotlib import colors as mcolors +import traceback def create_y_values(func, xvals): @@ -62,6 +63,7 @@ def plot(func, xpoints, color_name, xlabel, ylabel, theme, gui, line_style, file except Exception: print("An error occured.") + print(traceback.format_exc()) if file_path != "": plt.savefig(file_path)