Backwards compatibility issues

I have an application which I have built using wxPython 2.2.5 running on
Python 2.0 and am running on Linux (SuSE 7.2). I am trying to port this to
wxPython 2.5.2.7 running on Python 2.3.4 running on Windows 2000/XP.
Unfortunately, I don't want to have to maintain two versions so I'm looking
to minimise the changes I have to make and make them backwards compatible.

1) First problem is with the NewId function - it doesn't exist. The wxNewId
function does. I added the following line to wxPython/_utils.py after line
131:

NewId = wx._misc.NewId

But I realise that it is autogenerated from the XML file so I guess the
change needs to go in there but I can't figure out if an additional <method>
entry is allowed or not.

2) I realise that wxGridSizer has been deprecated but I still need to use it
:-(. I seem to be having a few problems with this.

i) I have fixed on problem: in wx/lib/grids.py. Here is the patch:

--- grids.orig.py 2004-08-19 17:12:45.947649600 +0100
+++ grids.py 2004-08-19 14:08:34.175982400 +0100
@@ -201,7 +201,7 @@

class PyFlexGridSizer(PyGridSizer):
     def __init__(self, rows=0, cols=0, hgap=0, vgap=0):
- wxGridSizer.__init__(self, rows, cols, hgap, vgap)
+ PyGridSizer.__init__(self, rows, cols, hgap, vgap)
         self.rowHeights = []
         self.colWidths = []
         self.growableRows = []

ii) Trying to resize a dialog with a wxGridSizer in a panel doesn't seem to
work whereas it did before:

        # Instatiate Outer Box Sizer
        oOuterBox = wxBoxSizer(wxVERTICAL)

        # Instatiate Grid Box Sizer
        oGridBox = wxFlexGridSizer(2, 3, 2, 2) # rows, cols, hgap, vgap

        # Other stuff here...

        oOuterBox.Add(oGridBox, 0, wxALIGN_LEFT)

        #### Get the Panel to use the Sizer ####

        self.SetAutoLayout(true)
        self.SetSizer(oOuterBox)

        # Tell the Sizer to resize the Panel to match the sizer's minimal
size,
        # and then tell the Sizer to set the minimal size of this Frame to
that size
        oOuterBox.Fit(self)
        oOuterBox.SetSizeHints(self)

Any idea how I should be doing this? I remember fiddling when I first wrote
this but this seemed to work so I just stuck with it.

iii) I get an exception when trying to create another square grid as
follows:

Traceback (most recent call last):
  File "C:\Python23\lib\site-packages\wx\lib\grids.py", line 290, in
RecalcSizes
    self.SetItemBounds(items[i], x, y, w, h)
  File "C:\Python23\lib\site-packages\wx\lib\grids.py", line 195, in
SetItemBounds
    item.SetDimension(ipt, isz)
  File "C:\Python23\Lib\site-packages\wx\_core.py", line 8722, in
SetDimension
    return _core_.SizerItem_SetDimension(*args, **kwargs)
TypeError: Expected a pointer

Again, I never use to get this. I can supply code if required.

Robert Cragie, Design Engineer

Direct: +44 (0) 114 281 4512

···

_______________________________________________________________
Jennic Ltd, Furnival Street, Sheffield, S1 4QT, UK
http://www.jennic.com Tel: +44 (0) 114 281 2655 Confidential
_______________________________________________________________

deprecation will be your worst enemy. Have you considered using *only* 2.5.2.7 and provide staticaly linked versions for the old systems?

···

On Thu, 19 Aug 2004 17:28:54 +0100, Robert Cragie <rcc@jennic.com> wrote:

I have an application which I have built using wxPython 2.2.5 running on
Python 2.0 and am running on Linux (SuSE 7.2). I am trying to port this to
wxPython 2.5.2.7 running on Python 2.3.4 running on Windows 2000/XP.
Unfortunately, I don't want to have to maintain two versions so I'm looking
to minimise the changes I have to make and make them backwards compatible.

--
Peter Damoc
Hacker Wannabe

Robert Cragie wrote:

I have an application which I have built using wxPython 2.2.5 running on
Python 2.0 and am running on Linux (SuSE 7.2). I am trying to port this to
wxPython 2.5.2.7 running on Python 2.3.4 running on Windows 2000/XP.
Unfortunately, I don't want to have to maintain two versions so I'm looking
to minimise the changes I have to make and make them backwards compatible.

That is a HUGE amount of time (3.5 years!) and changes between versions! (Not to mention going through two series of API-unstable revisions.) You will probably be much better off to update the wxPython install on the SuSE machine, and then fully migrate your app.

1) First problem is with the NewId function - it doesn't exist. The wxNewId
function does. I added the following line to wxPython/_utils.py after line
131:

NewId = wx._misc.NewId

But I realise that it is autogenerated from the XML file so I guess the
change needs to go in there but I can't figure out if an additional <method>
entry is allowed or not.

If you do it that way you'll lose it when updating wxPython to the nexct version. Probably better is to do something like this in your own code:

  try:
    NewId
  except NameError:
    NewId = wxNewId

2) I realise that wxGridSizer has been deprecated but I still need to use it
:-(. I seem to be having a few problems with this.

You'll probably be better off using the C++-wrapped versions of the wxGridSizer and wxFlexGridSizer in the newer version, as the Python versions havn't been maintained much since they were ported to C++. Some creative import statements will help you to choose one or the other for your two versions of wxPython:

  try:
    # check if it's already in the namespace
    wxGridSizer
  except NameError:
    # import from the library if not
    from wxPython.lib.grids import wxGridSizer, wxFlexgridSizer

i) I have fixed on problem: in wx/lib/grids.py. Here is the patch:

--- grids.orig.py 2004-08-19 17:12:45.947649600 +0100
+++ grids.py 2004-08-19 14:08:34.175982400 +0100
@@ -201,7 +201,7 @@

class PyFlexGridSizer(PyGridSizer):
     def __init__(self, rows=0, cols=0, hgap=0, vgap=0):
- wxGridSizer.__init__(self, rows, cols, hgap, vgap)
+ PyGridSizer.__init__(self, rows, cols, hgap, vgap)
         self.rowHeights =
         self.colWidths =
         self.growableRows =

Thanks.

ii) Trying to resize a dialog with a wxGridSizer in a panel doesn't seem to
work whereas it did before:

[...]

In what way doesn't it work?

iii) I get an exception when trying to create another square grid as
follows:

Traceback (most recent call last):
  File "C:\Python23\lib\site-packages\wx\lib\grids.py", line 290, in
RecalcSizes
    self.SetItemBounds(items[i], x, y, w, h)
  File "C:\Python23\lib\site-packages\wx\lib\grids.py", line 195, in
SetItemBounds
    item.SetDimension(ipt, isz)
  File "C:\Python23\Lib\site-packages\wx\_core.py", line 8722, in
SetDimension
    return _core_.SizerItem_SetDimension(*args, **kwargs)
TypeError: Expected a pointer

One of the parameters is not an instance of the expected type. What are ipt and isz?

Again, I never use to get this. I can supply code if required.

A sample app is always helpful.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!