audio-tuner-gui 0.9.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ # This file is part of Audio Tuner.
4
+ #
5
+ # Copyright 2025, 2026 Jessie Blue Cassell <bluesloth600@gmail.com>
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+
20
+
21
+ """Message log for the GUI."""
22
+
23
+
24
+ __author__ = 'Jessie Blue Cassell'
25
+
26
+
27
+ __all__ = [
28
+ 'LOG_LEVEL_ERROR',
29
+ 'LOG_LEVEL_WARNING',
30
+ 'LOG_LEVEL_NORMAL',
31
+ 'LogViewer',
32
+ ]
33
+
34
+
35
+ from PyQt6.QtCore import (
36
+ Qt,
37
+ )
38
+ from PyQt6.QtWidgets import (
39
+ QWidget,
40
+ QPushButton,
41
+ QMessageBox,
42
+ QVBoxLayout,
43
+ QTextEdit,
44
+ )
45
+ from PyQt6.QtGui import (
46
+ QIcon,
47
+ QAction,
48
+ QColor,
49
+ QFont,
50
+ QTextCursor,
51
+ QPalette,
52
+ )
53
+
54
+ import audio_tuner_gui.common as gcom
55
+
56
+
57
+ _CLEAR_CONFIRMATION_MESSAGE = ('This will clear the entire message log.'
58
+ '\nAre you sure?')
59
+
60
+ # Severity levels
61
+ LOG_LEVEL_ERROR = 3
62
+ LOG_LEVEL_WARNING = 2
63
+ LOG_LEVEL_NORMAL = 1
64
+
65
+
66
+ class _LogText(QTextEdit):
67
+ def __init__(self, parent):
68
+ super().__init__(parent)
69
+ self.clear_act = QAction('Clear log', self)
70
+ self.clear_act.setIcon(QIcon.fromTheme(gcom.ICON_CLEAR))
71
+ self.clear_act.triggered.connect(self.clear)
72
+
73
+ def contextMenuEvent(self, event):
74
+ menu = self.createStandardContextMenu()
75
+ if self.document().isEmpty():
76
+ self.clear_act.setEnabled(False)
77
+ else:
78
+ self.clear_act.setEnabled(True)
79
+ menu.addAction(self.clear_act)
80
+ menu.exec(event.globalPos())
81
+
82
+ def clear(self):
83
+ reply = QMessageBox.question(
84
+ self,
85
+ 'Clear message log',
86
+ _CLEAR_CONFIRMATION_MESSAGE,
87
+ QMessageBox.StandardButton.Yes
88
+ | QMessageBox.StandardButton.No,
89
+ QMessageBox.StandardButton.No)
90
+
91
+ if reply == QMessageBox.StandardButton.Yes:
92
+ super().clear()
93
+
94
+
95
+ class LogViewer(QWidget):
96
+ """A window for storing and viewing log messages. Inherits from
97
+ QWidget.
98
+
99
+ Parameters
100
+ ----------
101
+ parent
102
+ The parent widget.
103
+ """
104
+
105
+ def __init__(self, parent):
106
+ super().__init__(parent)
107
+
108
+ self.setWindowFlag(Qt.WindowType.Window)
109
+ self.setWindowTitle('Message log')
110
+
111
+ palette = QPalette()
112
+ self.normal_color = palette.windowText().color()
113
+ self.error_color = QColor(255, 0, 0)
114
+
115
+ self.vbox = QVBoxLayout(self)
116
+
117
+ self.text = _LogText(self)
118
+ self.text.setReadOnly(True)
119
+ self.text.setLineWrapMode(QTextEdit.LineWrapMode.NoWrap)
120
+ self.vbox.addWidget(self.text)
121
+
122
+ self.button = QPushButton('Close')
123
+ self.button.clicked.connect(self.close)
124
+ self.vbox.addWidget(self.button)
125
+
126
+ self.resize(600, 400)
127
+
128
+ def add_message(self, message, level):
129
+ """Add a message to the log.
130
+
131
+ Parameters
132
+ ----------
133
+ message : str
134
+ The message.
135
+ level : int
136
+ The severity level (LOG_LEVEL_ERROR, LOG_LEVEL_WARNING or
137
+ LOG_LEVEL_NORMAL).
138
+ """
139
+
140
+ self.text.moveCursor(QTextCursor.MoveOperation.End)
141
+ if level == LOG_LEVEL_ERROR:
142
+ self.text.setTextColor(self.error_color)
143
+ else:
144
+ self.text.setTextColor(self.normal_color)
145
+ if level >= LOG_LEVEL_WARNING:
146
+ self.text.setFontWeight(QFont.Weight.Bold)
147
+ else:
148
+ self.text.setFontWeight(QFont.Weight.Normal)
149
+ self.text.insertPlainText(message)
150
+
151
+ def close(self):
152
+ """Hide the window."""
153
+
154
+ self.hide()