Skip to content

Commit

Permalink
fix #130 and fix #131 (#132)
Browse files Browse the repository at this point in the history
* fix #130

* tests : fix time in Quizz

* fix #131
  • Loading branch information
jgirardet authored Apr 10, 2021
1 parent 2c1be61 commit 8bd37e8
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 12 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"python.pythonPath": ".venv/bin/python",
"python.pythonPath": ".venv/bin/python3.8",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black"
}
4 changes: 3 additions & 1 deletion src/mycartable/classeur/sections/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def update(self, curseur, event):

@pyqtSlot(int, result=bool)
def isEquationFocusable(self, curseur: int) -> bool:
if not any((self.content, curseur)):
return True
return TextEquation(
str(self.content), curseur, {"key": None, "text": None, "modifiers": None}
).is_focusable
Expand Down Expand Up @@ -123,7 +125,7 @@ def __init__(self, lines: str, curseur: int, event):
def __call__(self):

if not self.lines_string:
if self.text and self.key != Qt.Key_Return:
if self.text and self.key != Qt.Key_Return and self.key != Qt.Key_Backspace:
return f" \n{self.text}\n ", 3
else:
return "", 0
Expand Down
5 changes: 4 additions & 1 deletion src/mycartable/classeur/sections/operations/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ def convert_addition(numbers):
signe = "+" if num_index else "" # pas de signe pour la premiere ligne
res.append(
[signe]
+ num.to_string_list_addition(n_col - 1, apres_virgule=n_apres_virgule,)
+ num.to_string_list_addition(
n_col - 1,
apres_virgule=n_apres_virgule,
)
) # n_col-1 car signe prend une colonne
num_index += 1
return n_row, n_col, virgule, list(itertools.chain.from_iterable(res))
Expand Down
2 changes: 1 addition & 1 deletion src/qml/annotations/AnnotationDessin.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Canvas {
property color fillStyle: annot.bgColor
property real lineWidth: annot.pointSize
property string tool: annot.tool
property int index
property int modelIndex: index // à priori pas utilisé ici mais on garde pour l'interface

function checkPointIsNotDraw(mx, my) {
var ctx = canvas.getContext("2d");
Expand Down
5 changes: 3 additions & 2 deletions src/qml/annotations/AnnotationText.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TextArea {
property int moveStep: 5
property int fontSizeFactor: annot && annot.pointSize ? annot.pointSize : 0
property bool key_accepted: false // true pour le chargement initial
property int index
property int modelIndex:index

function move(key) {
if (key == Qt.Key_Left)
Expand All @@ -39,7 +39,7 @@ TextArea {
onTextChanged: {
// on ne sauvegarde pas (pas de creation de command) si c un undo/redo/initial load
if (key_accepted)
annot.set(index, {
annot.set(modelIndex, {
"text": text
}, "frappe");

Expand Down Expand Up @@ -107,6 +107,7 @@ TextArea {
function onTextChanged() {
if (text != annot.text)
text = annot.text;
// annot.set(modelIndex, {"text":text}, "frappe");

}

Expand Down
1 change: 0 additions & 1 deletion src/qml/annotations/BaseAnnotation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Loader {
root.setSource("qrc:/qml/annotations/" + annot.classtype + ".qml", {
"referent": referent,
"annot": annot,
"index": index
});
}
states: [
Expand Down
12 changes: 12 additions & 0 deletions tests/python/classeur/test_equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def test_isequationfocusable(self, fk):
assert not e.isEquationFocusable(0)
assert e.isEquationFocusable(4)

def test_isequationfocusable_bug_131(self, fk):
eq = fk.f_equationSection(content="")
e = EquationSection.get(eq.id, parent=None, undoStack=QUndoStack())
e.content=""
assert e.isEquationFocusable(0)


UN = """
||1¤............¤12...1234....||
Expand Down Expand Up @@ -1228,3 +1234,9 @@ def test_sub(self):
a = Fragment(5, 10, "\u2000\u2000bla\u2000", 0)
a.sub(2, "X")
assert a.value == "\u2000\u2000Xla\u2000"


def test_bug_131_backspace_sur_empty(eq):
a = eq("", 0, {"key": Qt.Key_Backspace ,"text": b'\x08'.decode(), "modifiers": None})
a.lines_string=""
assert a()[0].encode() == b''
2 changes: 1 addition & 1 deletion tests/python/lexique/test_lexique.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_updateActivesLocales(qtbot):
Test Quizz
"""


@pytest.mark.freeze_time('2017-03-03')
class TestQuizz:

provider = {
Expand Down
7 changes: 4 additions & 3 deletions tests/qml/tst_AnnotationText.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ FocusScope {
annotobj = ref.model.data(ref.model.index(0, 0), th.getRole("AnnotationRole")); //258:AnnotationRole
params = {
"annot": annotobj,
"referent": item
"referent": item,
"modelIndex":0
};
annotobj.index = 0;
}

function test_initY() {
Expand Down Expand Up @@ -83,7 +83,8 @@ FocusScope {
let aannoott2 = th.getBridgeInstance(ref, "AnnotationText", annot2.id);
var tested2 = createObj(testedNom, {
"annot": aannoott2,
"referent": item
"referent": item,
"modelIndex": 1
}, item);
compare(tested2.fontSizeFactor, 3);
compare(tested2.font.pixelSize, 66); // 200/3
Expand Down
6 changes: 6 additions & 0 deletions tests/qml/tst_EquationSection.qml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Item {
compare(tested.text, "1 \n__ + 1a\n15 ");
}

function test_bug_131() {
eqObj.content = ""
mouseClick(tested)
keyClick(Qt.Key_Backspace)
}

name: "EquationSection"
testedNom: "qrc:/qml/sections/EquationSection.qml"
params: {
Expand Down
25 changes: 25 additions & 0 deletions tests/qml/tst_ImageSection.qml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,31 @@ Item {
verify(!stack.canRedo);
}

function test_bug_130() {
mouseClick(tested, 50, 50)
keySequence('a')
tryCompare(tested.annotations.itemAt(0).item,"text", "a") // on sépare pour avoir un poil de temps entre chaque clique
mouseClick(tested, 200, 200)
keySequence('e')
tryCompare(tested.annotations.itemAt(1).item,"text", "e")
mouseClick(tested, 400, 400)
keySequence('i')
tryCompare(tested.annotations.itemAt(2).item,"text", "i")
compare(tested.annotations.itemAt(0).item.modelIndex, 0)
compare(tested.annotations.itemAt(1).item.modelIndex, 1)
compare(tested.annotations.itemAt(2).item.modelIndex, 2)
mouseClick(tested, 51, 51, Qt.MiddleButton)
// verifie que l'index se met à jour
tryCompare(tested.annotations.itemAt(0).item,"text", "e")
tryCompare(tested.annotations.itemAt(1).item,"text", "i")
compare(tested.annotations.itemAt(0).item.modelIndex, 0)
compare(tested.annotations.itemAt(1).item.modelIndex, 1)
mouseMove(tested, 200, 200)
keySequence('m,n,o,p')
tryCompare(tested.annotations.itemAt(0).item,"text", "emnop")
compare(tested.annotations.itemAt(1).item.text, "i")
}

name: "ImageSection"
testedNom: "qrc:/qml/sections/ImageSection.qml"
params: {
Expand Down

0 comments on commit 8bd37e8

Please sign in to comment.