View Issue Details

IDProjectCategoryView StatusLast Update
0009115ScribusScripterpublic2014-10-24 23:00
Reporterarvee Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
Status newResolutionopen 
Product Version1.5.0svn 
Summary0009115: [PATCH] new get/setUndoEnabled commands for scriptplugin
Descriptionget/set the undo-manager status.
TagsNo tags attached.
PatchYes

Activities

arvee

2010-05-20 10:05

reporter  

undomanager-2010-05-20.diff (5,960 bytes)   
Index: Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(revision 15091)
+++ Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(working copy)
@@ -8,6 +8,7 @@
 #include "cmdutil.h"
 #include "scribuscore.h"
 #include "scribusdoc.h"
+#include "undomanager.h"
 
 /* getObjectType(name) */
 PyObject *scribus_getobjecttype(PyObject* /* self */, PyObject* args)
@@ -327,6 +328,13 @@
 	return l;
 }
 
+PyObject *scribus_getundoenabled(PyObject* /* self */, PyObject* args)
+{
+	if(!checkHaveDocument())
+		return NULL;
+	return PyBool_FromLong(UndoManager::undoEnabled() ? 1 : 0);
+}
+
 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
 with header files structure untouched (docstrings are kept near declarations)
 PV */
@@ -342,5 +350,6 @@
 	  << scribus_getfillshade__doc__ << scribus_getcornerrad__doc__ 
 	  << scribus_getimgscale__doc__ << scribus_getimgname__doc__ 
 	  << scribus_getposi__doc__ << scribus_getsize__doc__ 
-	  << scribus_getrotation__doc__ <<  scribus_getallobj__doc__;
+	  << scribus_getrotation__doc__ <<  scribus_getallobj__doc__
+	  << scribus_getundoenabled__doc__;
 }
Index: Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(revision 15091)
+++ Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(working copy)
@@ -219,5 +219,14 @@
 /*! Returns a list with all objects in page */
 PyObject *scribus_getallobj(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getundoenabled__doc__,
+QT_TR_NOOP("getUndoEnabled(bool)\n\
+\n\
+Get undo-manager status.\n\
+"));
+/*! Enable/disable the undo-manager. */
+PyObject *scribus_getundoenabled(PyObject * /*self*/, PyObject* args);
+
 #endif
 
Index: Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp	(revision 15091)
+++ Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp	(working copy)
@@ -16,6 +16,7 @@
 #include "scribusdoc.h"
 #include "fonts/scfontmetrics.h"
 #include "prefsmanager.h"
+#include "undomanager.h"
 
 PyObject *scribus_setredraw(PyObject* /* self */, PyObject* args)
 {
@@ -771,6 +772,15 @@
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_setundoenabled(PyObject* /* self */, PyObject* args)
+{
+	int e;
+	if (!PyArg_ParseTuple(args, "i", &e))
+		return NULL;
+	UndoManager::instance()->setUndoEnabled(static_cast<bool>(e));
+	Py_RETURN_NONE;
+}
+
 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
 with header files structure untouched (docstrings are kept near declarations)
 PV */
@@ -790,5 +800,6 @@
 	  << scribus_glayerblend__doc__ << scribus_glayertrans__doc__ 
 	  << scribus_removelayer__doc__ << scribus_createlayer__doc__ 
 	  << scribus_getlanguage__doc__ << scribus_moveselectiontofront__doc__
-	  << scribus_moveselectiontoback__doc__ << scribus_filequit__doc__;
+	  << scribus_moveselectiontoback__doc__ << scribus_filequit__doc__
+	  << scribus_setundoenabled__doc__;
 }
Index: Scribus/scribus/plugins/scriptplugin/cmdmisc.h
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdmisc.h	(revision 15091)
+++ Scribus/scribus/plugins/scriptplugin/cmdmisc.h	(working copy)
@@ -348,6 +348,17 @@
 /*! 04.01.2007 : Joachim Neu : Moves item selection to back. */
 PyObject *scribus_moveselectiontoback(PyObject*);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_setundoenabled__doc__,
+QT_TR_NOOP("setUndoEnabled(bool)\n\
+\n\
+Set undo-manager status.\n\
+This change will persist even after the script exits, so make sure to call\n\
+setUndoEnabled(True) in a finally: clause at the top level of your script.\n\
+"));
+/*! Enable/disable page redrawing. */
+PyObject *scribus_setundoenabled(PyObject * /*self*/, PyObject* args);
+
 #endif
 
 
Index: Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(revision 15091)
+++ Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(working copy)
@@ -329,6 +329,7 @@
 	{const_cast<char*>("editMasterPage"), scribus_editmasterpage, METH_VARARGS, tr(scribus_editmasterpage__doc__)},
 	{const_cast<char*>("fileDialog"), (PyCFunction)scribus_filedia, METH_VARARGS|METH_KEYWORDS, tr(scribus_filedia__doc__)},
 	{const_cast<char*>("fileQuit"), scribus_filequit, METH_VARARGS, tr(scribus_filequit__doc__)},
+	{const_cast<char*>("getUndoEnabled"), scribus_getundoenabled, METH_VARARGS, tr(scribus_getundoenabled__doc__)},
 	{const_cast<char*>("getActiveLayer"), (PyCFunction)scribus_getactlayer, METH_NOARGS, tr(scribus_getactlayer__doc__)},
 	{const_cast<char*>("getAllObjects"), scribus_getallobj, METH_VARARGS, tr(scribus_getallobj__doc__)},
 	{const_cast<char*>("getAllStyles"), (PyCFunction)scribus_getstylenames, METH_NOARGS, tr(scribus_getstylenames__doc__)},
@@ -443,6 +444,7 @@
 	{const_cast<char*>("setActiveLayer"), scribus_setactlayer, METH_VARARGS, tr(scribus_setactlayer__doc__)},
 	{const_cast<char*>("setPDFBookmark"), scribus_setpdfbookmark, METH_VARARGS, tr(scribus_setpdfbookmark__doc__)},
 	{const_cast<char*>("isPDFBookmark"), scribus_ispdfbookmark, METH_VARARGS, tr(scribus_ispdfbookmark__doc__)},
+	{const_cast<char*>("setUndoEnabled"), scribus_setundoenabled, METH_VARARGS, tr(scribus_setundoenabled__doc__)},
 	{const_cast<char*>("setTextDistances"), scribus_settextdistances, METH_VARARGS, tr(scribus_settextdistances__doc__)},
 	{const_cast<char*>("setColumnGap"), scribus_setcolumngap, METH_VARARGS, tr(scribus_setcolumngap__doc__)},
 	{const_cast<char*>("setColumns"), scribus_setcolumns, METH_VARARGS, tr(scribus_setcolumns__doc__)},
undomanager-2010-05-20.diff (5,960 bytes)   

jghali

2010-05-20 13:01

administrator   ~0023945

Hmmm, that one is really dangerous to provide for scripts. One incorrectly balanced call and you have all chance that the app will not function correctly anymore.

arvee

2010-05-21 08:54

reporter   ~0023949

Not really dangerous, just like setRedraw() there is a particular docstring available:

"This change will persist even after the script exits, so make sure to call
setUndoEnabled(True) in a finally: clause at the top level of your script."

I really need this function due to the following scenario: if a script imports a pdf or svg where all text is present as outlines, that will result in pages with some 20.000 or more page-items.
When such item is then manipulated (moveObjAbs() or deleteColor() for example) all 20.000 items are going through the UndoManager, resulting in script run durations of more than 45 minutes in some cases for a single deleteColor() operation. When undo is disabled that time is cut short to maybe 10 seconds (or less). At the end of my script runs, the file is always saved and then closed so there is no need for any undo handling.

Scribus handles the 20.000 page-items without issues btw.

Kunda

2014-08-31 14:28

updater   ~0033399

renamed summary.

Issue History

Date Modified Username Field Change
2010-05-20 10:05 arvee New Issue
2010-05-20 10:05 arvee File Added: undomanager-2010-05-20.diff
2010-05-20 13:01 jghali Note Added: 0023945
2010-05-21 08:54 arvee Note Added: 0023949
2014-08-31 14:28 Kunda Note Added: 0033399
2014-08-31 14:28 Kunda Summary patch: new get/setUndoEnabled commands for scriptplugin => [PATCH] new get/setUndoEnabled commands for scriptplugin
2014-10-24 22:57 Kunda Patch => Yes