View Issue Details

IDProjectCategoryView StatusLast Update
0010970ScribusScripterpublic2024-03-14 21:18
Reporterale Assigned Toale  
PrioritynormalSeverityfeatureReproducibilityN/A
Status assignedResolutionopen 
Product Version1.5.0svn 
Summary0010970: [PATCH] new scripter: make sure that one can choose the page of the pdf loaded into an image frame
Descriptionmake sure that one can choose the page of the pdf loaded into an image frame
TagsNo tags attached.
PatchYes

Activities

ale

2024-03-13 21:18

manager   ~0051031

as a reaction to https://forums.scribus.net/index.php/topic,2044.msg22990.html#msg22990 , i have created a patch adding setImagePage() and getImagePage()

ale

2024-03-14 06:30

manager   ~0051032

somehow, the diff has not been attached to my post...
get-set-image-page.diff (6,981 bytes)   
diff --git a/scribus/plugins/scriptplugin/cmdgetprop.cpp b/scribus/plugins/scriptplugin/cmdgetprop.cpp
index ef0eecae8..98a1e3335 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.cpp
+++ b/scribus/plugins/scriptplugin/cmdgetprop.cpp
@@ -261,6 +261,22 @@ PyObject *scribus_getimageoffset(PyObject* /* self */, PyObject* args)
 	return Py_BuildValue("(ff)", item->imageXOffset() * item->imageXScale(), item->imageYOffset() * item->imageYScale());
 }
 
+PyObject *scribus_getimagepage(PyObject* /* self */, PyObject* args)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return nullptr;
+
+	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+	if (item == nullptr)
+		return nullptr;
+
+	return PyLong_FromLong(static_cast<long>(item->pixm.imgInfo.actualPageNumber));
+}
+
 PyObject *scribus_getimagescale(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -478,6 +494,7 @@ void cmdgetpropdocwarnings()
 	  << scribus_getimagecolorspace__doc__
 	  << scribus_getimagefile__doc__
 	  << scribus_getimageoffset__doc__
+	  << scribus_getimagepage__doc__
 	  << scribus_getimagescale__doc__
 	  << scribus_getlinecolor__doc__ 
 	  << scribus_getlineblendmode__doc__ 
diff --git a/scribus/plugins/scriptplugin/cmdgetprop.h b/scribus/plugins/scriptplugin/cmdgetprop.h
index 3ea399b4d..3e0965698 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.h
+++ b/scribus/plugins/scriptplugin/cmdgetprop.h
@@ -206,6 +206,17 @@ frame \"name\".  If \"name\" is not given the currently selected item is used.\n
 /*! Returns image scale of the object */
 PyObject *scribus_getimageoffset(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getimagepage__doc__,
+	QT_TR_NOOP("getImagePage([\"name\"]) -> (x,y)\n\
+\n\
+Return the page for multiple page images (like PDFs) in the image frame \"name\".\n\
+0 means that the value is set to \"auto\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+"));
+/*! Returns image scale of the object */
+PyObject *scribus_getimagepage(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_getimagescale__doc__,
 	QT_TR_NOOP("getImageScale([\"name\"]) -> (x,y)\n\
diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp
index 991325bab..8ecd2e1ef 100644
--- a/scribus/plugins/scriptplugin/cmdmani.cpp
+++ b/scribus/plugins/scriptplugin/cmdmani.cpp
@@ -78,6 +78,39 @@ PyObject *scribus_scaleimage(PyObject* /* self */, PyObject* args)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_setimagepage(PyObject* /* self */, PyObject* args)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+
+	char *name = const_cast<char*>("");
+	int page;
+	if (!PyArg_ParseTuple(args, "i|es", &page, "utf-8", &name))
+		return nullptr;
+
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (item == nullptr)
+		return nullptr;
+	if (!item->isImageFrame())
+	{
+		PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	if (page < 0 || page > item->pixm.imgInfo.numberOfPages)
+	{
+		PyErr_SetString(ScribusException, QObject::tr("The image has %1 pages: cannot switch to page %2.","python error").arg(item->pixm.imgInfo.numberOfPages).arg(page).toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	item->pixm.imgInfo.actualPageNumber = page;
+
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	currentDoc->updatePic();
+
+	Py_RETURN_NONE;
+}
+
 PyObject *scribus_setimagescale(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -792,6 +825,7 @@ void cmdmanidocwarnings()
 	  << scribus_setimagebrightness__doc__
 	  << scribus_setimagegrayscale__doc__
 	  << scribus_setimageoffset__doc__
+	  << scribus_setimagepage__doc__
 	  << scribus_setimagescale__doc__
 	  << scribus_setnormalmode__doc__
 	  << scribus_setrotation__doc__
diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h
index c3858210e..a15df7dd8 100644
--- a/scribus/plugins/scriptplugin/cmdmani.h
+++ b/scribus/plugins/scriptplugin/cmdmani.h
@@ -222,6 +222,18 @@ May raise WrongFrameTypeError if the target frame is not an image frame\n\
 /*! Scale Image. */
 PyObject *scribus_setimageoffset(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_setimagepage__doc__,
+QT_TR_NOOP("setImagePage(page [, \"name\"])\n\
+\n\
+Set the page for multiple page images (like PDFs) in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used. The number must be between 0\n\
+(\"auto\") and the actual number of pages.\n\
+\n\
+May raise WrongFrameTypeError if the target frame is not an image frame\n\
+"));
+PyObject *scribus_setimagepage(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setimagescale__doc__,
 QT_TR_NOOP("setImageScale(x, y [, \"name\"])\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 10ba25c84..54527b38a 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -370,6 +370,7 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("getImageColorSpace"), scribus_getimagecolorspace, METH_VARARGS, tr(scribus_getimagecolorspace__doc__) },
 	{const_cast<char*>("getImageFile"), scribus_getimagefile, METH_VARARGS, tr(scribus_getimagefile__doc__)},
 	{const_cast<char*>("getImageOffset"), scribus_getimageoffset, METH_VARARGS, tr(scribus_getimageoffset__doc__)},
+	{const_cast<char*>("getImagePage"), scribus_getimagepage, METH_VARARGS, tr(scribus_getimagepage__doc__)},
 	{const_cast<char*>("getImageScale"), scribus_getimagescale, METH_VARARGS, tr(scribus_getimagescale__doc__)},
 	{const_cast<char*>("getInfo"), (PyCFunction)scribus_getinfo, METH_VARARGS, tr(scribus_getinfo__doc__)},
 	{const_cast<char*>("getItemPageNumber"), scribus_getitempagenumber, METH_VARARGS, tr(scribus_getitempagenumber__doc__)},
@@ -538,6 +539,7 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("setImageBrightness"), scribus_setimagebrightness, METH_VARARGS, tr(scribus_setimagebrightness__doc__)},
 	{const_cast<char*>("setImageGrayscale"), scribus_setimagegrayscale, METH_VARARGS, tr(scribus_setimagegrayscale__doc__)},
 	{const_cast<char*>("setImageOffset"), scribus_setimageoffset, METH_VARARGS, tr(scribus_setimageoffset__doc__)},
+	{const_cast<char*>("setImagePage"), scribus_setimagepage, METH_VARARGS, tr(scribus_setimagepage__doc__)},
 	{const_cast<char*>("setImageScale"), scribus_setimagescale, METH_VARARGS, tr(scribus_setimagescale__doc__)},
 	{const_cast<char*>("setInfo"), scribus_setinfo, METH_VARARGS, tr(scribus_setinfo__doc__)},
 	{const_cast<char*>("setItemName"), scribus_setitemname, METH_VARARGS, tr(scribus_setitemname__doc__)},
get-set-image-page.diff (6,981 bytes)   

ale

2024-03-14 21:18

manager   ~0051040

a new version of the patch that also adds getImagePageCount()

with this, it should be trivial to create a script that adds a page with an image frame for each page in the pdf, as requested in the forum post linked above.
get-set-image-page-2.diff (7,997 bytes)   
diff --git a/scribus/plugins/scriptplugin/cmdgetprop.cpp b/scribus/plugins/scriptplugin/cmdgetprop.cpp
index ef0eecae8..25ce0d96d 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.cpp
+++ b/scribus/plugins/scriptplugin/cmdgetprop.cpp
@@ -261,6 +261,38 @@ PyObject *scribus_getimageoffset(PyObject* /* self */, PyObject* args)
 	return Py_BuildValue("(ff)", item->imageXOffset() * item->imageXScale(), item->imageYOffset() * item->imageYScale());
 }
 
+PyObject *scribus_getimagepage(PyObject* /* self */, PyObject* args)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return nullptr;
+
+	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+	if (item == nullptr)
+		return nullptr;
+
+	return PyLong_FromLong(static_cast<long>(item->pixm.imgInfo.actualPageNumber));
+}
+
+PyObject *scribus_getimagepagecount(PyObject* /* self */, PyObject* args)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return nullptr;
+
+	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+	if (item == nullptr)
+		return nullptr;
+
+	return PyLong_FromLong(static_cast<long>(item->pixm.imgInfo.numberOfPages));
+}
+
 PyObject *scribus_getimagescale(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -478,6 +510,8 @@ void cmdgetpropdocwarnings()
 	  << scribus_getimagecolorspace__doc__
 	  << scribus_getimagefile__doc__
 	  << scribus_getimageoffset__doc__
+	  << scribus_getimagepage__doc__
+	  << scribus_getimagepagecount__doc__
 	  << scribus_getimagescale__doc__
 	  << scribus_getlinecolor__doc__ 
 	  << scribus_getlineblendmode__doc__ 
diff --git a/scribus/plugins/scriptplugin/cmdgetprop.h b/scribus/plugins/scriptplugin/cmdgetprop.h
index 3ea399b4d..0c68e4f82 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.h
+++ b/scribus/plugins/scriptplugin/cmdgetprop.h
@@ -206,6 +206,27 @@ frame \"name\".  If \"name\" is not given the currently selected item is used.\n
 /*! Returns image scale of the object */
 PyObject *scribus_getimageoffset(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getimagepage__doc__,
+	QT_TR_NOOP("getImagePage([\"name\"]) -> (x,y)\n\
+\n\
+Return the page for multiple page images (like PDFs) in the image frame \"name\".\n\
+0 means that the value is set to \"auto\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+"));
+/*! Returns the current of page of the object */
+PyObject *scribus_getimagepage(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
+PyDoc_STRVAR(scribus_getimagepagecount__doc__,
+	QT_TR_NOOP("getImagePageCount([\"name\"]) -> (x,y)\n\
+\n\
+Return the number of pages for multiple page images (like PDFs) in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+"));
+/*! Returns the number of pages of the object */
+PyObject *scribus_getimagepagecount(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_getimagescale__doc__,
 	QT_TR_NOOP("getImageScale([\"name\"]) -> (x,y)\n\
diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp
index 991325bab..8ecd2e1ef 100644
--- a/scribus/plugins/scriptplugin/cmdmani.cpp
+++ b/scribus/plugins/scriptplugin/cmdmani.cpp
@@ -78,6 +78,39 @@ PyObject *scribus_scaleimage(PyObject* /* self */, PyObject* args)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_setimagepage(PyObject* /* self */, PyObject* args)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+
+	char *name = const_cast<char*>("");
+	int page;
+	if (!PyArg_ParseTuple(args, "i|es", &page, "utf-8", &name))
+		return nullptr;
+
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (item == nullptr)
+		return nullptr;
+	if (!item->isImageFrame())
+	{
+		PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	if (page < 0 || page > item->pixm.imgInfo.numberOfPages)
+	{
+		PyErr_SetString(ScribusException, QObject::tr("The image has %1 pages: cannot switch to page %2.","python error").arg(item->pixm.imgInfo.numberOfPages).arg(page).toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	item->pixm.imgInfo.actualPageNumber = page;
+
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	currentDoc->updatePic();
+
+	Py_RETURN_NONE;
+}
+
 PyObject *scribus_setimagescale(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -792,6 +825,7 @@ void cmdmanidocwarnings()
 	  << scribus_setimagebrightness__doc__
 	  << scribus_setimagegrayscale__doc__
 	  << scribus_setimageoffset__doc__
+	  << scribus_setimagepage__doc__
 	  << scribus_setimagescale__doc__
 	  << scribus_setnormalmode__doc__
 	  << scribus_setrotation__doc__
diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h
index c3858210e..a15df7dd8 100644
--- a/scribus/plugins/scriptplugin/cmdmani.h
+++ b/scribus/plugins/scriptplugin/cmdmani.h
@@ -222,6 +222,18 @@ May raise WrongFrameTypeError if the target frame is not an image frame\n\
 /*! Scale Image. */
 PyObject *scribus_setimageoffset(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_setimagepage__doc__,
+QT_TR_NOOP("setImagePage(page [, \"name\"])\n\
+\n\
+Set the page for multiple page images (like PDFs) in the image frame \"name\".\n\
+If \"name\" is not given the currently selected item is used. The number must be between 0\n\
+(\"auto\") and the actual number of pages.\n\
+\n\
+May raise WrongFrameTypeError if the target frame is not an image frame\n\
+"));
+PyObject *scribus_setimagepage(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setimagescale__doc__,
 QT_TR_NOOP("setImageScale(x, y [, \"name\"])\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index be2452f3d..0839a0031 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -371,6 +371,8 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("getImageColorSpace"), scribus_getimagecolorspace, METH_VARARGS, tr(scribus_getimagecolorspace__doc__) },
 	{const_cast<char*>("getImageFile"), scribus_getimagefile, METH_VARARGS, tr(scribus_getimagefile__doc__)},
 	{const_cast<char*>("getImageOffset"), scribus_getimageoffset, METH_VARARGS, tr(scribus_getimageoffset__doc__)},
+	{const_cast<char*>("getImagePage"), scribus_getimagepage, METH_VARARGS, tr(scribus_getimagepage__doc__)},
+	{const_cast<char*>("getImagePageCount"), scribus_getimagepagecount, METH_VARARGS, tr(scribus_getimagepage__doc__)},
 	{const_cast<char*>("getImageScale"), scribus_getimagescale, METH_VARARGS, tr(scribus_getimagescale__doc__)},
 	{const_cast<char*>("getInfo"), (PyCFunction)scribus_getinfo, METH_VARARGS, tr(scribus_getinfo__doc__)},
 	{const_cast<char*>("getItemPageNumber"), scribus_getitempagenumber, METH_VARARGS, tr(scribus_getitempagenumber__doc__)},
@@ -539,6 +541,7 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("setImageBrightness"), scribus_setimagebrightness, METH_VARARGS, tr(scribus_setimagebrightness__doc__)},
 	{const_cast<char*>("setImageGrayscale"), scribus_setimagegrayscale, METH_VARARGS, tr(scribus_setimagegrayscale__doc__)},
 	{const_cast<char*>("setImageOffset"), scribus_setimageoffset, METH_VARARGS, tr(scribus_setimageoffset__doc__)},
+	{const_cast<char*>("setImagePage"), scribus_setimagepage, METH_VARARGS, tr(scribus_setimagepage__doc__)},
 	{const_cast<char*>("setImageScale"), scribus_setimagescale, METH_VARARGS, tr(scribus_setimagescale__doc__)},
 	{const_cast<char*>("setInfo"), scribus_setinfo, METH_VARARGS, tr(scribus_setinfo__doc__)},
 	{const_cast<char*>("setItemName"), scribus_setitemname, METH_VARARGS, tr(scribus_setitemname__doc__)},
get-set-image-page-2.diff (7,997 bytes)   

Issue History

Date Modified Username Field Change
2012-07-29 21:06 ale New Issue
2012-07-29 21:06 ale Status new => assigned
2012-07-29 21:06 ale Assigned To => jainbasil
2024-03-13 21:18 ale Note Added: 0051031
2024-03-13 21:19 ale Assigned To jainbasil => ale
2024-03-13 21:19 ale Summary new scripter: make sure that one can choose the page of the pdf loaded into an image frame => [PATCH] new scripter: make sure that one can choose the page of the pdf loaded into an image frame
2024-03-13 21:19 ale Patch => Yes
2024-03-14 06:30 ale Note Added: 0051032
2024-03-14 06:30 ale File Added: get-set-image-page.diff
2024-03-14 21:18 ale Note Added: 0051040
2024-03-14 21:18 ale File Added: get-set-image-page-2.diff