diff --git a/src/plugin/python/bindings/PyXournal.cpp b/src/plugin/python/bindings/PyXournal.cpp index d1e11f62..61480859 100644 --- a/src/plugin/python/bindings/PyXournal.cpp +++ b/src/plugin/python/bindings/PyXournal.cpp @@ -442,6 +442,31 @@ PyXournal_setCurrentPageBackground(PyXournal * self, PyObject * args) { Py_RETURN_NONE; } +static PyObject * +PyXournal_getEraserType(PyXournal * self) { + EraserType type = self->control->getToolHandler()->getEraserType(); + return PyInt_FromLong(type); +} + +static PyObject * +PyXournal_setEraserType(PyXournal * self, PyObject * args) { + int eraserType = -1; + + if (!PyArg_ParseTuple(args, "i", &eraserType)) { + PyErr_SetString(PyExc_AttributeError, "int"); + return NULL; + } + + if (eraserType < ERASER_TYPE_DEFAULT || eraserType > ERASER_TYPE_DELETE_STROKE) { + PyErr_SetString(PyExc_AttributeError, "Erasertype out of range, please use the constants BACKGROUND_TYPE_*"); + return NULL; + } + + self->control->getToolHandler()->setEraserType((EraserType)eraserType); + + Py_RETURN_NONE; +} + static PyMethodDef PyXournal_methods[] = { { "setSelectedTool", (PyCFunction) PyXournal_setSelectedTool, METH_VARARGS, "Selects a tool (see constatns TOOL_*" }, { "getSelectedTool", (PyCFunction) PyXournal_getSelectedTool, METH_NOARGS, "Return the selected tool" }, @@ -465,8 +490,8 @@ static PyMethodDef PyXournal_methods[] = { { "getToolSize", (PyCFunction) PyXournal_getToolSize, METH_NOARGS, "Return the selected tool size" }, { "getCurrentPageBackground", (PyCFunction) PyXournal_getCurrentPageBackground, METH_NOARGS, "Return the background type of the current page (see BACKGROUND_TYPE_*)" }, { "setCurrentPageBackground", (PyCFunction) PyXournal_setCurrentPageBackground, METH_VARARGS, "Set the background type of the current page (see BACKGROUND_TYPE_*)\nDon't use BACKGROUND_TYPE_PDF or BACKGROUND_TYPE_PDF" }, -// { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, -// { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, + { "setEraserType", (PyCFunction) PyXournal_setEraserType, METH_VARARGS, "Set the eraser type (ERASER_TYPE_*)" }, + { "getEraserType", (PyCFunction) PyXournal_getEraserType, METH_VARARGS, "Returns the eraser type (ERASER_TYPE_*)" }, // { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, // { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, // { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, @@ -545,8 +570,6 @@ void initxournal() { ADD_CONST(TOOL_SIZE_THICK); ADD_CONST(TOOL_SIZE_VERY_THICK); - - ADD_CONST(BACKGROUND_TYPE_NONE); ADD_CONST(BACKGROUND_TYPE_PDF); ADD_CONST(BACKGROUND_TYPE_IMAGE); @@ -554,6 +577,10 @@ void initxournal() { ADD_CONST(BACKGROUND_TYPE_RULED); ADD_CONST(BACKGROUND_TYPE_GRAPH); + ADD_CONST(ERASER_TYPE_DEFAULT); + ADD_CONST(ERASER_TYPE_WHITEOUT); + ADD_CONST(ERASER_TYPE_DELETE_STROKE); + m = Py_InitModule3("xournal", module_methods, "Xournal API modul"); if (m == NULL) { diff --git a/src/plugin/python/documentation/Xournal.java b/src/plugin/python/documentation/Xournal.java index 1136c449..e3b56468 100644 --- a/src/plugin/python/documentation/Xournal.java +++ b/src/plugin/python/documentation/Xournal.java @@ -24,6 +24,10 @@ public interface Xournal { int BACKGROUND_TYPE_RULED = 5; int BACKGROUND_TYPE_GRAPH = 6; + int ERASER_TYPE_DEFAULT = 1; + int ERASER_TYPE_WHITEOUT = 2; + int ERASER_TYPE_DELETE_STROKE = 3; + /** * Sets the current tool * @param tool A constant defined above @@ -78,6 +82,16 @@ public interface Xournal { */ boolean isShapeRecognizerEnabled(); + /** + * Set the eraser type (ERASER_TYPE_*) + */ + void setEraserType(int eraserType); + + /** + * Returns the eraser type (ERASER_TYPE_*) + */ + int getEraserType(); + /** * Return the background type of the current page (see BACKGROUND_TYPE_*) */ diff --git a/testing/tools/ToolEraser/ToolEraser.py b/testing/tools/ToolEraser/ToolEraser.py index 8ab8cd2a..c0a8c22d 100644 --- a/testing/tools/ToolEraser/ToolEraser.py +++ b/testing/tools/ToolEraser/ToolEraser.py @@ -21,16 +21,38 @@ class ToolEraser(ToolTest): self.testDeleteStroke() def testWhiteout(self): - path = os.path.realpath(__file__ + '/../source.xoj') - self.xoj.openFile(path) + self.xoj.setEraserType(self.xoj.ERASER_TYPE_WHITEOUT) + + self.doTestInput() path = os.path.realpath(__file__ + '/../resultWhiteout.xoj') self.checkContents(path) def testStandard(self): - # test with normal stroke, with pressure, with ruler - pass + self.xoj.newFile(True) + path = os.path.realpath(__file__ + '/../source.xoj') + self.xoj.openFile(path) + + self.xoj.setEraserType(self.xoj.ERASER_TYPE_DEFAULT) + + points = [[100, 40]] + points.append([150, 300]); + self.mouseInput(points, 1); + + path = os.path.realpath(__file__ + '/../resultStandard.xoj') + self.checkContents(path) def testDeleteStroke(self): - pass + self.xoj.newFile(True) + path = os.path.realpath(__file__ + '/../source.xoj') + self.xoj.openFile(path) + + self.xoj.setEraserType(self.xoj.ERASER_TYPE_DELETE_STROKE) + + points = [[100, 40]] + points.append([150, 300]); + self.mouseInput(points, 1); + + path = os.path.realpath(__file__ + '/../resultDelete.xoj') + self.checkContents(path) diff --git a/testing/tools/ToolEraser/resultDelete.xoj b/testing/tools/ToolEraser/resultDelete.xoj new file mode 100644 index 00000000..1df34ad8 Binary files /dev/null and b/testing/tools/ToolEraser/resultDelete.xoj differ diff --git a/testing/tools/ToolEraser/resultStandard.xoj b/testing/tools/ToolEraser/resultStandard.xoj new file mode 100644 index 00000000..93eddad7 Binary files /dev/null and b/testing/tools/ToolEraser/resultStandard.xoj differ diff --git a/testing/tools/ToolEraser/resultWhiteout.xoj b/testing/tools/ToolEraser/resultWhiteout.xoj new file mode 100644 index 00000000..71a2a2ab Binary files /dev/null and b/testing/tools/ToolEraser/resultWhiteout.xoj differ