Python events, panel with text

SMALLp pofuk at mzm.hr
Wed Jan 2 08:04:47 EST 2008


SMALLp wrote:
> Hy!
> 
> I have many small panels with text and I want do bind wx.EVT_LEFT_DOWN 
> when clicked on panel, but i need to bind that in parent class. So I 
> have instance of that small panel and when i bind it efects only part of 
> small panel where is no text.
> 
> <code>
> 
> import wx
> 
> class RequestedFilesItems(wx.Panel):
>     def __init__(self, parent, id):
>         wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
>         sizer = wx.BoxSizer(wx.HORIZONTAL)
>            
>         upButton = PanelButton(self, -1, "Upload")
>         upButton.Bind(wx.EVT_LEFT_DOWN, self.upload)

i did smothing like this nad it works but id doesn't look so good:
	upButton.text.Bind(wx.EVT_LEFT_DOWN, self.upload)

>         sizer.Add(upButton, 0, wx.LEFT, 15)
> 
> 
> 
>         self.SetSizer(sizer)   
> 
>     def upload(self, event):
>         print "Please print this"
> 
>     
>        
> class PanelButton(wx.Panel):
>     def __init__(self, parent, id, buttonName):
>         wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)
>         self.SetBackgroundColour("GREY")
>         sizer = wx.BoxSizer(wx.HORIZONTAL)
>         self.text = wx.StaticText(self, -1, buttonName)       
>         sizer.Add(self.text, -1, wx.EXPAND | wx.ALL, 1)
>         self.text.Bind(wx.EVT_LEFT_DOWN, self.OnClick)
>         self.SetSizer(sizer)
> 
>     def OnClick(self, event):
>         print "It only works for text, not for panel what I expected here"
> 
> 
> if __name__ == '__main__':
>     app = wx.PySimpleApp()
>     frm = wx.Frame(None, wx.ID_ANY, 'Mouse-click test')
>     panel = RequestedFilesItems(frm, wx.ID_ANY)
>     frm.Show()
>     app.MainLoop()
> 
> 
> 
> app.MainLoop()
> 
> <code>



More information about the Python-list mailing list