View Issue Details

IDProjectCategoryView StatusLast Update
0014453ScribusScripterpublic2016-12-14 00:00
Reportergpittman Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status newResolutionopen 
Product Version1.5.3.svn 
Summary0014453: Scripter command setStyle() doesn't work
DescriptionsetStyle() is supposed to change the Paragraph Style of text in a selected or named frame.
If text is not selected, it should set the style for the entire frame. It doesn't.
Steps To ReproduceMake a document with a text frame, enter or load some text.
Create a Paragraph Style with a particular NAME.
Select the frame, run the uploaded script (the script is designed to work on one or more selected frames).
Enter the NAME of the Style in the valueDialog which appears.

Result: typically there will be some assignment of the style but not the entire frame. It seems that only the last paragraph will have a change in style.

Another curious feature is that if you select and delete the last paragraph, the last paragraph remaining will change to the assigned style.
TagsNo tags attached.
PatchNo

Relationships

related to 0008957 assignedjainbasil [patch] Add setTextPreserveStyle() that wont default back to the default style. (Silimar to Scribus 1.3.3 setText) 
related to 0009273 acknowledged Additional scripter methods for paragraph and style handling 

Activities

gpittman

2016-12-11 20:18

developer  

changetextstyle.py (1,516 bytes)   
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# selectojbects.py
# © 2016.11.20  Gregory Pittman
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

"""
USAGE

Before running this script, you should have created and selected one or more image frames.

"""

import sys
import os

try:
	import scribus
except ImportError:
	print 'Unable to import the scribus module. This script will only run within'
	print 'the Python interpreter embedded in Scribus. Try Script->Execute Script.'
	sys.exit(1)

if not scribus.haveDoc():
	scribus.messageBox('Error','You must have a document open',scribus.ICON_WARNING,scribus.BUTTON_OK)
	sys.exit(2)

scribus.setRedraw(False)
framecount = scribus.selectionCount()
if framecount == 0:
    scribus.messageBox('Scribus - Script Error','There is no object selected. Please select at least one image frame and try again.',scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(2)

count = 0
newstyle = scribus.valueDialog('What Style to Apply?','Give a style name')
frames = []
while count <= framecount-1:
        currframe = scribus.getSelectedObject(count)
        frames.append(currframe)
        count += 1

for item in frames:
        frametype = scribus.getObjectType(item)
        if frametype == "TextFrame":
                scribus.setStyle(newstyle, item)
scribus.setRedraw(True)
changetextstyle.py (1,516 bytes)   

gpittman

2016-12-13 23:45

developer  

changetextstyleV2.py (1,625 bytes)   
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# selectojbects.py
# © 2016.11.20  Gregory Pittman
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

"""
USAGE

Before running this script, you should have created and selected one or more image frames.

"""

import sys
import os

try:
	import scribus
except ImportError:
	print 'Unable to import the scribus module. This script will only run within'
	print 'the Python interpreter embedded in Scribus. Try Script->Execute Script.'
	sys.exit(1)

if not scribus.haveDoc():
	scribus.messageBox('Error','You must have a document open',scribus.ICON_WARNING,scribus.BUTTON_OK)
	sys.exit(2)

scribus.setRedraw(False)
framecount = scribus.selectionCount()
if framecount == 0:
    scribus.messageBox('Scribus - Script Error','There is no object selected. Please select at least one image frame and try again.',scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(2)

count = 0
newstyle = scribus.valueDialog('What Style to Apply?','Give a style name')
frames = []
while count <= framecount-1:
        currframe = scribus.getSelectedObject(count)
        frames.append(currframe)
        count += 1

for item in frames:
        frametype = scribus.getObjectType(item)
        if frametype == "TextFrame":
                lentext = scribus.getTextLength(item)
                scribus.selectText(0,lentext -1, item)
                scribus.setStyle(newstyle, item)
scribus.setRedraw(True)
changetextstyleV2.py (1,625 bytes)   

gpittman

2016-12-13 23:47

developer   ~0042972

I've uploaded another version of the script, which attempts to select all the text in the frame, but still only part of the text had the style changed. In a 3-paragraph portion of text, only the middle paragraph had the style changed.

gpittman

2016-12-13 23:51

developer   ~0042973

Last edited: 2016-12-13 23:56

Here is an excerpt from cmdobj.cpp, beginning at line 622, that seems to be the actual point of application of the style, after various error checks:

        // for current item only
        if (ScCore->primaryMainWindow()->doc->m_Selection->count() == 0 || (strlen(name) > 0))
        {
            // quick hack to always apply on the right frame - pv
            ScCore->primaryMainWindow()->view->Deselect(true);
            //CB I dont think we need to draw here. Its faster if we dont.
            ScCore->primaryMainWindow()->view->SelectItem(item, false);
            // Now apply the style.
            int mode = ScCore->primaryMainWindow()->doc->appMode;
            ScCore->primaryMainWindow()->doc->appMode = modeEdit;
            ScCore->primaryMainWindow()->setNewParStyle(QString::fromUtf8(style));
            ScCore->primaryMainWindow()->doc->appMode = mode;
        }

I don't know why this isn't working but it obviously isn't.

I tried changing the bool values to the opposite, but this made no difference.

gpittman

2016-12-14 00:00

developer   ~0042976

If I run the script with the frame in Edit Contents mode, the paragraph style is applied to the paragraph where the cursor is.

Issue History

Date Modified Username Field Change
2016-12-11 20:17 gpittman New Issue
2016-12-11 20:18 gpittman File Added: changetextstyle.py
2016-12-11 21:04 Kunda Relationship added related to 0008957
2016-12-11 21:07 Kunda Relationship added related to 0009273
2016-12-13 23:45 gpittman File Added: changetextstyleV2.py
2016-12-13 23:47 gpittman Note Added: 0042972
2016-12-13 23:51 gpittman Note Added: 0042973
2016-12-13 23:56 gpittman Note Edited: 0042973
2016-12-14 00:00 gpittman Note Added: 0042976