[Tutor] wxPython shaped window

Adam Bark adam.jtm30 at gmail.com
Thu Jun 30 14:04:03 CEST 2005


On 6/26/05, Adam Cripps <kabads at gmail.com> wrote: 
> 
> On 6/25/05, Adam Bark <adam.jtm30 at gmail.com> wrote:
> > Thanks for the info Adam I just seem to be having a problem with the 
> panel
> > size it greys out nearly all the image. Ideally I would like to make the 
> 
> > panel transparent but I can't work out how to do that.
> >
> >
> > On 6/25/05, Adam Cripps <kabads at gmail.com> wrote:
> > > On 6/25/05, Adam Bark < adam.jtm30 at gmail.com > wrote:
> > > > Is it possible to put controls into a shaped window in wxPython. I 
> have
> > > > tried putting a button on the demo and it becomes the exact size and 
> 
> > shape
> > > > of the window. Also when I tried to bind it to an action it wouldn't
> > even
> > > > start.
> > > >
> > > > Adam
> > > >
> > >
> > > I'm working through something similar myself at the moment. 
> > >
> > > Try adding a wx.Panel to the frame and then the button to the panel.
> > > You can position them through pos parameter, but it should default to
> > > the top left of the panel and have a good size if you use 
> > > button.SetSize(button.GetBestSize())
> > >
> > > HTH
> > >
> > > Adam
> 
> Adam - how much code do you have? Why not post it either here or the
> wxpython-users list (to which I'm also subscribed) and we can take a 
> look.
> 
> Adam
> 
> --
> http://www.monkeez.org
> PGP key: 0x7111B833


I tried posting to the wxpython-users list but I'm not sure it worked nobody 
replied anyway.
Here's my test script:

import wx

class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Shaped Window",
style =
wx.FRAME_SHAPED
| wx.SIMPLE_BORDER
| wx.FRAME_NO_TASKBAR
| wx.STAY_ON_TOP
)
self.hasShape = False
self.delta = (0,0)

self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_MOTION, self.OnMouseMove)

self.bkground = wx.Bitmap("/home/adam/bkgrnd.gif", wx.BITMAP_TYPE_GIF)
w, h = self.bkground.GetWidth(), self.bkground.GetHeight()
self.SetClientSize((w, h))
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
panel = Panel(self, w, h)
panel.Show()
dc = wx.ClientDC(self)
dc.DrawBitmap(self.bkground, 0,0, True)

def SetWindowShape(self, evt):
# Use the bitmap's mask to determine the region
r = wx.RegionFromBitmap(self.bkground)
self.hasShape = self.SetShape(r)

def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bkground, 0,0, True)

def OnMouseMove(self, evt):
if evt.Dragging() and evt.LeftIsDown():
x, y = self.ClientToScreen(evt.GetPosition())
fp = (x - self.delta[0], y - self.delta[1])
self.Move(fp)

class Panel(wx.Panel):
def __init__(self, parent, width, height):
wx.Panel.__init__(self, parent, -1, size=(width, height))

button = wx.Button(self, -1, "hello")
button.SetSize(button.GetBestSize())
self.SetSize((width, height))
#print dir(self)

if __name__ == "__main__":
app = wx.PySimpleApp()
frame = Frame()
frame.Show()
app.MainLoop()

Thanks.
Adam.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050630/14dd80c5/attachment.htm


More information about the Tutor mailing list