Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import *
- from tkinter import ttk
- from tkinter import messagebox
- import tkinter.messagebox
- from pump_two_on import PumpTwoOn
- from pump_two_off import PumpTwoOff
- from pump_one_on import PumpOneOn
- from pump_one_off import PumpOneOff
- from drain import TankDrain
- from exit import Exit
- import RPi.GPIO as GPIO
- import math
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(36, GPIO.IN) # pump one
- GPIO.setup(40, GPIO.IN) # pumo two
- GPIO.setup(38, GPIO.IN) # pumo three
- # tank one gpio senzors setup
- GPIO.setup(18, GPIO.IN)
- GPIO.setup(22, GPIO.IN)
- GPIO.setup(21, GPIO.IN)
- GPIO.setup(23, GPIO.IN)
- GPIO.setup(24, GPIO.IN)
- # tank two gpio sen+zors setup
- GPIO.setup(11, GPIO.IN)
- GPIO.setup(12, GPIO.IN)
- GPIO.setup(13, GPIO.IN)
- GPIO.setup(15, GPIO.IN)
- GPIO.setup(16, GPIO.IN)
- # tank three gpio senzors setup
- GPIO.setup(29, GPIO.IN)
- GPIO.setup(31, GPIO.IN)
- GPIO.setup(33, GPIO.IN)
- GPIO.setup(35, GPIO.IN)
- GPIO.setup(37, GPIO.IN)
- class Window:
- def __init__(self, root):
- # --------------------------------TK-------------------------------
- # root setup
- self.window = root
- self.background_color = '#999da0'
- self.window.attributes('-fullscreen', True)
- self.window.title("Control Panel")
- self.window.configure(background='#999da0')
- self.animating_one = False
- self.animating_two = False
- self.animating_three = False
- # root geometry
- self.screen_width = self.window.winfo_screenwidth() # 1920
- self.screen_height = self.window.winfo_screenheight() # 1080
- # manual mode
- self.manual = Label(root, text="РЪЧНО УПРАВЛЕНИЕ", font=('Arial', 30), bg=self.background_color, fg="black")
- self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 20)
- self.pumpOne = Label(root, text="ПОМПА 1", font=('Arial', 20), bg=self.background_color, fg="black")
- self.pumpOne.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 8)
- self.pumpTwo = Label(root, text="ПОМПА 2", font=('Arial', 20), bg=self.background_color, fg="black")
- self.pumpTwo.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 8)
- # buttons
- self.pump_one_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_on_func, bg="#198FF5", fg="white")
- self.pump_one_on_btn.place(x=(self.screen_width / 3) * 2.18, y=self.screen_height / 5.8)
- self.pump_one_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_off_func, bg="#696969", fg="white")
- self.pump_one_off_btn.place(x=(self.screen_width / 3) * 2.16, y=self.screen_height / 4.5)
- # separator
- self.separator_frame = Frame(root, bg="black", width=2, height=150)
- self.separator_frame.place(x=1590, y=137)
- self.pump_two_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_two_on_func, bg="#198FF5", fg="white")
- self.pump_two_on_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 5.8)
- self.pump_two_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_two_off_func, bg="#696969", fg="white")
- self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 4.5)
- # draning
- self.manual = Label(root, text="ГЛАВЕН РЕЗЕРВОАР", font=('Arial', 30), bg=self.background_color, fg="black")
- self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 3.3)
- self.pump_two_off_btn = Button(root, text="ИЗТОЧВАНЕ", font=("Arial", 15, "bold"), command=self.drain_func, bg="#F06B5D", fg="white")
- self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.35, y=self.screen_height / 2.7)
- # separator
- self.separator_frame = Frame(root, bg="black", width=470, height=2)
- self.separator_frame.place(x=1360, y=480)
- # exit program button
- self.exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"),
- command=self.Exit_btn_func, bg="#EF4324", fg="white")
- self.exit_btn.place(x=self.screen_width - 55, y=self.screen_height - (self.screen_height - 5))
- # automatic mode
- self.automatic = Label(root, text="АВТОМАТИЧНО УПРАВЛЕНИЕ", font=('Arial', 25), bg=self.background_color,
- fg="black")
- self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 2.1)
- self.tankOne = Label(root, text="РЕЗЕРВОАР 1", font=('Arial', 20), bg=self.background_color, fg="black")
- self.tankOne.place(x=(self.screen_width / 3) * 2.13, y=self.screen_height / 1.9)
- # separator
- self.separator_frame = Frame(root, bg="black", width=2, height=120)
- self.separator_frame.place(x=1590, y=570)
- self.tankTwo = Label(root, text="РЕЗЕРВОАР 2", font=('Arial', 20), bg=self.background_color, fg="black")
- self.tankTwo.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.9)
- # dropdown menus
- self.tank1_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
- self.tank1_label.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 1.7)
- self.tank1_value_inside = tk.StringVar(value="0%")
- self.tank1_options = ["0%", "20%", "40%", "60%", "80%", "100%"]
- self.tank1_dropdown = tk.OptionMenu(root, self.tank1_value_inside, *self.tank1_options)
- self.tank1_dropdown.place(x=(self.screen_width / 3) * 2.32, y=self.screen_height / 1.7)
- # dropdown menus
- self.tank2_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
- self.tank2_label.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.7)
- self.tank2_value_inside = tk.StringVar(value="0%")
- self.tank2_options = ["0%", "20%", "40%", "60%", "80%", "100%"]
- self.tank2_dropdown = tk.OptionMenu(root, self.tank2_value_inside, *self.tank2_options)
- self.tank2_dropdown.place(x=(self.screen_width / 3) * 2.70, y=self.screen_height / 1.7)
- # sequence option
- self.automatic = Label(root, text="ИЗБЕРИ ПОСЛЕДОВАТЕЛНОСТ", font=('Arial', 25), bg=self.background_color,
- fg="black")
- self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 1.5)
- # create a label and two radio buttons for the first sequence option
- self.sequence1_label = tk.Label(root, text='ЕДНО', bg=self.background_color, font=('Arial', 20))
- self.sequence1_label.place(x=(self.screen_width / 3) * 2.3, y=self.screen_height / 1.4)
- self.sequence1_var = tk.StringVar(root)
- self.sequence1_var.set('Резервоар 1')
- self.sequence1_rb1 = tk.Radiobutton(root, text='Резервоар 1 ', bg=self.background_color, font=('Arial', 15),
- variable=self.sequence1_var, value='Резервоар 1')
- self.sequence1_rb1.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 1.31)
- self.sequence1_rb2 = tk.Radiobutton(root, text='Резервоар 2 ', bg=self.background_color, font=('Arial', 15),
- variable=self.sequence1_var, value='Резервоар 2')
- self.sequence1_rb2.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 1.24)
- # separator
- self.separator_frame = Frame(root, bg="black", width=2, height=122)
- self.separator_frame.place(x=1590, y=780)
- # create a label and two radio buttons for the second sequence option
- self.sequence2_label = tk.Label(root, text='ДВЕ', font=('Arial', 20), bg=self.background_color, fg="black")
- self.sequence2_label.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.4)
- self.sequence2_var = tk.StringVar(root)
- self.sequence2_var.set('Резервоар 2')
- self.sequence2_rb1 = tk.Radiobutton(root, text='Резервоар 1 ', bg=self.background_color, font=('Arial', 15),
- variable=self.sequence2_var, value='Резервоар 1')
- self.sequence2_rb1.place(x=(self.screen_width / 3) * 2.57, y=self.screen_height / 1.31)
- self.sequence2_rb2 = tk.Radiobutton(root, text='Резервоар 2 ', bg=self.background_color, font=('Arial', 15),
- variable=self.sequence2_var, value='Резервоар 2')
- self.sequence2_rb2.place(x=(self.screen_width / 3) * 2.57, y=self.screen_height / 1.24)
- # start and stop button
- self.start = Button(root, text="СТАРТИРАЙ", font=('Arial', 25), bg="#41be87", fg="white",
- command=self.overflow_btn_on)
- self.start.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 1.15)
- self.stop = Button(root, text="СПРИ", font=('Arial', 25), bg="#e2651d", fg="white",
- command=self.overflow_btn_off)
- self.stop.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 1.15)
- # --------------------------------Canvas-------------------------------
- # canvas setup
- self.canvas = Canvas(root, width=(self.screen_width / 3) * 2, height=self.screen_height,
- bg=self.background_color)
- self.canvas.pack()
- self.canvas.place(bordermode=OUTSIDE)
- # heading
- self.canvas.create_text(self.screen_width / 3, self.screen_height / 18, text='К О Н Т Р О Л Е Н П А Н Е Л',
- fill='black', font='Arial 25')
- # create scale tank One
- self.canvas.create_line(65, 140, 65, 520, width=2)
- for i in range(6):
- self.p1 = 100 - i * 20
- self.y1 = 140
- self.y1 = self.y1 + i * 76
- self.canvas.create_text(25, self.y1, text=self.p1, font=("Arial", 13, "bold"))
- self.canvas.create_text(45, self.y1, text="%", font=("Arial", 13, "bold"))
- self.canvas.create_line(65, self.y1, 75, self.y1, width=2)
- # create scale tank Two
- self.canvas.create_line(65, 600, 65, 980, width=2)
- for i in range(6):
- self.p = 100 - i * 20
- self.y = 600
- self.y = self.y + i * 76
- self.canvas.create_text(25, self.y, text=self.p, font=("Arial", 13, "bold"))
- self.canvas.create_text(45, self.y, text=" %", font=("Arial", 13, "bold"))
- self.canvas.create_line(65, self.y, 75, self.y, width=2)
- # create scale tank Three
- self.canvas.create_line(1185, 200, 1185, 900, width=3)
- for i in range(6):
- self.p = 100 - i * 20
- self.y2 = 200
- self.y2 = self.y2 + i * 140
- self.canvas.create_text(1205, self.y2, text=self.p, font=("Arial", 15, "bold"))
- self.canvas.create_text(1230, self.y2, text=" %", font=("Arial", 15, "bold"))
- self.canvas.create_line(1160, self.y2, 1186, self.y2, width=3)
- # tank One (T1)
- self.canvas.create_rectangle(80, 140, 360, 520, fill='#d9dddc')
- # tank One Water
- self.waterOne = self.canvas.create_rectangle(80, 140, 360, 520, fill='blue')
- self.tank1_label_canvas = tk.Label(root, text="Резервоар 1", bg=self.background_color, font=('Arial', 18))
- self.tank1_label_canvas.place(x=80, y=100)
- # tank Two (T2)
- self.canvas.create_rectangle(80, 600, 360, 980, fill='#d9dddc')
- # tank Two Water
- self.waterTwo = self.canvas.create_rectangle(80, 600, 360, 980, fill='blue')
- self.tank2_label_canvas = tk.Label(root, text="Резервоар 2", bg=self.background_color, font=('Arial', 18))
- self.tank2_label_canvas.place(x=80, y=560)
- # tank Three (T3)
- self.canvas.create_rectangle(750, 200, 1150, 900, fill='#d9dddc')
- # tank Three Water
- self.waterThree = self.canvas.create_rectangle(750, 200, 1150, 900, fill='blue')
- self.tank3_label_canvas = tk.Label(root, text="Резервоар 3", bg=self.background_color, font=('Arial', 20))
- self.tank3_label_canvas.place(x=995, y=155)
- # pump One (p40)
- self.ovalOne = self.canvas.create_oval(385, 380, 515, 510, fill='#6b6b6b', width=15)
- self.Pump1line1 = self.canvas.create_line(400, 450, 500, 450, width=3)
- self.Pump1line2 = self.canvas.create_line(450, 400, 450, 500, width=3)
- self.pump1_label_canvas = tk.Label(root, text="Помпа 1", bg=self.background_color, font=('Arial', 18))
- self.pump1_label_canvas.place(x=405, y=340)
- # pump Two (p40)
- self.ovalTwo = self.canvas.create_oval(385, 835, 515, 965, fill='#6b6b6b', width=15)
- self.Pump2line1 = self.canvas.create_line(400, 900, 500, 900, width=3)
- self.Pump2line2 = self.canvas.create_line(450, 850, 450, 950, width=3)
- self.pump2_label_canvas = tk.Label(root, text="Помпа 2", bg=self.background_color, font=('Arial', 18))
- self.pump2_label_canvas.place(x=405, y=790)
- # pump Three (p38)
- self.ovalTwo = self.canvas.create_oval(985, 910, 1115, 1040, fill='#6b6b6b', width=15)
- self.Pump2line1 = self.canvas.create_line(1000, 980, 1100, 980, width=3)
- self.Pump2line2 = self.canvas.create_line(1050, 930, 1050, 1030, width=3)
- self.pump3_label_canvas = tk.Label(root, text="Помпа 3", bg=self.background_color, font=('Arial', 15), wraplength=1)
- self.pump3_label_canvas.place(x=1130, y=903)
- def Exit_btn_func(self):
- self.Exit_btn = Exit().exit()
- if self.Exit_btn > 0:
- self.window.destroy()
- return
- def check_condition_water_tank_one(self):
- if self.sum == 1:
- return 444
- elif self.sum == 2:
- return 368
- elif self.sum == 3:
- return 292
- elif self.sum == 4:
- return 216
- elif self.sum == 5:
- return 140
- else:
- return 520
- def check_condition_water_tank_two(self):
- if self.sum == 1:
- return 904
- elif self.sum == 2:
- return 828
- elif self.sum == 3:
- return 752
- elif self.sum == 4:
- return 676
- elif self.sum == 5:
- return 600
- else:
- return 980
- def check_condition_water_tank_three(self):
- if self.sum == 1:
- return 760
- elif self.sum == 2:
- return 620
- elif self.sum == 3:
- return 480
- elif self.sum == 4:
- return 340
- elif self.sum == 5:
- return 200
- else:
- return 900
- def update_water_tank_one(self):
- self.sum = GPIO.input(18) + GPIO.input(22) + GPIO.input(21) + GPIO.input(23) + GPIO.input(24)
- self.y1 = self.check_condition_water_tank_one()
- self.canvas.coords(self.waterOne, 80, self.y1, 360, 520)
- self.window.after(300, self.update_water_tank_one)
- def update_water_tank_two(self):
- self.sum = GPIO.input(15) + GPIO.input(13) + GPIO.input(12) + GPIO.input(16) + GPIO.input(11)
- self.y1 = self.check_condition_water_tank_two()
- self.canvas.coords(self.waterTwo, 80, self.y1, 360, 980)
- self.window.after(300, self.update_water_tank_two)
- def update_water_tank_three(self):
- self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
- self.y1 = self.check_condition_water_tank_three()
- self.canvas.coords(self.waterThree, 750, self.y1, 1150, 900)
- self.window.after(300, self.update_water_tank_three)
- def animate_one(self, angle):
- x1, y1, x2, y2 = self.canvas.coords(self.Pump1line1)
- cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
- new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
- new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
- new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
- new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
- self.canvas.coords(self.Pump1line1, new_x1, new_y1, new_x2, new_y2)
- x1, y1, x2, y2 = self.canvas.coords(self.Pump1line2)
- cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
- new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
- new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
- new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
- new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
- self.canvas.coords(self.Pump1line2, new_x1, new_y1, new_x2, new_y2)
- if self.animating_one:
- self.canvas.after(10, self.animate_one, angle + 0.1)
- def animate_two(self, angle):
- x1, y1, x2, y2 = self.canvas.coords(self.Pump2line1)
- cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
- new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
- new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
- new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
- new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
- self.canvas.coords(self.Pump2line1, new_x1, new_y1, new_x2, new_y2)
- x1, y1, x2, y2 = self.canvas.coords(self.Pump2line2)
- cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
- new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
- new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
- new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
- new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
- self.canvas.coords(self.Pump2line2, new_x1, new_y1, new_x2, new_y2)
- if self.animating_two:
- self.canvas.after(10, self.animate_two, angle + 0.1)
- def pump_one_on_func(self):
- PumpOneOn()
- if not self.animating_one:
- self.animating_one = True
- self.animate_one(0)
- def pump_one_off_func(self):
- PumpOneOff()
- self.animating_one = False
- def pump_two_on_func(self):
- PumpTwoOn()
- if not self.animating_two:
- self.animating_two = True
- self.animate_two(0)
- def pump_two_off_func(self):
- PumpTwoOff()
- self.animating_two = False
- def drain_func(self):
- TankDrain()
- if not self.animating_three:
- self.animating_three = True
- self.animate_three(0)
- def is_empty(self):
- if (GPIO.input(18) + GPIO.input(22) + GPIO.input(21) + GPIO.input(23) + GPIO.input(24) + GPIO.input(15) + GPIO.input(13) + GPIO.input(12) + GPIO.input(16) + GPIO.input(11)) == 0:
- self.animating_three = False
- obj.is_empty()
- def overflow_btn_on(self):
- if int(self.tank2_value_inside.get()[:-1]) + int(self.tank1_value_inside.get()[:-1]) != 100 \
- or self.sequence2_var.get() == self.sequence1_var.get():
- messagebox.showwarning("Предупреждение", "Въведените данни не са равни на 100%!")
- else:
- print("OK!")
- def overflow_btn_off(self):
- ...
- if __name__ == "__main__":
- root = tk.Tk()
- obj = Window(root)
- obj.update_water_tank_one()
- obj.update_water_tank_two()
- obj.update_water_tank_three()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement