First I had a frame with wx.STAY_ON_TOP with some info, this frame stayed always on the same position on top of my application, now I’m trying to attach that frame to the videoplayer, so I can resize the window and move it around (in the case I have multiple screens). After tinkering with the code I finally managed to attach it to the video, but now I cannot get it to stay on top of the video. It just stays on the background hidden by the video.
I tried to create it as wx.STAY_ON_TOP and wx.FRAME_FLOAT_ON_PARENT but nothing changes which is weird.
In order for the program to work you should have a mp4 file in the inside the Vid1 folder, the exec name is play_this.py and use esccape to exit the program.
I’ll paste the code, since I can’t attach the code (it needs a couple of folders to run vlc, and it does’nt allow to upload folders)
class DragShape:
def __init__(self, bmp):
self.bmp = bmp
self.pos = (0,0)
self.shown = True
def draw(self, dc, op=wx.COPY):
if self.bmp.Ok():
#self.SetTransparent(76)
memDC = wx.MemoryDC()
memDC.SelectObject(self.bmp)
#dc.Blit(13, 13, 930, 700, memDC, 0, 0, op, True)
#dc.Blit(self.pos[0], self.pos[1], self.bmp.GetWidth(), self.bmp.GetHeight(), memDC, 0, 0, op, True)
dc.Blit(self.pos[0], self.pos[1], self.bmp.GetWidth(), self.bmp.GetHeight(), memDC, 0, 0, op, True)
# Blit(self, xdest, ydest, width, height, source, xsrc, ysrc, rop=COPY, useMask=False, xsrcMask=-1, ysrcMask=-1)
return True
else:
return False
# ----------------------------------------------------------------------
class DragCanvas(wx.ScrolledWindow):
'''Finds and paints the name of the video we are playing'''
def __init__(self, parent, ID):
#def __init__(self, *args, **kwargs):
#wx.ScrolledWindow.__init__(self, *args, **kwargs)
#wx.ScrolledWindow.__init__(self, parent, ID, size=(2000, 1000),style=wx.STAY_ON_TOP)
wx.ScrolledWindow.__init__(self, parent, ID, size=(2000, 1000),style=wx.FRAME_FLOAT_ON_PARENT)
self.shapes = []
pos = (1500, 80)
# Size of the label
image_path = '.\i_assets\\turnTable.png'
# Trying to put the logo image with transparency
mono = wx.Image(image_path, wx.BITMAP_TYPE_PNG)
self.SetTransparent(76)
bmp_mono = wx.BitmapFromImage(mono)
shape0 = DragShape(bmp_mono)
shape0.pos = pos
self.shapes.append(shape0)
logo = wx.Image('.\i_assets\\logo.png', wx.BITMAP_TYPE_ANY)
bmp_logo = wx.BitmapFromImage(logo)
shape0 = DragShape(bmp_logo)
shape0.pos = pos
self.shapes.append(shape0)
# Make a shape from some text
#bg_colour = wx.Colour(128, 128, 128) # matches the bg image
bg_colour = wx.Colour(0, 0, 0) # matches the bg image
# Remember: .* is for clear the path
p = re.compile(r'.*\d+_\w*_(.*)_(KW\d+)_(.*)_*(.*)\.mp4|.*\d+_\w*_(.*)_(KW\d+).*_*(.*)\.mp4')
try:
text1 = p.match(Hash[title]).group(1).replace('_', ' ')
text2 = p.match(Hash[title]).group(2).replace('_', ' ')
text3 = p.match(Hash[title]).group(3).replace('_', ' ')
except:
text1 = p.match(Hash[title]).group(5).replace('_', ' ')
text2 = p.match(Hash[title]).group(6).replace('_', ' ')
text3 = ""
# Create canvas, we can control the margins
#bmp1 = wx.EmptyBitmap(screensize[0], screensize[1])
bmp1 = wx.EmptyBitmap(2000, 1000)
# 'draw' the text onto the bitmap
dc = wx.MemoryDC()
dc.SelectObject(bmp1)
dc.SetBackground(wx.Brush(bg_colour, wx.SOLID))
dc.Clear()
dc.SetTextForeground(wx.WHITE)
# Header
font = wx.Font(17, wx.SWISS, wx.NORMAL, wx.BOLD)
dc.SetFont(font)
dc.DrawText(text1, 17, 11)
# Week
font = wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL)
dc.SetFont(font)
dc.DrawText(text2, 17, 52)
# Description
font = wx.Font(17, wx.SWISS, wx.NORMAL, wx.NORMAL)
dc.SetFont(font)
dc.DrawText(text3, 100, 52) # '210, 52
dc.SelectObject(wx.NullBitmap)
mask1 = wx.Mask(bmp1, bg_colour)
bmp1.SetMask(mask1)
shape1 = DragShape(bmp1)
shape1.pos = pos
self.shapes.append(shape1)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Layout()
self.Show()
# Go through our list of shapes and draw them in whatever place they are.
def drawshapes(self, dc):
for shape in self.shapes:
if shape.shown:
shape.draw(dc)
# Fired whenever a paint event occurs
def OnPaint(self, evt):
dc = wx.PaintDC(self)
self.PrepareDC(dc)
self.drawshapes(dc)
Thanks for the help! I’ll be updating the post if I find anything new