ALEXANDAR_GEORGIEV

new_car

Jun 8th, 2023 (edited)
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.40 KB | Source Code | 0 0
  1. from json import dump
  2. import tkinter as tk
  3.  
  4.  
  5. class CarProperties:
  6.     def __init__(self, car_update=None):
  7.         print(f"CarProperties::__init__() car_update {car_update}")
  8.         self.properties = tk.Tk()
  9.         self.properties.title("Информация за автомобила")
  10.         screen_width = self.properties.winfo_screenwidth()
  11.         screen_height = self.properties.winfo_screenheight()
  12.         w, h = 800, 800
  13.         print(f"{screen_width} x {screen_height}")
  14.         self.properties.geometry(f"{w}x{h}+{int(screen_width / 2 - w / 2)}+{int(screen_height / 2 - h / 2)}")
  15.         self.screen_width = self.properties.winfo_screenwidth()
  16.         self.properties.attributes('-topmost', True)
  17.  
  18.         self.check_status = False
  19.         self.on_update = car_update
  20.         self.entries_list = []
  21.         self.car_init = {}
  22.  
  23.         self.widgets = {}
  24.  
  25.     def save_b(self):
  26.         print(f"self.entries_list: {self.entries_list}")
  27.         for entry in self.entries_list:
  28.             self.car_init[f"{entry.winfo_name()}"] = entry.get()
  29.  
  30.         print(self.car_init)
  31.         # TODO -> ДОбавя се в базата JSON file новата кола
  32.         with open("db/list_cars.json", "a", encoding=('UTF-8')) as json_file:   # , encoding="utf-8"
  33.             dump(self.car_init, json_file, ensure_ascii=False)
  34.             json_file.write("\n")
  35.  
  36.         print(f"CarProperties::save_b() self.on_update {self.on_update}")
  37.         if (self.on_update):
  38.             self.on_update()
  39.  
  40.         self.properties.destroy()
  41.  
  42.     def props(self):
  43.         self.check_status = False
  44.         # TODO -> Frames
  45.         frame_data = tk.Frame(self.properties, width=700, height=400, relief="groove", borderwidth=5,)
  46.         frame_data.grid(row=0, column=0, sticky="ewns", pady=(0, 6))
  47.         frame_bottom = tk.Frame(self.properties, width=100, height=100, borderwidth=5)
  48.         frame_bottom.grid(row=1, column=0, columnspan=2, sticky="ewns")
  49.         frame_right = tk.Frame(self.properties, width=100, height=100, borderwidth=5)
  50.         frame_right.grid(row=0, column=1, rowspan=2, sticky="ewns")
  51.  
  52.         # TODO -> Labels
  53.         tk.Label(frame_data, text="Регистрационен номер:", ).grid(row=0, column=0, padx=20, pady=(10), sticky="w")
  54.         tk.Label(frame_data, text="Модел:").grid(row=1, column=0, padx=20, pady=(10), sticky="w")
  55.         tk.Label(frame_data, text="Обем на резервоара (л):").grid(row=2, column=0, padx=20, pady=(10), sticky="w")
  56.         tk.Label(frame_data, text="Разходна норма min, max, avr (л/100км):").grid(row=3, column=0, padx=20, pady=(10, 10), sticky="w")
  57.         tk.Label(frame_data, text="Гориво:").grid(row=4, column=0, padx=20, pady=(10, 10), sticky="w")
  58.         tk.Label(frame_data, text="Начален километраж:").grid(row=5, column=0, padx=20, pady=(10, 10), sticky="w")
  59.         tk.Label(frame_data, text="Начална дата:").grid(row=6, column=0, padx=20, pady=(10, 10), sticky="w")
  60.         tk.Label(frame_data, text="Технически преглед (дата):").grid(row=7, column=0, padx=20, pady=(10, 10), sticky="w")
  61.         tk.Label(frame_data, text="Данък (дата):").grid(row=8, column=0, padx=20, pady=(10, 10), sticky="w")
  62.         tk.Label(frame_data, text="Венетка (дата):").grid(row=9, column=0, padx=20, pady=(10, 10), sticky="w")
  63.         tk.Label(frame_data, text="Застраховка ГО (дата):").grid(row=10, column=0, padx=20, pady=(10, 10), sticky="w")
  64.         tk.Label(frame_data, text="Застраховка каско (дата):").grid(row=11, column=0, padx=20, pady=(10, 10), sticky="w")
  65.         tk.Label(frame_data, text="Гуми (дата/км):").grid(row=12, column=0, padx=20, pady=(10, 10), sticky="w")
  66.         tk.Label(frame_data, text="Акумулатор (дата):").grid(row=13, column=0, padx=20, pady=(10, 10), sticky="w")
  67.         tk.Label(frame_data, text="Смяна на масло (дата/км):").grid(row=14, column=0, padx=20, pady=(10, 10), sticky="w")
  68.         tk.Label(frame_data, text="Пожарогасител (дата):").grid(row=15, column=0, padx=20, pady=(10, 10), sticky="w")
  69.         tk.Label(frame_data, text="Аптечка (дата):").grid(row=16, column=0, padx=20, pady=(10, 10), sticky="w")
  70.         tk.Label(frame_data, text="Тип автомобил:").grid(row=17, column=0, padx=20, pady=(10, 10), sticky="w")
  71.  
  72.         # TODO -> Entry
  73.         #self.widgets["reg_number_e"] = tk.Entry(frame_data, width=12, justify='center', name="reg_number_e")
  74.         reg_number_e = tk.Entry(frame_data, width=12, justify='center', name="reg_number_e")
  75.         reg_number_e.grid(row=0, column=1, padx=10, pady=10, sticky="w")
  76.         tk.Entry(frame_data, width=15, justify='left', name="model_e").grid(row=1, column=1, padx=10, pady=10, sticky="w")
  77.         tank_e = tk.Entry(frame_data, width=4, justify='center', name="tank_e")
  78.         tank_e.grid(row=2, column=1, padx=10, pady=10, sticky="w")
  79.         tk.Entry(frame_data, width=4, justify='center', name="fuel_min_e").grid(row=3, column=1, padx=10, pady=10, sticky="w")
  80.         tk.Entry(frame_data, width=4, justify='center', name="fuel_max_e").grid(row=3, column=2, padx=10, pady=10, sticky="w")
  81.         tk.Entry(frame_data, width=4, justify='center', name="fuel_avr_e").grid(row=3, column=3, padx=10, pady=10, sticky="w")
  82.         fuel_type_e = tk.Entry(frame_data, width=12, justify='center', name="fuel_type_e")
  83.         fuel_type_e.grid(row=4, column=1, padx=10, pady=10, sticky="w")
  84.         tk.Entry(frame_data, width=12, justify='center', name="start_km_e").grid(row=5, column=1, padx=10, pady=10, sticky="w")
  85.         start_date_e = tk.Entry(frame_data, width=12, justify='center', name="start_date_e")
  86.         start_date_e.grid(row=6, column=1, padx=10, pady=10, sticky="w")
  87.         tk.Entry(frame_data, width=12, justify='center', name="service_date_e").grid(row=7, column=1, padx=10, pady=10, sticky="w")
  88.         tk.Entry(frame_data, width=12, justify='center', name="tax_date_e").grid(row=8, column=1, padx=10, pady=10, sticky="w")
  89.         tk.Entry(frame_data, width=12, justify='center', name="venete_date_e").grid(row=9, column=1, padx=10, pady=10, sticky="w")
  90.         tk.Entry(frame_data, width=12, justify='center', name="inscomm_date_e").grid(row=10, column=1, padx=10, pady=10, sticky="w")
  91.         tk.Entry(frame_data, width=12, justify='center', name="inscasco_date_e").grid(row=11, column=1, padx=10, pady=10, sticky="w")
  92.         tk.Entry(frame_data, width=12, justify='center', name="tire_date_e").grid(row=12, column=1, padx=10, pady=10, sticky="w")
  93.         tk.Entry(frame_data, width=12, justify='center', name="tire_km_e").grid(row=12, column=2, padx=10, pady=10, sticky="w")
  94.         tk.Entry(frame_data, width=12, justify='center', name="acumul_e").grid(row=13, column=1, padx=10, pady=10, sticky="w")
  95.         tk.Entry(frame_data, width=12, justify='center', name="oil_date_e").grid(row=14, column=1, padx=10, pady=10, sticky="w")
  96.         tk.Entry(frame_data, width=12, justify='center', name="oil_km_e").grid(row=14, column=2, padx=10, pady=10, sticky="w")
  97.         tk.Entry(frame_data, width=12, justify='center', name="fireext_date_e").grid(row=15, column=1, padx=10, pady=10, sticky="w")
  98.         tk.Entry(frame_data, width=12, justify='center', name="aid_date_e").grid(row=16, column=1, padx=10, pady=10, sticky="w")
  99.         type_car_e = tk.Entry(frame_data, width=12, justify='center', name="type_car_e")
  100.         type_car_e.grid(row=17, column=1, padx=10, pady=10, sticky="w")
  101.  
  102.         self.entries_list = [reg_number_e, tank_e, fuel_type_e, type_car_e, start_date_e]
  103.  
  104.         # TODO -> Buttons
  105.         save_b = tk.Button(frame_bottom, text="ЗАПИС", fg="blue", command=self.save_b)
  106.  
  107.         save_b.grid(row=0, column=0, padx=(476, 10))
  108.  
  109.         # TODO -> Бутона НОВ да се разреши!
  110.         print(f"Opit {self.car_init}")
  111.         # return self.car_init
  112.         return self.check_status
  113.  
  114.     def have_new_data(self):  # Проверка дали има нова кола
  115.  
  116.         # unmapped_acc = self.acc_tree.get_unmapped_acc(self.mapped_accounts)
  117.         # print("unmapped_acc", unmapped_acc)
  118.         if len(self.car_init) == 0:
  119.             return False
  120.         return True
  121.         # self.properties.mainloop()
  122.  
  123.  
  124. if __name__ == '__main__':
  125.     test = CarProperties()
  126.     test.props()
  127.  
  128.     # print(test.car_init)
  129.  
  130.     test.properties.mainloop()
  131.  
  132.  
  133.  
  134.  
Add Comment
Please, Sign In to add comment