preventing "illegal" resizing of the AuiPane? (wxPython)

No, the GetAllPanes() call will give you a PaneInfo object. It will NOT
give you a reference to the window itself. So far I have not found any
way to get a reference to the managed windows from the AUI-manager,
that’s why I have to keep my own dict (or list) of references. So if
anybody knows how to get this info from the aui-manager please tell me…

BTW, I tried the event.Veto() suggestion but I never got it to work…

Vlastimil Brom wrote:

···

2008/1/16, Max Landaeus max@landaeus.com:

Hi
all,

I find this bug quite bad. If you drag the vertical sash in the wxPython

Demo to the right and beyond the main window you’ll loose the center

panel and have to restart the program to get it back.

While I’m waiting for a proper solution from the AUI experts I came up

with a quick and dirty fix that at seems to work (at least for me). A

sample is attached and I hope it can be of use to others. In this
sample

the panes will not change if you try to drag them outside the main
window.

Basically I intercept the EVT_AUI_RENDER event and check that all

windows are greater than a minimum size. If they are not I restore the

previous perspective.

Unfortunately I have to manage my own dictionary (or list if you prefer)

of managed windows since I couldn’t find any way to get them directly

from the AUI-manager. If anybody knows how to do this please let me
know…

Comments are wellcome,

Max

[…]

import
wx

import wx.aui

class AUIFrame(wx.Frame):

def __init__(self, parent, id=-1, title="", pos=wx.DefaultPosition,

             size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |

wx.SUNKEN_BORDER |

                                        wx.CLIP_CHILDREN):



    wx.Frame.__init__(self, parent, id, title, pos, size, style)



    # tell FrameManager to manage this frame

    self._mgr = wx.aui.AuiManager()

    self._mgr.SetManagedWindow(self)



    # panels is a dictionary containing references to the

“aui-managed”

    self.panels={}



    # Create some panels

    for index in range(4):

        name="Window " + str(index)

        txtC=wx.TextCtrl(self,wx.ID_ANY)

        txtC.AppendText('This is '+name)

        self._mgr.AddPane(txtC,

wx.aui.AuiPaneInfo().Name(name).

                          Caption(name).Show(True))

        # keep a reference to the windows that you add to the

aui-manager

        self.panels[name]=txtC



    # make one of the panes a center pane


    self._mgr.GetPane("Window 0").CenterPane()

    self._mgr.GetPane("Window 1").Right()



    self._mgr.Update()



    # The following lines MUST be positioned AFTER the first call

to _mgr.Update()

    # Save the initial perspective

    self.lastGoodPerspective=self._mgr.SavePerspective()

    # Intercept the aui-renderer

    self.Bind(wx.aui.EVT_AUI_RENDER,self.onRender)



def onRender(self,event):


    outOfRange=False

    for thisPane in self.panels:

        x,y=self.panels[thisPane].GetSize()

        # Here you put minimum acceptable sizes for x and y. If x

is to

        # low it might look ugly if you are using maximize- and

close-buttons:

        if (x < 20 or y < 10):

            outOfRange=True

    if outOfRange:

        # If any window is to small restore the previous perspective

        self._mgr.LoadPerspective(

self.lastGoodPerspective)

        self._mgr.Update()

    else:

        # All windows are OK save this perspective for next time

        self.lastGoodPerspective=self._mgr.SavePerspective()

event.Skip()

if name == ‘main’:

app = wx.App(False)

f = AUIFrame(None)

f.Show()

app.MainLoop()

To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

Hi, thank you very much for posting your code!

It works well for the problems I reported.

I don’t have many experiences with wx.aui, but it seems, that

for thisPane in self._mgr.GetAllPanes():

(x, y) = thisPane.window.GetSize()

would be equivalent to yours:

for thisPane in self.panels:

x,y=self.panels

[thisPane].GetSize()

At least, they seem to behave identically in my tests sofar …

However, I get an infinite loop and a RuntimeError due to the recursive
calls, when I resize the whole program window in a way, which would
leave some auiPane smaller than the hardcoded limits x, y. It would be
probably useful to intercept the size event of the frame too.

RuntimeError: maximum recursion depth exceeded

Traceback (most recent call last):

File “…aui-test-2.py”, line 44, in onRender

x,y=self.panels[thisPane].GetSize()

I also thought about a simpler approach using event.Veto() instead of
saving each perspective, but I haven’t been able to make it work sofar.

Thanks again,

Vlasta

Thanks Vlasta,

The “window” property seems to be what I was looking for. I don’t know
if there are any subtle differences but it looks like it works just as
well.

Now there is no need to keep a separate dict of managed windows which
makes the code a bit cleaner.

Max

Vlastimil Brom wrote:

···

2008/1/16, Max Landaeus max@landaeus.com:

No, the GetAllPanes() call
will give you a PaneInfo object. It will NOT give you a reference to
the window itself. So far I have not found any way to get a reference
to the managed windows from the AUI-manager, that’s why I have to keep
my own dict (or list) of references. So if anybody knows how to get
this info from the aui-manager please tell me…

Unfortunately, I did’t find any detailed documentation other than http://www.wxpython.org/docs/api/wx.aui.AuiPaneInfo-class.html

, but it seems, that the “window” property of the AuiPaneInfo would
reference the respective window (at least I get some
reasonable changing values when I print x,y produced the code I sent

for thisPane in self._mgr.GetAllPanes():

(x, y) = thisPane.window.GetSize()

print (x, y)

or am I missing some diefference here?

Vlasta