You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cast/main.py

102 lines
3.3 KiB

#!/usr/bin/env python3
from typing import NewType
import wx
import wx.lib.scrolledpanel as scrolled
import wx.media
from ChannelProvider import SVT, ChannelProvider
ChannelProvider = NewType('ChannelProvider', ChannelProvider)
class Cast(wx.Frame):
def __init__(self, *args, **kw):
"""__init__.
:param args:
:param kw:
"""
super().__init__(*args, **kw)
self.m_index = 0
self.m_sizer: wx.Sizer = wx.BoxSizer(wx.VERTICAL)
self.m_panel: wx.lib.scrolledpanel.ScrolledPanel = scrolled.ScrolledPanel(
self, -1, style=wx.VSCROLL)
self.m_control = None
self.m_panel.SetupScrolling()
self.m_panel.SetSizer(self.m_sizer)
self.m_channels: list[ChannelProvider] = [SVT.SVT()]
self.show_list(None)
def show_list(self, _):
self.m_sizer.Clear(delete_windows=True)
self.m_sizer = wx.BoxSizer(wx.VERTICAL)
for channel in self.m_channels:
for item in channel.get_items():
title = wx.StaticText(self.m_panel, -1, item['title'])
description = wx.StaticText(self.m_panel, -1,
item['description'])
bitmap = item['thumbnail']
btn = wx.BitmapButton(self.m_panel, id=self.m_index, bitmap=bitmap)
btn.Bind(wx.EVT_BUTTON,
lambda event, link=item['link']: self.show_player(
event, link))
self.m_sizer.Add(title)
self.m_sizer.Add(btn)
self.m_sizer.Add(description)
self.m_index = self.m_index + 1
self.m_panel.SetSizer(self.m_sizer)
self.m_panel.Layout()
def show_player(self, _, uri):
self.m_sizer.Clear(delete_windows=True)
self.m_sizer = wx.GridBagSizer()
self.m_control = wx.media.MediaCtrl(
self.m_panel,
size=(480, 480),
style=wx.SIMPLE_BORDER,
szBackend=wx.media.MEDIABACKEND_GSTREAMER)
play_button = wx.Button(self.m_panel, -1, "Play")
play_button.Bind(wx.EVT_BUTTON, self.play)
pause_button = wx.Button(self.m_panel, -1, "Pause")
pause_button.Bind(wx.EVT_BUTTON, self.pause)
back_button = wx.Button(self.m_panel, -1, "Back")
back_button.Bind(wx.EVT_BUTTON, self.show_list)
self.m_sizer.Add(self.m_control, (0, 0))
self.m_sizer.SetItemSpan(0, (0, 6))
self.m_sizer.Add(play_button, (1, 1))
self.m_sizer.Add(pause_button, (1, 2))
self.m_sizer.Add(back_button, (1, 3))
self.Bind(wx.media.EVT_MEDIA_LOADED, self.play)
self.Bind(wx.media.EVT_MEDIA_FINISHED, self.show_list)
self.load_uri(uri)
self.m_panel.SetSizer(self.m_sizer)
self.m_panel.Layout()
self.m_panel.ScrollChildIntoView(self.m_control)
def load_uri(self, uri):
self.m_control.LoadURI(uri)
def play(self, _):
self.m_control.Play()
def pause(self, _):
self.m_control.Pause()
def quit(self, _):
self.Destroy()
if __name__ == '__main__':
# When this module is run (not imported) then create the app, the
# frame, show it, and start the event loop.
app: wx.App = wx.App()
frm: Cast = Cast(None, title='Cast')
frm.Show()
app.MainLoop()