View Issue Details

IDProjectCategoryView StatusLast Update
0003209ScribusScripterpublic2010-12-13 15:18
Reportermichaelcole Assigned Toh_a_j_s  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
PlatformLinuxOSMandriva 2006OS VersionMandriva 2006
Product Version1.3.2 
Fixed in Version1.5.0svn 
Summary0003209: Python crashes constantly Scripter and documentation is wrong.
DescriptionScripter.. Sig 11 or Sig 6 errors constantly.

Run the hello world First script works.

Run the second one crashes..

Open the Examples they crash as well..

Only the calendar and the font sample work..

The documentation is poorly would be an understatement. It starts with a hello world which then breaks the Scribus then does not even attempt to create a document or edit one..

Steps To ReproduceCopy these and run them..

This will run but closes Scribus on close
#!/usr/bin/env Python
import sys
import qt

a = qt.qApp

hello = qt.QPushButton("Hello world!", None)
hello.resize(100, 30)

a.setMainWidget(hello)
hello.show()
sys.exit(a.exec_loop())



This will run then run again and then die with sig 6...
#!/usr/bin/env Python
import sys
import qt

a = qt.qApp

hello = qt.QPushButton("Hello world!", None)
hello.resize(100, 30)

#a.setMainWidget(hello)
hello.show()
sys.exit(a.exec_loop())


This will crash.. below
#!/usr/bin/env Python
import sys
import qt

a = qt.qApp

hello = qt.QPushButton("Hello world!", None)
hello.resize(100, 30)

#a.setMainWidget(hello)
hello.show()
#sys.exit(a.exec_loop())



Quote.py
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

""" This script changes quotation marks from " " to french style """

import sys

try:
    from scribus import *
except ImportError:
    print "This script only runs from within Scribus."
    sys.exit(1)

import re

TITLE = "Text quoting"

# These need to be declared as unicode strings until some
# charset issues in the scripter are worked out.
QUOTE_START = u""
QUOTE_END = u""

def quote(textobj):
    quoted_re = re.compile('"[^"]*"')
    try:
        text = getText(textobj)
    except WrongFrameTypeError:
        messageBox("quote.py", "Cannot quote text in a non-text frame", ICON_INFORMATION);
        sys.exit(1)
    if len(text) == 0:
        return 0 # We can't very well change anything in an empty frame
    count = 0
    i = 0
    selectText(0, 0, textobj)
    while i < len(text):
        match = quoted_re.match(text[i:])
        if match:
            end = match.end()
            selectText(i, 1, textobj)
            deleteText(textobj)
            insertText(QUOTE_START, i, textobj)
            selectText(i + end - 1, 1, textobj)
            deleteText(textobj)
            insertText(QUOTE_END, i + end - 1, textobj)
            count += 1
            i = i + end
        else:
            i = i + 1
    return count


def main():
    changed = 0
    sel_count = selectionCount()
    if sel_count:
        for i in range(sel_count):
            changed += quote(getSelectedObject(i))
    else:
        for page in range(pageCount()):
            gotoPage(page)
            for obj in getAllObjects():
                changed += quote(obj)
    messageBox(TITLE, "%s quotations changed" % changed,
               ICON_INFORMATION, BUTTON_OK)

if __name__ == '__main__':
    if haveDoc():
        try:
            setRedraw(False)
            main()
        finally:
            setRedraw(True)
            redrawAll()
    else:
        messageBox(TITLE, "No document open", ICON_WARNING, BUTTON_OK)
TagsNo tags attached.
Patch

Relationships

has duplicate 0007879 closedsubik "import qt" in startup script crashes Scribus 
child of 0003813 acknowledged Metabug: Scripter 

Activities

michaelcole

2006-02-10 08:44

reporter   ~0008683

Reminder sent to: michaelcole

Scripter Bugs..

plinnell

2006-02-10 09:05

viewer   ~0008684

Reminder sent to: ringerc, subik

Thoughts on this ?

subik

2006-02-14 11:49

manager   ~0008742

ad PyQt: Fatal Python error: PyThreadState_Get: no current thread

it's due the problematic PyQt interpretters init etc. It's under slow development. Please, consult the scribus documentation for using PyQt in your scripts (chapter Scripter Extensions). There is small tutorial to get Scribus working with PyQt.

Anyway I have no problems with sample scripts (quote.py etc. here). Which Python version you have on Mandriva? Is this right one with is Scribus built?

ringerc

2006-02-15 00:45

reporter   ~0008754

Scripts using PyQt *will* *not* *work* under the normal execution mode for scripts. They must be run with the "extension script" option. This is due to Scribus's use of sub-interpreters for normal scripts, which PyQt doesn't seem to like (at least not the bodgy way we use them - they're not made for single-threaded execution).

It has proved difficult to reliably prevent the user from trying to load scripts that use PyQt. Suggestions on how to accomplish this would be much appreciated. I actually can't remember if I ended up committing the check-and-abort for the module name "PyQt" or not, and I don't have any sane access to CVS right now (on holiday with intermittent 56k access).

Additonally, that example is just wrong. I really hope that's not in CVS, because it (a) calls sys.exit and (b) sets the main widget. If it is in CVS, then my apologies - it should never have made it there, and there was a correct one in my local tree.

I'll review the examples and documentation when I get back from holiday. We do need to try to prevent users from running scripts that'll crash Scribus, but the scripts should work correctly if run as "extension scripts".

ringerc

2006-03-05 09:00

reporter   ~0009059

The only real fix here is to remove support for the use of subinterpreters. That'd probably be the "most correct" fix as the way we use subinterpreters is actually not designed to work ... but it'd introduce bunch of potential issues. The biggest would be memory leakage after each script run (from the objects the script creates in the __main__ scope and does not destroy at exit). Another would be that scripts would be less independent in some ways.

I'm increasingly coming to think that it's a good idea anyway.

Failing that, I have an __import__() wrapper almost ready. It replaces __builtin__.__import__ with a new import implementation that blacklists certain modules except in extension script mode. It's a dirty hack at best IMO, and I'd at this point I'd much prefer to just remove support for subinterpreters (they might be able to go back in with Qt4, where threading restrictions are less harsh).

Petr, any strong opinions either way re subinterpreters?

ringerc

2006-03-13 03:09

reporter   ~0009231

Petr, any comments re the future use of sub-interpreters?

ringerc

2006-04-02 05:49

reporter   ~0009585

I need to ensure there's a better way for scripts to detect that they're running under the 'extension script' mode and abort otherwise. A functional blacklist of modules would also be good, but it proving harder to get working than I expected.

Beyond that it's not clear if there's anything to be done about this issue at present.

plinnell

2010-12-13 15:18

viewer   ~0025117

Scripter2 was written to overcome this.

Issue History

Date Modified Username Field Change
2006-02-10 08:43 michaelcole New Issue
2006-02-10 08:44 michaelcole Note Added: 0008683
2006-02-10 09:05 plinnell Note Added: 0008684
2006-02-14 11:49 subik Note Added: 0008742
2006-02-15 00:45 ringerc Note Added: 0008754
2006-02-15 20:55 ringerc Status new => assigned
2006-02-15 20:55 ringerc Assigned To => ringerc
2006-03-05 09:00 ringerc Note Added: 0009059
2006-03-13 03:09 ringerc Note Added: 0009231
2006-04-02 05:49 ringerc Note Added: 0009585
2006-05-13 21:06 christoph_s Relationship added child of 0003813
2008-03-14 06:54 ringerc Assigned To ringerc =>
2008-03-14 06:54 ringerc Status assigned => confirmed
2009-03-17 07:32 jghali Relationship added has duplicate 0007879
2010-12-13 15:17 plinnell Status confirmed => resolved
2010-12-13 15:17 plinnell Fixed in Version => 1.5.0svn
2010-12-13 15:17 plinnell Resolution open => fixed
2010-12-13 15:17 plinnell Assigned To => h_a_j_s
2010-12-13 15:18 plinnell Note Added: 0025117
2010-12-13 15:18 plinnell Status resolved => closed