Fully visible button- unclickable button until parent frame resize

Hi I have a button in this panel whose code I have given below. I am running this on Mac OSX.

If I set the border around the button to be 50 pixels , then the button does not respond to clicks even though I can see the entire button

Only if I resize the window can I suddenly click the button

The problem does not happen if the border is only 10 pixels.

I am trying to understand why a fully visible and event bound button does not respond to clicks

thanks for your help

hari

Funky unclickeable button

import wx

class MaFrame(wx.Frame):

def init(self,*args,**kwds):

wx.Frame.init(self,*args, **kwds)

self.SetSize((634,440))

self.Layout()

class PlatePanel(wx.Panel):

def init(self,*args,**kwds):

wx.Panel.init(self,*args,**kwds)

self.platelabel = wx.StaticText(parent=self,id=-1,label=“Plate”)

self.text_ctrl_1 = wx.TextCtrl(self, -1, “A1”,(150,0))

self.text_ctrl_2 = wx.TextCtrl(self,-1,“A12”,(150,0))

self.plate_add_button = wx.Button(self,label=“AddPlate”)

self.do_connections()

self.do_layout()

def do_layout(self):

sizer_top = wx.BoxSizer(wx.VERTICAL)

sizer_widgets = wx.BoxSizer(wx.HORIZONTAL)

sizer_widgets.Add(self.platelabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_1,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_2,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_top.Add(sizer_widgets,3,wx.EXPAND)

sizer_top.Add(self.plate_add_button,1,wx.ALL|wx.ALIGN_RIGHT,50)

self.SetSizer(sizer_top)

self.Fit()

def do_connections(self):

self.Bind(wx.EVT_BUTTON,self.add_plate_def,self.plate_add_button)

print “Bound”

def add_plate_def(self,event):

print “Clicked Button for plate add”

if name==“main”:

app = wx.PySimpleApp()

maframe = MaFrame(parent=None,title=“Gzilla”,size=(500,440))

plate_panel = PlatePanel(parent=maframe)

maframe.Show()

app.MainLoop()

On Windows XP with wxPython 2.8.9.2, the button is very skinny and
unreadable, but clickable. I think your border size is forcing the
size of the button to be too small, but I don't really know why.

- Mike

···

On Jul 14, 4:08 pm, hari jayaram <hari...@gmail.com> wrote:

Hi I have a button in this panel whose code I have given below. I am running
this on Mac OSX.
If I set the border around the button to be 50 pixels , then the button does
not respond to clicks even though I can see the entire button

Only if I resize the window can I suddenly click the button

The problem does not happen if the border is only 10 pixels.

I am trying to understand why a fully visible and event bound button does
not respond to clicks

thanks for your help
hari

# Funky unclickeable button

import wx

class MaFrame(wx.Frame):

def \_\_init\_\_\(self,\*args,\*\*kwds\):
    wx\.Frame\.\_\_init\_\_\(self,\*args, \*\*kwds\)
    self\.SetSize\(\(634,440\)\)
    self\.Layout\(\)

class PlatePanel(wx.Panel):

def \_\_init\_\_\(self,\*args,\*\*kwds\):
    wx\.Panel\.\_\_init\_\_\(self,\*args,\*\*kwds\)
    self\.platelabel = wx\.StaticText\(parent=self,id=\-1,label=&quot;Plate&quot;\)
    self\.text\_ctrl\_1 = wx\.TextCtrl\(self, \-1, &quot;A1&quot;,\(150,0\)\)
    self\.text\_ctrl\_2 = wx\.TextCtrl\(self,\-1,&quot;A12&quot;,\(150,0\)\)
    self\.plate\_add\_button = wx\.Button\(self,label=&quot;AddPlate&quot;\)
    self\.do\_connections\(\)
    self\.do\_layout\(\)

def do\_layout\(self\):
    sizer\_top = wx\.BoxSizer\(wx\.VERTICAL\)
    sizer\_widgets = wx\.BoxSizer\(wx\.HORIZONTAL\)

sizer_widgets.Add(self.platelabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_1,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_2,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)
sizer_top.Add(sizer_widgets,3,wx.EXPAND)
sizer_top.Add(self.plate_add_button,1,wx.ALL|wx.ALIGN_RIGHT,50)
self.SetSizer(sizer_top)
self.Fit()

def do\_connections\(self\):
    self\.Bind\(wx\.EVT\_BUTTON,self\.add\_plate\_def,self\.plate\_add\_button\)
    print &quot;Bound&quot;

def add\_plate\_def\(self,event\):
    print &quot;Clicked Button for plate add&quot;

if __name__=="__main__":
app = wx.PySimpleApp()
maframe = MaFrame(parent=None,title="Gzilla",size=(500,440))
plate_panel = PlatePanel(parent=maframe)
maframe.Show()
app.MainLoop()

On Mac OSX Leopard , the button looks very much normal and click-able. ( see attached png screenshot )

But does not respond.

Any ideas on how to troubleshoot this ?

Hari

···

On Tue, Jul 14, 2009 at 5:30 PM, Mike Driscoll kyosohma@gmail.com wrote:

On Jul 14, 4:08 pm, hari jayaram hari...@gmail.com wrote:

Hi I have a button in this panel whose code I have given below. I am running

this on Mac OSX.

If I set the border around the button to be 50 pixels , then the button does

not respond to clicks even though I can see the entire button

Only if I resize the window can I suddenly click the button

The problem does not happen if the border is only 10 pixels.

I am trying to understand why a fully visible and event bound button does

not respond to clicks

thanks for your help

hari

Funky unclickeable button

import wx

class MaFrame(wx.Frame):

def __init__(self,*args,**kwds):
    wx.Frame.__init__(self,*args, **kwds)
    self.SetSize((634,440))
    self.Layout()

class PlatePanel(wx.Panel):

def __init__(self,*args,**kwds):
    wx.Panel.__init__(self,*args,**kwds)
    self.platelabel = wx.StaticText(parent=self,id=-1,label="Plate")
    self.text_ctrl_1 = wx.TextCtrl(self, -1, "A1",(150,0))
    self.text_ctrl_2 = wx.TextCtrl(self,-1,"A12",(150,0))
    self.plate_add_button = wx.Button(self,label="AddPlate")
    self.do_connections()
    self.do_layout()
def do_layout(self):
    sizer_top = wx.BoxSizer(wx.VERTICAL)
    sizer_widgets = wx.BoxSizer(wx.HORIZONTAL)

sizer_widgets.Add(self.platelabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_1,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_2,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

    sizer_top.Add(sizer_widgets,3,wx.EXPAND)
    sizer_top.Add(self.plate_add_button,1,wx.ALL|wx.ALIGN_RIGHT,50)
    self.SetSizer(sizer_top)
    self.Fit()
def do_connections(self):
    self.Bind(wx.EVT_BUTTON,self.add_plate_def,self.plate_add_button)
    print "Bound"
def add_plate_def(self,event):
    print "Clicked Button for plate add"

if name==“main”:

app = wx.PySimpleApp()
maframe = MaFrame(parent=None,title="Gzilla",size=(500,440))
plate_panel = PlatePanel(parent=maframe)
maframe.Show()
app.MainLoop()

On Windows XP with wxPython 2.8.9.2, the button is very skinny and

unreadable, but clickable. I think your border size is forcing the

size of the button to be too small, but I don’t really know why.

  • Mike

The frame is explicitly sized at (634, 440), but your panel would like to be (531, 480). I’m not sure why this breaks in such a weird way - probably some implementation detail of wxMac - but when the frame is set to (634, 480) instead, the problem goes away.

-Nat

···

On Tue, Jul 14, 2009 at 3:50 PM, hari jayaram harijay@gmail.com wrote:

On Mac OSX Leopard , the button looks very much normal and click-able. ( see attached png screenshot )
But does not respond.

The frame is explicitly sized at (634, 440), but your panel would like to be (531, 480)

Does my panel want to be 480 based on the fact that 480 is divisible by three , the number of children in the horizontal sizer associated in the panel?

Thanks

Hari

···

On Tue, Jul 14, 2009 at 7:12 PM, Nathaniel Echols nathaniel.echols@gmail.com wrote:

On Tue, Jul 14, 2009 at 3:50 PM, hari jayaram harijay@gmail.com wrote:

On Mac OSX Leopard , the button looks very much normal and click-able. ( see attached png screenshot )
But does not respond.

The frame is explicitly sized at (634, 440), but your panel would like to be (531, 480). I’m not sure why this breaks in such a weird way - probably some implementation detail of wxMac - but when the frame is set to (634, 480) instead, the problem goes away.

-Nat

I suspect it has something to do with this:

sizer_top.Add(sizer_widgets,3,wx.EXPAND)

sizer_top.Add(self.plate_add_button,1,wx.ALL|wx.ALIGN_RIGHT,50)

So you have a button of approximately 20 pixels height (just at a glance - looks about right), bordered on all sides by 50 pixels for a total height of 120 pixels, with a proportion of 1 versus a proportion of 3 for sizer_widgets, e.g. 1120 + 3120.

But I would recommend against assuming anything about the resulting size, since it will vary from platform to platform and subtle changes to layout may give you something unexpected. I’ve appended a modified version of your code that just uses Fit() to size the windows; if you want the frame to be wider you can just pad the spacers some more on the side, or to reduce the height, change the proportions or borders.

I do still set frame sizes explicitly in some situations, but this is usually when I have a more complex layout involving a notebook and can’t get the frame to fit around the notebook contents (and I’m probably missing something obvious - in fact, I think I’ll post that question tomorrow). I can get away with this, however, because I use ScrolledPanels for just about everything, so I’m not worried about panel contents falling outside the frame.

-Nat

import wx

class MaFrame(wx.Frame):

def init(self,*args,**kwds):

wx.Frame.init(self,*args, **kwds)

self.Layout()

class PlatePanel(wx.Panel):

def init(self,*args,**kwds):

wx.Panel.init(self,*args,**kwds)

self.platelabel = wx.StaticText(parent=self,id=-1,label=“Plate”)

self.text_ctrl_1 = wx.TextCtrl(self, -1, “A1”,(150,-1))

self.text_ctrl_2 = wx.TextCtrl(self,-1,“A12”,(150,-1))

self.plate_add_button = wx.Button(self,label=“AddPlate”)

self.do_connections()

self.do_layout()

def do_layout(self):

sizer_top = wx.BoxSizer(wx.VERTICAL)

sizer_widgets = wx.BoxSizer(wx.HORIZONTAL)

sizer_widgets.Add(self.platelabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_1,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_widgets.Add(self.text_ctrl_2,0,wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT,50)

sizer_top.Add(sizer_widgets,3,wx.EXPAND)

sizer_top.Add(self.plate_add_button,1,wx.ALL|wx.ALIGN_RIGHT,50)

self.SetSizer(sizer_top)

sizer_top.Layout()

sizer_top.Fit(self)

def do_connections(self):

self.Bind(wx.EVT_BUTTON,self.add_plate_def,self.plate_add_button)

print “Bound”

def add_plate_def(self,event):

print “Clicked Button for plate add”

if name==“main”:

app = wx.PySimpleApp()

maframe = MaFrame(parent=None,title=“Gzilla”)

plate_panel = PlatePanel(parent=maframe)

maframe.Fit()

maframe.Show()

app.MainLoop()

···

On Tue, Jul 14, 2009 at 4:42 PM, hari jayaram harijay@gmail.com wrote:

Does my panel want to be 480 based on the fact that 480 is divisible by three , the number of children in the horizontal sizer associated in the panel?

hari jayaram wrote:

On Mac OSX Leopard , the button looks very much normal and click-able. ( see attached png screenshot )
But does not respond.

The native button on Mac is a little weird. It is always drawn with the same height (depending on the window variant) no matter what size is given to it. If you add the WIT to your sample and highlight the button with it, you'll see it actually has a height of only a five pixels. (And if you click on the very top of the button it does register the click.)

The button is being set to a very small height because of how you add it to the sizer. With a proportion of 1 you are telling it to take one share of the remaining space, but since the total space available is not enough for the whole layout as Nathaniel mentioned, then the button's share of the available space ends up being smaller than it needs. There is no reason for the button to be proportional since it won't resize anyway, so just change that 1 to a 0.

BTW, the WIT is *very* helpful for diagnosing things like this. http://wiki.wxpython.org/Widget_Inspection_Tool

···

--
Robin Dunn
Software Craftsman

Thanks Robin ,
WIT is amazing!

It really makes it a lot easier to Debug wxpython widgets .
I have already caught a few errors in some of my code .

Particular to this example , I have stopped using borders to force positioning .

I am still trying to understand sizers.
But WIT makes visualizing the sizer and class hierarchy so much easier .

Saw that my new wxpython in action Book has a chapter on PyCrust and debugging Guis

Thanks everyone for your help with this

Hari

···

On Thu, Jul 16, 2009 at 3:38 PM, Robin Dunn robin@alldunn.com wrote:

hari jayaram wrote:

On Mac OSX Leopard , the button looks very much normal and click-able. (

see attached png screenshot )

But does not respond.

The native button on Mac is a little weird. It is always drawn with the

same height (depending on the window variant) no matter what size is

given to it. If you add the WIT to your sample and highlight the button

with it, you’ll see it actually has a height of only a five pixels. (And

if you click on the very top of the button it does register the click.)

The button is being set to a very small height because of how you add it

to the sizer. With a proportion of 1 you are telling it to take one

share of the remaining space, but since the total space available is not

enough for the whole layout as Nathaniel mentioned, then the button’s

share of the available space ends up being smaller than it needs. There

is no reason for the button to be proportional since it won’t resize

anyway, so just change that 1 to a 0.

BTW, the WIT is very helpful for diagnosing things like this.

http://wiki.wxpython.org/Widget_Inspection_Tool

Robin Dunn

Software Craftsman

http://wxPython.org

Hari,

···

On Jul 17, 11:03 am, hari jayaram <hari...@gmail.com> wrote:

Thanks Robin ,
WIT is amazing!

It really makes it a lot easier to Debug wxpython widgets .
I have already caught a few errors in some of my code .

Particular to this example , I have stopped using borders to force
positioning .

I am still trying to understand sizers.
But WIT makes visualizing the sizer and class hierarchy so much easier .

Saw that my new wxpython in action Book has a chapter on PyCrust and
debugging Guis

Thanks everyone for your help with this

Hari

There are some sizer examples on the wiki that you might find helpful.
Here's a link: SizerTutorials - wxPyWiki

- Mike