Загрузка данных


import time
import os
import tkinter as tk
from tkinter import filedialog, messagebox
from datetime import datetime

class SimpleXMLTimer:
    def __init__(self):
        self.window = tk.Tk()
        self.window.title("Секундомер резки")
        self.window.geometry("400x300")
        self.window.attributes('-topmost', True)
        
        self.xml_path = None
        self.last_modified = None
        self.total_time = 0
        self.is_cutting = False
        self.start_time = None
        
        # Кнопка выбора файла
        select_btn = tk.Button(self.window, text="ВЫБРАТЬ materials.xml",
                              command=self.select_file,
                              font=("Arial", 12),
                              width=20, height=2)
        select_btn.pack(pady=20)
        
        # Таймер
        self.time_label = tk.Label(self.window, text="00:00:00",
                                   font=("Arial", 50, "bold"))
        self.time_label.pack(pady=20)
        
        # Статус
        self.status_label = tk.Label(self.window, text="Выберите файл",
                                     font=("Arial", 12), fg="gray")
        self.status_label.pack()
        
        # Кнопка сброса
        reset_btn = tk.Button(self.window, text="СБРОС",
                             command=self.reset,
                             font=("Arial", 12),
                             width=10, height=2)
        reset_btn.pack(pady=10)
        
        self.update()
    
    def select_file(self):
        filename = filedialog.askopenfilename(
            title="Выберите materials.xml",
            filetypes=[("XML files", "*.xml"), ("All files", "*.*")]
        )
        if filename:
            self.xml_path = filename
            self.last_modified = os.path.getmtime(filename)
            self.status_label.config(text=f"Файл выбран: {os.path.basename(filename)}", 
                                    fg="green")
    
    def check_file_changes(self):
        if not self.xml_path or not os.path.exists(self.xml_path):
            return None
        
        current_modified = os.path.getmtime(self.xml_path)
        
        if current_modified != self.last_modified:
            self.last_modified = current_modified
            return True
        return None
    
    def update(self):
        if self.xml_path:
            # Проверяем изменился ли файл
            if self.check_file_changes():
                # Файл изменился - значит что-то происходит
                if not self.is_cutting:
                    self.is_cutting = True
                    self.start_time = time.time()
                    self.status_label.config(text="РЕЗКА", fg="green")
                else:
                    # Файл изменился снова - возможно остановка
                    self.total_time += time.time() - self.start_time
                    self.is_cutting = False
                    self.status_label.config(text="ПАУЗА", fg="orange")
        
        # Обновляем таймер
        if self.is_cutting:
            current = self.total_time + (time.time() - self.start_time)
        else:
            current = self.total_time
        
        hours = int(current // 3600)
        minutes = int((current % 3600) // 60)
        seconds = int(current % 60)
        self.time_label.config(text=f"{hours:02d}:{minutes:02d}:{seconds:02d}")
        
        self.window.after(500, self.update)
    
    def reset(self):
        self.total_time = 0
        self.is_cutting = False
        self.time_label.config(text="00:00:00")
    
    def run(self):
        self.window.mainloop()

if __name__ == "__main__":
    app = SimpleXMLTimer()
    app.run()