Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #84: Create Drop down Menu in GUI for different lines styles #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 45 additions & 21 deletions gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropdown does not change color on changing theme. Please look into this.


self.current_line_style = StringVar(top)
self.current_line_style.set('-')
self.line_styles = {'-', '--', '-.', ':'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows only symbols in the drop down which looks a bit weird. Please show style names on drop down. Like solid line, dashed, dot dashed. Symbols should be present in bracket.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position of the drop down is a bit too down. Please move it up a little.

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,
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions lib/plotutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down