Selecting WX2.8 in examples

Hello,
we are facing a problem in Debian where a user has problems running
embedding_in_wx*.py examples.

The problem is:

from wx import *

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__DocFilter'

import wx
print wx.__version__

2.6.3.2

Since WX2.8 is the one to use, the solution is simple:

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

Regards,

···

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

Moreover, I will provide a patch to move from

from wx import *

to

import wx

that's much more clear. Just let me know if in the patch I will add
the wxversion.select or no.

Regards,

···

On Fri, Mar 6, 2009 at 22:12, Sandro Tosi <morph@...12...> wrote:
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

Sandro Tosi wrote:

···

On Fri, Mar 6, 2009 at 22:12, Sandro Tosi <morph@...12...> wrote:

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

Moreover, I will provide a patch to move from

from wx import *

to

import wx

that's much more clear. Just let me know if in the patch I will add
the wxversion.select or no.

Regards,

Sounds good to me, but I am not a wx user, so I might be missing something. The only reservation that occurs to me is this: suppose version 2.10 comes out, and someone has only that installed. Is there a way to select 2.8 or higher, instead of requiring 2.8?

Eric

Sandro Tosi wrote:

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

Moreover, I will provide a patch to move from

from wx import *

to

import wx

that's much more clear. Just let me know if in the patch I will add
the wxversion.select or no.

Regards,

Sounds good to me, but I am not a wx user, so I might be missing something.
The only reservation that occurs to me is this: suppose version 2.10 comes
out, and someone has only that installed. Is there a way to select 2.8 or
higher, instead of requiring 2.8?

AFAIUI, it's not possible to say "2.8+" == "2.8 and all the higher
versions", but we can specify a list of version to be searched, the
first match is the one "mapped" as default wx. If no-one of the
specified version are available, then an exception is thrown:

import wxversion
wxversion.select(['2.5','2.3','2.9'])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/wxversion.py", line 149, in select
    raise VersionError("Requested version of wxPython not found")
wxversion.VersionError: Requested version of wxPython not found

wxversion.select(['2.5','2.3','2.8'])
import wx
wx.__version__

'2.8.7.1'

In any case, the example code doesn't work with wx2.6 so, as even a
temporary workaround, I think we should enforce the needs for wx2.8.

Cheers,

···

On Fri, Mar 6, 2009 at 23:00, Eric Firing <efiring@...229...> wrote:

On Fri, Mar 6, 2009 at 22:12, Sandro Tosi <morph@...12...> wrote:

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

Sandro Tosi wrote:

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

hmmm - only the examples? or should it be in the wx back-end itself? Maybe at least a version check?

Anyway -- certainly the examples

Moreover, I will provide a patch to move from

from wx import *

to

import wx

who hoo! thanks!

AFAIUI, it's not possible to say "2.8+" == "2.8 and all the higher
versions",

I think there is:

http://www.wxpython.org/docs/api/wxversion-module.html

you need:

import wxversion
wxversion.ensureMinimal('2.8')

I think that will do it, but I haven't tested much -- I only have one version installed now. If it does work, I say we definitely ue it in the.

Another option is to put it in the wx back-end in a try block:

wxversion.ensureMinimal('2.4')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/local/lib/wxPython-unicode-2.8.9.1/lib/python2.5/site-packages/wxversion.py", line 181, in ensureMinimal
     raise AlreadyImportedError("wxversion.ensureMinimal() must be called before wxPython is imported")
wxversion.AlreadyImportedError: wxversion.ensureMinimal() must be called before wxPython is imported

which might be the safest, and would catch both pylab use, and people's home-written apps that need the wxversion call.

thanks for working on this,

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...

Sandro Tosi wrote:

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

hmmm - only the examples? or should it be in the wx back-end itself?
Maybe at least a version check?

I'll leave this to the mpl gurus...

Anyway -- certainly the examples

...while I'll concentrate on them :slight_smile:

Moreover, I will provide a patch to move from

from wx import *

to

import wx

who hoo! thanks!

AFAIUI, it's not possible to say "2.8+" == "2.8 and all the higher
versions",

I think there is:

wxPython API Documentation — wxPython Phoenix 4.2.1 documentation

you need:

import wxversion
wxversion.ensureMinimal('2.8')

I think that will do it, but I haven't tested much -- I only have one
version installed now. If it does work, I say we definitely ue it in the.

Another option is to put it in the wx back-end in a try block:

wxversion.ensureMinimal('2.4')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/wxPython-unicode-2.8.9.1/lib/python2.5/site-packages/wxversion.py",
line 181, in ensureMinimal
raise AlreadyImportedError("wxversion.ensureMinimal() must be
called before wxPython is imported")
wxversion.AlreadyImportedError: wxversion.ensureMinimal() must be called
before wxPython is imported

which might be the safest, and would catch both pylab use, and people's
home-written apps that need the wxversion call.

yeah, that's what we need: I got 2 version installed (2.6 and 2.8) and
here is the output

In [1]: import wxversion

In [2]: help(wxversion.ensureMinimal)

In [3]: wxversion.ensureMinimal('2.6')

In [4]: import wx

In [5]: wx.__version__
Out[5]: '2.6.3.2'

and

In [2]: import wxversion

In [3]: wxversion.ensureMinimal('2.8')

In [4]: import wx

In [5]: wx.__version__
Out[5]: '2.8.7.1'

So I'm going to use it in the examples. Thanks for spotting it out!

I only hope that 2.8->2.10 (or higher) would not introduce such corner
cases like in 2.6->2.8.

Cheers,

···

On Mon, Mar 9, 2009 at 21:55, Christopher Barker <Chris.Barker@...236...> wrote:
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

Sandro Tosi wrote:

What do you think about adding those 2 line into wx examples?

hmmm - only the examples? or should it be in the wx back-end itself?
Maybe at least a version check?

I'll leave this to the mpl gurus...

fair enough.

yeah, that's what we need: I got 2 version installed (2.6 and 2.8) and
here is the output

In [2]: import wxversion

In [3]: wxversion.ensureMinimal('2.8')

In [4]: import wx

In [5]: wx.__version__
Out[5]: '2.8.7.1'

So I'm going to use it in the examples. Thanks for spotting it out!

great -- thanks for working on those -- good examples are key!

I only hope that 2.8->2.10 (or higher) would not introduce such corner
cases like in 2.6->2.8.

Less likely, with 2.8, we eliminated the compiled parts of the wx back-end, by using some new features.

However, if future versions of wxPython get the new enhanced buffer interface, it might be nice to use it.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...

Here it is the promised patch (sorry for the late, that proves how
busy I am these days).

It uses the 'wxversion.ensureMinimal' function as Chris pointed out,
and move from "from wx import *" to "import wx".

I tested them on a sys (Debian sid) with both wx2.6 and wx2.8: before
the patch the examples goes in abort, after they select wx2.8 and uses
it displaying the windows (even though ex2 and 3 seems a little "too
compress" do not know if it's due to code or patch :wink: ).

HTH, cheers,

examples_wx2.8_import.patch (9.66 KB)

···

On Fri, Mar 6, 2009 at 22:24, Sandro Tosi <morph@...12...> wrote:

On Fri, Mar 6, 2009 at 22:12, Sandro Tosi <morph@...12...> wrote:

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

Moreover, I will provide a patch to move from

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

Sandro Tosi wrote:

···

On Fri, Mar 6, 2009 at 22:24, Sandro Tosi <morph@...12...> wrote:

On Fri, Mar 6, 2009 at 22:12, Sandro Tosi <morph@...12...> wrote:

import wxversion
wxversion.select('2.8')
from wx import *
wx.__version__

'2.8.7.1'

That solves the problem of multi-wx on a system.

What do you think about adding those 2 line into wx examples?

Moreover, I will provide a patch to move from

Here it is the promised patch (sorry for the late, that proves how
busy I am these days).

It uses the 'wxversion.ensureMinimal' function as Chris pointed out,
and move from "from wx import *" to "import wx".

I tested them on a sys (Debian sid) with both wx2.6 and wx2.8: before
the patch the examples goes in abort, after they select wx2.8 and uses
it displaying the windows (even though ex2 and 3 seems a little "too
compress" do not know if it's due to code or patch :wink: ).

Sandro,

I have applied your patch, plus related changes to backend_wx and backend_wxagg as suggested by Chris, to the 0.98.5 maintenance branch, and then used svnmerge to propagate the changes to the trunk. (In other words, I judged the changes to be a bug fix rather than a new feature.)

Eric

Yes, indeed they are a bugfix... hence: thanks for merging them!! :slight_smile:

Cheers,

···

On Wed, Mar 11, 2009 at 20:49, Eric Firing <efiring@...229...> wrote:

I have applied your patch, plus related changes to backend_wx and
backend_wxagg as suggested by Chris, to the 0.98.5 maintenance branch, and
then used svnmerge to propagate the changes to the trunk. (In other words,
I judged the changes to be a bug fix rather than a new feature.)

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

Eric Firing wrote:

I have applied your patch, plus related changes to backend_wx and backend_wxagg as suggested by Chris, to the 0.98.5 maintenance branch, and then used svnmerge to propagate the changes to the trunk. (In other words, I judged the changes to be a bug fix rather than a new feature.)

Great, thanks! thanks for taking care of us wx users...

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...