views:

161

answers:

2

Hello,

I have this code:

import wx

class Plugin(wx.Panel):
    def __init__(self, parent, *args, **kwargs):
        panel = wx.Panel.__init__(self, parent, *args, **kwargs)
        self.colorOver = ((89,89,89))
        self.colorLeave = ((110,110,110))
        self.colorFont = ((131,131,131))
        self.SetBackgroundColour(self.colorLeave)
        self.SetForegroundColour(self.colorLeave)
        self.name = "Plugin"
        self.overPanel = 0
        self.overLabel = 0

        sizer = wx.BoxSizer(wx.VERTICAL)
        name = wx.StaticText(self, -1, ' ' + self.getName())
        close = wx.StaticText(self, -1, ' X ')

        gs = wx.GridSizer(2, 2, 0, 0)
        gs.AddMany([(name, 0, wx.ALIGN_LEFT), (close, 0, wx.ALIGN_RIGHT)])

        sizer.Add(gs, 1, wx.EXPAND)
        self.SetSizer(sizer)

        .... ....

Is it possible to left click on the StaticText close and hide the panel itself?

+2  A: 

I dont know if it is possible to bind a wx.EVT_LEFT_DOWN to a StaticText widget. You could use a button to call self.Hide(). Maybe a BitmapButton if you want a custom look.

class myPanel(wx.Panel):
    def __init__(self, parent, *args, **kwargs):
        wx.Panel.__init__(self, parent, *args, **kwargs)
        bitmap = wx.EmptyBitmap(15,15)
        self.button = wx.BitmapButton(self, -1, bitmap=bitmap, size=(15,15), style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.onClick, self.button)

def onClick(self, event):
    self.Hide()
lambeaux
this worked quite well. thanks m8 :)
aF
+1  A: 

I seem to recall having to put the static text inside a frame or some object that could receive events, but was made to be invisible. Then, the click event on the text gets passed to the parent. I used to have a special derived class for clickable labels.

Harvey
can you give me that :)
aF
let me find it... may take a few minutes and it's in C++, but it should convert easily. I figured it was better to point you in the right direction first rather than spend time searching my old code.
Harvey
Harvey thanks but I don't need it anymore :PI used the BitmapButton ^^
aF