excel2moodle 0.5.1__tar.gz → 0.6.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 (66) hide show
  1. {excel2moodle-0.5.1/excel2moodle.egg-info → excel2moodle-0.6.0}/PKG-INFO +67 -2
  2. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/README.md +65 -0
  3. excel2moodle-0.6.0/excel2moodle/core/bullets.py +98 -0
  4. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/dataStructure.py +6 -7
  5. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/globals.py +3 -8
  6. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/parser.py +37 -65
  7. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/question.py +144 -76
  8. excel2moodle-0.6.0/excel2moodle/extra/variableGenerator.py +250 -0
  9. excel2moodle-0.6.0/excel2moodle/question_types/cloze.py +373 -0
  10. excel2moodle-0.6.0/excel2moodle/question_types/nfm.py +73 -0
  11. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/UI_mainWindow.py +63 -36
  12. excel2moodle-0.6.0/excel2moodle/ui/UI_variableGenerator.py +197 -0
  13. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/appUi.py +107 -44
  14. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/dialogs.py +44 -77
  15. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/equationChecker.py +2 -2
  16. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/treewidget.py +9 -24
  17. {excel2moodle-0.5.1 → excel2moodle-0.6.0/excel2moodle.egg-info}/PKG-INFO +67 -2
  18. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle.egg-info/SOURCES.txt +4 -13
  19. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle.egg-info/requires.txt +1 -1
  20. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/pyproject.toml +11 -2
  21. excel2moodle-0.6.0/test/test_bullets.py +45 -0
  22. excel2moodle-0.6.0/test/test_nfmParsing.py +83 -0
  23. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/test/test_parseQuestion.py +0 -1
  24. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/test/test_picture.py +16 -14
  25. excel2moodle-0.5.1/docs/_build/html/exampleQuestions.html +0 -599
  26. excel2moodle-0.5.1/docs/_build/html/excel2moodle.core.html +0 -1687
  27. excel2moodle-0.5.1/docs/_build/html/excel2moodle.extra.html +0 -237
  28. excel2moodle-0.5.1/docs/_build/html/excel2moodle.html +0 -467
  29. excel2moodle-0.5.1/docs/_build/html/excel2moodle.ui.html +0 -667
  30. excel2moodle-0.5.1/docs/_build/html/genindex.html +0 -908
  31. excel2moodle-0.5.1/docs/_build/html/howto.html +0 -384
  32. excel2moodle-0.5.1/docs/_build/html/index.html +0 -228
  33. excel2moodle-0.5.1/docs/_build/html/py-modindex.html +0 -228
  34. excel2moodle-0.5.1/docs/_build/html/search.html +0 -133
  35. excel2moodle-0.5.1/docs/_build/html/userReference.html +0 -444
  36. excel2moodle-0.5.1/excel2moodle/core/numericMultiQ.py +0 -80
  37. excel2moodle-0.5.1/excel2moodle/question_types/cloze.py +0 -207
  38. excel2moodle-0.5.1/excel2moodle/question_types/nfm.py +0 -134
  39. excel2moodle-0.5.1/excel2moodle/ui/windowDoc.py +0 -27
  40. excel2moodle-0.5.1/test/test_nfmParsing.py +0 -30
  41. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/LICENSE +0 -0
  42. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/MANIFEST.in +0 -0
  43. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/__init__.py +0 -0
  44. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/__main__.py +0 -0
  45. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/__init__.py +0 -0
  46. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/category.py +0 -0
  47. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/etHelpers.py +0 -0
  48. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/exceptions.py +0 -0
  49. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/settings.py +0 -0
  50. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/stringHelpers.py +0 -0
  51. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/core/validator.py +0 -0
  52. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/extra/__init__.py +0 -0
  53. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/extra/equationVerification.py +0 -0
  54. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/logger.py +0 -0
  55. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/question_types/__init__.py +0 -0
  56. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/question_types/mc.py +0 -0
  57. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/question_types/nf.py +0 -0
  58. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/UI_equationChecker.py +0 -0
  59. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/UI_exportSettingsDialog.py +0 -0
  60. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/UI_variantDialog.py +0 -0
  61. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle/ui/__init__.py +0 -0
  62. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle.egg-info/dependency_links.txt +0 -0
  63. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle.egg-info/entry_points.txt +0 -0
  64. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/excel2moodle.egg-info/top_level.txt +0 -0
  65. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/setup.cfg +0 -0
  66. {excel2moodle-0.5.1 → excel2moodle-0.6.0}/test/test_questionDataGet.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: excel2moodle
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: A package for converting questions from a spreadsheet, to valid moodle-xml
5
5
  Author: Jakob Bosse
6
6
  License-Expression: GPL-3.0-or-later
@@ -12,11 +12,11 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.10
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: pyside6>=6.8.0
16
15
  Requires-Dist: pandas>=2.1.3
17
16
  Requires-Dist: lxml>=5.4.0
18
17
  Requires-Dist: asteval>=1.0.6
19
18
  Requires-Dist: python-calamine>=0.3.2
19
+ Requires-Dist: pyside6-essentials>=6.8.0
20
20
  Dynamic: license-file
21
21
 
22
22
  # excel 2 Moodle
@@ -81,6 +81,71 @@ If You want to support my work as well, you can by me a [coffee](https://ko-fi.c
81
81
 
82
82
  # Changelogs
83
83
 
84
+ ## 0.6.0 (2025-07-12)
85
+ Added variable generator and other architechtural improvements
86
+
87
+ ### documentation (1 change)
88
+
89
+ - [Documenting variable generator usage](https://gitlab.com/jbosse3/excel2moodle/-/commit/3e4d3019b29872b5cfddf5539d5ebe7638bca049)
90
+
91
+ ### feature (5 changes)
92
+
93
+ - [Opening spreadsheet file works from within excel2moodle](https://gitlab.com/jbosse3/excel2moodle/-/commit/9470f12ea5f098745a3210b281a5144a938ae8b5)
94
+ - [Variables are copied to clipboard](https://gitlab.com/jbosse3/excel2moodle/-/commit/87a7e5ec75f899b293e89ad3c1742567e3ec1c29)
95
+ - [Removed dependence on pyside6-addons](https://gitlab.com/jbosse3/excel2moodle/-/commit/2b3a7cf48581c14bd9cb570cd61d1d41aa410e11)
96
+ - [Var Generator ready](https://gitlab.com/jbosse3/excel2moodle/-/commit/ea97f0639dc35a4c99a64ae3976ccc8a0ac5d109)
97
+ - [Merge development of BulletsObj, Parametrization and VarGenerator](https://gitlab.com/jbosse3/excel2moodle/-/commit/40b46f3c143e082f1bb985d6c8c4e68bb6b6a7a8)
98
+
99
+ ### improvement (7 changes)
100
+
101
+ - [Adapted Param. Parser to use bullet Obj](https://gitlab.com/jbosse3/excel2moodle/-/commit/194cab7cc6aecb2d25d1cb9c1538ed7d607dd9e1)
102
+ - [Added bulleList Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/4ea982b8d8dc270675d2cb059c59fa980ce38894)
103
+ - [Parametrics in beta stage](https://gitlab.com/jbosse3/excel2moodle/-/commit/7d04d8ef2fc603c1b12b6934c827ce079df5d540)
104
+ - [Refactor parse() method, to construct complete xml-Tree](https://gitlab.com/jbosse3/excel2moodle/-/commit/8dc4bea9aa0673d39357115254dd55b02c04114e)
105
+ - [Refactored question assembly to only update fields.](https://gitlab.com/jbosse3/excel2moodle/-/commit/d7accb69be3b4a1e65f59eeecfb463f2663fabd4)
106
+ - [Adapted NFM Question to parametricResult](https://gitlab.com/jbosse3/excel2moodle/-/commit/fe552cd2b538ca8886415c200e4a2a3ecc1fbb2f) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
107
+ - [Implemented ParametricResult Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/e36d025955f1cab8e0542d66263ab70e3d8980df) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
108
+
109
+ ## 0.5.2 (2025-06-30)
110
+ Extended Documentation and bugfix for import Module
111
+
112
+ ### bugfix (2 changes)
113
+
114
+ - [Default question variant saved and reused.](https://gitlab.com/jbosse3/excel2moodle/-/commit/097705ba83727463a9b27cd76e99814a7ecf28df)
115
+ - [bugfix: Import module working again](https://gitlab.com/jbosse3/excel2moodle/-/commit/5f293970bcdac3858911cdcc102b72714af057bd)
116
+
117
+ ### documentation (1 change)
118
+
119
+ - [documentation: Added how to build question database](https://gitlab.com/jbosse3/excel2moodle/-/commit/71ceb122aa37e8bf2735b659359ae37d81017599)
120
+
121
+ ### feature (1 change)
122
+
123
+ - [Implemented MC question string method](https://gitlab.com/jbosse3/excel2moodle/-/commit/c4f2081d0000ee60322fe8eec8468fa3317ce7be)
124
+
125
+ ### improvement (1 change)
126
+
127
+ - [Implemented ClozePart object](https://gitlab.com/jbosse3/excel2moodle/-/commit/878f90f45e37421384c4f8f602115e7596b4ceb9)
128
+
129
+ ## 0.5.2 (2025-06-30)
130
+ Extended Documentation and bugfix for import Module
131
+
132
+ ### bugfix (2 changes)
133
+
134
+ - [Default question variant saved and reused.](https://gitlab.com/jbosse3/excel2moodle/-/commit/097705ba83727463a9b27cd76e99814a7ecf28df)
135
+ - [bugfix: Import module working again](https://gitlab.com/jbosse3/excel2moodle/-/commit/5f293970bcdac3858911cdcc102b72714af057bd)
136
+
137
+ ### documentation (1 change)
138
+
139
+ - [documentation: Added how to build question database](https://gitlab.com/jbosse3/excel2moodle/-/commit/71ceb122aa37e8bf2735b659359ae37d81017599)
140
+
141
+ ### feature (1 change)
142
+
143
+ - [Implemented MC question string method](https://gitlab.com/jbosse3/excel2moodle/-/commit/c4f2081d0000ee60322fe8eec8468fa3317ce7be)
144
+
145
+ ### improvement (1 change)
146
+
147
+ - [Implemented ClozePart object](https://gitlab.com/jbosse3/excel2moodle/-/commit/878f90f45e37421384c4f8f602115e7596b4ceb9)
148
+
84
149
  ## 0.5.1 (2025-06-24)
85
150
  Minor docs improvement and question variant bugfix
86
151
 
@@ -60,6 +60,71 @@ If You want to support my work as well, you can by me a [coffee](https://ko-fi.c
60
60
 
61
61
  # Changelogs
62
62
 
63
+ ## 0.6.0 (2025-07-12)
64
+ Added variable generator and other architechtural improvements
65
+
66
+ ### documentation (1 change)
67
+
68
+ - [Documenting variable generator usage](https://gitlab.com/jbosse3/excel2moodle/-/commit/3e4d3019b29872b5cfddf5539d5ebe7638bca049)
69
+
70
+ ### feature (5 changes)
71
+
72
+ - [Opening spreadsheet file works from within excel2moodle](https://gitlab.com/jbosse3/excel2moodle/-/commit/9470f12ea5f098745a3210b281a5144a938ae8b5)
73
+ - [Variables are copied to clipboard](https://gitlab.com/jbosse3/excel2moodle/-/commit/87a7e5ec75f899b293e89ad3c1742567e3ec1c29)
74
+ - [Removed dependence on pyside6-addons](https://gitlab.com/jbosse3/excel2moodle/-/commit/2b3a7cf48581c14bd9cb570cd61d1d41aa410e11)
75
+ - [Var Generator ready](https://gitlab.com/jbosse3/excel2moodle/-/commit/ea97f0639dc35a4c99a64ae3976ccc8a0ac5d109)
76
+ - [Merge development of BulletsObj, Parametrization and VarGenerator](https://gitlab.com/jbosse3/excel2moodle/-/commit/40b46f3c143e082f1bb985d6c8c4e68bb6b6a7a8)
77
+
78
+ ### improvement (7 changes)
79
+
80
+ - [Adapted Param. Parser to use bullet Obj](https://gitlab.com/jbosse3/excel2moodle/-/commit/194cab7cc6aecb2d25d1cb9c1538ed7d607dd9e1)
81
+ - [Added bulleList Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/4ea982b8d8dc270675d2cb059c59fa980ce38894)
82
+ - [Parametrics in beta stage](https://gitlab.com/jbosse3/excel2moodle/-/commit/7d04d8ef2fc603c1b12b6934c827ce079df5d540)
83
+ - [Refactor parse() method, to construct complete xml-Tree](https://gitlab.com/jbosse3/excel2moodle/-/commit/8dc4bea9aa0673d39357115254dd55b02c04114e)
84
+ - [Refactored question assembly to only update fields.](https://gitlab.com/jbosse3/excel2moodle/-/commit/d7accb69be3b4a1e65f59eeecfb463f2663fabd4)
85
+ - [Adapted NFM Question to parametricResult](https://gitlab.com/jbosse3/excel2moodle/-/commit/fe552cd2b538ca8886415c200e4a2a3ecc1fbb2f) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
86
+ - [Implemented ParametricResult Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/e36d025955f1cab8e0542d66263ab70e3d8980df) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
87
+
88
+ ## 0.5.2 (2025-06-30)
89
+ Extended Documentation and bugfix for import Module
90
+
91
+ ### bugfix (2 changes)
92
+
93
+ - [Default question variant saved and reused.](https://gitlab.com/jbosse3/excel2moodle/-/commit/097705ba83727463a9b27cd76e99814a7ecf28df)
94
+ - [bugfix: Import module working again](https://gitlab.com/jbosse3/excel2moodle/-/commit/5f293970bcdac3858911cdcc102b72714af057bd)
95
+
96
+ ### documentation (1 change)
97
+
98
+ - [documentation: Added how to build question database](https://gitlab.com/jbosse3/excel2moodle/-/commit/71ceb122aa37e8bf2735b659359ae37d81017599)
99
+
100
+ ### feature (1 change)
101
+
102
+ - [Implemented MC question string method](https://gitlab.com/jbosse3/excel2moodle/-/commit/c4f2081d0000ee60322fe8eec8468fa3317ce7be)
103
+
104
+ ### improvement (1 change)
105
+
106
+ - [Implemented ClozePart object](https://gitlab.com/jbosse3/excel2moodle/-/commit/878f90f45e37421384c4f8f602115e7596b4ceb9)
107
+
108
+ ## 0.5.2 (2025-06-30)
109
+ Extended Documentation and bugfix for import Module
110
+
111
+ ### bugfix (2 changes)
112
+
113
+ - [Default question variant saved and reused.](https://gitlab.com/jbosse3/excel2moodle/-/commit/097705ba83727463a9b27cd76e99814a7ecf28df)
114
+ - [bugfix: Import module working again](https://gitlab.com/jbosse3/excel2moodle/-/commit/5f293970bcdac3858911cdcc102b72714af057bd)
115
+
116
+ ### documentation (1 change)
117
+
118
+ - [documentation: Added how to build question database](https://gitlab.com/jbosse3/excel2moodle/-/commit/71ceb122aa37e8bf2735b659359ae37d81017599)
119
+
120
+ ### feature (1 change)
121
+
122
+ - [Implemented MC question string method](https://gitlab.com/jbosse3/excel2moodle/-/commit/c4f2081d0000ee60322fe8eec8468fa3317ce7be)
123
+
124
+ ### improvement (1 change)
125
+
126
+ - [Implemented ClozePart object](https://gitlab.com/jbosse3/excel2moodle/-/commit/878f90f45e37421384c4f8f602115e7596b4ceb9)
127
+
63
128
  ## 0.5.1 (2025-06-24)
64
129
  Minor docs improvement and question variant bugfix
65
130
 
@@ -0,0 +1,98 @@
1
+ import logging
2
+ import re
3
+
4
+ import lxml.etree as ET
5
+
6
+ from excel2moodle.core import stringHelpers
7
+ from excel2moodle.core.globals import TextElements
8
+ from excel2moodle.core.question import ParametricQuestion
9
+ from excel2moodle.logger import LogAdapterQuestionID
10
+
11
+ loggerObj = logging.getLogger(__name__)
12
+
13
+
14
+ class BulletList:
15
+ def __init__(self, rawBullets: list[str], qID: str) -> None:
16
+ self.rawBullets: list[str] = rawBullets
17
+ self.element: ET.Element = ET.Element("ul")
18
+ self.bullets: dict[str, BulletP] = {}
19
+ self.id = qID
20
+ self.logger = LogAdapterQuestionID(loggerObj, {"qID": self.id})
21
+ self._setupBullets(rawBullets)
22
+
23
+ def updateBullets(
24
+ self, variables: dict[str, list[float]], variant: int = 1
25
+ ) -> None:
26
+ for var, bullet in self.bullets.items():
27
+ bullet.update(value=variables[var][variant - 1])
28
+
29
+ def getVariablesDict(self, question: ParametricQuestion) -> dict[str, list[float]]:
30
+ """Read variabel values for vars in `question.rawData`.
31
+
32
+ Returns
33
+ -------
34
+ A dictionary containing a list of values for each variable name
35
+
36
+ """
37
+ keyList = self.varNames
38
+ dic: dict = {}
39
+ for k in keyList:
40
+ val = question.rawData[k.lower()]
41
+ if isinstance(val, str):
42
+ li = stringHelpers.getListFromStr(val)
43
+ variables: list[float] = [float(i.replace(",", ".")) for i in li]
44
+ dic[str(k)] = variables
45
+ else:
46
+ dic[str(k)] = [str(val)]
47
+ loggerObj.debug("The following variables were provided: %s", dic)
48
+ return dic
49
+
50
+ @property
51
+ def varNames(self) -> list[str]:
52
+ names = [i for i in self.bullets if isinstance(i, str)]
53
+ if len(names) > 0:
54
+ self.logger.debug("returning Var names: %s", names)
55
+ return names
56
+ msg = "Bullet variable names not given."
57
+ raise ValueError(msg)
58
+
59
+ def _setupBullets(self, bps: list[str]) -> ET.Element:
60
+ self.logger.debug("Formatting the bulletpoint list")
61
+ varFinder = re.compile(r"=\s*\{(\w+)\}")
62
+ for i, item in enumerate(bps):
63
+ sc_split = item.split()
64
+ name = sc_split[0]
65
+ var = sc_split[1]
66
+ quant = sc_split[3]
67
+ unit = sc_split[4]
68
+
69
+ match = re.search(varFinder, item)
70
+ if match is None:
71
+ self.logger.debug("Got a normal bulletItem")
72
+ num: float = float(quant.replace(",", "."))
73
+ bulletName: str = str(i + 1)
74
+ else:
75
+ bulletName = match.group(1)
76
+ num: float = 0.0
77
+ self.logger.debug("Got an variable bulletItem, match: %s", match)
78
+
79
+ self.bullets[bulletName] = BulletP(name=name, var=var, unit=unit, value=num)
80
+ self.element.append(self.bullets[bulletName].element)
81
+ return self.element
82
+
83
+
84
+ class BulletP:
85
+ def __init__(self, name: str, var: str, unit: str, value: float = 0.0) -> None:
86
+ self.name: str = name
87
+ self.var: str = var
88
+ self.unit: str = unit
89
+ self.element: ET.Element
90
+ self.update(value=value)
91
+
92
+ def update(self, value: float = 1) -> None:
93
+ if not hasattr(self, "element"):
94
+ self.element = TextElements.LISTITEM.create()
95
+ valuestr = str(value).replace(".", r",\!")
96
+ self.element.text = (
97
+ f"{self.name} \\( {self.var} = {valuestr} \\mathrm{{ {self.unit} }} \\)"
98
+ )
@@ -11,8 +11,8 @@ from typing import TYPE_CHECKING
11
11
 
12
12
  import lxml.etree as ET # noqa: N812
13
13
  import pandas as pd
14
- from PySide6 import QtWidgets
15
14
  from PySide6.QtCore import QObject, Signal
15
+ from PySide6.QtWidgets import QDialog
16
16
 
17
17
  from excel2moodle.core import stringHelpers
18
18
  from excel2moodle.core.category import Category
@@ -131,7 +131,7 @@ class QuestionDB:
131
131
  if Tags.IMPORTMODULE in self.settings:
132
132
  logger.warning(
133
133
  "Appending: %s to sys.path. All names defined by it will be usable",
134
- sheetPath,
134
+ sheetPath.parent,
135
135
  )
136
136
  sys.path.append(str(sheetPath.parent))
137
137
  if Tags.PICTURESUBFOLDER not in self.settings:
@@ -286,7 +286,7 @@ class QuestionDB:
286
286
  self.signals.categoryQuestionsReady.emit(category)
287
287
 
288
288
  @classmethod
289
- def setupAndParseQuestion(cls, category: Category, qNumber: int) -> Question | None:
289
+ def setupAndParseQuestion(cls, category: Category, qNumber: int) -> Question:
290
290
  """Check if the Question Data is valid. Then parse it.
291
291
 
292
292
  The Question data is accessed from `category.dataframe` via its number
@@ -322,7 +322,7 @@ class QuestionDB:
322
322
  question = QuestionTypeMapping[qtype].create(category, validData)
323
323
  if question.isParsed:
324
324
  locallogger.info("Question already parsed")
325
- return None
325
+ return question
326
326
  if isinstance(question, NFQuestion):
327
327
  cls.nfParser.setup(question)
328
328
  locallogger.debug("setup a new NF parser ")
@@ -381,10 +381,9 @@ class QuestionDB:
381
381
  if hasattr(q, "variants") and q.variants is not None:
382
382
  if variant == 0 or variant > q.variants:
383
383
  dialog = QuestionVariantDialog(self.window, q)
384
- if dialog.exec() == QtWidgets.QDialog.Accepted:
384
+ if dialog.exec() == QDialog.Accepted:
385
385
  variant = dialog.variant
386
386
  logger.debug("Die Fragen-Variante %s wurde gewählt", variant)
387
387
  else:
388
388
  logger.warning("Keine Fragenvariante wurde gewählt.")
389
- q.assemble(variant=variant)
390
- tree.append(q.element)
389
+ tree.append(q.getUpdatedElement(variant=variant))
@@ -17,14 +17,9 @@ class TextElements(Enum):
17
17
  SPANRED = "span", "color: rgb(239, 69, 64)"
18
18
  SPANGREEN = "span", "color: rgb(152, 202, 62)"
19
19
  SPANORANGE = "span", "color: rgb(152, 100, 100)"
20
- ULIST = (
21
- "ul",
22
- "",
23
- )
24
- LISTITEM = (
25
- "li",
26
- "text-align: left;",
27
- )
20
+ ULIST = "ul", ""
21
+ LISTITEM = "li", "text-align: left;"
22
+ DIV = "div", ""
28
23
 
29
24
  def create(self, tag: str | None = None):
30
25
  if tag is None:
@@ -1,9 +1,9 @@
1
1
  import logging
2
- import re
3
2
 
4
3
  import lxml.etree as ET
5
4
 
6
5
  import excel2moodle.core.etHelpers as eth
6
+ from excel2moodle.core.bullets import BulletList
7
7
  from excel2moodle.core.exceptions import QNotParsedException
8
8
  from excel2moodle.core.globals import (
9
9
  Tags,
@@ -58,65 +58,19 @@ class QuestionParser:
58
58
  )
59
59
  return bool(self.question.picture.ready)
60
60
 
61
- def setMainText(self) -> None:
62
- paragraphs: list[ET._Element] = [TextElements.PLEFT.create()]
63
- ET.SubElement(paragraphs[0], "b").text = f"ID {self.question.id}"
61
+ def getMainTextElement(self) -> ET.Element:
62
+ """Get the root question Text with the question paragraphs."""
63
+ textHTMLroot: ET._Element = ET.Element("div")
64
+ ET.SubElement(
65
+ ET.SubElement(textHTMLroot, "p"), "b"
66
+ ).text = f"ID {self.question.id}"
64
67
  text = self.rawInput[Tags.TEXT]
65
68
  for t in text:
66
- paragraphs.append(TextElements.PLEFT.create())
67
- paragraphs[-1].text = t
68
- self.question.qtextParagraphs = paragraphs
69
+ par = TextElements.PLEFT.create()
70
+ par.text = t
71
+ textHTMLroot.append(par)
69
72
  self.logger.debug("Created main Text with: %s paragraphs", len(text))
70
-
71
- def setBPoints(self) -> None:
72
- """If there bulletPoints are set in the Spreadsheet it creates an unordered List-Element in ``Question.bulletList``."""
73
- if Tags.BPOINTS in self.rawInput:
74
- bps: list[str] = self.rawInput[Tags.BPOINTS]
75
- try:
76
- bulletList = self.formatBulletList(bps)
77
- except IndexError:
78
- msg = f"konnt Bullet Liste {self.question.id} nicht generieren"
79
- raise QNotParsedException(
80
- msg,
81
- self.question.id,
82
- # exc_info=e,
83
- )
84
- self.logger.debug(
85
- "Generated BPoint List: \n %s",
86
- ET.tostring(bulletList, encoding="unicode"),
87
- )
88
- self.question.bulletList = bulletList
89
-
90
- def formatBulletList(self, bps: list[str]) -> ET.Element:
91
- self.logger.debug("Formatting the bulletpoint list")
92
- name = []
93
- var = []
94
- quant = []
95
- unit = []
96
- unorderedList = TextElements.ULIST.create()
97
- for item in bps:
98
- sc_split = item.split()
99
- name.append(sc_split[0])
100
- var.append(sc_split[1])
101
- quant.append(sc_split[3])
102
- unit.append(sc_split[4])
103
- for i in range(len(name)):
104
- if re.fullmatch(r"{\w+}", quant[i]):
105
- self.logger.debug("Got an variable bulletItem")
106
- num_s = quant[i]
107
- else:
108
- self.logger.debug("Got a normal bulletItem")
109
- num = quant[i].split(",")
110
- if len(num) == 2:
111
- num_s = f"{num[0]!s},\\!{num[1]!s}~"
112
- else:
113
- num_s = f"{num[0]!s},\\!0~"
114
- bullet = TextElements.LISTITEM.create()
115
- bullet.text = (
116
- f"{name[i]}: \\( {var[i]} = {num_s} \\mathrm{{ {unit[i]} }}\\)\n"
117
- )
118
- unorderedList.append(bullet)
119
- return unorderedList
73
+ return textHTMLroot
120
74
 
121
75
  def appendToTmpEle(
122
76
  self,
@@ -148,7 +102,7 @@ class QuestionParser:
148
102
  """Parse the Question.
149
103
 
150
104
  Generates an new Question Element stored as ``self.tmpEle:ET.Element``
151
- if no Exceptions are raised, ``self.tmpEle`` is passed to ``self.question.element``
105
+ if no Exceptions are raised, ``self.tmpEle`` is passed to ``question.element``
152
106
  """
153
107
  self.logger.info("Starting to parse")
154
108
  self.tmpEle: ET.Elemnt = ET.Element(
@@ -156,21 +110,39 @@ class QuestionParser:
156
110
  )
157
111
  self.appendToTmpEle(XMLTags.NAME, text=Tags.NAME, txtEle=True)
158
112
  self.appendToTmpEle(XMLTags.ID, text=self.question.id)
159
- if self.hasPicture():
160
- self.tmpEle.append(self.question.picture.element)
161
- self.tmpEle.append(ET.Element(XMLTags.QTEXT, format="html"))
113
+ textRootElem = ET.Element(XMLTags.QTEXT, format="html")
114
+ mainTextEle = ET.SubElement(textRootElem, "text")
115
+ self.tmpEle.append(textRootElem)
162
116
  self.appendToTmpEle(XMLTags.POINTS, text=str(self.question.points))
163
117
  self._appendStandardTags()
164
118
  for feedb in self.genFeedbacks:
165
119
  self.tmpEle.append(eth.getFeedBEle(feedb))
120
+
121
+ self.htmlRoot = ET.Element("div")
122
+ self.htmlRoot.append(self.getMainTextElement())
123
+ if Tags.BPOINTS in self.rawInput:
124
+ bps: list[str] = self.rawInput[Tags.BPOINTS]
125
+ try:
126
+ bullets: BulletList = BulletList(bps, self.question.id)
127
+ except IndexError:
128
+ msg = f"konnt Bullet Liste {self.question.id} nicht generieren"
129
+ raise QNotParsedException(
130
+ msg,
131
+ self.question.id,
132
+ )
133
+ self.htmlRoot.append(bullets.element)
134
+ self.question.bulletList = bullets
135
+ if self.hasPicture():
136
+ self.htmlRoot.append(self.question.picture.htmlTag)
137
+ textRootElem.append(self.question.picture.element)
166
138
  ansList = self._parseAnswers()
167
- self.setMainText()
168
- self.setBPoints()
169
139
  if ansList is not None:
170
140
  for ele in ansList:
171
141
  self.tmpEle.append(ele)
172
- self.question.element = self.tmpEle
142
+ self.question._element = self.tmpEle
143
+ self.question.htmlRoot = self.htmlRoot
173
144
  self.question.isParsed = True
145
+ self.question.textElement = mainTextEle
174
146
  self.logger.info("Sucessfully parsed")
175
147
 
176
148
  def getFeedBEle(
@@ -195,7 +167,7 @@ class QuestionParser:
195
167
 
196
168
  def getNumericAnsElement(
197
169
  self,
198
- result: float,
170
+ result: float = 0.0,
199
171
  fraction: float = 100,
200
172
  format: str = "moodle_auto_format",
201
173
  ) -> ET.Element: