Support for Qt5 has begun

188 views
Skip to first unread message

Edward K. Ream

unread,
Jun 12, 2014, 12:17:32 PM6/12/14
to leo-e...@googlegroups.com
As of rev d8f026289718... Leo's core loads with PyQt5.

Here is the checkin log:

QQQ
A mass update to support Qt5.  When Qt5 is in effect, QtGui is QtWidgets, and QtGui2 is QtGui.  When Qt4 is in effect, both are the same as QtGui.  Next: carefully rename QtGui -> QtWidgets and QtGui2 -> QtGui
QQQ

I forgot to mention that most calls to anObject.connect fail when Qt5 is in effect.  These are disabled with the isQt5 compile-time (module-level) constant.

Next, I'll do the renaming mentioned above.  To repeat, in the Qt4 world both QtGui and QtWidgets mean the QtGui module.

After the renaming works and is tested, I'll attempt to fix the "connect" problem.

Edward

Edward K. Ream

unread,
Jun 12, 2014, 12:54:27 PM6/12/14
to leo-e...@googlegroups.com
On Thursday, June 12, 2014 11:17:32 AM UTC-5, Edward K. Ream wrote:

> As of rev d8f026289718... Leo's core loads with PyQt5.

> Next, I'll do the renaming mentioned above.  To repeat, in the Qt4 world both QtGui and QtWidgets mean the QtGui module.

Done at rev 3ed6491149db...

**Important**: from now on, you must use the PyQt5 names for modules even if you are using PyQt4.

This shouldn't be odious: just use QtWidgets.aWidget instead of QtGui.aWidget.

The recommended way to import Qt is as follows::

try:
    import PyQt5.QtCore as QtCore
    import PyQt5.QtGui as QtGui
    from PyQt5 import QtWidgets
    isQt5 = True
except ImportError:
    import PyQt4.QtCore as QtCore
    import PyQt4.QtGui as QtGui
    QtWidgets = QtGui
    isQt5 = False

It's also fine to use this style of imports::

   from PyQt5 import QtWidgets # etc.

The last task will be hook up connections again when using Qt5.  At present, they are disabled with the isQt5 switch. Not sure what is going on.  Should be no big deal.

Oh yes, several plugins use Qt:  I'll be munging them as well.

Edward

duf...@gmail.com

unread,
Jun 12, 2014, 4:38:23 PM6/12/14
to leo-e...@googlegroups.com
Just to get it right, do you advise us to uninstall PyQt4 and install PyQt instead?
To do so would be no trouble at all for me, so no problem.

I only need to know which of the two is expected to be less problematic from now on.

Edward K. Ream

unread,
Jun 12, 2014, 5:05:29 PM6/12/14
to leo-editor
On Thu, Jun 12, 2014 at 3:38 PM, <duf...@gmail.com> wrote:
> Just to get it right, do you advise us to uninstall PyQt4 and install PyQt
> instead?
> To do so would be no trouble at all for me, so no problem.

On Windows, it is very easy to install PyQt5 just for some versions of
Python. I'm not so sure about Linux.

I have just converted the last few bits of code that are different
between Qt4 and Qt5. Most involve the new, simplified, Qt5 signals.
Everything now appears to work. All differences are marked with "if
isQt5:"

I'll up the changes as soon as all tests pass.

Edward

Terry Brown

unread,
Jun 12, 2014, 5:15:37 PM6/12/14
to leo-e...@googlegroups.com, edre...@gmail.com
On Thu, 12 Jun 2014 16:03:27 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> On Thu, Jun 12, 2014 at 3:38 PM, <duf...@gmail.com> wrote:
> > Just to get it right, do you advise us to uninstall PyQt4 and
> > install PyQt instead?
> > To do so would be no trouble at all for me, so no problem.

To answer dufriz, I'd say don't change anything right now, just keep
using the current Leo so you're testing the new code, for Qt4 for now.

> On Windows, it is very easy to install PyQt5 just for some versions of
> Python. I'm not so sure about Linux.

I couldn't get more than one Qt running in Windows when I tried, I was
aiming for Qt4+Py2.7 and Qt5+Py3.4 but whichever one I installed last
always seemed to break the other one (DLL load failure).

So I wouldn't encourage anyone to mess with multiple Qt installs in
Windows unless they're ok with things breaking.

> I have just converted the last few bits of code that are different
> between Qt4 and Qt5. Most involve the new, simplified, Qt5 signals.
> Everything now appears to work. All differences are marked with "if
> isQt5:"

Great, now I can develop the Qt5/Py3.4 + Py2.7 windows app. I'm
working on :-) I.e. the UI is in Qt5/Py3.4, but it calls an app. whose
python API is 2.7 only.

Cheers -Terry

dufriz

unread,
Jun 12, 2014, 6:04:16 PM6/12/14
to leo-e...@googlegroups.com
>To answer dufriz, I'd say don't change anything right now, just keep using the current Leo so you're testing the new code, for Qt4 for now.

Thanks. I'll stick to this piece of advice.

Edward K. Ream

unread,
Jun 12, 2014, 6:55:46 PM6/12/14
to leo-editor
On Thu, Jun 12, 2014 at 11:54 AM, Edward K. Ream <edre...@gmail.com> wrote:

> The last task will be hook up connections again when using Qt5.

Actually, there were a few more items, but as of rev dc9568360f7d...
just about everything appears to be working. Some notes:

1. The new signal code is much simpler than the old. I haven't
attempted to use the new code with PyQt4, though in one or two places
the new style seems to be in use already...

2. The viewrendered.py plugin now works with PyQt5, at least enough to
put up help messages. More advanced features (like movies) need to be
tested.

3. Several other plugins need to be revised, including (I suspect)
viewrendered2.py.

Please report any problems/crashes immediately. Aside from revising
imports in plugins I don't plan any more work on this project.

Edward

Edward K. Ream

unread,
Jun 12, 2014, 7:00:23 PM6/12/14
to Terry Brown, leo-editor
On Thu, Jun 12, 2014 at 4:15 PM, Terry Brown <terry_...@yahoo.com> wrote:

> I couldn't get more than one Qt running in Windows when I tried, I was
> aiming for Qt4+Py2.7 and Qt5+Py3.4 but whichever one I installed last
> always seemed to break the other one (DLL load failure).

Did you uninstall Qt4 using the uninstall.exe in site-packages/PyQt4?
That should zap the dll's.

> So I wouldn't encourage anyone to mess with multiple Qt installs in
> Windows unless they're ok with things breaking.

Always good advice :-)

> Great, now I can develop the Qt5/Py3.4 + Py2.7 windows app. I'm
> working on :-) I.e. the UI is in Qt5/Py3.4, but it calls an app. whose
> python API is 2.7 only.

Please keep us informed :-)

Edward

Terry Brown

unread,
Jun 12, 2014, 7:20:27 PM6/12/14
to leo-e...@googlegroups.com
On Thu, 12 Jun 2014 17:55:45 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> On Thu, Jun 12, 2014 at 11:54 AM, Edward K. Ream
> <edre...@gmail.com> wrote:
>
> > The last task will be hook up connections again when using Qt5.
>
> Actually, there were a few more items, but as of rev dc9568360f7d...
> just about everything appears to be working. Some notes:

Great, it's running for me, Py 3.4, Qt 5.3.0, Win 7. Great timing,
just when I needed to work in that environment with Leo :-)

Minor non-import thing, line 464 in qtGui.py, QWheelEvent.delta() is
now QWheelEvent.angleDelta(), to separate it from the new
QWheelEvent.pixelDelta().

Cheers -Terry

Terry Brown

unread,
Jun 12, 2014, 7:30:21 PM6/12/14
to leo-e...@googlegroups.com
On Thu, 12 Jun 2014 18:00:22 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> On Thu, Jun 12, 2014 at 4:15 PM, Terry Brown
> <terry_...@yahoo.com> wrote:
>
> > I couldn't get more than one Qt running in Windows when I tried, I
> > was aiming for Qt4+Py2.7 and Qt5+Py3.4 but whichever one I
> > installed last always seemed to break the other one (DLL load
> > failure).
>
> Did you uninstall Qt4 using the uninstall.exe in site-packages/PyQt4?
> That should zap the dll's.

At the time, I wanted Qt4 in Py 2.7 for Leo, and Qt 5 in Py 3.4 for the
GUI part of my app., but of course now it doesn't matter :-)

BTW, in the interlude I looked at Sublime Text, Notepad++, and ScITE,
but they all have dysfunctional outlining - they collapse all ok to
see the classes and top-level functions, but when I expand a class I
don't want all its methods expanded - defeats the whole point of
outlining :)

Cheers -Terry

gatesphere

unread,
Jun 12, 2014, 8:19:12 PM6/12/14
to leo-e...@googlegroups.com
Just updated Leo from github, and Win7/Python 2.7/PyQt4 gives me this error:

exception importing plugin leo.plugins.viewrendered2
Traceback (most recent call last):
File
"C:\cygwin\home\Jake\programming\leo\leo-editor\leo\core\leoPlugins.py",
line 548, in loadOnePlugin
__import__(moduleName)
File
"C:\cygwin\home\Jake\programming\leo\leo-editor\leo\plugins\viewrendered2.py",
line 663, in <module>
class WebViewPlus(QtWidgets.QWidget):
NameError: name 'QtWidgets' is not defined

Looks like vr2 is still in a half-and-half state. There's a block of
imports that might be tricky to fix:

# PyQt...
from PyQt4 import QtCore, QtGui, QtSvg, QtWebKit
from PyQt4.QtCore import QUrl
try:
import PyQt4.phonon as phonon
phonon = phonon.Phonon
except ImportError:
phonon = None

-->Jake

Edward K. Ream

unread,
Jun 12, 2014, 10:04:35 PM6/12/14
to leo-editor
On Thu, Jun 12, 2014 at 7:19 PM, gatesphere <gates...@gmail.com> wrote:
> Just updated Leo from github, and Win7/Python 2.7/PyQt4 gives me this error:

I'll get to vr2 next.

EKR

Edward K. Ream

unread,
Jun 12, 2014, 10:31:03 PM6/12/14
to leo-editor
On Thu, Jun 12, 2014 at 6:20 PM, 'Terry Brown' via leo-editor
<leo-e...@googlegroups.com> wrote:

> Minor non-import thing, line 464 in qtGui.py, QWheelEvent.delta() is
> now QWheelEvent.angleDelta(), to separate it from the new
> QWheelEvent.pixelDelta().

Fixed at recent rev.

Also fixed onIndexChanged for the Chapter Combo box. As a result,
chapters appear to be fully functional with Qt5.

Next, fixing vr2 and other plugins that presently use Qt4.

EKR

Terry Brown

unread,
Jun 15, 2014, 12:53:12 PM6/15/14
to leo-e...@googlegroups.com

PyQt5 conversion seems mostly straight forward, apart from the parts
that are not straight forward :-}

Trying to work out what's going on in todo.py, let's use a simple test
case, just running the 'insert-icon' command on an outline with a
single node.

'insert-icon' uses g.app.gui.runOpenFileDialog, and *Py*Qt 5 has changed the return value for QFileDialog.getOpenFileNames() from
[list of file names]
to
[[list of file names], <selected filter>]

Ok, no big deal.

Here's a trap though:

- def setter(pri=pri): o.setPri(pri)
- self.connect(w, QtCore.SIGNAL("clicked()"), setter)
+ def setter(pri=pri):
+ o.setPri(pri)
+ if isQt5:
+ w.clicked.connect(setter)
+ else:
+ self.connect(w, QtCore.SIGNAL("clicked()"), setter)

The old form calls setter() with no parameters, the new form calls
setter with `bool is_checked`, seeing buttons can be checked or
unchecked when they're clicked.

I think the best solution is to change setter() to be
def setter(checked, pri=pri): ...
which will work in both Qt4 and Qt5, basically the old style .connect()
let you select whether that parameter got passed or not, but I think
everything's cleaner if we just make the callbacks match the basic
definition of the signals.

Cheers -Terry

lewis

unread,
Jun 16, 2014, 9:46:46 AM6/16/14
to leo-e...@googlegroups.com
Hi Edward,

Thanks for your continued work on Leo.
It seems the find command is not working fully with Qt5. Ctrl-F brings up the Find menu/tabs.
However a mouseclick on any button Find Next: F3, Find Previous: F2, or Find All, or any Replace button generates the traceback.
Here is the logfile:

Leo Log Window
Leo 4.11 final, build 3c4725628b28 (branch: master), 2014-06-16 23:20:01
Python 3.4.1, PyQt version 5.3.0
Windows 7 AMD64 (build 6.1.7601) SP1
'@focused-border-unfocus-color' from style-sheet comment definition, please use regular @string / @color type @settings.
Abbreviations off
reading: N:\leo\workbook.leo
reading: @edit mail_sig.txtTraceback (most recent call last):
  File "C:\Python34\Lib\site-packages\leo-editor\leo\plugins\qtGui.py", line 2583, in find_tab_button_callback
    fc = c.findCommands
AttributeError: 'bool' object has no attribute 'findCommands'


Some good news :)
While writing this I noticed that using the keyboard function keys F2 or F3 will successfully find text, and not give any errors.

Regards
Lewis

Terry Brown

unread,
Jun 26, 2014, 1:52:37 PM6/26/14
to leo-e...@googlegroups.com
On Sun, 15 Jun 2014 11:53:07 -0500
"'Terry Brown' via leo-editor" <leo-e...@googlegroups.com> wrote:

Another instance of this trap:
https://github.com/leo-editor/leo-editor/commit/ecca25af

I think searching for all occurrences of clicked() and triggered() with
both kinds of quotes would find these. In the above fix I didn't
follow my own advice, "make the callbacks match the basic definition of
the signals", hmmm.

Cheers -Terry

Edward K. Ream

unread,
Jun 27, 2014, 12:17:01 PM6/27/14
to leo-e...@googlegroups.com

On Thursday, June 26, 2014 12:52:37 PM UTC-5, Terry wrote:

I think searching for all occurrences of clicked() and triggered() with
both kinds of quotes would find these.

Just added an "event" arg (the first arg) for several "clicked" callbacks.  The find buttons now work again ;-)

I'll do the same for "triggered" next.

Edward

Edward K. Ream

unread,
Jun 27, 2014, 12:24:03 PM6/27/14
to leo-e...@googlegroups.com
On Friday, June 27, 2014 11:17:01 AM UTC-5, Edward K. Ream wrote:

Just added an "event" arg (the first arg) for several "clicked" callbacks.  The find buttons now work again ;-)

I'll do the same for "triggered" next.

Done at the latest rev.  However, some callbacks are defined using lambda.  I didn't change these and some of them (detach tab, for instance) appear to work.

Terry, when you get a chance, please review all the triggered callbacks.  Thanks.

Edward

Terry Brown

unread,
Jun 29, 2014, 10:44:50 PM6/29/14
to leo-e...@googlegroups.com
On Fri, 27 Jun 2014 09:24:03 -0700 (PDT)
"Edward K. Ream" <edre...@gmail.com> wrote:

I've made a note.

I think it's generally a bool 'checked' arg. rather than the event
object that's passed in these cases, e.g.:
http://qt-project.org/doc/qt-5/qabstractbutton.html#clicked
but that doesn't stop adding an arg. named 'event' fixing things.

I think the lambda cases are either more robust or will produce a
runtime error more convincingly, but I'll have a look at them.

Of course the problem would never have arisen if Qt wasn't also trying
to support legacy languages like C++ ;-) (kidding).

Cheers -Terry
Reply all
Reply to author
Forward
0 new messages