|
|
|
@ -1,27 +1,54 @@
|
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
import io
|
|
|
|
|
from os import path
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
import wx
|
|
|
|
|
from copy import copy
|
|
|
|
|
from typing import Union, Callable
|
|
|
|
|
|
|
|
|
|
SIZE = wx.Size(200,135)
|
|
|
|
|
MYPATH = path.dirname(path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
def get_default_log_url(providerid: str = 'default') -> str:
|
|
|
|
|
def get_default_logo(providerid: str = 'default') -> wx.Bitmap:
|
|
|
|
|
if providerid == 'SVT':
|
|
|
|
|
return 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Logotyp_SVT_Play.png/480px-Logotyp_SVT_Play.jpg'
|
|
|
|
|
return wx.Bitmap('{}/assets/SVT.png'.format(MYPATH))
|
|
|
|
|
if providerid == 'YouTube':
|
|
|
|
|
return 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Youtube.png/480px-Youtube.jpg'
|
|
|
|
|
return wx.Bitmap('{}/assets/YouTube.png'.format(MYPATH))
|
|
|
|
|
else:
|
|
|
|
|
return wx.Bitmap('{}/assets/Default.png'.format(MYPATH))
|
|
|
|
|
|
|
|
|
|
def make_sized_button(parent_pnl: wx.Panel, bitmap_or_str: Union[wx.Bitmap,str], text: str, callback: Callable) -> wx.BoxSizer:
|
|
|
|
|
btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
|
if type(bitmap_or_str) == type(str):
|
|
|
|
|
if bitmap_or_str.startswith('http'): # type: ignore
|
|
|
|
|
bitmap = make_bitmap_from_url(bitmap_or_str) # type: ignore
|
|
|
|
|
else:
|
|
|
|
|
bitmap = wx.Bitmap(bitmap_or_str, wx.BITMAP_TYPE_ANY)
|
|
|
|
|
else:
|
|
|
|
|
return 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Cartoon_Hand_Playing_Multiple_Online_Videos.svg/480px-Cartoon_Hand_Playing_Multiple_Online_Videos.svg.jpg'
|
|
|
|
|
bitmap = bitmap_or_str
|
|
|
|
|
btn_style = wx.BORDER_NONE | wx.BU_AUTODRAW | wx.BU_EXACTFIT | wx.BU_NOTEXT
|
|
|
|
|
btn_logo = wx.BitmapButton(parent_pnl, wx.ID_ANY, bitmap , style=btn_style)
|
|
|
|
|
btn_logo.SetMinSize(SIZE)
|
|
|
|
|
btn_logo.SetToolTip(text)
|
|
|
|
|
btn_sizer.Add(btn_logo, 0, wx.BOTTOM | wx.EXPAND | wx.LEFT | wx.TOP, 1)
|
|
|
|
|
|
|
|
|
|
btn_text = wx.Button(parent_pnl, wx.ID_ANY, text, style=wx.BORDER_NONE | wx.BU_AUTODRAW)
|
|
|
|
|
btn_text.SetMinSize(SIZE)
|
|
|
|
|
btn_text.SetToolTip(text)
|
|
|
|
|
btn_sizer.Add(btn_text, 0, wx.BOTTOM | wx.RIGHT | wx.TOP, 1)
|
|
|
|
|
parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_logo)
|
|
|
|
|
parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_text)
|
|
|
|
|
|
|
|
|
|
return btn_sizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_bitmap_from_url(logo_url: str = get_default_log_url()) -> wx.Bitmap:
|
|
|
|
|
def make_bitmap_from_url(logo_url: str ) -> wx.Bitmap:
|
|
|
|
|
res = requests.get(logo_url)
|
|
|
|
|
content = res.content
|
|
|
|
|
content_bytes = io.BytesIO(content)
|
|
|
|
|
logo = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
|
return wx.Bitmap(logo)
|
|
|
|
|
image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1)
|
|
|
|
|
image = image.Resize(SIZE, (0,0))
|
|
|
|
|
return wx.Bitmap(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def resolve_svt_channel(svt_id: str) -> dict:
|
|
|
|
@ -29,36 +56,31 @@ def resolve_svt_channel(svt_id: str) -> dict:
|
|
|
|
|
"ch-barnkanalen": {
|
|
|
|
|
"name":
|
|
|
|
|
"Barnkanalen",
|
|
|
|
|
"thumbnail_url":
|
|
|
|
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/SVT_Barnkanalen_logo_2008%E2%80%932012.svg/480px-SVT_Barnkanalen_logo_2008%E2%80%932012.svg.jpg"
|
|
|
|
|
"thumbnail": wx.Bitmap('{}/assets/Barnkanalen.png'.format(MYPATH))
|
|
|
|
|
},
|
|
|
|
|
"ch-svt1": {
|
|
|
|
|
"name":
|
|
|
|
|
"SVT 1",
|
|
|
|
|
"thumbnail_url":
|
|
|
|
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/SVT1_logo_2012.svg/480px-SVT1_logo_2012.svg.jpg"
|
|
|
|
|
"thumbnail": wx.Bitmap('{}/assets/SVT1.png'.format(MYPATH))
|
|
|
|
|
},
|
|
|
|
|
"ch-svt2": {
|
|
|
|
|
"name":
|
|
|
|
|
"SVT 2",
|
|
|
|
|
"thumbnail_url":
|
|
|
|
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/SVT2_logo_2012.svg/480px-SVT2_logo_2012.svg.jpg"
|
|
|
|
|
"thumbnail": wx.Bitmap('{}/assets/SVT2.png'.format(MYPATH))
|
|
|
|
|
},
|
|
|
|
|
"ch-svt24": {
|
|
|
|
|
"name":
|
|
|
|
|
"SVT 24",
|
|
|
|
|
"thumbnail_url":
|
|
|
|
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/8f/SVT24_logo.svg/480px-SVT24_logo.svg.jpg"
|
|
|
|
|
"thumbnail": wx.Bitmap('{}/assets/SVT24.png'.format(MYPATH))
|
|
|
|
|
},
|
|
|
|
|
"kunskapskanalen": {
|
|
|
|
|
"name":
|
|
|
|
|
"Kunskapskanalen",
|
|
|
|
|
"thumbnail_url":
|
|
|
|
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Kunskapskanalen_logo.png/480px-Kunskapskanalen_logo.jpg"
|
|
|
|
|
"thumbnail": wx.Bitmap('{}/assets/Kunskapskanalen.png'.format(MYPATH))
|
|
|
|
|
},
|
|
|
|
|
"feed": {
|
|
|
|
|
"name": "Senaste program",
|
|
|
|
|
"thumbnail_url": get_default_log_url('SVT')
|
|
|
|
|
"thumbnail": wx.Bitmap('{}/assets/SVT.png'.format(MYPATH))
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|