help resizing a ctrl

Hello,
I pasted some sample code below. I'm having trouble changing the size
of a ctrl. The functionality I want is to make a ctrl large if the
mouse is hovered over it, and small when the mouse is not hovered over
it. seems simple but for some reason I can't get it to work. Any
ideas?

thanks,
Jeff

import wx

class Frame(wx.Frame):
    def __init__(self, title):
        wx.Frame.__init__(self, None, title=title, size=(350,500))

        self.panel = wx.Panel(self)
        self.panel_color = self.panel.GetBackgroundColour()
        self.sizer = wx.BoxSizer(orient=wx.VERTICAL)

        self.ctrls = []
        for i in range(5):
            self.ctrls.append(wx.TextCtrl(self.panel,
size=wx.Size(250, 25)))
            self.ctrls[i].Bind(wx.EVT_ENTER_WINDOW,
self.OnEnterWindow)
            self.ctrls[i].Bind(wx.EVT_LEAVE_WINDOW,
self.OnLeaveWindow)
            self.sizer.Add(self.ctrls[i], 0, border=2, flag=wx.ALL)

        self.panel.SetSizer(self.sizer)

    def OnEnterWindow(self, evt):
        print 'on enter window'
        evt.GetEventObject().SetSize(wx.Size(250, 100))
        self.sizer.Layout()

    def OnLeaveWindow(self, evt):
        print 'on leave window'
        evt.GetEventObject().SetSize(wx.Size(250, 25))
        self.sizer.Layout()

app = wx.App(redirect=True)
top = Frame("Hello World")
top.Show()
app.MainLoop()

Is it necessary for the whole sizer to re-layout -- or it is OK for
just that control to grow?

See below for the latter (works with wx2.8, OS-X ) - though I can't
help thinking that there's a better UI design that might meet your
needs -- this looks confusing to me.

-Chris

import wx

class Frame(wx.Frame):
   def __init__(self, title):
       wx.Frame.__init__(self, None, title=title, size=(350,500))

       self.panel = wx.Panel(self)
       self.panel_color = self.panel.GetBackgroundColour()
       self.sizer = wx.BoxSizer(orient=wx.VERTICAL)

       self.ctrls =
       for i in range(5):
           self.ctrls.append(wx.TextCtrl(self.panel,
size=wx.Size(250, 25)))
           self.ctrls[i].Bind(wx.EVT_ENTER_WINDOW,
self.OnEnterWindow)
           self.ctrls[i].Bind(wx.EVT_LEAVE_WINDOW,
self.OnLeaveWindow)
           self.sizer.Add(self.ctrls[i], 0, border=2, flag=wx.ALL)

       self.panel.SetSizer(self.sizer)

   def OnEnterWindow(self, evt):
       print 'on enter window'
       obj = evt.GetEventObject()
       obj.SetSize(wx.Size(250, 100))
       obj.Refresh()
       obj.Update()
       #self.sizer.Layout()

   def OnLeaveWindow(self, evt):
       print 'on leave window'
       obj = evt.GetEventObject()
       obj.SetSize(wx.Size(250, 25))
       obj.Refresh()
       obj.Update()
       #self.sizer.Layout()

app = wx.App(redirect=False)
top = Frame("Hello World")
top.Show()
app.MainLoop()

···

On Mon, Apr 23, 2012 at 11:01 AM, jeff <jeffpeery@yahoo.com> wrote:

The functionality I want is to make a ctrl large if the
mouse is hovered over it, and small when the mouse is not hovered over
it.

--

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@noaa.gov

thanks! thats a bit closer to what I need. However I would like the
control to grow, so that I can still see the surrounding controls. As
it is, the resized control overlays the ctrls below it.

thanks,
Jeff

···

On Apr 23, 11:18 am, Chris Barker <chris.bar...@noaa.gov> wrote:

On Mon, Apr 23, 2012 at 11:01 AM, jeff <jeffpe...@yahoo.com> wrote:
> The functionality I want is to make a ctrl large if the
> mouse is hovered over it, and small when the mouse is not hovered over
> it.

Is it necessary for the whole sizer to re-layout -- or it is OK for
just that control to grow?

See below for the latter (works with wx2.8, OS-X ) - though I can't
help thinking that there's a better UI design that might meet your
needs -- this looks confusing to me.

-Chris

import wx

class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, size=(350,500))

   self\.panel = wx\.Panel\(self\)
   self\.panel\_color = self\.panel\.GetBackgroundColour\(\)
   self\.sizer = wx\.BoxSizer\(orient=wx\.VERTICAL\)

   self\.ctrls = \[\]
   for i in range\(5\):
       self\.ctrls\.append\(wx\.TextCtrl\(self\.panel,

size=wx.Size(250, 25)))
self.ctrls[i].Bind(wx.EVT_ENTER_WINDOW,
self.OnEnterWindow)
self.ctrls[i].Bind(wx.EVT_LEAVE_WINDOW,
self.OnLeaveWindow)
self.sizer.Add(self.ctrls[i], 0, border=2, flag=wx.ALL)

   self\.panel\.SetSizer\(self\.sizer\)

def OnEnterWindow(self, evt):
print 'on enter window'
obj = evt.GetEventObject()
obj.SetSize(wx.Size(250, 100))
obj.Refresh()
obj.Update()
#self.sizer.Layout()

def OnLeaveWindow(self, evt):
print 'on leave window'
obj = evt.GetEventObject()
obj.SetSize(wx.Size(250, 25))
obj.Refresh()
obj.Update()
#self.sizer.Layout()

app = wx.App(redirect=False)
top = Frame("Hello World")
top.Show()
app.MainLoop()

--

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.Bar...@noaa.gov

thanks! thats a bit closer to what I need. However I would like the
control to grow, so that I can still see the surrounding controls. As
it is, the resized control overlays the ctrls below it.

Try throwing few more "Refresh" and "Update" calls in there -- you may
get it to work -- though I don't expect the wx devs had this sort of
thing in mind at the beginning, so it could be tenuous.

-Chris

···

On Mon, Apr 23, 2012 at 12:54 PM, jeff <jeffpeery@yahoo.com> wrote:

thanks,
Jeff

On Apr 23, 11:18 am, Chris Barker <chris.bar...@noaa.gov> wrote:

On Mon, Apr 23, 2012 at 11:01 AM, jeff <jeffpe...@yahoo.com> wrote:
> The functionality I want is to make a ctrl large if the
> mouse is hovered over it, and small when the mouse is not hovered over
> it.

Is it necessary for the whole sizer to re-layout -- or it is OK for
just that control to grow?

See below for the latter (works with wx2.8, OS-X ) - though I can't
help thinking that there's a better UI design that might meet your
needs -- this looks confusing to me.

-Chris

import wx

class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, size=(350,500))

   self\.panel = wx\.Panel\(self\)
   self\.panel\_color = self\.panel\.GetBackgroundColour\(\)
   self\.sizer = wx\.BoxSizer\(orient=wx\.VERTICAL\)

   self\.ctrls = \[\]
   for i in range\(5\):
       self\.ctrls\.append\(wx\.TextCtrl\(self\.panel,

size=wx.Size(250, 25)))
self.ctrls[i].Bind(wx.EVT_ENTER_WINDOW,
self.OnEnterWindow)
self.ctrls[i].Bind(wx.EVT_LEAVE_WINDOW,
self.OnLeaveWindow)
self.sizer.Add(self.ctrls[i], 0, border=2, flag=wx.ALL)

   self\.panel\.SetSizer\(self\.sizer\)

def OnEnterWindow(self, evt):
print 'on enter window'
obj = evt.GetEventObject()
obj.SetSize(wx.Size(250, 100))
obj.Refresh()
obj.Update()
#self.sizer.Layout()

def OnLeaveWindow(self, evt):
print 'on leave window'
obj = evt.GetEventObject()
obj.SetSize(wx.Size(250, 25))
obj.Refresh()
obj.Update()
#self.sizer.Layout()

app = wx.App(redirect=False)
top = Frame("Hello World")
top.Show()
app.MainLoop()

--

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.Bar...@noaa.gov

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--

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@noaa.gov

Sizers don't use the current size of a widget to calculate the layout. They use the best size and/or the min size of a widget, and then they call SetSize themselves if needed. Your code was changing the size, and then the Layout() was resetting it to the best/min size. So if you instead use SetMinSize you'll get what you want.

resizetest.py (1.13 KB)

···

On 4/23/12 11:01 AM, jeff wrote:

Hello,
I pasted some sample code below. I'm having trouble changing the size
of a ctrl. The functionality I want is to make a ctrl large if the
mouse is hovered over it, and small when the mouse is not hovered over
it. seems simple but for some reason I can't get it to work. Any
ideas?

--
Robin Dunn
Software Craftsman