ptyx-mcq-editor 1.0.0__tar.gz

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.
Files changed (67) hide show
  1. ptyx_mcq_editor-1.0.0/.gitignore +2 -0
  2. ptyx_mcq_editor-1.0.0/PKG-INFO +13 -0
  3. ptyx_mcq_editor-1.0.0/README.md +0 -0
  4. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/__init__.py +0 -0
  5. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/__main__.py +3 -0
  6. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/app.py +92 -0
  7. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/editor/__init__.py +0 -0
  8. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/editor/editor_tab.py +48 -0
  9. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/editor/editor_widget.py +630 -0
  10. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/editor/find_and_replace.py +256 -0
  11. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/editor/lexer.py +413 -0
  12. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/enhanced_widget.py +22 -0
  13. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/events_handler.py +618 -0
  14. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/files_book.py +149 -0
  15. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/generated_ui/__init__.py +0 -0
  16. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/generated_ui/about_ui.py +32 -0
  17. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/generated_ui/ask_for_saving_ui.py +49 -0
  18. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/generated_ui/dbg_send_scintilla_messages_ui.py +64 -0
  19. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/generated_ui/main_ui.py +390 -0
  20. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/main_window.py +227 -0
  21. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/param.py +12 -0
  22. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/preview/__init__.py +0 -0
  23. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/preview/compiler.py +178 -0
  24. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/preview/latex_viewer.py +97 -0
  25. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/preview/log_lexer.py +158 -0
  26. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/preview/log_viewer.py +48 -0
  27. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/preview/pdf_viewer.py +40 -0
  28. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/preview/tab_widget.py +249 -0
  29. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/publish/__init__.py +0 -0
  30. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/publish/compiler.py +169 -0
  31. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/publish/toolbar.py +225 -0
  32. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/settings.py +464 -0
  33. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/signal_wake_up.py +40 -0
  34. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/tools/__init__.py +0 -0
  35. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/tools/desktop_shortcut.py +37 -0
  36. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/tools/external_tools.py +90 -0
  37. ptyx_mcq_editor-1.0.0/ptyx_mcq_editor/tools/python_code_tools.py +134 -0
  38. ptyx_mcq_editor-1.0.0/pyproject.toml +114 -0
  39. ptyx_mcq_editor-1.0.0/ressources/mcq-editor-icon-src.svg +70 -0
  40. ptyx_mcq_editor-1.0.0/ressources/mcq-editor.svg +10 -0
  41. ptyx_mcq_editor-1.0.0/ressources/ptyx-mcq-editor.desktop +19 -0
  42. ptyx_mcq_editor-1.0.0/ressources/wait/make_svg.py +29 -0
  43. ptyx_mcq_editor-1.0.0/ressources/wait/wait-0.svg +204 -0
  44. ptyx_mcq_editor-1.0.0/ressources/wait/wait-1.svg +204 -0
  45. ptyx_mcq_editor-1.0.0/ressources/wait/wait-10.svg +204 -0
  46. ptyx_mcq_editor-1.0.0/ressources/wait/wait-11.svg +204 -0
  47. ptyx_mcq_editor-1.0.0/ressources/wait/wait-12.svg +204 -0
  48. ptyx_mcq_editor-1.0.0/ressources/wait/wait-13.svg +204 -0
  49. ptyx_mcq_editor-1.0.0/ressources/wait/wait-14.svg +204 -0
  50. ptyx_mcq_editor-1.0.0/ressources/wait/wait-15.svg +204 -0
  51. ptyx_mcq_editor-1.0.0/ressources/wait/wait-16.svg +204 -0
  52. ptyx_mcq_editor-1.0.0/ressources/wait/wait-17.svg +204 -0
  53. ptyx_mcq_editor-1.0.0/ressources/wait/wait-18.svg +204 -0
  54. ptyx_mcq_editor-1.0.0/ressources/wait/wait-19.svg +204 -0
  55. ptyx_mcq_editor-1.0.0/ressources/wait/wait-2.svg +204 -0
  56. ptyx_mcq_editor-1.0.0/ressources/wait/wait-20.svg +204 -0
  57. ptyx_mcq_editor-1.0.0/ressources/wait/wait-21.svg +204 -0
  58. ptyx_mcq_editor-1.0.0/ressources/wait/wait-22.svg +204 -0
  59. ptyx_mcq_editor-1.0.0/ressources/wait/wait-23.svg +204 -0
  60. ptyx_mcq_editor-1.0.0/ressources/wait/wait-3.svg +204 -0
  61. ptyx_mcq_editor-1.0.0/ressources/wait/wait-4.svg +204 -0
  62. ptyx_mcq_editor-1.0.0/ressources/wait/wait-5.svg +204 -0
  63. ptyx_mcq_editor-1.0.0/ressources/wait/wait-6.svg +204 -0
  64. ptyx_mcq_editor-1.0.0/ressources/wait/wait-7.svg +204 -0
  65. ptyx_mcq_editor-1.0.0/ressources/wait/wait-8.svg +204 -0
  66. ptyx_mcq_editor-1.0.0/ressources/wait/wait-9.svg +204 -0
  67. ptyx_mcq_editor-1.0.0/ressources/wait/wait.svg +204 -0
@@ -0,0 +1,2 @@
1
+ .idea/
2
+ __pycache__/
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: ptyx-mcq-editor
3
+ Version: 1.0.0
4
+ Project-URL: Repository, https://github.com/wxgeo/ptyx-mcq-editor
5
+ Author-email: Nicolas Pourcelot <nicolas.pourcelot@gmail.com>
6
+ License-Expression: GPL-3.0-or-later
7
+ Keywords: exam,gui,latex,mcq,pdf,python,student,tikz
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: psutil<8,>=7.0.0
10
+ Requires-Dist: ptyx-mcq~=30.0
11
+ Requires-Dist: pyqt6-qscintilla<3,>=2.14.1
12
+ Requires-Dist: ruff<0.10,>=0.9.1
13
+ Requires-Dist: tomli-w<2,>=1.0.0
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ from ptyx_mcq_editor.app import main
2
+
3
+ main()
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/python3
2
+ import os
3
+ import signal
4
+ import sys
5
+ from argparse import ArgumentParser
6
+ from functools import partial
7
+ from pathlib import Path
8
+ from types import TracebackType
9
+ from typing import Type
10
+
11
+ import argcomplete
12
+ from PyQt6.QtCore import QRect, QPoint
13
+ from PyQt6.QtGui import QIcon
14
+ from PyQt6.QtWidgets import QMainWindow, QApplication, QMessageBox
15
+ from argcomplete import FilesCompleter
16
+
17
+ from ptyx_mcq_editor.main_window import McqEditorMainWindow
18
+ from ptyx_mcq_editor.param import ICON_PATH
19
+
20
+ from ptyx_mcq_editor.signal_wake_up import SignalWakeupHandler
21
+
22
+
23
+ def my_excepthook(
24
+ type_: Type[BaseException],
25
+ value: BaseException,
26
+ traceback: TracebackType | None,
27
+ window: QMainWindow = None,
28
+ ) -> None:
29
+ print("Exception detected!")
30
+ # TODO: Log the exception here?
31
+ # noinspection PyTypeChecker
32
+ QMessageBox.critical(window, "Something went wrong!", f"{type(value).__name__}: {value}")
33
+ # Call the default handler.
34
+ sys.__excepthook__(type_, value, traceback)
35
+
36
+
37
+ def main(args: list | None = None, _verify_env=True) -> None:
38
+ # Make compilations more reproducible, by disabling PYTHONHASHSEED by default.
39
+ if _verify_env:
40
+ if not os.getenv("PYTHONHASHSEED"):
41
+ os.environ["PYTHONHASHSEED"] = "0"
42
+ os.execv(sys.executable, [sys.executable] + sys.argv)
43
+ assert os.getenv("PYTHONHASHSEED")
44
+ print("PYTHONHASHSEED:", os.getenv("PYTHONHASHSEED"))
45
+
46
+ parser = ArgumentParser(description="Editor for pTyX and MCQ files.")
47
+ parser.add_argument(
48
+ "paths",
49
+ nargs="*",
50
+ metavar="PATHS",
51
+ type=Path,
52
+ help="One or more pTyX file to open (with '.ptyx' or '.ex' extension).",
53
+ ).completer = FilesCompleter( # type: ignore
54
+ ("ex", "ptyx")
55
+ )
56
+ parser.add_argument("--dry-run", action="store_true")
57
+ argcomplete.autocomplete(parser, always_complete_options=False)
58
+ parsed_args = parser.parse_args(args)
59
+ try:
60
+ app = QApplication(sys.argv)
61
+ app.setWindowIcon(QIcon(str(ICON_PATH)))
62
+ # Used to handle Ctrl+C
63
+ # https://stackoverflow.com/questions/4938723/what-is-the-correct-way-to-make-my-pyqt-application-quit-when-killed-from-the-co
64
+ SignalWakeupHandler(app)
65
+ main_window = McqEditorMainWindow(parsed_args)
66
+ # Don't close pyQt application on failure.
67
+ sys.excepthook = partial(my_excepthook, window=main_window)
68
+ # Used to handle Ctrl+C
69
+ signal.signal(signal.SIGINT, lambda sig, _: app.quit())
70
+ main_window.move(
71
+ main_window.screen().geometry().center() # type: ignore
72
+ - QRect(QPoint(), main_window.frameGeometry().size()).center()
73
+ )
74
+ if parsed_args.dry_run:
75
+ app.exit()
76
+ sys.exit(0)
77
+ else:
78
+ main_window.show()
79
+ print("Application launched.")
80
+ return_code = app.exec()
81
+ except BaseException as e:
82
+ # Warning: SystemExit doesn't seem to been catchable, it's probably already caught
83
+ # at PyQt level, and cause Qt to quit.
84
+ print("Exception catched.")
85
+ raise e
86
+ print("Bye!")
87
+ sys.exit(return_code)
88
+
89
+
90
+ # TODO: support for arguments (file to open)
91
+ if __name__ == "__main__":
92
+ main()
@@ -0,0 +1,48 @@
1
+ from typing import Final
2
+
3
+ from PyQt6.QtWidgets import QWidget, QVBoxLayout
4
+ from ptyx_mcq_editor.enhanced_widget import EnhancedWidget
5
+
6
+ from ptyx_mcq_editor.settings import Document
7
+
8
+ from ptyx_mcq_editor.editor.editor_widget import EditorWidget, Marker
9
+
10
+
11
+ class EditorTab(EnhancedWidget):
12
+ def __init__(self, parent: QWidget, doc: Document, content: str = None):
13
+ super().__init__(parent)
14
+ self.doc: Final[Document] = doc
15
+ self.inner_layout = QVBoxLayout(self)
16
+ self.editor = EditorWidget(self)
17
+ self.inner_layout.addWidget(self.editor)
18
+ self.reload(content=content)
19
+ self.connect_signals()
20
+
21
+ def reload(self, content: str = None, preserve_history=False):
22
+ """Reload file content from disk. History is not preserved by default."""
23
+ path = self.doc.path
24
+ if content is None:
25
+ content = path.read_text(encoding="utf-8") if path is not None else ""
26
+ lines = content.split("\n")
27
+ new_index: list[int] = []
28
+ for i, line in enumerate(lines):
29
+ if line.startswith("@new: -- "):
30
+ lines[i] = line[6:]
31
+ new_index.append(i)
32
+ content = "\n".join(lines)
33
+ self.editor.setText(content, preserve_history=preserve_history)
34
+ # Markers must be added *after* using setText().
35
+ for i in new_index:
36
+ self.editor.markerAdd(i, Marker.NEW)
37
+
38
+ def connect_signals(self):
39
+ self.editor.selectionChanged.connect(self.main_window.search_dock.highlight_all_find_results)
40
+ # If the cursor position change, we must start a new search from this new cursor position.
41
+ self.editor.cursorPositionChanged.connect(self.main_window.search_dock.reset_search)
42
+
43
+ handler = self.main_window.file_events_handler
44
+ # Save states
45
+ self.editor.SCN_SAVEPOINTREACHED.connect(
46
+ lambda: handler.change_doc_state(doc=self.doc, is_saved=True)
47
+ )
48
+ self.editor.SCN_SAVEPOINTLEFT.connect(lambda: handler.change_doc_state(doc=self.doc, is_saved=False))