r22772 by jghali - #15483: add setJSActionScript and getJSActionScript python functions <dockatt>

scribus-commit scribus-commit at lists.scribus.net
Sun Nov 18 14:57:45 UTC 2018


Author: jghali
Date: Sun Nov 18 14:57:45 2018
New Revision: 22772

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22772
Log:
#15483: add setJSActionScript and getJSActionScript python functions <dockatt>

Modified:
    trunk/Scribus/doc/en/scripterapi-pdfannotations.html
    trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.h
    trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp

Modified: trunk/Scribus/doc/en/scripterapi-pdfannotations.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22772&path=/trunk/Scribus/doc/en/scripterapi-pdfannotations.html
==============================================================================
--- trunk/Scribus/doc/en/scripterapi-pdfannotations.html	(original)
+++ trunk/Scribus/doc/en/scripterapi-pdfannotations.html	Sun Nov 18 14:57:45 2018
@@ -14,9 +14,45 @@
 
 <dt><a name="-createPdfAnnotation"><strong>createPdfAnnotation</strong></a>(...)</dt>
 <dd><code>createPdfAnnotation(type, x, y, w, h, ["name"]) -> string</code>
-<p>Creates a new PDF Annotation frame. "type" refers to the kind of PDF annotation with the following key: (0 PDFBUTTON, 1 PDFRADIOBUTTON, 2 PDFTEXTFIELD,
-3 PDFCHECKBOX, 4 PDFCOMBOBOX, 5 PDFLISTBOX, 6 PDFTEXTANNOTATION, 7 PDFLINKANNOTATION, 8 PDF3DANNOTATION). <strong>x</strong> and <strong>y</strong> are the upper left coordinates for the frame, having <strong>w</strong> width and <strong>h</strong> height. If "name" is not given Scribus will create one for you.</p>
+<p>Creates a new PDF Annotation frame. "type" refers to the kind of PDF annotation with the following key: 
+	<ul style="list-style-type:none">
+		<li>0 - PDFBUTTON</li>
+		<li>1 - PDFRADIOBUTTON</li>
+		<li>2 - PDFTEXTFIELD</li>
+		<li>3 - PDFCHECKBOX</li>
+		<li>4 - PDFCOMBOBOX</li>
+		<li>5 - PDFLISTBOX</li>
+		<li>6 - PDFTEXTANNOTATION</li>
+		<li>7 - PDFLINKANNOTATION</li>
+		<li>8 - PDF3DANNOTATION.</li>
+	</ul>
+</p>
+<p><strong>x</strong> and <strong>y</strong> are the upper left coordinates for the frame, having <strong>w</strong> width and <strong>h</strong> height. If "name" is not given Scribus will create one for you.</p>
 <p>On systems without OSG installed a runtime error will be raised. May raise <a href="scripterapi.html#NameExistsError">NameExistsError</a> if you explicitly pass a name that's already used. </p></dd>
+
+<dt><a name="-getJSActionScript"><strong>getJSActionScript</strong></a>(...)</dt>
+<dd><code>getJSActionScript(which, ["name"]) -> string</code>
+<p>Gets the JavaScript action script for a particular event</p>
+<p>This functions accepts following arguments:
+	<ul>
+		<li><strong>which</strong> is an integer in range 0-9 describing the kind of event:</li>
+		<ul style="list-style-type:none">
+			<li>0 - Mouse Up</li>
+			<li>1 - Mouse Down</li>
+			<li>2 - Mouse Enter</li>
+			<li>3 - Mouse Exit</li>
+			<li>4 - Focus In</li>
+			<li>5 - Focus Out</li>
+			<li>6 - Selection Change</li>
+			<li>7 - Field Format</li>
+			<li>8 - Field Validate</li>
+			<li>9 - Field Calculate</li>
+		</ul>
+		<li><strong>name</strong> is the object name. If "name" is not provided, the currently selected item will be used.</li>
+	</ul>
+</p>
+<p>Returns a string if object's action type is Javascript, NONE otherwise.</p>
+<p>Page item must be an annotation or an error will be raised. May raise <a href="scripterapi.html#NameExistsError">NameExistsError</a> if you explicitly pass a name that doesn't exist.</p></dd>
 
 <dt><a name="-isAnnotated"><strong>isAnnotated</strong></a>(...)</dt>
 <dd><code>isAnnotated(["name"], ["deannotate=False"]) -> tuple</code>
@@ -28,6 +64,32 @@
 <p>Converts a text frame to a PDF link annotation to a file. <strong>path</strong> is the absolute or relative path to the file. <strong>page</strong> is the page in the document to link to, and <strong>x</strong> and <strong>y</strong> are the page coordinates. The currently selected frame will be converted unless another name is given. The default value for <strong>absolute</strong> is True, which means the path is absolute; if set to False the path is relative. </p>
 <p>May raise <a href="scripterapi.html#NameExistsError">NameExistsError</a> if you explicitly pass a name that doesn't exist. May raise <a href="scripterapi.html#WrongFrameTypeError">WrongFrameTypeError</a> if object is not a text frame.</p></dd>
 
+<dt><a name="-setJSActionScript"><strong>setJSActionScript</strong></a>(...)</dt>
+<dd><code>setJSActionScript(which, script, ["name"]) -> string</code>
+<p>Sets the JavaScript action for a particular event and returns NONE.</p>
+<p>Also sets the annotation's action to JavaScript.</p>
+<p>This functions accepts following arguments:
+	<ul>
+		<li><strong>which</strong> is an integer in range 0-9 describing the kind of event:</li>
+		<ul style="list-style-type:none">
+			<li>0 - Mouse Up</li>
+			<li>1 - Mouse Down</li>
+			<li>2 - Mouse Enter</li>
+			<li>3 - Mouse Exit</li>
+			<li>4 - Focus In</li>
+			<li>5 - Focus Out</li>
+			<li>6 - Selection Change</li>
+			<li>7 - Field Format</li>
+			<li>8 - Field Validate</li>
+			<li>9 - Field Calculate</li>
+		</ul>
+		<li><strong>script</strong> is the JavaScript to set to the action</li>
+		<li><strong>name</strong> is the object name. If "name" is not provided, the currently selected item will be used.</li>
+	</ul>
+</p>
+<p>Page item must be an annotation or an error will be raised. May raise <a href="scripterapi.html#NameExistsError">NameExistsError</a> if you explicitly pass a name that doesn't exist.</p></dd>
+
+
 <dt><a name="-setLinkAnnotation"><strong>setLinkAnnotation</strong></a>(...)</dt>
 <dd><code>setLinkAnnotation(page, x, y, ["name"])</code>
 <p>Converts a text frame to a PDF link annotation to a page in the current document. <strong>page</strong> is the page in the document to link to, and must be in the range of pages, starting with 1. <strong>x</strong> and <strong>y</strong> are the page coordinates. The currently selected frame will be converted unless another name is given.</p>
@@ -35,7 +97,24 @@
 
 <dt><a name="-setTextAnnotation"><strong>setTextAnnotation</strong></a>(...)</dt>
 <dd><code>setTextAnnotation(icon, isopen, ["name"])</code>
-<p>Converts a text frame to a text annotation. <strong>icon</strong> is a number 0-8 with the following key: 0 = Note, 1 = Comment, 2 = Key, 3 = Help, 4 = NewParagraph, 5 = Paragraph, 6 = Insert,7 = Cross, 8 = Circle. <strong>isopen</strong> is either True or False. The currently selected frame will be converted unless another name is given.</p>
+<p>Converts a text frame to a text annotation. Function accepts following arguments:
+	<ul>
+		<li><strong>icon</strong> is a number in range 0-8 with the following key:</li>
+		<ul style="list-style-type:none">
+			<li>0 = Note</li>
+			<li>1 = Comment</li>
+			<li>2 = Key</li>
+			<li>3 = Help</li>
+			<li>4 = NewParagraph</li>
+			<li>5 = Paragraph</li>
+			<li>6 = Insert</li>
+			<li>7 = Cross</li>
+			<li>8 = Circle</li>
+		</ul>
+		<li><strong>isopen</strong> is either True or False.</li>
+	</ul>
+</p>
+<p>The currently selected frame will be converted unless another name is given.</p>
 <p>May raise <a href="scripterapi.html#NameExistsError">NameExistsError</a> if you explicitly pass a name that doesn't exist. May raise <a href="scripterapi.html#WrongFrameTypeError">WrongFrameTypeError</a> if object is not a text frame.</p></dd>
 
 <dt><a name="-setURIAnnotation"><strong>setURIAnnotation</strong></a>(...)</dt>

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22772&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp	Sun Nov 18 14:57:45 2018
@@ -15,6 +15,163 @@
 static void setactioncoords(Annotation &a, int x, int y);
 static bool testPageItem(PageItem *i);
 static void add_text_to_dict(PyObject *drv, PageItem *i);
+
+PyObject *scribus_setjsactionscript(PyObject * /*self*/, PyObject* args)
+{
+	/*
+		Java_ReleaseButton	= 0,
+		Java_PressButton	= 1,
+		Java_EnterWidget	= 2,
+		Java_LeaveWidget	= 3,
+		Java_FocusIn		= 4,
+		Java_FocusOut		= 5,
+		Java_SelectionChg	= 6,
+		Java_FieldFormat	= 7,
+		Java_FieldValidate	= 8,
+		Java_FieldCalculate	= 9
+	*/
+	int action;
+	char *script = const_cast<char*>("");
+	char *name = const_cast<char*>("");
+
+	if (!PyArg_ParseTuple(args, "is|es",&action,&script,"utf-8", &name))
+		return nullptr;
+
+	if (action < 0 || action > 9)
+	{
+		QString qnum = QString("%1").arg(action);
+		PyErr_SetString(PyExc_RuntimeError,
+			QObject::tr("Action must be an integer in range 0-9 " + qnum.toUtf8(), "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	if (!checkHaveDocument())
+		return nullptr;
+
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (item == nullptr)
+		return nullptr;
+
+	if (item->isAnnotation() == false)
+	{
+		PyErr_SetString(PyExc_RuntimeError,
+			QObject::tr("Page item must be an annotation", "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+	
+	Annotation &annotation = item->annotation();
+	annotation.setActionType(Annotation::Action_JavaScript);
+	QString javascript = QString::fromUtf8(script); 
+
+	switch (action)
+	{
+	case Annotation::Java_ReleaseButton:
+		annotation.setAction(javascript);
+		break;
+	case Annotation::Java_PressButton:
+		annotation.setD_act(javascript);
+		break;
+	case Annotation::Java_EnterWidget:
+		annotation.setE_act(javascript);
+		break;
+	case Annotation::Java_LeaveWidget:
+		annotation.setX_act(javascript);
+		break;
+	case Annotation::Java_FocusIn:
+		annotation.setFo_act(javascript);
+		break;
+	case Annotation::Java_FocusOut:
+		annotation.setBl_act(javascript);
+		break;
+	case Annotation::Java_SelectionChg:
+		annotation.setK_act(javascript);
+		break;
+	case Annotation::Java_FieldFormat:
+		annotation.setF_act(javascript);
+		break;
+	case Annotation::Java_FieldValidate:
+		annotation.setV_act(javascript);
+		break;
+	case Annotation::Java_FieldCalculate:
+		annotation.setC_act(javascript);
+		break;
+	}
+
+	Py_RETURN_NONE;
+}
+
+PyObject *scribus_getjsactionscript(PyObject * /*self*/, PyObject* args)
+{
+	int action;
+	char *name = const_cast<char*>("");
+
+	if (!PyArg_ParseTuple(args, "i|es",&action,"utf-8", &name))
+		return nullptr;
+
+	if (action < 0 || action > 9)
+	{
+		QString qnum = QString("%1").arg(action);
+		PyErr_SetString(PyExc_RuntimeError,
+			QObject::tr("Action must be be 0-9 " + qnum.toUtf8(), "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	if (!checkHaveDocument())
+		return nullptr;
+
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (item == nullptr)
+		return nullptr;
+
+	if (item->isAnnotation() == false)
+	{
+		PyErr_SetString(PyExc_RuntimeError,
+			QObject::tr("Page item must be an annotation", "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+    Annotation &annotation = item->annotation();
+	if (annotation.ActionType() != Annotation::Action_JavaScript)
+		Py_RETURN_NONE;
+
+	QString rv;
+	switch (action)
+	{
+	case Annotation::Java_ReleaseButton:
+		rv = annotation.Action();
+		break;
+	case Annotation::Java_PressButton:
+		rv = annotation.D_act();
+		break;
+	case Annotation::Java_EnterWidget:
+		rv = annotation.E_act();
+		break;
+	case Annotation::Java_LeaveWidget:
+		rv = annotation.X_act();
+		break;
+	case Annotation::Java_FocusIn:
+		rv = annotation.Fo_act();
+		break;
+	case Annotation::Java_FocusOut:
+		rv = annotation.Bl_act();
+		break;
+	case Annotation::Java_SelectionChg:
+		rv = annotation.K_act();
+		break;
+	case Annotation::Java_FieldFormat:
+		rv = annotation.F_act();
+		break;
+	case Annotation::Java_FieldValidate:
+		rv = annotation.V_act();
+		break;
+	case Annotation::Java_FieldCalculate:
+		rv = annotation.C_act();
+		break;
+	}
+
+	PyObject *rstr = PyString_FromString(rv.toUtf8());
+	return rstr;
+}
 
 PyObject *scribus_isannotated(PyObject * /*self*/, PyObject* args, PyObject *keywds)
 {
@@ -446,7 +603,9 @@
       << scribus_setfileannotation__doc__
       << scribus_seturiannotation__doc__
       << scribus_settextannotation__doc__
-      << scribus_createpdfannotation__doc__;
+      << scribus_createpdfannotation__doc__
+      << scribus_setjsactionscript__doc__
+      << scribus_getjsactionscript__doc__;
 }
 
 
@@ -484,8 +643,8 @@
 {
 	if (i->isBookmark)
 	{
-	  i->isBookmark = false;
-	  ScCore->primaryMainWindow()->DelBookMark(i);
+		i->isBookmark = false;
+		ScCore->primaryMainWindow()->DelBookMark(i);
 	}
 	i->setIsAnnotation(true);
 }

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22772&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.h	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.h	Sun Nov 18 14:57:45 2018
@@ -157,4 +157,43 @@
 /*!creates a pdf annotation and a text frame.*/
 PyObject *scribus_createpdfannotation(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getjsactionscript__doc__,
+	QT_TR_NOOP("getJSActionScript(which,[\"name\"])\n\
+\n\
+Gets the JavaScript action for a particular event\n\
+\"which\" is one of the following:\n\
+(0 Mouse Up, 1 Mouse Down, 2 Mouse Enter,\n\
+3 Mouse Exit, 4 Focus In, 5 Focus Out,\n\
+6 Selection Change, 7 Field Format,\n\
+8 Field Validate, 9 Field Calculate)\n\
+\"name\" uses the currently selected item if not given.\n\
+Page item must be an annotation or an error will be raised.\n\
+Returns:\n\
+Returns a string if object's action type is Javascript, \n\
+NONE otherwise.\n\
+"));
+/*!gets the JavaScript for an annotation action.*/
+PyObject *scribus_getjsactionscript(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
+PyDoc_STRVAR(scribus_setjsactionscript__doc__,
+ QT_TR_NOOP("setJSActionScript(which,script,[\"name\"])\n\
+\n\
+Sets the JavaScript action for a particular event.\n\
+Also sets the annotation's action to JavaScript.\n\
+\"which\" is one of the following:\n\
+(0 Mouse Up, 1 Mouse Down, 2 Mouse Enter,\n\
+3 Mouse Exit, 4 Focus In, 5 Focus Out,\n\
+6 Selection Change, 7 Field Format,\n\
+8 Field Validate, 9 Field Calculate)\n\
+\"script\" is the JavaScript set to the action.\n\
+\"name\" uses the currently selected item if not given.\n\
+Page item must be an annotation or an error will be raised.\n\
+Returns:\n\
+None\n\
+"));
+/*!sets the JavaScript on an annotation action.*/
+PyObject *scribus_setjsactionscript(PyObject * /*self*/, PyObject* args);
+
 #endif

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22772&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	Sun Nov 18 14:57:45 2018
@@ -595,6 +595,8 @@
 	{const_cast<char*>("setTextAnnotation"), scribus_settextannotation, METH_VARARGS,tr(scribus_settextannotation__doc__)},
 	{const_cast<char*>("createPdfAnnotation"), scribus_createpdfannotation, METH_VARARGS,tr(scribus_createpdfannotation__doc__)},
 	{const_cast<char*>("isAnnotated"),(PyCFunction)scribus_isannotated, METH_VARARGS|METH_KEYWORDS,tr(scribus_isannotated__doc__)},
+	{const_cast<char*>("setJSActionScript"), scribus_setjsactionscript, METH_VARARGS,tr(scribus_setjsactionscript__doc__)},
+	{const_cast<char*>("getJSActionScript"), scribus_getjsactionscript, METH_VARARGS,tr(scribus_getjsactionscript__doc__)},
 	{nullptr, (PyCFunction)(nullptr), 0, nullptr} /* sentinel */
 };
 




More information about the scribus-commit mailing list