[PyKDE] Qtranslator problems w/ setAccel

stuff at mailzilla.net stuff at mailzilla.net
Mon Jan 12 03:19:01 GMT 2004


Thanks for the reply Phil.  I suppose that fix you mentioned in the change
log did indeed fix the problem.  However, since I'm somewhat committed to
making things work w/ earlier versions of PyQt I created a small python
script that fixes the pyuic created file (such that translations will 
work).  Since I'm working on an open source project I have little control 
of which PyQt distributions people are using (for instance, I am using 3.8 
because it shipped with BlackAdder).

If anybody is interested in the script please email me directly 
and I will be happy to provide it.  Basically, I have a shell script which 
calls pyuic and then my python "fixer" script.  Rather than calling pyuic 
directly, I call my wrapper shell script which does everything seemlessly 
and I'm left with a python file that works well with older versions of 
PyQt.  The "fixer" script itself simply replaces lines in the 
pyuic-created module that look like this:

    self.fileNewAction.setAccel(self.__tr("Ctrl+N"))

with:

    self.fileNewAction.setAccel(QKeySequence(self.__tr("Ctrl+N")))

The explicit cast to QKeySequence fixes the problem for PyQt versions 
released prior to 12/23/2003.

Phil



On Sun, 11 Jan 2004, Phil Thompson wrote:

> On Wednesday 07 January 2004 6:58 pm, stuff at mailzilla.net wrote:
> > To followup on the problem I reported earlier, I've provided the pyuic
> > generated main.py module as an attachment.  I've modified the __tr()
> > method to print it's arguments.
> >
> > Output of executing test.py is now this:
> >
> > $ python test.py
> > __tr(MainWindow, None)
> > __tr(New, None)
> > __tr(&New, None)
> > __tr(Ctrl+N, None)
> > Fatal Python error: PyEval_SaveThread: NULL tstate
> > Aborted
> >
> >
> > The __tr(Ctrl+N, None) line is a result of the setAccel() method in
> > the MainWindow class.  Commenting out this line (and all other setAccel
> > lines) and things work as they should.  However, with the pyuic generated
> > code (where the setAccel() method invokes the __tr() method), the
> > application crashes as indicated by the above output.
> >
> > I've confirmed this behavior on Windows and Linux (Redhat 9.0) using the
> >
> > PyQt distribution included with BlackAdder.  On my linux box:
> > >>> from qt import *
> > >>> PYQT_VERSION_STR
> >
> > '3.8'
> >
> > >>> QT_VERSION_STR
> >
> > '3.2.2'
> >
> >
> > Interestingly, if I modify the __tr() method to simply return it's first
> > argument (return s) the output is now:
> >
> > $ python test.py
> > __tr(MainWindow, None)
> > __tr(New, None)
> > __tr(&New, None)
> > __tr(Ctrl+N, None)
> > Traceback (most recent call last):
> >   File "test.py", line 11, in ?
> >     m = MainWindow()
> >   File "main.py", line 587, in __init__
> >     self.languageChange()
> >   File "main.py", line 613, in languageChange
> >     self.fileNewAction.setAccel(self.__tr("Ctrl+N"))
> > TypeError: Argument 1 of QAction.setAccel() has an invalid type
> >
> > I would appreciate it if someone could run the test.py script to see if it
> > works on their version of PyQt/Qt.  Perhaps this problem has been fixed in
> > a more recent version of either package (I did glance at the change log
> > for PyQt but did not see anything pertinent).
> 
> With current snapshots (PyQt, SIP v3.x, SIP v4.x) there isn't a problem.
> 
> My guess is the bug is the one with the following entry in the PyQt ChangeLog:
> 
> 2003/12/21 16:07:00  phil
> Fixed a bug when automatically converting to a QKeySequence.
> 
> Phil
> 




More information about the PyQt mailing list