Skip to content

Commit 7da7ca6

Browse files
committed
changed logic_controller to logic
1 parent b35b4bb commit 7da7ca6

13 files changed

Lines changed: 107 additions & 94 deletions

src/core/gui.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import webbrowser
44
import requests
55
from PyQt6.QtWidgets import (
6-
QApplication, QWidget, QLabel, QVBoxLayout, QMessageBox
6+
QApplication, QWidget, QLabel, QVBoxLayout, QMessageBox,
7+
QListWidget, QGridLayout
78
)
89
from PyQt6.QtGui import QIcon
910
from PyQt6.QtCore import Qt
@@ -90,23 +91,29 @@ def splash_screen():
9091
QApplication.processEvents()
9192
splash.close()
9293

93-
class GUIRoot(QWidget):
94+
class SessionsList(QListWidget):
95+
def onItemClicked(self, item):
96+
QMessageBox.information(self, "QListWidget Interaction", "You selected: " + item.text())
97+
98+
class MainWindow(QWidget):
9499
def __init__(self):
95100
super().__init__()
96101
self.init_ui()
97102

98103
# Initialize LogicRoot
99-
self.logic_controller = LogicRoot(self)
104+
self.logic = LogicRoot(self)
100105

101106
# calls to create the app directories
102107
sessions_exist()
103108
user_dir_exists()
104109

105110
def init_ui(self):
106111
splash_screen()
107-
layout = QVBoxLayout()
108-
label = QLabel("Welcome to AppUsageGUI")
109-
layout.addWidget(label)
112+
113+
# define the layout type --
114+
layout = QGridLayout()
115+
116+
# app setup --
110117
self.setLayout(layout)
111118
# self.setWindowFlags()
112119
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
@@ -118,14 +125,20 @@ def init_ui(self):
118125
if is_dark_mode():
119126
self.setStyleSheet("background-color: #2E2E2E; color: white;")
120127

128+
# create widgets --
129+
label = QLabel("Welcome to AppUsageGUI")
130+
131+
# add widgets to the layout --
132+
layout.addWidget(label)
133+
121134
def on_close(self):
122135
# Stop trackers
123-
if self.logic_controller.app_tracker:
124-
self.logic_controller.app_tracker.reset()
125-
if self.logic_controller.time_tracker:
126-
self.logic_controller.time_tracker.reset()
127-
if self.logic_controller.mouse_tracker:
128-
self.logic_controller.mouse_tracker.stop()
136+
if self.logic.app_tracker:
137+
self.logic.app_tracker.reset()
138+
if self.logic.time_tracker:
139+
self.logic.time_tracker.reset()
140+
if self.logic.mouse_tracker:
141+
self.logic.mouse_tracker.stop()
129142

130143
self.close()
131144
sessions_exist()
@@ -134,6 +147,6 @@ def on_close(self):
134147
def closeEvent(self, event):
135148
print("Closing the application...")
136149
self.on_close()
137-
self.logic_controller.close()
150+
self.logic.close()
138151
QApplication.instance().quit()
139152
event.accept()

src/core/gui_root.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, parent):
1818
self.parent = parent
1919

2020
# Initialize LogicRoot
21-
self.logic_controller = LogicRoot(self)
21+
self.logic = LogicRoot(self)
2222

2323
self.container = tk.Frame(self)
2424
self.container.pack(side="top", fill="both", expand=True)
@@ -36,7 +36,7 @@ def init_screens(self):
3636
# Pass the logic_controller when initializing screens
3737
for F in (MainWindow, SessionsWindow, SelectAppWindow, TrackerWindow, SaveWindow, CreateSessionWindow, SessionTotalWindow, TrackerSettingsWindow):
3838
page_name = F.__name__
39-
frame = F(parent=self.container, controller=self, logic_controller=self.logic_controller)
39+
frame = F(parent=self.container, controller=self, logic_controller=self.logic)
4040
self.frames[page_name] = frame
4141

4242
frame.grid(row=0, column=0, sticky="nsew")
@@ -49,12 +49,12 @@ def show_frame(self, page_name):
4949

5050
def reset_frames(self):
5151
# Stop trackers
52-
if self.logic_controller.app_tracker:
53-
self.logic_controller.app_tracker.reset()
54-
if self.logic_controller.time_tracker:
55-
self.logic_controller.time_tracker.reset()
56-
if self.logic_controller.mouse_tracker:
57-
self.logic_controller.mouse_tracker.stop()
52+
if self.logic.app_tracker:
53+
self.logic.app_tracker.reset()
54+
if self.logic.time_tracker:
55+
self.logic.time_tracker.reset()
56+
if self.logic.mouse_tracker:
57+
self.logic.mouse_tracker.stop()
5858

5959
# Stop GUI threads
6060
for frame_name, frame in self.frames.items():
@@ -75,16 +75,16 @@ def reset_frames(self):
7575
def on_close(self):
7676
"""Handle cleanup and close the application."""
7777
# Stop the AppTracker thread
78-
if self.logic_controller.app_tracker:
79-
self.logic_controller.app_tracker.stop()
78+
if self.logic.app_tracker:
79+
self.logic.app_tracker.stop()
8080

8181
# stop the TimeTracker thread
82-
if self.logic_controller.time_tracker:
83-
self.logic_controller.time_tracker.stop()
82+
if self.logic.time_tracker:
83+
self.logic.time_tracker.stop()
8484

8585
# stop the MouseTracker thread
86-
if self.logic_controller.mouse_tracker:
87-
self.logic_controller.mouse_tracker.stop()
86+
if self.logic.mouse_tracker:
87+
self.logic.mouse_tracker.stop()
8888

8989
# Destroy the root window
9090
self.parent.destroy()

src/core/logic/user_trackers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, parent, logic_controller):
1919
self.idle_time_limit = 300 # Default value
2020
x = 0
2121
y = 0
22-
self.logic_controller = logic_controller
22+
self.logic = logic_controller
2323
self.mouse_position = x, y
2424
self.last_mouse_position = x , y
2525
self.stop_event = threading.Event() # Used to stop the thread gracefully
@@ -37,7 +37,7 @@ def _update_mouse_position(self):
3737
self.last_mouse_position = self.mouse_position
3838

3939
# time limit handling
40-
if not self.logic_controller.time_tracker.get_is_paused():
40+
if not self.logic.time_tracker.get_is_paused():
4141
time.sleep(self.idle_time_limit)
4242
else:
4343
time.sleep(1)
@@ -47,10 +47,10 @@ def _update_mouse_position(self):
4747

4848
# pause the timer
4949
if self.last_mouse_position == self.mouse_position:
50-
self.logic_controller.time_tracker.pause()
50+
self.logic.time_tracker.pause()
5151
self.pausing = True
52-
elif self.logic_controller.time_tracker.get_is_paused():
53-
self.logic_controller.time_tracker.resume()
52+
elif self.logic.time_tracker.get_is_paused():
53+
self.logic.time_tracker.resume()
5454
self.pausing = False
5555

5656
def start(self):

src/core/screens/analyze_data_window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AnalyzeDataWindow(tk.Toplevel):
66
def __init__(self, parent, controller, logic_controller):
77
super().__init__(parent) # Toplevel window with `parent` as master
88
self.controller = controller
9-
self.logic_controller = logic_controller
9+
self.logic = logic_controller
1010

1111
self.title("Popout Window")
1212
self.geometry("1600x1200")

src/core/screens/create_session_window.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CreateSessionWindow(tk.Frame):
1919
def __init__(self, parent, controller, logic_controller):
2020
tk.Frame.__init__(self, parent)
2121
self.controller = controller
22-
self.logic_controller = logic_controller
22+
self.logic = logic_controller
2323

2424
vcmd = (self.register(validate_name), '%P')
2525
self.session_name = tk.StringVar()
@@ -43,15 +43,15 @@ def __init__(self, parent, controller, logic_controller):
4343
def on_confirm(self):
4444
"""Saves session and resets trackers upon confirmation"""
4545
self.session_save(self.session_name.get())
46-
self.logic_controller.time_tracker.reset()
47-
self.logic_controller.app_tracker.reset()
46+
self.logic.time_tracker.reset()
47+
self.logic.app_tracker.reset()
4848
self.controller.show_frame("SessionTotalWindow")
4949

5050
def session_save(self, session_name):
51-
self.logic_controller.file_handler.set_file_name(session_name)
52-
session_time = self.logic_controller.time_tracker.get_time(saved=True)
53-
session_app_name = self.logic_controller.app_tracker.get_selected_app()
54-
captures = self.logic_controller.time_tracker.get_time_captures()
51+
self.logic.file_handler.set_file_name(session_name)
52+
session_time = self.logic.time_tracker.get_time(saved=True)
53+
session_app_name = self.logic.app_tracker.get_selected_app()
54+
captures = self.logic.time_tracker.get_time_captures()
5555
try:
5656
self.config = read_file(config_file())
5757
except FileNotFoundError:
@@ -64,4 +64,4 @@ def session_save(self, session_name):
6464
'time_captures': captures # {'starts': [], 'stops': [], 'pauses': [{start: 0, how_long: 0}]}
6565
}
6666

67-
self.logic_controller.file_handler.save_session_data(data)
67+
self.logic.file_handler.save_session_data(data)

src/core/screens/main_window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class MainWindow(tk.Frame):
77
def __init__(self, parent, controller, logic_controller):
88
tk.Frame.__init__(self, parent)
99
self.controller = controller # GUI controller
10-
self.logic_controller = logic_controller
10+
self.logic = logic_controller
1111

1212
label_text = "To begin app tracking, start a new session:"
1313

src/core/screens/save_window.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SaveWindow(tk.Frame):
66
def __init__(self, parent, controller, logic_controller):
77
tk.Frame.__init__(self, parent)
88
self.controller = controller
9-
self.logic_controller = logic_controller
9+
self.logic = logic_controller
1010

1111
# display the page label
1212
self.page_label = tk.Label(self, text="Would you like to save the recorded data?")
@@ -22,10 +22,10 @@ def __init__(self, parent, controller, logic_controller):
2222
back_button.pack(pady=5, side='bottom')
2323

2424
def save(self):
25-
if self.logic_controller.file_handler.get_continuing_session():
26-
session_time = self.logic_controller.time_tracker.get_total_time()
27-
session_app_name = self.logic_controller.app_tracker.get_selected_app()
28-
captures = self.logic_controller.time_tracker.get_time_captures()
25+
if self.logic.file_handler.get_continuing_session():
26+
session_time = self.logic.time_tracker.get_total_time()
27+
session_app_name = self.logic.app_tracker.get_selected_app()
28+
captures = self.logic.time_tracker.get_time_captures()
2929
try:
3030
self.config = read_file(config_file())
3131
except FileNotFoundError:
@@ -38,7 +38,7 @@ def save(self):
3838
'time_captures': captures # {'starts': [], 'stops': [], 'pauses': [{start: 0, how_long: 0}]}
3939
}
4040

41-
self.logic_controller.file_handler.save_session_data(data)
41+
self.logic.file_handler.save_session_data(data)
4242

4343
# show to session total window
4444
self.controller.show_frame("SessionTotalWindow")
@@ -49,7 +49,7 @@ def dont_save(self):
4949
"""confirm data deletion"""
5050
ans = tk.messagebox.askyesno("AppUsageGUI", "Are you sure you don't want to save?")
5151
if ans:
52-
self.logic_controller.time_tracker.reset()
53-
self.logic_controller.app_tracker.reset()
52+
self.logic.time_tracker.reset()
53+
self.logic.app_tracker.reset()
5454
self.controller.reset_frames()
5555
self.controller.show_frame("MainWindow")

src/core/screens/select_app_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SelectAppWindow(tk.Frame):
1717
def __init__(self, parent, controller, logic_controller):
1818
tk.Frame.__init__(self, parent)
1919
self.controller = controller
20-
self.logic_controller = logic_controller
20+
self.logic = logic_controller
2121

2222
label = tk.Label(self, text="Ensure the desired application is running.\nYou may need to hit \'Refresh List\' if it was not.\n\nSelect which application you would like to track:")
2323
label.pack(side="top", fill="x", pady=5)
@@ -52,7 +52,7 @@ def __init__(self, parent, controller, logic_controller):
5252
self.app_listbox.config(yscrollcommand=scrollbar.set)
5353

5454
# Track the apps and filtered apps
55-
self.app_tracker = self.logic_controller.app_tracker
55+
self.app_tracker = self.logic.app_tracker
5656
self.all_apps = [] # Store all apps to filter through
5757
self.refresh_apps() # Populate list initially
5858

src/core/screens/session_total_window.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SessionTotalWindow(tk.Frame):
99
def __init__(self, parent, controller, logic_controller):
1010
tk.Frame.__init__(self, parent)
1111
self.controller = controller
12-
self.logic_controller = logic_controller
12+
self.logic = logic_controller
1313

1414
self.update_queue = queue.Queue()
1515

@@ -50,9 +50,9 @@ def update_total_time(self):
5050
def total_time_thread(self):
5151
while not self.stop_event.is_set():
5252
try:
53-
if self.logic_controller.time_tracker.get_time() > 0 and self.logic_controller.time_tracker.is_running():
53+
if self.logic.time_tracker.get_time() > 0 and self.logic.time_tracker.is_running():
5454
# Get the total session time from the logic controller
55-
total_time = self.logic_controller.time_tracker.get_total_time()
55+
total_time = self.logic.time_tracker.get_total_time()
5656

5757
# Put the total time into the queue to update the UI
5858
self.update_queue.put(total_time)

src/core/screens/sessions_window.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class SessionsWindow(tk.Frame):
88
def __init__(self, parent, controller, logic_controller):
99
tk.Frame.__init__(self, parent)
1010
self.controller = controller
11-
self.logic_controller = logic_controller
11+
self.logic = logic_controller
1212

1313
# label for SessionsWindow
1414
label = tk.Label(self, text="Select a Session to continue from:")
@@ -46,16 +46,16 @@ def load_sessions(self):
4646
for session in sessions:
4747
session_name = session.split(".")[0]
4848
# Load data for the current session
49-
self.logic_controller.file_handler.load_session_data(session_name)
50-
session_data = self.logic_controller.file_handler.get_data()
49+
self.logic.file_handler.load_session_data(session_name)
50+
session_data = self.logic.file_handler.get_data()
5151
if session_data is not None:
5252
app_name = session_data['app_name']
5353
time_spent = session_data['time_spent']
5454
# Format the time spent
5555
formatted_time = format_time(round(time_spent))
5656
# Insert into the Listbox
5757
self.session_listbox.insert(tk.END, f"{session_name}: {app_name}, {formatted_time} on record")
58-
corrupt_sessions = self.logic_controller.file_handler.get_corrupt_sessions()
58+
corrupt_sessions = self.logic.file_handler.get_corrupt_sessions()
5959
if len(corrupt_sessions) > 0:
6060
error_string = "The following session(s) failed to load:\n\n"
6161
for session in corrupt_sessions:
@@ -77,21 +77,21 @@ def select_session(self):
7777
selected_session_name = self.get_session_text().split(": ")[0]
7878

7979
# update the logic session name var
80-
self.logic_controller.file_handler.set_file_name(selected_session_name)
80+
self.logic.file_handler.set_file_name(selected_session_name)
8181

8282
# tell the controller we are continuing from a session
83-
self.logic_controller.file_handler.set_continuing_session(True)
83+
self.logic.file_handler.set_continuing_session(True)
8484

8585
# load selected session data into the file handler,
8686
# so it's ready to be pulled
87-
self.logic_controller.file_handler.load_session_data(selected_session_name)
87+
self.logic.file_handler.load_session_data(selected_session_name)
8888

8989
# start/reset tracking threads
90-
self.logic_controller.app_tracker.reset()
91-
self.logic_controller.app_tracker.set_selected_app(selected_app_name)
92-
self.logic_controller.time_tracker.reset(add_time=self.logic_controller.file_handler.get_data()['time_spent'])
93-
self.logic_controller.time_tracker.start()
94-
self.logic_controller.time_tracker.clock()
90+
self.logic.app_tracker.reset()
91+
self.logic.app_tracker.set_selected_app(selected_app_name)
92+
self.logic.time_tracker.reset(add_time=self.logic.file_handler.get_data()['time_spent'])
93+
self.logic.time_tracker.start()
94+
self.logic.time_tracker.clock()
9595

9696
# show the TrackerWindow
9797
self.controller.show_frame('TrackerWindow')

0 commit comments

Comments
 (0)