View Issue Details

IDProjectCategoryView StatusLast Update
0017114ScribusScripterpublic2024-01-13 00:24
Reporterale Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version1.7.0.svn 
Summary0017114: scripter: duplicateObjects() does not find items that are defined in a master page
DescriptionduplicateObjects() does not find items that are defined in a master page
TagsNo tags attached.
PatchNo

Activities

ale

2024-01-10 12:28

manager   ~0050865

get-selected-master-page-item.diff (611 bytes)   
diff --git a/scribus/plugins/scriptplugin/cmdutil.cpp b/scribus/plugins/scriptplugin/cmdutil.cpp
index bbb26392d..3f39626ba 100644
--- a/scribus/plugins/scriptplugin/cmdutil.cpp
+++ b/scribus/plugins/scriptplugin/cmdutil.cpp
@@ -123,6 +123,11 @@ PageItem* getPageItemByName(const QString& name)
 		if (name == currentDoc->Items->at(i)->itemName())
 			return currentDoc->Items->at(i);
 	}
+	for (const auto& item: currentDoc->MasterItems)
+	{
+		if (name == item->itemName())
+			return item;
+	}
 
 	PyErr_SetString(NoValidObjectError, QString("Object not found").toLocal8Bit().constData());
 	return nullptr;

jghali

2024-01-10 19:51

administrator   ~0050869

This is expected behavior if you are not in masterpage mode : manipulating master pages objects when not in master page mode is unsupported, so this patch will not be accepted. You have to call editMasterPage() before accessing master page objects.

ale

2024-01-10 20:46

manager   ~0050872

the goal is to duplicate an item from a master page into a normal page.

cold just this be a supported action?

if this is ok, i would work on a different patch that would only affect duplicateObjects().
would that be ok?

ale

2024-01-10 21:03

manager   ~0050873

for now i'm going to use copyObjects(), which can copy from the master page even in normal mode, but i feel uncomfortable with modifying the clipboard from a script.

jghali

2024-01-10 23:50

administrator   ~0050875

duplicateObjects() should reflect what Item > Duplicate/Transform > Duplicate does, so no, a patch to duplicateObjects() will not be accepted either.

I would however expect something like this to work:
editMasterPage("Nouveau gabarit 1")
copyObject("Texte1")
closeMasterPage()
pasteObject()

However it doesn't, currently it causes a crash. I tried to do some modifications, but I'm currently hit by the fact that the page palette is essentially disabled while scripts are running, for obvious performance reasons, and because of this I get other crashes. The equivalent manipulation performed manually in GUI however works as expected.

ale

2024-01-11 07:02

manager   ~0050877

the problem with copying objects is, that it affects the clipboard in a way that the user can't understand (since they don't see the exact steps i'm doing in the script).
a "random" item will be in the clipboard and when the user next pastes that object will be inserted.

i think that there should be at least a clearClipboard() command, so that the script leaves sribus in a clean state.
(yes, in my eyes it's much better to have the latest copy disappear from the clipboard, rather than seeing a "random" one getting into there)
(it is even worse for people (do they exist?) that actively use the copied items panel: they will see lot of items appear in there! spooky...)

this having being said, duplicateObject is not the same as the "item > duplicate" from the UI menu.
in the UI i will only duplicate things on the same page (ctr-d), and mostly use copy paste when copying to a different page.

but in the scripter i can (and often will) duplicate an object from a different page into the current one.
i simply need the name of the original item.

in this context, i really don't see why duplicateObject should not be able to duplicate an item from the masterPage, if i have the name of that item.
if tjhere are technical issues that cannot be solved i'm fine with it, but as a script writer i would expect to be able to duplicate any item, wherever it is.

finally, i also had some crashes when testing my script, but, most of the time (and all the later runs) did go through correctly and i got the object pasted into the page.

ale

2024-01-11 09:24

manager   ~0050880

in 1.7 i keep on having crashes...
seem to be related to copy pastes...

cbradney

2024-01-12 19:07

administrator   ~0050887

copyObject() should probably have a parameter to determine which copy/paste buffer its putting something into. That is, it should/should not by default affect the users copy/paste buffer based on a choice

ale

2024-01-13 00:24

manager   ~0050888

well, i wonder if we could find a better name for that copyObject() that does not affect the clipboard, instead of adding a parameter...

duplicateObject(source[, target]) might be a good one...

Issue History

Date Modified Username Field Change
2024-01-10 12:02 ale New Issue
2024-01-10 12:28 ale Note Added: 0050865
2024-01-10 12:28 ale File Added: get-selected-master-page-item.diff
2024-01-10 12:38 ale Summary scripter: duplicateObjects() does not find items that are defined in a master page => [PATCH] scripter: duplicateObjects() does not find items that are defined in a master page
2024-01-10 12:38 ale Patch No => Yes
2024-01-10 12:39 ale Tag Attached: patch
2024-01-10 19:51 jghali Note Added: 0050869
2024-01-10 20:46 ale Note Added: 0050872
2024-01-10 21:03 ale Note Added: 0050873
2024-01-10 23:50 jghali Note Added: 0050875
2024-01-11 07:02 ale Note Added: 0050877
2024-01-11 09:23 ale Tag Detached: patch
2024-01-11 09:23 ale Summary [PATCH] scripter: duplicateObjects() does not find items that are defined in a master page => scripter: duplicateObjects() does not find items that are defined in a master page
2024-01-11 09:23 ale Patch Yes => No
2024-01-11 09:24 ale Note Added: 0050880
2024-01-12 19:07 cbradney Note Added: 0050887
2024-01-13 00:24 ale Note Added: 0050888