Re: [wxPython-dev] Phoenix - Python 3.3

2 views
Skip to first unread message

Robin Dunn

unread,
Apr 30, 2013, 12:10:36 AM4/30/13
to wxPyth...@googlegroups.com
Maxim Kolosov wrote:
> Hello all.
>
> Error with AGW (Phoenix-2.9.5.81-r73873) and Python 3.3.1
>
> Traceback (most recent call last):
> File "python331.py", line 2, in <module>
> from wx.lib.agw.aui import AuiManager
> File "wx\lib\agw\aui\__init__.py", line 293, in <module>
> from .auibar import *
> File "wx\lib\agw\aui\auibar.py", line 20, in <module>
> import framemanager
> ImportError: No module named 'framemanager'
>
> on Python 2.7 work normal.

I expect that this is due to the absolute imports changes in Py3. Try
adding "from __future__ import absolute_import" and you'll probably get
the same error with Py27. Then you can fix it and send us a patch! :-)


--
Robin Dunn
Software Craftsman
http://wxPython.org

Maxim Kolosov

unread,
May 1, 2013, 5:26:23 AM5/1/13
to wxPyth...@googlegroups.com
Thanks Robin.
You is right about absolute import. I think main problem is cyclic imports, like auibar->framemanager->auibar, and perhaps Andrea Gavana will change internal structure of AUI to a more coherent.

I corrected some things for compatibility with Python 3, but not sure that everything is correct:
some constants from 'aui_constants.py' replaced with 'b' prefix;
dock.panes.sort(PaneSortFunc) changed to dock.panes.sort(key = lambda pane: pane.dock_pos), my module have only one pane and I append check for pane count;
if cli_size <= wx.Size(20, 20): changed to if tuple(cli_size) <= tuple(wx.Size(20, 20)):;
, however it works for me on py2 and py3. See attached file.

Sorry for my English.
aui_py3.zip

werner

unread,
May 1, 2013, 6:05:55 AM5/1/13
to wxPyth...@googlegroups.com
Hi Maxim,
I am sure Robin will want a patch and not the changed files.

If you are on Windows install something like TortoiseSVN and checkout:
http://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk

Copy your changed files into:
whereeveryouhave put the checkout\wxPhoenix\wx\lib\agw

Right click on the wxPhoenix folder and select "create patch" from the TortoiseSVN menu.

If you haven't already done so also check the following links:
http://wiki.wxpython.org/ProjectPhoenix/LibraryMigration  - add the tags to the changed files as mention in "Phase 2"
http://wxpython.org/Phoenix/docs/html/main.html

Werner

Maxim Kolosov

unread,
May 1, 2013, 11:33:41 AM5/1/13
to wxPyth...@googlegroups.com
Hi Werner,
 thanks for instructions
 my patch in attachement
agw_aui_20130501-1927.patch

Robin Dunn

unread,
May 1, 2013, 8:21:49 PM5/1/13
to wxPyth...@googlegroups.com
-import auibar
-import auibook
+from sys import hexversion
+if hexversion < 0x03000000:
+ import auibar
+ import auibook
+else:
+ from . import auibar
+ from . import auibook


First, please use wx.lib.six.PY3 for checking if Python3 is running or
not. Second, doesn't the "from . import foo" also work in Python 2.7?
If not then I would rather add the "from __future__ import
absolute_import" to make it work the same way instead of
conditionalizing the import statements based on version.

Maxim Kolosov

unread,
May 2, 2013, 1:36:48 AM5/2/13
to wxPyth...@googlegroups.com
четверг, 2 мая 2013 г., 4:21:49 UTC+4 пользователь Robin Dunn написал:
First, please use wx.lib.six.PY3 for checking if Python3 is running or  
not.  Second, doesn't the "from . import foo" also work in Python 2.7?
If not then I would rather add the "from __future__ import
absolute_import" to make it work the same way instead of
conditionalizing the import statements based on version.
Yes, this is work in Python 2.7, problem was my old 2.7b installation.
See other patch for "py" module.

What is problem with sys.hexversion?
wx_py.patch

Robin Dunn

unread,
May 2, 2013, 8:03:09 PM5/2/13
to wxPyth...@googlegroups.com
Maxim Kolosov wrote:
> О©╫О©╫О©╫О©╫О©╫О©╫О©╫, 2 О©╫О©╫О©╫ 2013 О©╫., 4:21:49 UTC+4 О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫ Robin Dunn О©╫О©╫О©╫О©╫О©╫О©╫О©╫:
>
> First, please use wx.lib.six.PY3 for checking if Python3 is running or
> not. Second, doesn't the "from . import foo" also work in Python 2.7?
> If not then I would rather add the "from __future__ import
> absolute_import" to make it work the same way instead of
> conditionalizing the import statements based on version.
>
> Yes, this is work in Python 2.7, problem was my old 2.7b installation.
> See other patch for "py" module.
>
> What is problem with sys.hexversion?

Nothing, other than we already have a way to test for Py3 that is more
readable and probably makes a lot more sense for a newbie reading the
code, and that I'd like to be consistent throughout the library instead
of having 3 or 4 ways of checking for Python3.

Maxim Kolosov

unread,
May 3, 2013, 3:02:35 AM5/3/13
to wxPyth...@googlegroups.com
Thanks for answer, Robin.
I have changed the way you advise.
20130503.patch

Robin Dunn

unread,
May 3, 2013, 2:31:31 PM5/3/13
to wxPyth...@googlegroups.com
Maxim Kolosov wrote:
> Thanks for answer, Robin.
> I have changed the way you advise.

In the future please keep separate sets of changes in separate patch
files. (In this case the aui and wx.py changes should have been kept
separate.)

I've applied the aui patches, with some modifications. Apparently you
didn't test with Py2.7 otherwise you probably would have seen that this
change doesn't make too much sense.

-import framemanager
+import wx.lib.six as six
+
+if not six.PY3:
+ import framemanager
from .aui_constants import *

which basically says that the framemanager module is not needed when
running with Python 2.7. I've changed those imports to be

from . import framemanager



For the wx.py patches this change:

-import cStringIO

+if not wx.lib.six.PY3:
+ from cStringIO import StringIO
+else:
+ from io import BytesIO as StringIO


doesn't work because wx.lib.six hasn't been imported. Also the six
module takes care of things like the modules and classes that have
changed names or locations. (It is much more than just the six.PY3
boolean.) So the above can be written as:

from wx.lib.six import StringIO


Here is another example, this:

+ if sys.hexversion < 0x03000000:
+ import __builtin__ as builtins
+ else:
+ import builtins

can be done like this:

from wx.lib.six.moves import builtins


I'll go ahead and commit these patches too since the rest of it looks
okay, but please do thoroughly test these changes when you get the next
snapshot, and also before submitting future patches.
Reply all
Reply to author
Forward
0 new messages