various size tuple conversion tip

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

various size tuple conversion tip

braidedlogix
I'll probably have a number of tips for anyone updating 2.8 code to work with Phoenix, but one of the more pressing ones concerns getting tuples for various size/position methods like:

GetMinSizeTuple
GetPositionTuple
GetBestSizeTuple
GetClientSizeTuple
GetScreenPositionTuple
GetSizeTuple

The proper way to convert for what I think is identical behavior is

GetMinSizeTuple() -> GetMinSize().Get()
GetPositionTuple() -> GetPosition().Get()
GetBestSizeTuple() -> GetBestSize().Get()
GetClientSizeTuple() -> GetClientSize().Get()
GetScreenPositionTuple() -> GetScreenPosition() .Get()
GetSizeTuple() -> GetSize() .Get()

Without the ".Get()", the returned value is a wx object. 

Cheers, Eric

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: various size tuple conversion tip

Matt Newville


On Sun, Apr 2, 2017 at 7:12 AM, <[hidden email]> wrote:

I'll probably have a number of tips for anyone updating 2.8 code to work with Phoenix, but one of the more pressing ones concerns getting tuples for various size/position methods like:

GetMinSizeTuple
GetPositionTuple
GetBestSizeTuple
GetClientSizeTuple
GetScreenPositionTuple
GetSizeTuple

The proper way to convert for what I think is identical behavior is

GetMinSizeTuple() -> GetMinSize().Get()
GetPositionTuple() -> GetPosition().Get()
GetBestSizeTuple() -> GetBestSize().Get()
GetClientSizeTuple() -> GetClientSize().Get()
GetScreenPositionTuple() -> GetScreenPosition() .Get()
GetSizeTuple() -> GetSize() .Get()

Without the ".Get()", the returned value is a wx object. 

Cheers, Eric


You may find  https://www.wxpython.org/Phoenix/docs/html/classic_vs_phoenix.html helpful.  With this (and the otherwise excellent documentation), I found the transition remarkably easy. I do have some tests for Phoenix (as  is_wxPhoenix = 'phoenix' in wx.PlatformInfo) in some places to support both versions.

For example, this handy part of the migration guide does  mention that GetSizeTuple() has been replaced by wx.GetSize(), which returns a wx.Size() object.  But, you don't *need* to use GetSize().Get(),  as you can use:
       width, height = window.GetSize()

That is, a wx.Size object can be used as a two-element sequence.  Or you can use the height and width attributes.  Or you can use the Get() method.

--Matt

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: various size tuple conversion tip

braidedlogix
When I test this out in PyCrust, the h,w=whatever.GetSize() works very well. On the other hand, this has been a consistent point of failure in the traitsui codes I've tried to get working. The error message is usually something like "too many values to unpack". Using the Get() method eliminates these errors and pushes the failure points farther downstream.

There are many contexts where previous codes did not use an explicit h,w=..Tuple(), but the outcomes expected tuple results. On the whole, I would stick with my tip to guarantee consistency with previous outcomes.

On the whole, this is very interesting for me, because it makes me wonder what's happening in the sequence of execution to prevent the proper assignment overload. I have one inexplicable segfault failure on a window.SetSize(a,b,c,d) .

The link you mention is really excellent, and I developed a script that will automatically make some of the drop-in substitutions. Anyone venturing down this pathway should also carefully read the stuff in
https://wxpython.org/Phoenix/docs/html/MigrationGuide.html


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...