[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] fixes for scribble issues
From:       "Hans-Peter Jansen" <hpj () urpla ! net>
Date:       2010-11-29 14:59:35
Message-ID: 201011291559.35922.hpj () urpla ! net
[Download RAW message or body]

Dear Phil,

examples/widgets/scribble.py suffers from a couple of issues at the 
moment. Most importantly, QtGui.QImageWriter.supportedImageFormats() 
and QAction.data() return QByteArrays now (with QVariant API 2), 
resulting in:

Traceback (most recent call last):
  File "./scribble.py", line 317, in <module>
    window = MainWindow()
  File "./scribble.py", line 178, in __init__
    self.createActions()
  File "./scribble.py", line 236, in createActions
    action = QtGui.QAction(text, self, triggered=self.save)
TypeError: arguments did not match any overloaded call:
  QAction(QObject): argument 1 has unexpected type 'QByteArray'
  QAction(QString, QObject): argument 1 has unexpected type 'QByteArray'
  QAction(QIcon, QString, QObject): argument 1 has unexpected type 'QByteArray'

on start up and

Traceback (most recent call last):
  File "./scribble.py", line 200, in save
    self.saveFile(fileFormat)
  File "./scribble.py", line 304, in saveFile
    "%s Files (*.%s);;All Files (*)" % (fileFormat.upper(), fileFormat))
AttributeError: 'QByteArray' object has no attribute 'upper'

Further more, printing (to PDF at least) leads to:

QPaintDevice: Cannot destroy paint device that is being painted
Speicherzugriffsfehler

(gdb) set args ./scribble.py
(gdb) run
Starting program: /usr/bin/python ./scribble.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb52c3b90 (LWP 29758)]
[New Thread 0xb48ffb90 (LWP 29759)]
QPaintDevice: Cannot destroy paint device that is being painted
[Thread 0xb52c3b90 (LWP 29758) exited]
[Thread 0xb48ffb90 (LWP 29759) exited]

Program received signal SIGSEGV, Segmentation fault.
0x00000002 in ?? ()
(gdb) bt
#0  0x00000002 in ?? ()
#1  0xb643b668 in ~QPainter (this=0x83dce70) at painting/qpainter.cpp:1504
#2  0xb6fe4010 in release_QPainter (sipCppV=0x83dce70) at \
QtGui/sipQtGuiQPainter.cpp:5596 #3  0xb6fe406c in dealloc_QPainter \
(sipSelf=0xb5b9a454) at QtGui/sipQtGuiQPainter.cpp:5607 #4  0xb7fc4f1f in \
forgetObject (sw=0xb5b9a454) at siplib.c:10001 #5  0xb7fc4fb1 in \
sipSimpleWrapper_dealloc (self=0xb5b9a454) at siplib.c:9230 #6  0xb7ebb68d in \
subtype_dealloc (self=0xb5b9a454) at Objects/typeobject.c:1018 #7  0xb7e8d24a in \
frame_dealloc (f=0x83b355c) at Objects/frameobject.c:417 #8  0xb7ef9bec in \
PyEval_EvalCodeEx (co=0xb7c39410, globals=0xb7c7702c, locals=0x0, args=0xb5ee73b8, \
argcount=1,   kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at \
Python/ceval.c:2953 #9  0xb7e8ea29 in function_call (func=0xb5ebce64, arg=0xb5ee73ac, \
kw=0x0) at Objects/funcobject.c:524 #10 0xb7e69c1c in PyObject_Call (func=0xb5ebce64, \
arg=0xb5ee73ac, kw=0x0) at Objects/abstract.c:2487 #11 0xb7e779fe in \
instancemethod_call (func=0xb5ebce64, arg=0xb5ee73ac, kw=0x0) at \
Objects/classobject.c:2579 #12 0xb7e69c1c in PyObject_Call (func=0xb7c276e4, \
arg=0xb7c5302c, kw=0x0) at Objects/abstract.c:2487 #13 0xb7ef277f in \
PyEval_CallObjectWithKeywords (func=0xb7c276e4, arg=0xb7c5302c, kw=0x0) at \
Python/ceval.c:3548 #14 0xb7fcf19f in sip_api_invoke_slot (slot=0x81eed8c, \
sigargs=0xb5ee71ec) at qtlib.c:203 #15 0xb78f2e8d in PyQtProxy::invokeSlot \
(slot=@0x81eed8c, qargs=0xbfffd4f0) at qpycore_pyqtproxy.cpp:474 #16 0xb78f2f98 in \
PyQtProxy::unislot (this=0x81eed70, qargs=0xbfffd4ec) at qpycore_pyqtproxy.cpp:416 \
#17 0xb78f30d7 in PyQtProxy::qt_metacall (this=0x81eed70, \
_c=QMetaObject::InvokeMetaMethod, _id=1, _a=0xbfffd4ec)  at qpycore_pyqtproxy.cpp:380
#18 0xb7614215 in QMetaObject::metacall (object=0x0, \
cl=QMetaObject::InvokeMetaMethod, idx=5, argv=0xbfffd4ec)  at \
kernel/qmetaobject.cpp:237 #19 0xb7626e93 in QMetaObject::activate (sender=0x81eec90, \
m=0xb6c38858, local_signal_index=1, argv=0xbfffd4ec)  at kernel/qobject.cpp:3272
#20 0xb62bad89 in QAction::triggered (this=0x81eec90, _t1=false) at \
.moc/release-shared/moc_qaction.cpp:263 #21 0xb62bc69f in QAction::activate \
(this=0x81eec90, event=QAction::Trigger) at kernel/qaction.cpp:1257 #22 0xb6786c57 in \
QMenuPrivate::activateCausedStack (this=0x81f1668, causedStack=@0xbfffd5c8, \
action=0x81eec90,   action_e=QAction::Trigger, self=true) at widgets/qmenu.cpp:993
#23 0xb678cbbb in QMenuPrivate::activateAction (this=0x81f1668, action=0x81eec90, \
action_e=QAction::Trigger,   self=<value optimized out>) at widgets/qmenu.cpp:1085

Explicitely end()ing the painter in print_ solved this.

While at it, add some obviously missing "self" references to size().

Pete


["scribble.diff" (text/x-diff)]

--- ./scribble.py.orig	2010-11-27 04:43:52.000000000 +0100
+++ ./scribble.py	2010-11-29 15:46:25.707908176 +0100
@@ -66,7 +66,7 @@ class ScribbleArea(QtGui.QWidget):
         if not loadedImage.load(fileName):
             return False
 
-        newSize = loadedImage.size().expandedTo(size())
+        newSize = loadedImage.size().expandedTo(self.size())
         self.resizeImage(loadedImage, newSize)
         self.image = loadedImage
         self.modified = False
@@ -75,7 +75,7 @@ class ScribbleArea(QtGui.QWidget):
 
     def saveImage(self, fileName, fileFormat):
         visibleImage = self.image
-        self.resizeImage(visibleImage, size())
+        self.resizeImage(visibleImage, self.size())
 
         if visibleImage.save(fileName, fileFormat):
             self.modified = False
@@ -110,7 +110,8 @@ class ScribbleArea(QtGui.QWidget):
 
     def paintEvent(self, event):
         painter = QtGui.QPainter(self)
-        painter.drawImage(QtCore.QPoint(0, 0), self.image)
+        dirtyRect = event.rect()
+        painter.drawImage(dirtyRect, self.image, dirtyRect)
 
     def resizeEvent(self, event):
         if self.width() > self.image.width() or self.height() > self.image.height():
@@ -154,6 +155,7 @@ class ScribbleArea(QtGui.QWidget):
             painter.setViewport(rect.x(), rect.y(), size.width(), size.height())
             painter.setWindow(self.image.rect())
             painter.drawImage(0, 0, self.image)
+            painter.end()
 
     def isModified(self):
         return self.modified
@@ -195,7 +197,7 @@ class MainWindow(QtGui.QMainWindow):
 
     def save(self):
         action = self.sender()
-        fileFormat = action.data()
+        fileFormat = str(action.data())
         self.saveFile(fileFormat)
 
     def penColor(self):
@@ -230,8 +232,7 @@ class MainWindow(QtGui.QMainWindow):
                 triggered=self.open)
 
         for format in QtGui.QImageWriter.supportedImageFormats():
-            text = format.toUpper() + "..."
-
+            text = str(format).upper() + "..."
             action = QtGui.QAction(text, self, triggered=self.save)
             action.setData(format)
             self.saveAsActs.append(action)


_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic