View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0016294 | Scribus | Scripter | public | 2020-10-30 09:26 | 2023-11-04 09:09 |
Reporter | ale | Assigned To | ale | ||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.5.6.svn | ||||
Fixed in Version | 1.6.0.svn | ||||
Summary | 0016294: [PATCH] add setNormalMode() (and setEditMode()) to the scripter | ||||
Description | the 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. | ||||
Tags | No tags attached. | ||||
Patch | Yes | ||||
|
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); } |
|
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. |
|
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) |
|
Answering my own question. Here is a use case for setEditMode(): https://forums.scribus.net/index.php/topic,4743.msg21816.html |
|
somehow, the patch above contains lines that have nothing to do with it. here is a cleaned up version that has been tested with the script posted in the forum article linked above. edit-and-normal-mode.diff (5,098 bytes)
diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp index 3941eb9a9..f3a87b71e 100644 --- a/scribus/plugins/scriptplugin/cmdmani.cpp +++ b/scribus/plugins/scriptplugin/cmdmani.cpp @@ -647,6 +647,58 @@ 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 */ @@ -669,10 +721,12 @@ void cmdmanidocwarnings() << scribus_scaleimage__doc__ << scribus_selectioncount__doc__ << scribus_selectobject__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_sizeobject__doc__ diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h index fb0c7e1f3..e4d4253a7 100644 --- a/scribus/plugins/scriptplugin/cmdmani.h +++ b/scribus/plugins/scriptplugin/cmdmani.h @@ -284,4 +284,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 c1c56f880..2836dfb96 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -521,6 +521,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__)}, @@ -538,6 +539,7 @@ PyMethodDef scribus_methods[] = { {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__)}, + {const_cast<char*>("setNormalMode"), (PyCFunction)scribus_setnormalmode, METH_NOARGS, tr(scribus_setnormalmode__doc__)}, {const_cast<char*>("setLayerBlendmode"), scribus_setlayerblendmode, METH_VARARGS, tr(scribus_setlayerblendmode__doc__)}, {const_cast<char*>("setLayerFlow"), scribus_setlayerflow, METH_VARARGS, tr(scribus_setlayerflow__doc__)}, {const_cast<char*>("setLayerLocked"), scribus_setlayerlocked, METH_VARARGS, tr(scribus_setlayerlocked__doc__)}, |
|
Applied with a minor change to remove the Selection* curSelection = currentDoc->m_Selection |
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 | |
2023-10-29 20:00 | ale | Note Added: 0050407 | |
2023-10-29 21:32 | ale | Note Added: 0050408 | |
2023-10-29 21:32 | ale | File Added: edit-and-normal-mode.diff | |
2023-10-31 21:15 | cbradney | Assigned To | => ale |
2023-10-31 21:15 | cbradney | Status | new => assigned |
2023-10-31 21:15 | cbradney | Status | assigned => resolved |
2023-10-31 21:15 | cbradney | Resolution | open => fixed |
2023-10-31 21:15 | cbradney | Fixed in Version | => 1.6.0.svn |
2023-10-31 21:15 | cbradney | Note Added: 0050411 | |
2023-11-04 09:09 | cbradney | Status | resolved => closed |