View Issue Details

IDProjectCategoryView StatusLast Update
0015403ScribusScripterpublic2019-06-04 20:56
Reportereudoxos Assigned Tojghali  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformLinusOSUbuntu 18.04 
Product Version1.5.4.svn 
Fixed in Version1.5.5.svn 
Summary0015403: scripter: getStyle for obtaining frame style
DescriptionThis is patch converted from github, which was also requested at the mailing list. Diff against github's head.
Tagsscripter
PatchYes

Activities

eudoxos

2018-08-17 11:47

reporter  

scribus-scripter-getstyle.patch (5,333 bytes)   
diff --git a/scribus/plugins/scriptplugin/cmdobj.cpp b/scribus/plugins/scriptplugin/cmdobj.cpp
index d9a89675b..28bd20f9a 100644
--- a/scribus/plugins/scriptplugin/cmdobj.cpp
+++ b/scribus/plugins/scriptplugin/cmdobj.cpp
@@ -580,39 +580,6 @@ PyObject *scribus_objectexists(PyObject* /* self */, PyObject* args)
 	return PyBool_FromLong(static_cast<long>(false));
 }
 
-
-/*
- * Vaclav Smilauer, 2017-21-21
- * Return style name of the obejct (or currently selected object)
- */
-PyObject *scribus_getstyle(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 style of a non-text frame.", "python error").toLocal8Bit().constData());
-		return NULL;
-	}
-	//std::cerr<<"itemtext default style: "<<item->itemText.defaultStyle().name().toStdString()<<std::endl;
-	//std::cerr<<"itemtext default style: "<<item->itemText.defaultStyle().name().toStdString()<<std::endl;
-	//if(item->itemText.defaultStyle().hasParent()){
-	//	std::cerr<<"itemtext default parent style: "<<item->itemText.defaultStyle().parentStyle()->name().toStdString()<<std::endl;
-	//}
-	//std::cerr<<"itemtext current style: "<<item->itemText.paragraphStyle().name().toStdString()<<std::endl;
-	//std::cerr<<"style: "<<item->currentStyle().name().toStdString()<<std::endl;
-	if(item->itemText.defaultStyle().hasParent()) return PyString_FromString(item->itemText.defaultStyle().parentStyle()->name().toUtf8());
-	Py_RETURN_NONE;
-};
-
-
-
 /*
  * Craig Ringer, 2004-09-09
  * Apply the named style to the currently selected object.
@@ -891,5 +858,5 @@ PV */
 void cmdobjdocwarnings()
 {
 	QStringList s;
-	s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_getstyle__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_duplicateobject__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__;
+	s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_duplicateobject__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__;
 }
diff --git a/scribus/plugins/scriptplugin/cmdobj.h b/scribus/plugins/scriptplugin/cmdobj.h
index 08b6acb7f..1acf273f7 100644
--- a/scribus/plugins/scriptplugin/cmdobj.h
+++ b/scribus/plugins/scriptplugin/cmdobj.h
@@ -234,22 +234,6 @@ ObjectName is now optional. When none set, search for selection...
 */
 PyObject *scribus_objectexists(PyObject * /*self*/, PyObject* args);
 
-
-
-/*! docstring */
-PyDoc_STRVAR(scribus_getstyle__doc__,
-QT_TR_NOOP("getStyle([\"name\"])\n\
-\n\
-Return style name of the object named \"name\". If no object name is given,\n\
-style of the selected object is returned.\n\
-"));
-/**
- Vaclav Smilauer, 2017-12-21
- Return style name of the obejct (or currently selected object)
- */
-PyObject *scribus_getstyle(PyObject * /*self*/, PyObject* args);
-
-
 /*! docstring */
 PyDoc_STRVAR(scribus_setstyle__doc__,
 QT_TR_NOOP("setStyle(\"style\" [, \"name\"])\n\
@@ -265,7 +249,6 @@ If no object name is given, style is applied on selected object.\n\
  */
 PyObject *scribus_setstyle(PyObject * /*self*/, PyObject* args);
 
-
 /*! docstring */
 PyDoc_STRVAR(scribus_setcharstyle__doc__,
 	QT_TR_NOOP("setCharacterStyle(\"style\" [, \"name\"])\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 01a71eb18..57854c83b 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -541,7 +541,6 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("hyphenateText"), scribus_hyphenatetext, METH_VARARGS, tr(scribus_hyphenatetext__doc__)},
 	{const_cast<char*>("dehyphenateText"), scribus_dehyphenatetext, METH_VARARGS, tr(scribus_dehyphenatetext__doc__)},
 	{const_cast<char*>("setScaleImageToFrame"), (PyCFunction)scribus_setscaleimagetoframe, METH_KEYWORDS, tr(scribus_setscaleimagetoframe__doc__)},
-	{const_cast<char*>("getStyle"), scribus_getstyle, METH_VARARGS, tr(scribus_getstyle__doc__)},
 	{const_cast<char*>("setStyle"), scribus_setstyle, METH_VARARGS, tr(scribus_setstyle__doc__)},
 	{const_cast<char*>("setCharacterStyle"), scribus_setcharstyle, METH_VARARGS, tr(scribus_setcharstyle__doc__) },
 	{const_cast<char*>("setTableStyle"), scribus_settablestyle, METH_VARARGS, tr(scribus_settablestyle__doc__)},

ale

2018-08-17 13:27

manager   ~0045388

euh... i think you did your patch in the wrong way round...

it removes the lines instead of adding them...

i have not tried it, but i fear that it only can return the paragraph style name applied to the frame (a think that is an aberration and leads to many error in scribus, btw...) and not the style in a specific text selection.
if it's so, i'm not sure that the patch should be accepted, since most people will want to get the style applied to a specific text selection...
and they will be very deceived to find out that it does not work they they would expect.
but if you have a use case thta needs such a command...

eudoxos

2018-08-17 14:42

reporter   ~0045391

> but if you have a use case thta needs such a command...
Yes, I do :) obviously. A frame which contains all test styled the same, then I can change the style of all text in that frame.

Plus, if you look at setStyle:

   setStyle(...)
   setStyle("style" [, "name"])
   Apply the named "style" to the object named "name". If object name is given, style is applied to the current text selection in object "name". If no object name is given, style is applied on selected object.

then this is just its symmetric getter. I needed to set style but only conditionally based on current style and was not able to query it.

ale

2018-08-17 15:19

manager   ~0045394

if you fix the patch, i can test it...

eudoxos

2018-08-17 16:10

reporter   ~0045398

Last edited: 2018-08-17 16:31

This one, again append .diff and that should be it - is that okay for you?

https://github.com/eudoxos/scribus/commit/27be147502016b11599ecf5401444b6d9344ffa8.diff

jghali

2018-08-27 21:00

administrator   ~0045417

Yes it's ok. I brought some modifications to the patch tho in order to make behavior of new function closer to other text related function, ie if object has a text selection, the name returned will be the one of style applied at start of selection, otherwise it will be the name of style applied at frame level.

eudoxos

2018-08-28 05:20

reporter   ~0045419

Thanks for adjusting & merging. Cheers!

Issue History

Date Modified Username Field Change
2018-08-17 11:47 eudoxos New Issue
2018-08-17 11:47 eudoxos File Added: scribus-scripter-getstyle.patch
2018-08-17 11:47 eudoxos Tag Attached: scripter
2018-08-17 13:27 ale Note Added: 0045388
2018-08-17 14:42 eudoxos Note Added: 0045391
2018-08-17 15:19 ale Note Added: 0045394
2018-08-17 16:10 eudoxos Note Added: 0045398
2018-08-17 16:31 ale Note Edited: 0045398
2018-08-27 20:55 jghali Summary scripter: getStyle for obtaining frame style (complements already existing setStyle) => scripter: getStyle for obtaining frame style
2018-08-27 21:00 jghali Assigned To => jghali
2018-08-27 21:00 jghali Status new => resolved
2018-08-27 21:00 jghali Resolution open => fixed
2018-08-27 21:00 jghali Fixed in Version => 1.5.5.svn
2018-08-27 21:00 jghali Note Added: 0045417
2018-08-28 05:20 eudoxos Note Added: 0045419
2019-06-04 20:56 cbradney Status resolved => closed