bouquin 0.4.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.
bouquin/__init__.py ADDED
File without changes
bouquin/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .main import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,128 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib.metadata
4
+
5
+ import requests
6
+
7
+ from PySide6.QtWidgets import (
8
+ QDialog,
9
+ QVBoxLayout,
10
+ QLabel,
11
+ QTextEdit,
12
+ QDialogButtonBox,
13
+ QMessageBox,
14
+ )
15
+
16
+ from . import strings
17
+
18
+
19
+ BUG_REPORT_HOST = "https://nr.mig5.net"
20
+ ROUTE = "forms/bouquin/bugs"
21
+
22
+
23
+ class BugReportDialog(QDialog):
24
+ """
25
+ Dialog to collect a bug report
26
+ """
27
+
28
+ MAX_CHARS = 5000
29
+
30
+ def __init__(self, parent=None):
31
+ super().__init__(parent)
32
+ self.setWindowTitle(strings._("report_a_bug"))
33
+
34
+ layout = QVBoxLayout(self)
35
+
36
+ header = QLabel(strings._("bug_report_explanation"))
37
+ header.setWordWrap(True)
38
+ layout.addWidget(header)
39
+
40
+ self.text_edit = QTextEdit()
41
+ self.text_edit.setPlaceholderText(strings._("bug_report_placeholder"))
42
+ layout.addWidget(self.text_edit)
43
+
44
+ self.text_edit.textChanged.connect(self._enforce_max_length)
45
+
46
+ # Buttons: Cancel / Send
47
+ button_box = QDialogButtonBox(QDialogButtonBox.Cancel)
48
+ button_box.addButton(strings._("send"), QDialogButtonBox.AcceptRole)
49
+ button_box.accepted.connect(self._send)
50
+ button_box.rejected.connect(self.reject)
51
+ layout.addWidget(button_box)
52
+
53
+ self.setMinimumWidth(560)
54
+
55
+ self.text_edit.setFocus()
56
+
57
+ # ------------Helpers ------------ #
58
+
59
+ def _enforce_max_length(self):
60
+ text = self.text_edit.toPlainText()
61
+ if len(text) <= self.MAX_CHARS:
62
+ return
63
+
64
+ # Remember cursor position
65
+ cursor = self.text_edit.textCursor()
66
+ pos = cursor.position()
67
+
68
+ # Trim and restore without re-entering this slot
69
+ self.text_edit.blockSignals(True)
70
+ self.text_edit.setPlainText(text[: self.MAX_CHARS])
71
+ self.text_edit.blockSignals(False)
72
+
73
+ # Clamp cursor position to end of text
74
+ if pos > self.MAX_CHARS:
75
+ pos = self.MAX_CHARS
76
+
77
+ cursor.setPosition(pos)
78
+ self.text_edit.setTextCursor(cursor)
79
+
80
+ def _send(self):
81
+ text = self.text_edit.toPlainText().strip()
82
+ if not text:
83
+ QMessageBox.warning(
84
+ self,
85
+ strings._("report_a_bug"),
86
+ strings._("bug_report_empty"),
87
+ )
88
+ return
89
+
90
+ # Get current app version
91
+ try:
92
+ version = importlib.metadata.version("bouquin")
93
+ except importlib.metadata.PackageNotFoundError:
94
+ version = "unknown"
95
+
96
+ payload: dict[str, str] = {
97
+ "message": text,
98
+ "version": version,
99
+ }
100
+
101
+ # POST as JSON
102
+ try:
103
+ resp = requests.post(
104
+ f"{BUG_REPORT_HOST}/{ROUTE}",
105
+ json=payload,
106
+ timeout=10,
107
+ )
108
+ except Exception as e:
109
+ QMessageBox.critical(
110
+ self,
111
+ strings._("report_a_bug"),
112
+ strings._("bug_report_send_failed") + f"\n{e}",
113
+ )
114
+ return
115
+
116
+ if resp.status_code == 201:
117
+ QMessageBox.information(
118
+ self,
119
+ strings._("report_a_bug"),
120
+ strings._("bug_report_sent_ok"),
121
+ )
122
+ self.accept()
123
+ else:
124
+ QMessageBox.critical(
125
+ self,
126
+ strings._("report_a_bug"),
127
+ strings._("bug_report_send_failed") + f" (HTTP {resp.status_code})",
128
+ )