Python events, panel with text

S

SMALLp

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)
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>
 
S

SMALLp

SMALLp said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top