-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
101 lines (81 loc) · 3.48 KB
/
app.py
File metadata and controls
101 lines (81 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import tkinter as tk
import logging
# Import from the 'gui' package
from gui.main_window import MainWindow
from gui.notification_window import NotificationWindow
from watcher import DirectoryWatcher
from config import load_config, save_config, add_directory
# Конфигуриране на logging за app.py
print('bevore logging config')
logging.basicConfig(filename='app.log', level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
def main():
logging.info("Entering main function")
print('Entering in main')
root = tk.Tk()
root.geometry("800x300+100+100")
root.title("File Watcher")
directories = load_config()
logging.info(f"Directories loaded from config: {directories}")
global watcher
watcher = None
# Създаване на независим прозорец за нотификации
notification_window = NotificationWindow(master=root)
def start_watching():
global watcher
print(" APP START")
logging.info("Inside start_watching function")
logging.info("Starting watching...")
logging.info(f"Watcher is None: {watcher is None}")
if watcher is not None:
watcher.stop_watching()
watcher = DirectoryWatcher(directories, notification_window)
watcher.start_watching()
# Update the watcher reference in MainWindow
app.set_watcher(watcher)
app.update_button_state("Stop Watching", "green") # Актуализиране на бутона в GUI
logging.info("Watching started successfully")
def stop_watching():
global watcher
logging.info("Stopping watching...")
if watcher is not None:
watcher.stop_watching()
watcher = None
app.update_button_state("Start Watching", "SystemButtonFace")
logging.info("Watching stopped successfully")
def toggle_watching():
"""Превключва състоянието на наблюдение."""
if app.is_watching:
stop_watching()
else:
start_watching()
def edit_directory(directory):
"""Функция за редактиране на директория."""
save_config(directories)
if watcher is not None:
watcher.update_directories(directories)
app.update_directory_list(directories)
def delete_directory(directory):
"""Функция за изтриване на директория."""
directories.remove(directory)
save_config(directories)
if watcher is not None:
watcher.remove_directory(directory['path'])
app.update_directory_list(directories)
def add_directory_callback(new_directory):
"""Функция за добавяне на нова директория."""
add_directory(directories, new_directory)
if watcher is not None:
watcher.update_directories(directories)
app.update_directory_list(directories)
# Основен прозорец - предаваме None за watcher първоначално
app = MainWindow(
root, directories, start_watching, stop_watching,
edit_directory, delete_directory, add_directory_callback,
notification_window, None # Pass None for watcher initially
)
# Показване на прозореца за нотификации
notification_window.show()
root.mainloop()
if __name__ == "__main__":
main()