View Issue Details

IDProjectCategoryView StatusLast Update
0015171ScribusScripterpublic2018-02-26 13:59
Reporterale Assigned To 
PrioritynormalSeverityminorReproducibilityN/A
Status newResolutionopen 
Product Version1.5.4.svn 
Summary0015171: scripter: add isexportable command
Descriptioncheck if an item is exportable (printable) in the same way it checks if it is visible.

patch is attached.
TagsNo tags attached.
PatchNo

Activities

ale

2018-02-25 17:21

manager  

isexportable.diff (5,067 bytes)   
diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp
index c77e0bdfbf..9739270179 100644
--- a/scribus/plugins/scriptplugin/cmdmani.cpp
+++ b/scribus/plugins/scriptplugin/cmdmani.cpp
@@ -503,6 +503,39 @@ PyObject *scribus_deselect(PyObject* /* self */)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_exportableobject(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;
+	item->togglePrintEnabled();
+	if (item->locked())
+		return PyInt_FromLong(1);
+	return PyInt_FromLong(0);
+}
+
+PyObject *scribus_isexportable(PyObject* /* self */, PyObject* args)
+{
+	char *name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
+		return NULL;
+	// FIXME: Rather than toggling the lock, we should probably let the user set the lock state
+	// and instead provide a different function like toggleLock()
+	if(!checkHaveDocument())
+		return NULL;
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (item == NULL)
+		return NULL;
+	if (item->printEnabled())
+		return PyBool_FromLong(1);
+	return PyBool_FromLong(0);
+}
+
 PyObject *scribus_lockobject(PyObject* /* self */, PyObject* args)
 {
 	char *name = const_cast<char*>("");
@@ -628,6 +661,8 @@ void cmdmanidocwarnings()
 	  << scribus_ungroupobj__doc__ << scribus_scalegroup__doc__
 	  << scribus_loadimage__doc__ << scribus_scaleimage__doc__
 	  << scribus_setimagescale__doc__ << scribus_lockobject__doc__
-	  << scribus_islocked__doc__ << scribus_setscaleimagetoframe__doc__ << scribus_setimagebrightness__doc__ << scribus_setimagegrayscale__doc__ << scribus_setimageoffset__doc__
+	  << scribus_islocked__doc__
+	  << scribus_exportablebject__doc__ << scribus_isexportable__doc__ <<
+      scribus_setscaleimagetoframe__doc__ << scribus_setimagebrightness__doc__ << scribus_setimagegrayscale__doc__ << scribus_setimageoffset__doc__
 	  << scribus_flipobject__doc__;
 }
diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h
index cfef82da19..fbc53d2201 100644
--- a/scribus/plugins/scriptplugin/cmdmani.h
+++ b/scribus/plugins/scriptplugin/cmdmani.h
@@ -220,6 +220,27 @@ May raise WrongFrameTypeError if the target frame is not an image frame\n\
 /*! Set Image Brightness. */
 PyObject *scribus_setimagegrayscale(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_exportablebject__doc__,
+QT_TR_NOOP("exportableObject([\"name\"]) -> bool\n\
+\n\
+Sets the object \"name\" as exportable if it's not (or viceversa).\n\
+If \"name\" is not given the currently selected item is used. Returns true\n\
+if exportable.\n\
+"));
+/*! (Un)Lock the object 2004/7/10 pv.*/
+PyObject *scribus_exportableobject(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
+PyDoc_STRVAR(scribus_isexportable__doc__,
+QT_TR_NOOP("isExportable([\"name\"]) -> bool\n\
+\n\
+Returns true if is the object \"name\" is exportable.  If \"name\" is not given the\n\
+currently selected item is used.\n\
+"));
+/*! Status of locking 2004/7/10 pv.*/
+PyObject *scribus_isexportable(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_lockobject__doc__,
 QT_TR_NOOP("lockObject([\"name\"]) -> bool\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 57854c83bc..cd0761c98f 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -433,10 +433,12 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("isLayerLocked"), scribus_glayerlock, METH_VARARGS, tr(scribus_glayerlock__doc__)},
 	{const_cast<char*>("isLayerOutlined"), scribus_glayeroutline, METH_VARARGS, tr(scribus_glayeroutline__doc__)},
 	{const_cast<char*>("isLayerFlow"), scribus_glayerflow, METH_VARARGS, tr(scribus_glayerflow__doc__)},
+	{const_cast<char*>("isExportable"), scribus_isexportable, METH_VARARGS, tr(scribus_isexportable__doc__)},
 	{const_cast<char*>("isLocked"), scribus_islocked, METH_VARARGS, tr(scribus_islocked__doc__)},
 	{const_cast<char*>("linkTextFrames"), scribus_linktextframes, METH_VARARGS, tr(scribus_linktextframes__doc__)},
 	{const_cast<char*>("loadImage"), scribus_loadimage, METH_VARARGS, tr(scribus_loadimage__doc__)},
 	{const_cast<char*>("loadStylesFromFile"), scribus_loadstylesfromfile, METH_VARARGS, tr(scribus_loadstylesfromfile__doc__)},
+	{const_cast<char*>("exportableObject"), scribus_exportableobject, METH_VARARGS, tr(scribus_exportablebject__doc__)},
 	{const_cast<char*>("lockObject"), scribus_lockobject, METH_VARARGS, tr(scribus_lockobject__doc__)},
 	{const_cast<char*>("masterPageNames"), (PyCFunction)scribus_masterpagenames, METH_NOARGS, tr(scribus_masterpagenames__doc__)},
 	{const_cast<char*>("mergeTableCells"), scribus_mergetablecells, METH_VARARGS, tr(scribus_mergetablecells__doc__)},
isexportable.diff (5,067 bytes)   

jghali

2018-02-25 18:04

administrator   ~0044986

Two remarks:
- why not name those functions isPrintable() / setPrintableObject() which would match what we have in UI?
- in scriptplugin.cpp, new methods are usually inserted into scribus_methods[] array in alphabetical order

ale

2018-02-26 13:59

manager   ~0044992

- because is not about being printable but being exportable...
- feel free to reorder it... and perhaps document the order... even if it will be hard to see anyway, in a 300LOC function

if you're comfortable with applying a patch from github, i can update my pull request there... otherwise, please patch the diff to suit your wishes.

Issue History

Date Modified Username Field Change
2018-02-25 17:21 ale New Issue
2018-02-25 17:21 ale File Added: isexportable.diff
2018-02-25 18:04 jghali Note Added: 0044986
2018-02-25 18:04 jghali Category - => Scripter
2018-02-26 13:59 ale Note Added: 0044992