Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 9c9ab90

Browse files
authored
Merge pull request #35 from MemerGamer/32-implement-better-logging-across-the-app
Resolve "Implement better logging across the app"
2 parents 4d2635c + 500f128 commit 9c9ab90

File tree

11 files changed

+137
-12
lines changed

11 files changed

+137
-12
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@
66
<h1 align="center">ManimStudio</h1>
77

88
</p>
9-
<br/>
109

10+
<div align="center">
11+
<a href="https://github.com/MemerGamer/ManimStudio/actions/workflows/documentation.yml">
12+
<img src="https://github.com/MemerGamer/ManimStudio/actions/workflows/documentation.yml/badge.svg?branch=main" alt="documentation">
13+
</a>
14+
15+
<a href="https://github.com/MemerGamer/ManimStudio/actions/workflows/pages/pages-build-deployment">
16+
<img src="https://github.com/MemerGamer/ManimStudio/actions/workflows/pages/pages-build-deployment/badge.svg" alt="pages-build-deployment">
17+
</a>
18+
19+
<a href="https://github.com/MemerGamer/ManimStudio/actions/workflows/release-please.yml">
20+
<img src="https://github.com/MemerGamer/ManimStudio/actions/workflows/release-please.yml/badge.svg" alt="release-please">
21+
</a>
22+
</div>
23+
<hr>
1124
ManimStudio is a video editor application for editing Python ManimCE video projects.
1225

1326
## Table of Contents

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
sys.path.insert(0, os.path.abspath("../src/core"))
55
sys.path.insert(0, os.path.abspath("../src/ui"))
6+
sys.path.insert(0, os.path.abspath("../src/utils"))
67

78
print("sys.path: ", sys.path)
89

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Welcome to ManimStudio's documentation!
1414
src/core/settings
1515
src/core/project_creation_dialog
1616
src/core/project_opening_dialog
17+
src/utils/logger_utility
1718
src/ui/form_ui
1819
src/ui/settings_ui
1920
src/ui/videoeditor_ui

docs/src/utils/logger_utility.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
logger_utility module
2+
=====================
3+
4+
.. automodule:: logger_utility
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
dill==0.3.8
2+
loguru==0.7.2
3+
markdown-it-py==3.0.0
4+
mdurl==0.1.2
5+
Pygments==2.17.2
26
PyQt6==6.6.1
37
PyQt6-Qt6==6.6.1
48
PyQt6-sip==13.6.0
59
PySide6==6.6.1
610
PySide6-Addons==6.6.1
711
PySide6-Essentials==6.6.1
12+
rich==13.7.0
813
shiboken6==6.6.1

src/core/main.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,28 @@
3232
from src.core.project_creation_dialog import ProjectCreationDialog
3333
from src.core.project_opening_dialog import ProjectOpeningDialog
3434

35+
# Logger
36+
from src.utils.logger_utility import logger
37+
3538

3639
class Main(QWidget):
3740
"""Main class for the application"""
3841

3942
styleSheetUpdated = Signal(str)
4043
videoEditorOpened = Signal(str)
4144

45+
@logger.catch
4246
def __init__(self, parent=None):
4347
"""Initializer"""
4448
super().__init__(parent)
4549
self.customStyleSheet = ""
4650
self.settings = load_settings()
4751
self.themes = load_themes()
4852
self.current_theme = load_current_theme()
49-
53+
logger.info("Main window initialized")
5054
self.load_ui()
5155

56+
@logger.catch
5257
def apply_stylesheet(self):
5358
"""Apply the stylesheet to the main window and update the image based on the theme"""
5459

@@ -68,7 +73,9 @@ def apply_stylesheet(self):
6873
self.ui.label.setPixmap(QPixmap(image_path))
6974

7075
self.styleSheetUpdated.emit(self.customStyleSheet)
76+
logger.info("Stylesheet applied")
7177

78+
@logger.catch
7279
def load_ui(self):
7380
"""Load the UI from the .ui file"""
7481
loader = QUiLoader()
@@ -86,6 +93,9 @@ def load_ui(self):
8693
self.ui.newProjectBtn.clicked.connect(self.showProjectCreationDialog)
8794
self.ui.openProjectBtn.clicked.connect(self.showProjectOpenDialog)
8895

96+
logger.info("UI loaded")
97+
98+
@logger.catch
8999
def open_settings_dialog(self):
90100
"""Open the settings dialog"""
91101
self.settingsDialog = QDialog()
@@ -124,6 +134,7 @@ def open_settings_dialog(self):
124134

125135
self.settingsDialog.exec()
126136

137+
@logger.catch
127138
def update_settings_from_dialog(self):
128139
"""Update the settings from the dialog, and update the UI"""
129140

@@ -159,6 +170,7 @@ def update_settings_from_dialog(self):
159170
# Apply the stylesheet
160171
self.apply_stylesheet()
161172

173+
@logger.catch
162174
def showProjectCreationDialog(self):
163175
"""Show the project creation dialog"""
164176
try:
@@ -176,8 +188,9 @@ def showProjectCreationDialog(self):
176188
if dialog.exec():
177189
pass
178190
except Exception as e:
179-
print(f"Error showing project creation dialog: {e}")
191+
logger.error(f"Error showing project creation dialog: {e}")
180192

193+
@logger.catch
181194
def showProjectOpenDialog(self):
182195
"""Show the project open dialog"""
183196
try:
@@ -191,8 +204,9 @@ def showProjectOpenDialog(self):
191204
) # Close the main window (WelcomeScreen) as well
192205
dialog.exec()
193206
except Exception as e:
194-
print(f"Error showing project open dialog: {e}")
207+
logger.error(f"Error showing project open dialog: {e}")
195208

209+
@logger.catch
196210
def openVideoEditor(self, projectFilePath):
197211
"""Open the video editor with the project file"""
198212
try:
@@ -206,10 +220,9 @@ def openVideoEditor(self, projectFilePath):
206220

207221
# Emit the signal after VideoEditor dialog is opened
208222
self.videoEditorOpened.emit(projectFilePath)
209-
210223
self.videoEditor.exec()
211224
except Exception as e:
212-
print(f"Error opening video editor: {e}")
225+
logger.error(f"Error opening video editor: {e}")
213226
pass
214227

215228

src/core/project_creation_dialog.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
3-
from pathlib import Path
43
import dill
4+
from pathlib import Path
55
from PySide6.QtWidgets import QDialog, QFileDialog, QMessageBox
66
from PySide6.QtCore import Signal
77

@@ -17,12 +17,15 @@
1717
getRecentProjectCreationPaths,
1818
)
1919

20+
from src.utils.logger_utility import logger
21+
2022

2123
class ProjectCreationDialog(QDialog):
2224
"""Dialog for creating a new project"""
2325

2426
projectCreated = Signal(str)
2527

28+
@logger.catch
2629
def __init__(self, parent=None):
2730
"""Initializer"""
2831
super(ProjectCreationDialog, self).__init__(parent)
@@ -32,18 +35,21 @@ def __init__(self, parent=None):
3235
self.ui.folderSelectComboBox.mouseDoubleClickEvent = self.selectFolder
3336
self.ui.createProjectPushButton.clicked.connect(self.createProject)
3437

38+
@logger.catch
3539
def loadRecentProjectPaths(self):
3640
"""Load the recent project paths into the combo box"""
3741
recentPaths = getRecentProjectCreationPaths()
3842
for path in recentPaths:
3943
self.ui.folderSelectComboBox.addItem(path)
4044

45+
@logger.catch
4146
def selectFolder(self, event):
4247
"""Select a folder for the project"""
4348
folder = QFileDialog.getExistingDirectory(self, "Select Project Folder")
4449
if folder:
4550
self.ui.folderSelectComboBox.addItem(folder)
4651

52+
@logger.catch
4753
def createProject(self):
4854
"""Create a new project and emit the projectCreated signal"""
4955
projectName = self.ui.projectNameLineEdit.text()
@@ -53,6 +59,7 @@ def createProject(self):
5359
QMessageBox.critical(
5460
self, "Error", "Please enter a project name and select a folder"
5561
)
62+
logger.error("Project name or folder not entered")
5663
return
5764

5865
projectPath = os.path.join(projectFolder, projectName)

src/core/project_opening_dialog.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import os
2+
import sys
3+
from pathlib import Path
24
from PySide6.QtWidgets import QDialog, QFileDialog, QMessageBox
35
from PySide6.QtCore import Signal
6+
7+
8+
# Add the parent directory of 'src' to sys.path
9+
current_dir = Path(__file__).resolve().parent
10+
parent_dir = current_dir.parent.parent # Adjust according to your project structure
11+
sys.path.append(str(parent_dir))
12+
13+
414
from src.ui.project_opening_dialog_ui import Ui_Form as Ui_ProjectOpeningDialog
515
from settings import getRecentProjectPaths, addRecentProjectPath
616

17+
from src.utils.logger_utility import logger
18+
719

820
class ProjectOpeningDialog(QDialog):
921
"""Dialog for opening an existing project"""
1022

1123
projectSelected = Signal(str)
1224

25+
@logger.catch
1326
def __init__(self, parent=None):
1427
"""Initializer"""
1528
super().__init__(parent)
@@ -20,12 +33,14 @@ def __init__(self, parent=None):
2033
self.ui.openProjectPushButton.clicked.connect(self.openProject)
2134
self.ui.projectSelectComboBox.mouseDoubleClickEvent = self.browseForProject
2235

36+
@logger.catch
2337
def loadRecentProjects(self):
2438
"""Load the recent projects into the combo box"""
2539
recentProjects = getRecentProjectPaths()
2640
for projectPath in recentProjects:
2741
self.ui.projectSelectComboBox.addItem(projectPath)
2842

43+
@logger.catch
2944
def browseForProject(self, event):
3045
"""Browse for a project"""
3146
projectPath, _ = QFileDialog.getOpenFileName(
@@ -36,6 +51,7 @@ def browseForProject(self, event):
3651
addRecentProjectPath(projectPath)
3752
self.accept()
3853

54+
@logger.catch
3955
def openProject(self, event):
4056
"""Open the selected project"""
4157
selectedProject = self.ui.projectSelectComboBox.currentText()

src/core/settings.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import sys
55
import json
66

7-
"""Settings"""
7+
from src.utils.logger_utility import logger
8+
89

9-
# Global static base settings path
10+
# Global base settings and theme path
1011
base_settings_path = Path(os.getcwd()) / ".config" / "settings.json"
1112
base_theme_path = Path(os.getcwd()) / "src" / "themes" / "themes.json"
1213

1314

15+
@logger.catch
1416
def getSettingsPath():
1517
"""Get the settings path based on the platform"""
1618
homeDir = Path.home()
@@ -38,47 +40,55 @@ def getSettingsPath():
3840
json.dump(settings, file, indent=4)
3941

4042

43+
@logger.catch
4144
def getThemesPath():
4245
"""Get the themes path"""
4346
return base_theme_path
4447

4548

4649
themesPath = getThemesPath()
4750

51+
"""Settings"""
52+
4853

54+
@logger.catch
4955
def load_settings():
5056
"""Load the settings from the settings.json file"""
5157
try:
5258
with open(settingsPath, "r") as file:
5359
return json.load(file)
5460
except Exception as e:
55-
print(e)
61+
logger.error(e)
5662
return {}
5763

5864

65+
@logger.catch
5966
def update_settings(new_settings):
6067
"""Overwrite the settings file with the new settings"""
6168
try:
6269
with open(settingsPath, "w") as file:
6370
json.dump(new_settings, file, indent=4)
6471
return True
6572
except Exception as e:
73+
logger.error(e)
6674
return False
6775

6876

6977
"""Themes"""
7078

7179

80+
@logger.catch
7281
def load_themes():
7382
"""Load the themes from the themes.json file"""
7483
try:
7584
with open(themesPath, "r") as file:
7685
return json.load(file)
7786
except Exception as e:
78-
print(e)
87+
logger.error(e)
7988
return {}
8089

8190

91+
@logger.catch
8292
def load_current_theme():
8393
"""Load the current theme"""
8494
settings = load_settings()
@@ -91,10 +101,11 @@ def load_current_theme():
91101
) as file:
92102
return json.load(file)
93103
except Exception as e:
94-
print(e)
104+
logger.error(e)
95105
return {}
96106

97107

108+
@logger.catch
98109
def addRecentProjectCreationPath(projectCreationPath):
99110
"""Add a recent project creation path to the settings file"""
100111
settings = load_settings()
@@ -107,6 +118,7 @@ def addRecentProjectCreationPath(projectCreationPath):
107118
update_settings(settings)
108119

109120

121+
@logger.catch
110122
def addRecentProjectPath(projectPath):
111123
"""Add a recent project path to the settings file"""
112124
settings = load_settings()
@@ -119,11 +131,13 @@ def addRecentProjectPath(projectPath):
119131
update_settings(settings)
120132

121133

134+
@logger.catch
122135
def getRecentProjectCreationPaths():
123136
"""Get the recent project creation paths"""
124137
return load_settings().get("recentProjectCreationPaths", [])
125138

126139

140+
@logger.catch
127141
def getRecentProjectPaths():
128142
"""Get the recent project paths"""
129143
return load_settings().get("recentProjectPaths", [])

src/utils/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)