diff --git a/src/plugin/python/bindings/PyXournal.cpp b/src/plugin/python/bindings/PyXournal.cpp index 5d8862c5..740f4e7e 100644 --- a/src/plugin/python/bindings/PyXournal.cpp +++ b/src/plugin/python/bindings/PyXournal.cpp @@ -29,7 +29,6 @@ void PyXournal_initPython(Control * control) { initxournal(); } - static void PyXournal_dealloc(PyXournal* self) { self->ob_type->tp_free((PyObject*) self); } @@ -41,6 +40,7 @@ PyXournal_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { self = (PyXournal *) type->tp_alloc(type, 0); if (self != NULL) { self->control = PyXournal_control; + self->undoRedoHandler = PyLong_FromLong(5); } return (PyObject *) self; @@ -51,45 +51,30 @@ static int PyXournal_init(PyXournal *self, PyObject *args, PyObject *kwds) { } static PyMemberDef PyXournal_members[] = { -// { "number", T_INT, offsetof(PyXournal, number), 0, "noddy number" }, + { "undoRedoHandler", T_OBJECT, offsetof(PyXournal, undoRedoHandler), 0, "Undo- / Redohandler" }, { NULL } /* Sentinel */ }; -static PyObject * -PyXournal_getName(PyXournal* self) { - static PyObject *format = NULL; - - if (format == NULL) { - format = PyString_FromString("Xournal object"); - if (format == NULL) - return NULL; - } - - Py_DECREF(format); - - return format; -} - static PyObject * PyXournal_newFile(PyXournal * self, PyObject * args) { PyObject * force = NULL; - if(!PyArg_ParseTuple(args, "|o", &force)) { - PyErr_SetString(PyExc_AttributeError, "[Boolean]"); - return NULL; - } + if (!PyArg_ParseTuple(args, "|o", &force)) { + PyErr_SetString(PyExc_AttributeError, "[Boolean]"); + return NULL; + } - if(!PyBool_Check(force)) { - PyErr_SetString(PyExc_AttributeError, "[Boolean]"); - return NULL; - } + if (!PyBool_Check(force)) { + PyErr_SetString(PyExc_AttributeError, "[Boolean]"); + return NULL; + } - if(PyObject_IsTrue(force)) { - self->control->getUndoRedoHandler()->clearContents(); - } + if (PyObject_IsTrue(force)) { + self->control->getUndoRedoHandler()->clearContents(); + } - if(self->control->newFile()) { + if (self->control->newFile()) { Py_RETURN_TRUE; } @@ -100,14 +85,14 @@ static PyObject * PyXournal_saveFile(PyXournal * self, PyObject * args) { char * path = NULL; - if(!PyArg_ParseTuple(args, "s", &path)) { - PyErr_SetString(PyExc_AttributeError, "String"); - return NULL; - } + if (!PyArg_ParseTuple(args, "s", &path)) { + PyErr_SetString(PyExc_AttributeError, "String"); + return NULL; + } - self->control->getDocument()->setFilename(path); + self->control->getDocument()->setFilename(path); - if(self->control->save(true)) { + if (self->control->save(true)) { Py_RETURN_TRUE; } @@ -119,24 +104,138 @@ PyXournal_openFile(PyXournal * self, PyObject * args) { char * path = NULL; int scrollToPage = -1; - if(!PyArg_ParseTuple(args, "s|i", &path, &scrollToPage)) { - PyErr_SetString(PyExc_AttributeError, "String [int]"); - return NULL; - } - + if (!PyArg_ParseTuple(args, "s|i", &path, &scrollToPage)) { + PyErr_SetString(PyExc_AttributeError, "String [int]"); + return NULL; + } - if(self->control->openFile(path, scrollToPage)) { + if (self->control->openFile(path, scrollToPage)) { Py_RETURN_TRUE; } Py_RETURN_FALSE; } + +static PyObject * +PyXournal_setSelectedTool(PyXournal * self, PyObject * args) { + int tool = -1; + + if (!PyArg_ParseTuple(args, "i", &tool)) { + PyErr_SetString(PyExc_AttributeError, "int"); + return NULL; + } + + if (tool < TOOL_PEN || tool > TOOL_HAND) { + PyErr_SetString(PyExc_AttributeError, "Tool out of range, please use the constants TOOL_*"); + } + + self->control->getToolHandler()->selectTool((ToolType) tool); + + Py_RETURN_NONE; +} + +static PyObject * +PyXournal_getSelectedTool(PyXournal* self) { + ToolType tt = self->control->getToolHandler()->getToolType(); + + return PyLong_FromLong(tt); +} + +static PyObject * +PyXournal_mousePressed(PyXournal * self, PyObject * args) { + int x = -1; + int y = -1; + + if (!PyArg_ParseTuple(args, "ii", &x, &y)) { + PyErr_SetString(PyExc_AttributeError, "int int"); + return NULL; + } + + // TODO: implememnt + g_warning("NOT IMPLEMENTED!\n"); + + Py_RETURN_NONE; +} + +static PyObject * +PyXournal_mouseMoved(PyXournal * self, PyObject * args) { + int x = -1; + int y = -1; + + if (!PyArg_ParseTuple(args, "ii", &x, &y)) { + PyErr_SetString(PyExc_AttributeError, "int int"); + return NULL; + } + + // TODO: implememnt + g_warning("NOT IMPLEMENTED!\n"); + + Py_RETURN_NONE; +} + +static PyObject * +PyXournal_mouseReleased(PyXournal * self) { + // TODO: implememnt + g_warning("NOT IMPLEMENTED!\n"); + + Py_RETURN_NONE; +} + +static PyObject * +PyXournal_getUndoRedoHandler(PyXournal * self) { + // TODO: implememnt + g_warning("NOT IMPLEMENTED!\n"); + + Py_RETURN_NONE; +} + +static PyObject * +PyXournal_getSelectedPage(PyXournal * self) { + // TODO: implememnt + g_warning("NOT IMPLEMENTED!\n"); + + Py_RETURN_NONE; +} + +static PyObject * +PyXournal_getDocument(PyXournal * self) { + // TODO: implememnt + g_warning("NOT IMPLEMENTED!\n"); + + Py_RETURN_NONE; +} + +static PyObject * +PyXournal_selectPage(PyXournal * self, PyObject * args) { + int page = -1; + + if (!PyArg_ParseTuple(args, "i", &page)) { + PyErr_SetString(PyExc_AttributeError, "int"); + return NULL; + } + + // TODO: implementieren + + Py_RETURN_NONE; +} + static PyMethodDef PyXournal_methods[] = { - { "getName", (PyCFunction) PyXournal_getName, METH_NOARGS, "Return the name" }, - { "newFile", (PyCFunction) PyXournal_newFile, METH_VARARGS, "Create a new document" }, - { "saveFile", (PyCFunction) PyXournal_saveFile, METH_VARARGS, "Save a document as" }, - { "openFile", (PyCFunction) PyXournal_openFile, METH_VARARGS, "Opens a file" }, - { NULL } /* Sentinel */ + { "setSelectedTool", (PyCFunction) PyXournal_setSelectedTool, METH_VARARGS, "Selects a tool (see constatns TOOL_*" }, + { "getSelectedTool", (PyCFunction) PyXournal_getSelectedTool, METH_NOARGS, "Return the selected tool" }, + { "newFile", (PyCFunction) PyXournal_newFile, METH_VARARGS, "Create a new document" }, + { "saveFile", (PyCFunction) PyXournal_saveFile, METH_VARARGS, "Save a document as" }, + { "openFile", (PyCFunction) PyXournal_openFile, METH_VARARGS, "Opens a file" }, + { "mousePressed", (PyCFunction) PyXournal_mousePressed, METH_VARARGS, "Simulate a mouse press on the current view" }, + { "mouseMoved", (PyCFunction) PyXournal_mouseMoved, METH_VARARGS, "Simulate a mouse move on the current view" }, + { "mouseReleased", (PyCFunction) PyXournal_mouseReleased, METH_NOARGS, "Simulate a mouse release" }, + { "getUndoRedoHandler", (PyCFunction) PyXournal_getUndoRedoHandler, METH_NOARGS, "Gets the Undo- / Redohandler" }, + { "getDocument", (PyCFunction) PyXournal_getDocument, METH_NOARGS, "Return the Xournal Document" }, + { "getSelectedPage", (PyCFunction) PyXournal_getSelectedPage, METH_NOARGS, "Gets the selected page ID (first Page: 0)" }, + { "selectPage", (PyCFunction) PyXournal_selectPage, METH_VARARGS, "Sets the selected page (first Page: 0)" }, +// { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, +// { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, +// { "xxxxxxxxxxxxx", (PyCFunction) xxxxxxxxxxxxxxxxx, METH_VARARGS, "Xxxxxxxxxxxxxxxx" }, + { NULL } /* Sentinel */ }; static PyTypeObject XournalType = { diff --git a/src/plugin/python/documentation/Document.java b/src/plugin/python/documentation/Document.java new file mode 100644 index 00000000..fcb06ff5 --- /dev/null +++ b/src/plugin/python/documentation/Document.java @@ -0,0 +1,8 @@ + +public interface Document { + + /** + * Gets the page count + */ + int getPageCount(); +} diff --git a/src/plugin/python/documentation/README b/src/plugin/python/documentation/README new file mode 100644 index 00000000..fb001bef --- /dev/null +++ b/src/plugin/python/documentation/README @@ -0,0 +1,3 @@ +This Java Interfaces are only for documentation purpose, +they are not used, but they show you the types which are used +(e.g. int, String) and what they do. \ No newline at end of file diff --git a/src/plugin/python/documentation/UndoRedoHandler.java b/src/plugin/python/documentation/UndoRedoHandler.java new file mode 100644 index 00000000..b1618e27 --- /dev/null +++ b/src/plugin/python/documentation/UndoRedoHandler.java @@ -0,0 +1,27 @@ + +public interface UndoRedoHandler { + /** + * If there is something to undo + * @return true if yes + */ + boolean canUndo(); + + /** + * If there is something to redo + * @return true if yes + */ + boolean canRedo(); + + /** + * Undo the last operation + * @return false on fail + */ + boolean undo(); + + /** + * Redo the last operation + * @return false on fail + */ + boolean redo(); + +} diff --git a/src/plugin/python/documentation/Xournal.java b/src/plugin/python/documentation/Xournal.java new file mode 100644 index 00000000..eb8d9441 --- /dev/null +++ b/src/plugin/python/documentation/Xournal.java @@ -0,0 +1,97 @@ +public interface Xournal { + int TOOL_PEN = 1; + int TOOL_ERASER = 2; + int TOOL_HILIGHTER = 3; + int TOOL_TEXT = 3; + int TOOL_IMAGE = 4; + int TOOL_SELECT_RECT = 5; + int TOOL_SELECT_REGION = 6; + int TOOL_SELECT_OBJECT = 7; + int TOOL_VERTICAL_SPACE = 8; + int TOOL_HAND = 9; + + /** + * Sets the current tool + * @param tool A constant defined above + */ + void setSelectedTool(int tool); + + /** + * Return the selected tool + * @return (See constants TOOL_*) + */ + int getSelectedTool(); + + /** + * Sets the tool Color in RGB + */ + void setToolColor(int color); + + /** + * Returns the tool color in RGB + */ + int getToolColor(); + + /** + * Creates a new file + * + * @param [optional] force force creation of a new file, loose your unsaved contents + * + * @return if a new file was created, false if the user canceled the operation + */ + boolean newFile(boolean force); + + /** + * Save the current document + * @param path a complete filename, e.g. /home/myname/test.xoj + * @return true if successfully, false if failed + */ + boolean saveFile(String path); + + /** + * Open a xournal file + * @param path a complete filename, e.g. /home/myname/test.xoj + * @param [optional] scrollToPage The page to scroll or -1 to not scroll + * @return true if successfully, false if failed + */ + boolean openFile(String path, int scrollToPage); + + /** + * Press the mouse on the selected View + * @param x The X Coordinate + * @param y The Y Coordinate + */ + void mousePressed(int x, int y); + + /** + * Press the mouse on the selected View + * @param x The X Coordinate + * @param y The Y Coordinate + */ + void mouseMoved(int x, int y); + + /** + * Press the mouse on the selected View + */ + void mouseReleased(); + + /** + * The Undo- / Redohandler + */ + UndoRedoHandler getUndoRedoHandler(); + + /** + * Return the Xournal Document + */ + Document getDocument(); + + /** + * Gets the selected page ID (first Page: 0) + */ + int getSelectedPage(); + + /** + * Sets the selected page (first Page: 0) + */ + void selectPage(int page); +} diff --git a/testing/Test.py b/testing/Test.py index 62b3d555..6f772302 100644 --- a/testing/Test.py +++ b/testing/Test.py @@ -4,8 +4,6 @@ def xournalTest(): print 'Testmethode' xoj = xournal.Xournal() - print xoj.getName() - print xoj.openFile('/home/andreas/tmp/Notiz-10-03-2011-16-57.xoj')