Equal Resize?

I'd like to allow a window to be resized but to keep the width and height equal. So no matter what the user resizes the window to, the largest dimension will be used as the width and height. I'm assuming SetClientSize() can be used somehow, but putting it in the resizing callback obviously creates a recursive problem. Is this possible? If so, what's the best way to do this? Any help is appreciated.

You can set an I'm-working-on-it flag to break the recursion.

In your resize callback:

    if self.resizeCB_flEnforcingResize:
         self.resizeCB_flEnforcingResize = False
     else:
         flMustResize = (new size not proportional to original)
         if flMustResize:
             #calculate new size
             self.resizeCB_flEnforcingResize = True
             SetClientSize(...)

- Sam

···

At 2004-05-25 02:21 AM -0400, you wrote:

I'd like to allow a window to be resized but to keep the width and height equal. So no matter what the user resizes the window to, the largest dimension will be used as the width and height. I'm assuming SetClientSize() can be used somehow, but putting it in the resizing callback obviously creates a recursive problem. Is this possible? If so, what's the best way to do this? Any help is appreciated.

__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com

Alex Zeiger wrote:

I'd like to allow a window to be resized but to keep the width and height equal. So no matter what the user resizes the window to, the largest dimension will be used as the width and height. I'm assuming SetClientSize() can be used somehow, but putting it in the resizing callback obviously creates a recursive problem. Is this possible? If so, what's the best way to do this? Any help is appreciated.

Something like this in an EVT_SIZE handler would probably do it:

     def OnSize(self, evt):
         w, h = self.GetSize()
         if w != h:
             m = max(w, h)
             wx.CallAfter(self.SetSize, (m, m))
         evt.Skip()

When w == h then recursion is prevented.

···

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

Samuel Reynolds wrote:

I'd like to allow a window to be resized but to keep the width and height equal. So no matter what the user resizes the window to, the largest dimension will be used as the width and height. I'm assuming SetClientSize() can be used somehow, but putting it in the resizing callback obviously creates a recursive problem. Is this possible? If so, what's the best way to do this? Any help is appreciated.

You can set an I'm-working-on-it flag to break the recursion.

In your resize callback:

   if self.resizeCB_flEnforcingResize:
        self.resizeCB_flEnforcingResize = False
    else:
        flMustResize = (new size not proportional to original)
        if flMustResize:
            #calculate new size
            self.resizeCB_flEnforcingResize = True
            SetClientSize(...)

- Sam

I see. Actually, couldn't it be simplier? Something like:

mustresize = (new size not proportional)
if mustresize:
  #calculate new size
  SetClientSize(...)

should work as long as you calculate the new size correctly

My problem was that I needed to resize the entire window so that a child frame's size ratio was unity. To do this, I did this within the child's resize cb:

def OnSize(self, evt, set=[0,0]):

         (w,h) = self.GetClientSize()
         (W,H) = self.parent.GetSize()

         #set border dimensions
         if set[0]==0 and set[1]==0:
             set[0]=W-w
             set[1]=H-h

         #make resizing ratio unity
         mustresize = (float(w)/float(h) != 1.0)
         if mustresize:
             #calculate new size
             if W>H:
                 W=H-set[1]+set[0]
                 w=W-set[0]
             else:
                 H=W-set[0]+set[1]
                 h=H-set[1]
             self.parent.SetSize((W,H))

···

At 2004-05-25 02:21 AM -0400, you wrote:

Robin Dunn wrote:

Alex Zeiger wrote:

I'd like to allow a window to be resized but to keep the width and height equal. So no matter what the user resizes the window to, the largest dimension will be used as the width and height. I'm assuming SetClientSize() can be used somehow, but putting it in the resizing callback obviously creates a recursive problem. Is this possible? If so, what's the best way to do this? Any help is appreciated.

Something like this in an EVT_SIZE handler would probably do it:

    def OnSize(self, evt):
        w, h = self.GetSize()
        if w != h:
            m = max(w, h)
            wx.CallAfter(self.SetSize, (m, m))
        evt.Skip()

When w == h then recursion is prevented.

That's exactly what I was looking for. Thanks for your help.

Yes, it could. I used the flag idiom because it applies
to *any* such recursive handler (i.e., it came to mind).
In this case, the fact that the new size has the desired
proportions is sufficient.

- Sam

···

At 2004-05-25 02:01 PM -0400, you wrote:

Samuel Reynolds wrote:

At 2004-05-25 02:21 AM -0400, you wrote:

I'd like to allow a window to be resized but to keep the width and height equal. So no matter what the user resizes the window to, the largest dimension will be used as the width and height. I'm assuming SetClientSize() can be used somehow, but putting it in the resizing callback obviously creates a recursive problem. Is this possible? If so, what's the best way to do this? Any help is appreciated.

You can set an I'm-working-on-it flag to break the recursion.
In your resize callback:
   if self.resizeCB_flEnforcingResize:
        self.resizeCB_flEnforcingResize = False
    else:
        flMustResize = (new size not proportional to original)
        if flMustResize:
            #calculate new size
            self.resizeCB_flEnforcingResize = True
            SetClientSize(...)
- Sam

I see. Actually, couldn't it be simplier? Something like:

mustresize = (new size not proportional)
if mustresize:
        #calculate new size
        SetClientSize(...)

should work as long as you calculate the new size correctly

__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com