View Issue Details

IDProjectCategoryView StatusLast Update
0015306ScribusScripterpublic2019-06-04 20:56
ReporterjurajF Assigned Tojghali  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Platformx86_64OSGNU/LinuxOS VersionDebian 8/Jessie
Product Version1.5.4.svn 
Target VersionFixed in Version1.5.5.svn 
Summary0015306: Add python command setScaleFrameToImage
DescriptionThis patch will add setScaleFrameToImage() function to python scripter.
Also included is very short script that uses this function as example.
Additional InformationPS; I had an impression I sent this patch back in 2016 but I can not find it in bugtracker so I am sending it now (sorry if there is duplicate somewhere)
TagsNo tags attached.
PatchYes

Activities

jurajF

2018-05-08 12:05

reporter  

0001-Add-python-command-setScaleFrameToImage.patch (4,153 bytes)
From 9a4856a5416759ad6ed1bd5234bb0f63c6070a93 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Tue, 8 May 2018 10:16:17 +0200
Subject: [PATCH] Add python command setScaleFrameToImage

---
 scribus/plugins/scriptplugin/cmdmani.cpp      | 24 +++++++++++++++++++
 scribus/plugins/scriptplugin/cmdmani.h        |  9 +++++++
 scribus/plugins/scriptplugin/scriptplugin.cpp |  1 +
 3 files changed, 34 insertions(+)

diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp
index c77e0bdfb..187cd4f7a 100644
--- a/scribus/plugins/scriptplugin/cmdmani.cpp
+++ b/scribus/plugins/scriptplugin/cmdmani.cpp
@@ -536,6 +536,29 @@ PyObject *scribus_islocked(PyObject* /* self */, PyObject* args)
 	return PyBool_FromLong(0);
 }
 
+PyObject *scribus_setscaleframetoimage(PyObject* /* self */, PyObject* args)
+{
+	if(!checkHaveDocument())
+		return NULL;
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return NULL;
+	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+	if (item == NULL)
+		return NULL;
+	if (!item->asImageFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData());
+		return NULL;
+	}
+	Selection *sel = new Selection(ScCore->primaryMainWindow());
+	sel->addItem(item);
+	ScCore->primaryMainWindow()->doc->itemSelection_AdjustFrametoImageSize(sel);
+	delete sel;
+
+	Py_RETURN_NONE;
+}
+
 PyObject *scribus_setscaleimagetoframe(PyObject* /* self */, PyObject* args, PyObject* kw)
 {
 	char *name = const_cast<char*>("");
@@ -629,5 +652,6 @@ void cmdmanidocwarnings()
 	  << 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_setscaleframetoimage__doc__
 	  << scribus_flipobject__doc__;
 }
diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h
index cfef82da1..c03a42717 100644
--- a/scribus/plugins/scriptplugin/cmdmani.h
+++ b/scribus/plugins/scriptplugin/cmdmani.h
@@ -241,6 +241,15 @@ currently selected item is used.\n\
 /*! Status of locking 2004/7/10 pv.*/
 PyObject *scribus_islocked(PyObject * /*self*/, PyObject* args);
 
+PyDoc_STRVAR(scribus_setscaleframetoimage__doc__,
+QT_TR_NOOP("setScaleFrameToImage([name])\n\
+\n\
+Set frame size to image size.\n\
+\n\
+May raise WrongFrameTypeError.\n\
+"));
+PyObject *scribus_setscaleframetoimage(PyObject * /*self*/, PyObject* args);
+
 PyDoc_STRVAR(scribus_setscaleimagetoframe__doc__,
 QT_TR_NOOP("setScaleImageToFrame(scaletoframe, proportional=None, name=<selection>)\n\
 \n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index f17c31a03..96f159860 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -540,6 +540,7 @@ PyMethodDef scribus_methods[] = {
 	// missing? {"setSelectedObject", scribus_setselobjnam, METH_VARARGS, "Returns the Name of the selecteted Object. \"nr\" if given indicates the Number of the selected Object, e.g. 0 means the first selected Object, 1 means the second selected Object and so on."},
 	{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*>("setScaleFrameToImage"), (PyCFunction)scribus_setscaleframetoimage, METH_VARARGS, tr(scribus_setscaleframetoimage__doc__)},
 	{const_cast<char*>("setScaleImageToFrame"), (PyCFunction)scribus_setscaleimagetoframe, METH_KEYWORDS, tr(scribus_setscaleimagetoframe__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__) },
-- 
2.17.0

scaleframe.py (532 bytes)

jghali

2018-05-13 12:56

administrator   ~0045233

You add previously posted a patch for setScaleImageToFrame(), patch for setScaleFrameToImage() was indeed missing.

Issue History

Date Modified Username Field Change
2018-05-08 12:05 jurajF New Issue
2018-05-08 12:05 jurajF File Added: 0001-Add-python-command-setScaleFrameToImage.patch
2018-05-08 12:05 jurajF File Added: scaleframe.py
2018-05-09 06:36 ale Summary Add python command setScaleFrameToImage => [PATCH] Add python command setScaleFrameToImage
2018-05-13 12:54 jghali Summary [PATCH] Add python command setScaleFrameToImage => Add python command setScaleFrameToImage
2018-05-13 12:56 jghali Assigned To => jghali
2018-05-13 12:56 jghali Status new => resolved
2018-05-13 12:56 jghali Resolution open => fixed
2018-05-13 12:56 jghali Fixed in Version => 1.5.5.svn
2018-05-13 12:56 jghali Note Added: 0045233
2019-06-04 20:56 cbradney Status resolved => closed