View raw

1 # This file is part of Marius Peter's airfoil analysis package (this program). 2 # 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation, either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <https://www.gnu.org/licenses/>. 15 16 from tools import creator, evaluator, generator 17 # import creator 18 # import evaluator 19 # import generator 20 import tkinter as tk 21 import tkinter.ttk as ttk 22 23 from matplotlib.backends.backend_tkagg import ( 24 FigureCanvasTkAgg, NavigationToolbar2Tk) 25 26 27 class MainWindow(tk.Frame): 28 """Main editor window.""" 29 30 def __init__(self, *args, **kwargs): 31 tk.Frame.__init__(self, *args, **kwargs) 32 root = tk.Tk() 33 root.wm_title('MAE 154B - Airfoil Design, Evaluation, Optimization') 34 35 # self.button = tk.Button(self, text="Create new window", 36 # command=self.create_window) 37 # self.button.pack(side="top") 38 frame_1 = ttk.Frame(root) 39 l_naca, e_naca = new_field(frame_1, 'naca') 40 l_chord, e_chord = new_field(frame_1, 'chord') 41 l_semi_span, e_semi_span = new_field(frame_1, 'semi_span') 42 af = generator.default_airfoil() 43 # Graph window 44 frame_2 = ttk.Frame(root) 45 fig, ax = creator.plot_geom(af, False) 46 plot = FigureCanvasTkAgg(fig, frame_2) 47 # plot.draw() 48 toolbar = NavigationToolbar2Tk(plot, frame_2) 49 # toolbar.update() 50 51 l_naca.grid(row=0, column=0) 52 e_naca.grid(row=0, column=1, padx=4) 53 # b_naca.grid(row=0, column=2) 54 l_chord.grid(row=1, column=0) 55 e_chord.grid(row=1, column=1, padx=4) 56 l_semi_span.grid(row=2, column=0, padx=4) 57 e_semi_span.grid(row=2, column=1, padx=4) 58 frame_1.pack(side=tk.LEFT) 59 # Graph window 60 plot.get_tk_widget().pack(expand=1, fill=tk.BOTH) 61 toolbar.pack() 62 frame_2.pack(side=tk.LEFT) 63 64 def create_window(self): 65 self.counter += 1 66 window = tk.Toplevel(self) 67 window.wm_title("Window #%s" % self.counter) 68 label = tk.Label(window, text="This is window #%s" % self.counter) 69 label.pack(side="top", fill="both", expand=True, padx=100, pady=100) 70 71 72 def new_field(parent, name): 73 """Add a new user input field.""" 74 75 label = ttk.Label(parent, text=name) 76 entry = ttk.Entry(parent) 77 return label, entry 78 79 80 def set_naca(name): 81 naca_num = name.get() 82 print(naca_num) 83 84 85 def set_chord(name): 86 chord = name.get() 87 print(chord) 88 89 90 def set_semi_span(name): 91 semi_span = name.get() 92 print(semi_span) 93 94 95 # plot.get_tk_widget().pack() 96 MainWindow().mainloop() 97