Skip to content

Commit a3cbd0a

Browse files
committed
feat: add debug flag
1 parent 281c8b6 commit a3cbd0a

File tree

12 files changed

+75
-24
lines changed

12 files changed

+75
-24
lines changed

.github/workflows/deploy.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
script-name: src/main.py
6565
mode: app
6666
include-data-dir: src/resources=resources
67-
macos-app-icon: src/resources/icons/logo.png
67+
macos-app-icon: src/resources/images/logo.png
6868
macos-signed-app-name: ${{ needs.prepare.outputs.signature }}
6969
macos-app-name: ${{ needs.prepare.outputs.name }}
7070
macos-app-version: ${{ needs.prepare.outputs.version }}
@@ -75,6 +75,7 @@ jobs:
7575
file-description: ${{ needs.prepare.outputs.name }} app, created by ${{ needs.prepare.outputs.author }}.
7676
output-dir: build
7777
enable-plugins: pyside6
78+
include-qt-plugins: sensible,multimedia
7879

7980
- name: Rename build
8081
working-directory: build
@@ -110,16 +111,17 @@ jobs:
110111
script-name: src/main.py
111112
mode: app
112113
include-data-dir: src/resources=resources
113-
linux-icon: src/resources/icons/logo.png
114+
linux-icon: src/resources/images/logo.png
114115
product-version: ${{ needs.prepare.outputs.version }}
115116
file-version: ${{ needs.prepare.outputs.version }}
116117
company-name: ${{ needs.prepare.outputs.author }}
117118
product-name: ${{ needs.prepare.outputs.name }}
118119
file-description: ${{ needs.prepare.outputs.name }} app, created by ${{ needs.prepare.outputs.author }}.
119120
output-dir: build
120-
enable-plugins: pyside6
121121
clang: true
122122
static-libpython: yes
123+
enable-plugins: pyside6
124+
include-qt-plugins: sensible,multimedia
123125

124126
- name: Rename build
125127
working-directory: build
@@ -155,7 +157,7 @@ jobs:
155157
script-name: src/main.py
156158
mode: app
157159
include-data-dir: src/resources=resources
158-
windows-icon-from-ico: src/resources/icons/logo.png
160+
windows-icon-from-ico: src/resources/images/logo.png
159161
windows-console-mode: disable
160162
product-version: ${{ needs.prepare.outputs.version }}
161163
file-version: ${{ needs.prepare.outputs.version }}
@@ -164,6 +166,7 @@ jobs:
164166
file-description: ${{ needs.prepare.outputs.name }} app, created by ${{ needs.prepare.outputs.author }}.
165167
output-dir: build
166168
enable-plugins: pyside6
169+
include-qt-plugins: sensible,multimedia
167170

168171
- name: Rename build
169172
working-directory: build

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ With the exception of the points above, we believe this template to be decently
6565
python src/main.py
6666
```
6767

68+
- The app will create and store logs in a diretory determined by `QStandardPaths.StandardLocation.GenericConfigLocation/AUTHOR_NAME/EXECUTABLE_NAME` which is OS independent.
69+
These logs can be requested from users to get data on why things are not working. Running the binary with the `--debug` flag will increase the verbosity of the logs, for more detailed information.
70+
6871
- ### Tooling 🧰
6972

7073
- Mypy is used for type checking:

src/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def __init__(self, argv: list[str]):
2222
self.setOrganizationName(AUTHOR_NAME)
2323
self.setOrganizationDomain(AUTHOR_DOMAIN)
2424
self.setApplicationVersion(__version__)
25-
self.setWindowIcon(QIcon(QPixmap(file_loader.loadResource(LOGO_PATH))))
2625

2726
data = [
2827
self.applicationName(),
@@ -43,3 +42,7 @@ def __init__(self, argv: list[str]):
4342
)
4443
logger.info(column)
4544
logger.info(row)
45+
46+
self.setWindowIcon(
47+
QIcon(QPixmap(file_loader.getResourcePath(LOGO_PATH)))
48+
)

src/config/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
AUTHOR_NAME = "NEIAAC"
88
AUTHOR_DOMAIN = "neiaac.com"
99

10-
LOGO_PATH = "icons/logo.png"
10+
LOGO_PATH = os.path.join("images", "logo.png")
1111

1212
DATA_PATH = os.path.join(
1313
QStandardPaths.writableLocation(

src/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import sys
3+
import tempfile
24

35
from PySide6 import QtCore
46

@@ -15,4 +17,14 @@
1517
window = Window()
1618
window.show()
1719

20+
if "NUITKA_ONEFILE_PARENT" in os.environ:
21+
splash_filename = os.path.join(
22+
tempfile.gettempdir(),
23+
"onefile_%d_splash_feedback.tmp"
24+
% int(os.environ["NUITKA_ONEFILE_PARENT"]),
25+
)
26+
27+
if os.path.exists(splash_filename):
28+
os.unlink(splash_filename)
29+
1830
sys.exit(app.exec())

src/pages/home.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QSizePolicy
23
from PySide6.QtCore import Qt, QUrl
34
from PySide6.QtMultimedia import QSoundEffect
@@ -29,7 +30,11 @@ def __init__(self):
2930

3031
self.finishSound = QSoundEffect()
3132
self.finishSound.setSource(
32-
QUrl.fromLocalFile(file_loader.loadResource("sounds/success.wav"))
33+
QUrl.fromLocalFile(
34+
file_loader.getResourcePath(
35+
os.path.join("sounds", "success.wav")
36+
)
37+
)
3338
)
3439
self.finishSound.setVolume(0.2)
3540

src/utils/file_loader.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
import os
22
import sys
33

4+
from utils.logger import logger
45

5-
def loadFile(fileName: str) -> str:
6+
7+
def getFilePath(fileName: str) -> str:
8+
locations = (
9+
# Files bundled inside the single binary build
10+
os.path.join(os.path.dirname(__file__), os.pardir),
11+
os.path.dirname(__file__),
12+
# Files in the directory the single binary build is in
13+
os.path.dirname(sys.argv[0]),
14+
)
615
try:
7-
file = os.path.join(__compiled__.containing_dir, fileName) # type: ignore
16+
# Files in the standalone build directory
17+
locations = locations + (__compiled__.containing_dir,) # type: ignore
818
except NameError:
9-
file = os.path.join(os.path.dirname(sys.argv[0]), fileName)
10-
return file
19+
pass
20+
21+
for location in locations:
22+
filePath = os.path.abspath(os.path.join(location, fileName))
23+
if os.path.isfile(filePath):
24+
logger.debug(f"Returning file path: {filePath}")
25+
return filePath
26+
logger.error(
27+
f"Got a request to load file {fileName} but it could not be found, returning empty string"
28+
)
29+
return ""
1130

1231

13-
def loadResource(resourceName: str) -> str:
14-
file = loadFile(os.path.join("resources", resourceName))
15-
return file
32+
def getResourcePath(resourceName: str) -> str:
33+
resourcePath = getFilePath(os.path.join("resources", resourceName))
34+
return resourcePath

src/utils/logger.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ class LogLevel(Enum):
2525
"[{time:YYYY-MM-DDTHH:mm:ss.SSS[Z]!UTC}] [<level>{level}</level>] {message}"
2626
)
2727

28-
dev = "__compiled__" not in globals()
28+
trace = "__compiled__" not in globals() or "--debug" in sys.argv[1:]
2929

3030
logger.remove()
3131
logger.level(LogLevel.INFO.value, color="<green>")
3232

33-
if dev:
33+
if trace:
3434
logger.add(
3535
sys.stdout,
3636
colorize=True,
3737
format=formatter,
38-
level=LogLevel.DEBUG.value,
38+
level=LogLevel.TRACE.value,
3939
enqueue=True,
4040
)
4141

@@ -45,21 +45,23 @@ class LogLevel(Enum):
4545
rotation=datetime.time(0, 0, 0, tzinfo=datetime.timezone.utc),
4646
retention="30 days",
4747
enqueue=True,
48-
level=LogLevel.DEBUG.value if dev else LogLevel.INFO.value,
48+
level=LogLevel.TRACE.value if trace else LogLevel.INFO.value,
4949
)
5050

5151

5252
def qMessageHandler(
5353
mode: QtCore.QtMsgType, _: QtCore.QMessageLogContext, message: str
5454
):
5555
match mode:
56+
case QtCore.QtMsgType.QtDebugMsg:
57+
logger.debug(message)
5658
case QtCore.QtMsgType.QtInfoMsg:
57-
logger.info(message)
59+
logger.debug(message)
5860
case QtCore.QtMsgType.QtWarningMsg:
5961
logger.warning(message)
6062
case QtCore.QtMsgType.QtCriticalMsg:
6163
logger.error(message)
6264
case QtCore.QtMsgType.QtFatalMsg:
6365
logger.critical(message)
6466
case _:
65-
logger.debug(message)
67+
logger.trace(message)

src/utils/system_tray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ class SystemTray(QSystemTrayIcon):
1111
def __init__(self, visible: bool = False):
1212
super().__init__()
1313

14-
self.setIcon(QIcon(QPixmap(file_loader.loadResource(LOGO_PATH))))
14+
self.setIcon(QIcon(QPixmap(file_loader.getResourcePath(LOGO_PATH))))
1515
self.setVisible(visible)

0 commit comments

Comments
 (0)