From 430a599dcd9454f95c85ab6eb6b72eb15d584b92 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Mon, 5 Apr 2021 19:52:58 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=D1=8C=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B8=20=D0=BF=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=B5=D1=87=D0=BD=D1=8B=D0=B5=20=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-graphics/main.py | 53 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'python-graphics/main.py') diff --git a/python-graphics/main.py b/python-graphics/main.py index 99ec770..fabdd92 100644 --- a/python-graphics/main.py +++ b/python-graphics/main.py @@ -2,6 +2,8 @@ import tkinter as tk from tkinter import filedialog as fd from tkinter import ttk +from plotter import plot_preset, plot_points + class PlotType: USER = 1 @@ -9,6 +11,15 @@ class PlotType: POINT = 3 +class GraphMode: + LINES = "Линии" + DOTS = "Точки" + + @classmethod + def options(cls): + return [cls.DOTS, cls.LINES] + + class PresetType: LINE = "ax + b = 0" PARABOLA = "ax^2 + bx + c = 0" @@ -131,25 +142,25 @@ class PresetPlotFrame(tk.Frame): cur_type = self.preset_type.get() v = self.variables[cur_type] try: - min_x = float(self.min.get()) + min_x = float(self.min.get().strip()) except ValueError: return {"status": "error", "message": "min(x) не является float"} try: - max_x = float(self.max.get()) + max_x = float(self.max.get().strip()) except ValueError: return {"status": "error", "message": "max(x) не является float"} try: - a = float(v[0][1].get()) + a = float(v[0][1].get().strip()) except ValueError: return {"status": "error", "message": "a не является float"} try: - b = float(v[1][1].get()) + b = float(v[1][1].get().strip()) except ValueError: return {"status": "error", "message": "b не является float"} if cur_type == PresetType.PARABOLA: try: - c = float(v[2][1].get()) + c = float(v[2][1].get().strip()) except ValueError: return {"status": "error", "message": "c не является float"} return { @@ -188,7 +199,7 @@ class UserPlotFrame(tk.Frame): self.grid(row=0, column=0, columnspan=1, rowspan=2, sticky=tk.NSEW) def collect_info(self): - return {"status": "ok"} + return {"status": "ok", "graph": "user"} class PointPlotFrame(tk.Frame): @@ -199,6 +210,7 @@ class PointPlotFrame(tk.Frame): self.show() self.create_widgets() self._path = "" + self.mode = "o" def create_widgets(self): self.choose_file = tk.Button(self) @@ -209,6 +221,25 @@ class PointPlotFrame(tk.Frame): self.filepath = tk.Entry(self) self.filepath.grid(row=1, column=0, sticky=tk.NSEW) + # Изменения этой переменной будут передаваться в метод type_changed + self.mode_var = tk.StringVar() + self.mode_var.trace("w", self.mode_changed) + + self.options = ttk.OptionMenu( + self, + self.mode_var, + GraphMode.DOTS, + *GraphMode.options(), + ) + self.options.grid(row=2, column=0, columnspan=1, rowspan=1, sticky=tk.NSEW) + + def mode_changed(self, *args): + mode = self.mode_var.get() + if mode == GraphMode.DOTS: + self.mode = "o" + elif mode == GraphMode.LINES: + self.mode = "r" + def open_file(self): file_handle = tk.filedialog.askopenfile() if file_handle is not None: @@ -236,7 +267,7 @@ class PointPlotFrame(tk.Frame): except ValueError: return {"status": "error", "message": "Неверный формат данных"} - return {"status": "ok", "graph": "point", "points": points} + return {"status": "ok", "graph": "point", "mode": self.mode, "points": points} class App(tk.Frame): @@ -313,7 +344,13 @@ class App(tk.Frame): self.error_label.grid(row=7, column=0, rowspan=1, columnspan=2, padx=10, pady=5, sticky=tk.NSEW) else: self.error_label.grid_forget() - print(info) + + if info["graph"] == "preset": + plot_preset(info) + elif info["graph"] == "point": + plot_points(info) + else: + print(info) def grid_conf(obj, rows, cols, uniform=False): -- cgit v1.2.3