Author: jghali
Date: Tue May 5 02:06:49 2020
New Revision: 23687
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23687
Log:
#16001: Scripter: add getCharacterStyle()
Modified:
trunk/Scribus/doc/de/scripterapi-manobj.html
trunk/Scribus/doc/en/scripterapi-manobj.html
trunk/Scribus/doc/fr/scripterapi-manobj.html
trunk/Scribus/doc/it/scripterapi-manobj.html
trunk/Scribus/doc/ru/scripterapi-manobj.html
trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.h
trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
Modified: trunk/Scribus/doc/de/scripterapi-manobj.html
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/doc/de/scripterapi-manobj.html
==============================================================================
--- trunk/Scribus/doc/de/scripterapi-manobj.html (original)
+++ trunk/Scribus/doc/de/scripterapi-manobj.html Tue May 5 02:06:49 2020
@@ -21,9 +21,15 @@
<dd><code>duplicateObject(["name"]) -> string</code>
<p>Creates a Duplicate of the selected Object (or Selection Group).</p></dd>
+<dt><a
name="-getCharacterStyle"><strong>getCharacterStyle</strong></a>(...)</dt>
+<dd><code>getCharacterStyle(["name"])</code>
+<p>Return name of character style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
+<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default character
style is returned.</p>
+<p>May raise WrongFrameTypeError.</p></dd>
+
<dt><a
name="-getParagraphStyle"><strong>getParagraphStyle</strong></a>(...)</dt>
<dd><code>getParagraphStyle(["name"])</code>
-<p>Return name of style applied to object named "name". If "name" is not
given, the currently selected object is used.<p>
+<p>Return name of paragraph style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default style is
returned.</p>
<p>May raise WrongFrameTypeError.</p></dd>
Modified: trunk/Scribus/doc/en/scripterapi-manobj.html
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/doc/en/scripterapi-manobj.html
==============================================================================
--- trunk/Scribus/doc/en/scripterapi-manobj.html (original)
+++ trunk/Scribus/doc/en/scripterapi-manobj.html Tue May 5 02:06:49 2020
@@ -21,9 +21,15 @@
<dd><code>duplicateObject(["name"]) -> string</code>
<p>Creates a Duplicate of the selected Object (or Selection Group).</p></dd>
+<dt><a
name="-getCharacterStyle"><strong>getCharacterStyle</strong></a>(...)</dt>
+<dd><code>getCharacterStyle(["name"])</code>
+<p>Return name of character style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
+<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default character
style is returned.</p>
+<p>May raise WrongFrameTypeError.</p></dd>
+
<dt><a
name="-getParagraphStyle"><strong>getParagraphStyle</strong></a>(...)</dt>
<dd><code>getParagraphStyle(["name"])</code>
-<p>Return name of style applied to object named "name". If "name" is not
given, the currently selected object is used.<p>
+<p>Return name of paragraph style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default style is
returned.</p>
<p>May raise WrongFrameTypeError.</p></dd>
Modified: trunk/Scribus/doc/fr/scripterapi-manobj.html
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/doc/fr/scripterapi-manobj.html
==============================================================================
--- trunk/Scribus/doc/fr/scripterapi-manobj.html (original)
+++ trunk/Scribus/doc/fr/scripterapi-manobj.html Tue May 5 02:06:49 2020
@@ -21,9 +21,15 @@
<dd><code>duplicateObject(["nom"]) -> chaîne</code>
<p>Crée une copie du ou des objects sélectionnés dans le document
courant.</p></dd>
+<dt><a
name="-getCharacterStyle"><strong>getCharacterStyle</strong></a>(...)</dt>
+<dd><code>getCharacterStyle(["nom"]) -> chaîne</code>
+<p>Retourne le nom du style de caractère appliqué à l'objet "nom". Si aucun
nom d'objet n'est fourni, l'élément sélectionné est utilisé.</p>
+<p>Si l'objet courant possède une sélection de texte, le nom retourné
est celui du style appliqué au début de la sélection. Sinon le nom retourné
est celui du style de caractère appliqué par défaut.</p>
+<p>Peut générer l'exception WrongFrameTypeError.</p></dd>
+
<dt><a
name="-getParagraphStyle"><strong>getParagraphStyle</strong></a>(...)</dt>
<dd><code>getParagraphStyle(["nom"]) -> chaîne</code>
-<p>Retourne le nom du style appliqué à l'objet "nom". Si aucun nom d'objet
n'est fourni, l'élément sélectionné est utilisé.</p>
+<p>Retourne le nom du style de paragraphe appliqué à l'objet "nom". Si aucun
nom d'objet n'est fourni, l'élément sélectionné est utilisé.</p>
<p>Si l'objet courant possède une sélection de texte, le nom retourné
est celui du style appliqué au début de la sélection. Sinon le nom retourné
est celui du style appliqué par défaut.</p>
<p>Peut générer l'exception WrongFrameTypeError.</p></dd>
Modified: trunk/Scribus/doc/it/scripterapi-manobj.html
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/doc/it/scripterapi-manobj.html
==============================================================================
--- trunk/Scribus/doc/it/scripterapi-manobj.html (original)
+++ trunk/Scribus/doc/it/scripterapi-manobj.html Tue May 5 02:06:49 2020
@@ -21,9 +21,15 @@
<dd><code>duplicateObject(["name"]) -> string</code>
<p>Creates a Duplicate of the selected Object (or Selection Group).</p></dd>
+<dt><a
name="-getCharacterStyle"><strong>getCharacterStyle</strong></a>(...)</dt>
+<dd><code>getCharacterStyle(["name"])</code>
+<p>Return name of character style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
+<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default character
style is returned.</p>
+<p>May raise WrongFrameTypeError.</p></dd>
+
<dt><a
name="-getParagraphStyle"><strong>getParagraphStyle</strong></a>(...)</dt>
<dd><code>getParagraphStyle(["name"])</code>
-<p>Return name of style applied to object named "name". If "name" is not
given, the currently selected object is used.<p>
+<p>Return name of paragraph style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default style is
returned.</p>
<p>May raise WrongFrameTypeError.</p></dd>
Modified: trunk/Scribus/doc/ru/scripterapi-manobj.html
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/doc/ru/scripterapi-manobj.html
==============================================================================
--- trunk/Scribus/doc/ru/scripterapi-manobj.html (original)
+++ trunk/Scribus/doc/ru/scripterapi-manobj.html Tue May 5 02:06:49 2020
@@ -21,9 +21,15 @@
<dd><code>duplicateObject(["name"]) -> string</code>
<p>Creates a Duplicate of the selected Object (or Selection Group).</p></dd>
+<dt><a
name="-getCharacterStyle"><strong>getCharacterStyle</strong></a>(...)</dt>
+<dd><code>getCharacterStyle(["name"])</code>
+<p>Return name of character style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
+<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default character
style is returned.</p>
+<p>May raise WrongFrameTypeError.</p></dd>
+
<dt><a
name="-getParagraphStyle"><strong>getParagraphStyle</strong></a>(...)</dt>
<dd><code>getParagraphStyle(["name"])</code>
-<p>Return name of style applied to object named "name". If "name" is not
given, the currently selected object is used.<p>
+<p>Return name of paragraph style applied to object named "name". If "name" is
not given, the currently selected object is used.<p>
<p>If current object has a text selection, the name of style applied to start
of selection is returned. Otherwise the name of the item default style is
returned.</p>
<p>May raise WrongFrameTypeError.</p></dd>
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp Tue May 5
02:06:49 2020
@@ -579,6 +579,41 @@
return PyBool_FromLong(static_cast<long>(false));
}
+PyObject *scribus_getcharacterstyle(PyObject* /* self */, PyObject* args)
+{
+ char *name = const_cast<char*>("");
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
+ return NULL;
+ if (!checkHaveDocument())
+ return NULL;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == NULL)
+ return NULL;
+ if ((item->itemType() != PageItem::TextFrame) && (item->itemType() !=
PageItem::PathText))
+ {
+ PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get
character style of a non-text frame.", "python
error").toLocal8Bit().constData());
+ return NULL;
+ }
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ StoryText& itemText = item->itemText;
+
+ int selectionLength = itemText.selectionLength();
+ if ((selectionLength > 0) || (currentDoc->appMode == modeEdit))
+ {
+ int cursorPos = (selectionLength > 0) ?
itemText.startOfSelection() : itemText.cursorPosition();
+ const CharStyle& currentStyle = itemText.charStyle(cursorPos);
+ if (currentStyle.hasParent())
+ return
PyUnicode_FromString(currentStyle.parentStyle()->name().toUtf8());
+ }
+ else
+ {
+ const CharStyle& itemDefaultStyle =
itemText.defaultStyle().charStyle();
+ if (itemDefaultStyle.hasParent())
+ return
PyUnicode_FromString(itemDefaultStyle.parentStyle()->name().toUtf8());
+ }
+ Py_RETURN_NONE;
+};
/*
* Vaclav Smilauer, 2017-21-21
@@ -600,11 +635,14 @@
return NULL;
}
- int selectionLength = item->itemText.selectionLength();
- if (selectionLength > 0)
- {
- int selectionStart = item->itemText.startOfSelection();
- const ParagraphStyle& currentStyle =
item->itemText.paragraphStyle(selectionStart);
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ StoryText& itemText = item->itemText;
+
+ int selectionLength = itemText.selectionLength();
+ if ((selectionLength > 0) || (currentDoc->appMode == modeEdit))
+ {
+ int cursorPos = (selectionLength > 0) ?
itemText.startOfSelection() : itemText.cursorPosition();
+ const ParagraphStyle& currentStyle =
itemText.paragraphStyle(cursorPos);
if (currentStyle.hasParent())
return
PyUnicode_FromString(currentStyle.parentStyle()->name().toUtf8());
}
@@ -900,6 +938,7 @@
<< scribus_copyobject__doc__
<< scribus_deleteobj__doc__
<< scribus_duplicateobject__doc__
+ << scribus_getcharacterstyle__doc__
<< scribus_getcharstylenames__doc__
<< scribus_getparagraphstyle__doc__
<< scribus_getstyle__doc__
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.h
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.h Tue May 5 02:06:49 2020
@@ -234,13 +234,22 @@
*/
PyObject *scribus_objectexists(PyObject * /*self*/, PyObject* args);
-
+/*! docstring */
+PyDoc_STRVAR(scribus_getcharacterstyle__doc__,
+QT_TR_NOOP("getCharacterStyle([\"name\"])\n\
+\n\
+Return name of character style applied to object named \"name\". If \"name\"
is not given,\n\
+the currently selected object is used. If current object has a text selection,
\n\
+the name of style applied to start of selection is returned. Otherwise the
name \n\
+of the item default character style is returned.\n\
+"));
+PyObject *scribus_getcharacterstyle(PyObject * /*self*/, PyObject* args);
/*! docstring */
PyDoc_STRVAR(scribus_getparagraphstyle__doc__,
QT_TR_NOOP("getParagraphStyle([\"name\"])\n\
\n\
-Return name of style applied to object named \"name\". If \"name\" is not
given,\n\
+Return name of paragraph style applied to object named \"name\". If \"name\"
is not given,\n\
the currently selected object is used. If current object has a text selection,
\n\
the name of style applied to start of selection is returned. Otherwise the
name \n\
of the item default style is returned.\n\
@@ -282,7 +291,7 @@
/*! docstring */
PyDoc_STRVAR(scribus_setcharstyle__doc__,
- QT_TR_NOOP("setCharacterStyle(\"style\" [, \"name\"])\n\
+QT_TR_NOOP("setCharacterStyle(\"style\" [, \"name\"])\n\
\n\
Apply the named character \"style\" to the object named \"name\". If object
name is\n\
given, style is applied to the current text selection in object \"name\".\n\
Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL:
http://scribus.net/websvn/diff.php?repname=Scribus&rev=23687&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp Tue May 5
02:06:49 2020
@@ -338,6 +338,7 @@
{const_cast<char*>("getCellColumnSpan"), scribus_getcellcolumnspan,
METH_VARARGS, tr(scribus_getcellcolumnspan__doc__)},
{const_cast<char*>("getCellRowSpan"), scribus_getcellrowspan,
METH_VARARGS, tr(scribus_getcellrowspan__doc__)},
{const_cast<char*>("getCellFillColor"), scribus_getcellfillcolor,
METH_VARARGS, tr(scribus_getcellfillcolor__doc__)},
+ {const_cast<char*>("getCharacterStyle"), scribus_getcharacterstyle,
METH_VARARGS, tr(scribus_getcharacterstyle__doc__) },
{const_cast<char*>("getCharStyles"),
(PyCFunction)scribus_getcharstylenames, METH_NOARGS,
tr(scribus_getcharstylenames__doc__)},
{const_cast<char*>("getColorNames"), (PyCFunction)scribus_colornames,
METH_NOARGS, tr(scribus_colornames__doc__)},
{const_cast<char*>("getColor"), scribus_getcolor, METH_VARARGS,
tr(scribus_getcolor__doc__)},
_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit