View Issue Details

IDProjectCategoryView StatusLast Update
0016294ScribusScripterpublic2020-11-03 18:39
Reporterale Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version1.5.6.svn 
Summary0016294: [PATCH] add setNormalMode() (and setEditMode()) to the scripter
Descriptionthe patch adds the setNormalMode() to the scripter, which exits the edit mode.

the setEditMode() command is added for "symmetry reasons", but i'm not sure that it's really useful.
feel free to remove it from the patch before you apply it.
TagsNo tags attached.
PatchYes

Activities

ale

2020-10-30 09:26

manager  

edit-mode.diff (6,844 bytes)   
diff --git a/scribus/pagestructs.h b/scribus/pagestructs.h
index a255ba080..8e9bb1b5c 100644
--- a/scribus/pagestructs.h
+++ b/scribus/pagestructs.h
@@ -48,11 +48,13 @@ struct DocumentSection
 	uint fromindex; //First page _index_ of the section in the document (old page number)
 	uint toindex; //Last page _index_ of the section in the document (old page number)
 	NumFormat type; //Type of section numbering, ie i,ii,iii or a,b,c or 1,2,3, etc
+	bool autoCount;
 	uint sectionstartindex; // Start of section, an index in the range of type, eg for type i,ii,iii, this would be 2 for "ii".
 	bool reversed; // Counting 10-1 ?
 	QChar pageNumberFillChar; //Prefix to be placed before page number
 	int pageNumberWidth; //Minimum width of page number string
 
+	// TODO: are == and != really needed? they shouldn't...
 	bool operator==(const DocumentSection &other) const
 	{
 		if (number != other.number)
@@ -65,6 +67,8 @@ struct DocumentSection
 			return false;
 		if (type != other.type)
 			return false;
+		if (autoCount != other.autoCount)
+			return false;
 		if (sectionstartindex != other.sectionstartindex)
 			return false;
 		if (reversed != other.reversed)
diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp
index db30970e3..d90cc4da5 100644
--- a/scribus/plugins/scriptplugin/cmdmani.cpp
+++ b/scribus/plugins/scriptplugin/cmdmani.cpp
@@ -649,6 +649,59 @@ PyObject *scribus_combinepolygons(PyObject * /* self */)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_seteditmode(PyObject * /* self */)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	Selection* curSelection = currentDoc->m_Selection;
+
+	if (curSelection->count() < 1)
+	{
+		PyErr_SetString(NoValidObjectError, QString("No item selected.").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	auto currItem = currentDoc->m_Selection->itemAt(0);
+	if (!currItem->isTextFrame() && !currItem->isImageFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QString("Only image and text frames are supported.").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	ScCore->primaryMainWindow()->view->requestMode(modeEdit);
+
+	Py_RETURN_NONE;
+}
+
+PyObject *scribus_setnormalmode(PyObject * /* self */)
+{
+	if (!checkHaveDocument())
+		return nullptr;
+
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	Selection* curSelection = currentDoc->m_Selection;
+
+	if (curSelection->count() < 1)
+	{
+		PyErr_SetString(NoValidObjectError, QString("No item selected.").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	auto currItem = currentDoc->m_Selection->itemAt(0);
+	if (!currItem->isTextFrame() && !currItem->isImageFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QString("Only image and text frames are supported.").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	ScCore->primaryMainWindow()->view->requestMode(modeNormal);
+
+	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 */
@@ -671,10 +724,12 @@ void cmdmanidocwarnings()
 	  << scribus_scaleimage__doc__
 	  << scribus_selcount__doc__
 	  << scribus_selectobj__doc__
+	  << scribus_seteditmode__doc__
 	  << scribus_setimagebrightness__doc__
 	  << scribus_setimagegrayscale__doc__
 	  << scribus_setimageoffset__doc__
 	  << scribus_setimagescale__doc__
+	  << scribus_setnormalmode__doc__
 	  << scribus_setscaleframetoimage__doc__
 	  << scribus_setscaleimagetoframe__doc__
 	  << scribus_sizeobjabs__doc__ 
diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h
index d8b8ecca9..e6acacdc9 100644
--- a/scribus/plugins/scriptplugin/cmdmani.h
+++ b/scribus/plugins/scriptplugin/cmdmani.h
@@ -278,4 +278,18 @@ Combine two or more selected Polygons\n\
 "));
 PyObject *scribus_combinepolygons(PyObject * /* self */);
 
+PyDoc_STRVAR(scribus_seteditmode__doc__,
+QT_TR_NOOP("setEditMode()\n\
+\n\
+Start the edit mode for the current item.\n\
+"));
+PyObject *scribus_seteditmode(PyObject * /*self*/);
+
+PyDoc_STRVAR(scribus_setnormalmode__doc__,
+QT_TR_NOOP("setNormalMode()\n\
+\n\
+Set the current item in normal mode (out of edit mode).\n\
+"));
+PyObject *scribus_setnormalmode(PyObject * /*self*/);
+
 #endif
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index ced8c5e50..c9ba0eb5e 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -514,6 +514,7 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("setCursor"), scribus_setcursor, METH_VARARGS, tr(scribus_setcursor__doc__)},
 	{const_cast<char*>("setCustomLineStyle"), scribus_setcustomlinestyle, METH_VARARGS, tr(scribus_setcustomlinestyle__doc__)},
 	{const_cast<char*>("setDocType"), scribus_setdoctype, METH_VARARGS, tr(scribus_setdoctype__doc__)},
+	{const_cast<char*>("setEditMode"), (PyCFunction)scribus_seteditmode, METH_NOARGS, tr(scribus_seteditmode__doc__)},
 	{const_cast<char*>("setFillBlendmode"), scribus_setfillblend, METH_VARARGS, tr(scribus_setfillblend__doc__)},
 	{const_cast<char*>("setFillColor"), scribus_setfillcolor, METH_VARARGS, tr(scribus_setfillcolor__doc__)},
 	{const_cast<char*>("setFillShade"), scribus_setfillshade, METH_VARARGS, tr(scribus_setfillshade__doc__)},
@@ -551,6 +552,7 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("setMargins"), scribus_setmargins, METH_VARARGS, tr(scribus_setmargins__doc__)},
 	{const_cast<char*>("setMultiLine"), scribus_setmultiline, METH_VARARGS, tr(scribus_setmultiline__doc__)},
 	{const_cast<char*>("setNewName"), scribus_setitemname, METH_VARARGS, tr(scribus_setitemname__doc__)}, // Deprecated, was in fact never documented
+	{const_cast<char*>("setNormalMode"), (PyCFunction)scribus_setnormalmode, METH_NOARGS, tr(scribus_setnormalmode__doc__)},
 	{const_cast<char*>("setObjectAttributes"), scribus_setobjectattributes, METH_VARARGS, tr(scribus_setobjectattributes__doc__)},
 	{const_cast<char*>("setPDFBookmark"), scribus_setpdfbookmark, METH_VARARGS, tr(scribus_setpdfbookmark__doc__)},
 	{const_cast<char*>("setParagraphStyle"), scribus_setparagraphstyle, METH_VARARGS, tr(scribus_setparagraphstyle__doc__)},
diff --git a/scribus/ui/prefs_documentsections.cpp b/scribus/ui/prefs_documentsections.cpp
index db90cb609..089ccbc0a 100644
--- a/scribus/ui/prefs_documentsections.cpp
+++ b/scribus/ui/prefs_documentsections.cpp
@@ -77,7 +77,7 @@ void Prefs_DocumentSections::updateTable()
 		//Style
 		{
 			NumFormatCombo *item = new NumFormatCombo(nullptr, true);
-			item->addItems(m_styles);
+			// item->addItems(m_styles);
 			sectionsTable->setCellWidget(row, i++, item);
 			item->setCurrentFormat(section.type);
 		}
edit-mode.diff (6,844 bytes)   

digirew

2020-11-03 17:00

reporter   ~0048313

the more I dive into it, the more I see a need for "setEditMode()" as well.

One example, we run a script on scribus launch and we want to have the cursor already in the correct field ready for typing. having setEditMode() would allow us to achieve this.

Im still trying other existing options, but I dont think its possible.

ale

2020-11-03 18:39

manager   ~0048318

setEditMode() is in the patch. but i really wonder in which case you will want to use.

i'd be curious to see a real use case.

on the other hand, setNormalMode() is for sure needed, if you want to apply the format to a frame. (well, one could select all each time, but that's not really friendly)

Issue History

Date Modified Username Field Change
2020-10-30 09:26 ale New Issue
2020-10-30 09:26 ale File Added: edit-mode.diff
2020-11-03 17:00 digirew Note Added: 0048313
2020-11-03 18:39 ale Note Added: 0048318