Fix button sizing

main
Micke Nordin 3 years ago
parent ff4f956343
commit d9cd63dc80

@ -83,7 +83,7 @@ class SVT(Channel):
self.m_cache[key]['description'] = description self.m_cache[key]['description'] = description
self.m_cache[key]['published_parsed'] = published_parsed self.m_cache[key]['published_parsed'] = published_parsed
self.m_cache[key]['title'] = title self.m_cache[key]['title'] = title
thumbnail = make_bitmap_from_url(thumbnail_link) thumbnail = make_bitmap_from_url(thumbnail_link,wx.Size(720,300))
if resolved_link: if resolved_link:
item = Item(description, resolved_link, item = Item(description, resolved_link,
self.m_provider_name, published_parsed, self.m_provider_name, published_parsed,

@ -87,7 +87,7 @@ class YouTube(Channel):
self.m_cache[key]['description'] = description self.m_cache[key]['description'] = description
self.m_cache[key]['published_parsed'] = published_parsed self.m_cache[key]['published_parsed'] = published_parsed
self.m_cache[key]['title'] = title self.m_cache[key]['title'] = title
thumbnail = make_bitmap_from_url(thumbnail_link) thumbnail = make_bitmap_from_url(thumbnail_link, wx.Size(720,300))
item = Item(description, resolved_link, self.m_provider_name, item = Item(description, resolved_link, self.m_provider_name,
published_parsed, thumbnail, title) published_parsed, thumbnail, title)
self.m_items.append(item) self.m_items.append(item)

@ -33,21 +33,21 @@ def make_sized_button(parent_pnl: wx.Panel, bitmap_or_str: Union[wx.Bitmap,str],
btn_sizer.Add(btn_logo, 0, wx.BOTTOM | wx.EXPAND | wx.LEFT | wx.TOP, 1) 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 = wx.Button(parent_pnl, wx.ID_ANY, text, style=wx.BORDER_NONE | wx.BU_AUTODRAW)
btn_text.SetMinSize(SIZE) btn_text.SetMinSize(wx.Size(720 - SIZE.GetWidth(),SIZE.GetHeight()))
btn_text.SetToolTip(text) btn_text.SetToolTip(text)
btn_sizer.Add(btn_text, 0, wx.BOTTOM | wx.RIGHT | wx.TOP, 1) btn_sizer.Add(btn_text, 0, wx.BOTTOM | wx.RIGHT | wx.TOP | wx.EXPAND, 1)
parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_logo) parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_logo)
parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_text) parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_text)
return btn_sizer return btn_sizer
def make_bitmap_from_url(logo_url: str ) -> wx.Bitmap: def make_bitmap_from_url(logo_url: str, size: wx.Size = SIZE ) -> wx.Bitmap:
res = requests.get(logo_url) res = requests.get(logo_url)
content = res.content content = res.content
content_bytes = io.BytesIO(content) content_bytes = io.BytesIO(content)
image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1) image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1)
image = image.Resize(SIZE, (0,0)) image = image.Resize(size, (0,0))
return wx.Bitmap(image) return wx.Bitmap(image)
@ -86,17 +86,3 @@ def resolve_svt_channel(svt_id: str) -> dict:
return channels[svt_id] return channels[svt_id]
def write_on_bitmap(text: str, bmap: wx.Bitmap) -> wx.Bitmap:
bitmap = wx.Bitmap(bmap)
dc = wx.MemoryDC(bitmap)
cblack = wx.Colour(0, 0, 0)
cwhite = wx.Colour(255, 255, 255)
dc.SetTextForeground(cwhite)
dc.SetTextBackground(cblack)
dc.SetFont(wx.Font().Bold())
dc.SetBackgroundMode(wx.BRUSHSTYLE_SOLID)
w, h = dc.GetSize()
tw, th = dc.GetTextExtent(text)
dc.DrawText(text, (w - tw) / 2, (h - th) / 2) #display text in center
del dc
return bitmap

@ -7,6 +7,8 @@ import wx
import wx.lib.scrolledpanel as scrolled import wx.lib.scrolledpanel as scrolled
import wx.media import wx.media
from typing import Callable
from Channel import SVT, YouTube from Channel import SVT, YouTube
from ChannelProvider import ChannelProvider from ChannelProvider import ChannelProvider
from Utils import make_sized_button from Utils import make_sized_button
@ -16,6 +18,8 @@ HEIGHT = 1440
BTN_HEIGHT = 40 BTN_HEIGHT = 40
SPACER_HEIGHT = 10 SPACER_HEIGHT = 10
BM_BTN_STYLE = wx.BOTTOM | wx.EXPAND | wx.LEFT | wx.TOP
class Cast(wx.Frame): class Cast(wx.Frame):
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
"""__init__. """__init__.
@ -31,7 +35,7 @@ class Cast(wx.Frame):
) )
self.m_chromecast_thr.start() self.m_chromecast_thr.start()
self.m_sizer: wx.Sizer = wx.BoxSizer(wx.VERTICAL) self.m_sizer: wx.Sizer = wx.BoxSizer(wx.VERTICAL)
self.m_panel: wx.lib.scrolledpanel.ScrolledPanel = scrolled.ScrolledPanel( self.m_panel: wx.lib.scrolledpanel.ScrolledPanel = scrolled.ScrolledPanel( # type: ignore
self, -1, style=wx.VSCROLL self, -1, style=wx.VSCROLL
) )
self.m_control = None self.m_control = None
@ -61,6 +65,13 @@ class Cast(wx.Frame):
self.m_selected_provider_index = None self.m_selected_provider_index = None
self.show_provider_list(None) self.show_provider_list(None)
def add_back_button(self, callback: Callable) -> None:
backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(WIDTH, BTN_HEIGHT))
backbtn.Bind(
wx.EVT_BUTTON, callback
)
self.m_sizer.Add(backbtn)
def get_chromecasts(self) -> None: def get_chromecasts(self) -> None:
""" """
[TODO:description] [TODO:description]
@ -80,19 +91,18 @@ class Cast(wx.Frame):
self.m_sizer.Add(btn_sizer) self.m_sizer.Add(btn_sizer)
provider_index += 1 provider_index += 1
self.m_panel.SetupScrolling()
self.m_panel.SetSizer(self.m_sizer) self.m_panel.SetSizer(self.m_sizer)
self.m_sizer.Fit(self) self.Fit()
self.m_panel.Layout() self.Layout()
def show_channel_list(self, _, provider_index) -> None: def show_channel_list(self, _, provider_index) -> None:
self.m_selected_provider_index = provider_index self.m_selected_provider_index = provider_index
self.m_selected_provider = self.m_providers[provider_index] self.m_selected_provider = self.m_providers[provider_index]
self.m_sizer.Clear(delete_windows=True) self.m_sizer.Clear(delete_windows=True)
self.m_sizer = wx.BoxSizer(wx.VERTICAL) self.m_sizer = wx.BoxSizer(wx.VERTICAL)
backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(WIDTH, BTN_HEIGHT)) bck_callback = lambda event: self.show_provider_list(event)
backbtn.Bind(wx.EVT_BUTTON, lambda event: self.show_provider_list(event)) self.add_back_button(bck_callback)
self.m_sizer.Add(backbtn, wx.ALIGN_CENTER_VERTICAL)
self.m_sizer.AddSpacer(SPACER_HEIGHT)
channel_index = 0 channel_index = 0
for channel in self.m_selected_provider.get_channels(): for channel in self.m_selected_provider.get_channels():
bitmap = channel.get_logo_as_bitmap() bitmap = channel.get_logo_as_bitmap()
@ -101,21 +111,14 @@ class Cast(wx.Frame):
self.m_sizer.Add(btn_sizer) self.m_sizer.Add(btn_sizer)
channel_index += 1 channel_index += 1
self.m_sizer.AddSpacer(SPACER_HEIGHT) self.m_panel.SetupScrolling()
self.m_panel.SetSizer(self.m_sizer) self.m_panel.SetSizer(self.m_sizer)
self.m_sizer.Fit(self) self.Fit()
self.m_panel.Layout() self.Layout()
def show_video_list(self, _, index=0) -> None: def show_video_list(self, _, index=0) -> None:
"""
Shows a list of videos
:param _ [TODO:type]: [TODO:description]
:rtype None: [TODO:description]
"""
self.m_sizer.Clear(delete_windows=True) self.m_sizer.Clear(delete_windows=True)
self.m_sizer = wx.BoxSizer(wx.VERTICAL) self.m_sizer = wx.BoxSizer(wx.VERTICAL)
channel = self.m_selected_provider.get_channel_by_index(index) channel = self.m_selected_provider.get_channel_by_index(index)
if channel.wait(): if channel.wait():
with wx.BusyInfo("Please wait, working..."): with wx.BusyInfo("Please wait, working..."):
@ -124,36 +127,35 @@ class Cast(wx.Frame):
time.sleep(1) time.sleep(1)
wx.GetApp().Yield() wx.GetApp().Yield()
backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(WIDTH, BTN_HEIGHT)) callback = lambda event: self.show_channel_list(event, self.m_selected_provider_index)
backbtn.Bind( self.add_back_button(callback)
wx.EVT_BUTTON,
lambda event: self.show_channel_list(event, self.m_selected_provider_index), for item in channel.get_items(): # type: ignore
) inner_sizer = wx.BoxSizer(wx.VERTICAL)
self.m_sizer.Add(backbtn, wx.ALIGN_CENTER_VERTICAL)
self.m_sizer.AddSpacer(SPACER_HEIGHT)
for item in channel.get_items():
title = wx.StaticText(self.m_panel, -1) title = wx.StaticText(self.m_panel, -1)
title.SetLabelMarkup("<span weight='bold' >{}</span>".format(item["title"])) title.SetLabelMarkup("<span weight='bold' >{}</span>".format(item["title"]))
description = wx.StaticText(self.m_panel, -1, item["description"]) description = wx.StaticText(self.m_panel, -1, item["description"])
description.Wrap(478) description.Wrap(WIDTH -2)
bitmap = item["thumbnail"] bitmap = item["thumbnail"]
btn = wx.BitmapButton(self.m_panel, id=self.m_index, bitmap=bitmap) btn = wx.BitmapButton(self.m_panel, id=self.m_index, bitmap=bitmap, style= BM_BTN_STYLE)
btn.Bind( btn.Bind(
wx.EVT_BUTTON, wx.EVT_BUTTON,
lambda event, link=item["link"], provider_index=index: self.show_player( lambda event, link=item["link"], provider_index=index: self.show_player(
event, link, provider_index event, link, provider_index
), ),
) )
self.m_sizer.Add(title) inner_sizer.Add(title)
self.m_sizer.Add(btn) inner_sizer.Add(btn)
self.m_sizer.Add(description) inner_sizer.Add(description)
self.m_sizer.Add(inner_sizer)
self.m_sizer.AddSpacer(SPACER_HEIGHT) self.m_sizer.AddSpacer(SPACER_HEIGHT)
self.m_index = self.m_index + 1 self.m_index = self.m_index + 1
self.m_sizer.AddSpacer(SPACER_HEIGHT) #self.m_sizer.AddStretchSpacer()
self.m_panel.SetupScrolling()
self.m_panel.SetSizer(self.m_sizer) self.m_panel.SetSizer(self.m_sizer)
self.m_sizer.Fit(self) self.Fit()
self.m_panel.Layout() self.Layout()
def show_player(self, _, uri, provider_index: int): def show_player(self, _, uri, provider_index: int):
""" """
@ -166,7 +168,7 @@ class Cast(wx.Frame):
self.m_sizer = wx.GridBagSizer() self.m_sizer = wx.GridBagSizer()
self.m_control = wx.media.MediaCtrl( self.m_control = wx.media.MediaCtrl(
self.m_panel, self.m_panel,
size=(WIDTH, HEIGHT), size=(WIDTH, HEIGHT/2),
style=wx.SIMPLE_BORDER, style=wx.SIMPLE_BORDER,
szBackend=wx.media.MEDIABACKEND_GSTREAMER, szBackend=wx.media.MEDIABACKEND_GSTREAMER,
) )
@ -209,17 +211,23 @@ class Cast(wx.Frame):
pause_button.Bind(wx.EVT_BUTTON, self.pause) pause_button.Bind(wx.EVT_BUTTON, self.pause)
self.Bind(wx.media.EVT_MEDIA_FINISHED, self.show_video_list) self.Bind(wx.media.EVT_MEDIA_FINISHED, self.show_video_list)
self.m_sizer.AddSpacer(SPACER_HEIGHT)
self.load_uri(uri) self.load_uri(uri)
self.m_panel.SetupScrolling()
self.m_panel.SetSizer(self.m_sizer) self.m_panel.SetSizer(self.m_sizer)
self.m_sizer.Fit(self) self.Fit()
self.m_panel.Layout() self.Layout()
self.m_panel.ScrollChildIntoView(self.m_control) self.m_panel.ScrollChildIntoView(self.m_control)
def select_chromecast(self, _, uri, provider_index): def select_chromecast(self, _, uri, provider_index):
self.m_sizer.Clear(delete_windows=True) self.m_sizer.Clear(delete_windows=True)
self.m_sizer = wx.BoxSizer(wx.VERTICAL) self.m_sizer = wx.BoxSizer(wx.VERTICAL)
cancel_btn = wx.Button(self.m_panel, -1, "Cancel")
cancel_btn.Bind(
wx.EVT_BUTTON,
lambda event, index=provider_index: self.show_video_list(event, index),
)
self.m_sizer.Add(cancel_btn, wx.ALIGN_CENTER_VERTICAL)
for cast in self.m_chromecasts: for cast in self.m_chromecasts:
friendly_name = cast.cast_info.friendly_name friendly_name = cast.cast_info.friendly_name
btn = wx.Button(self.m_panel, id=-1, label=friendly_name, size=(WIDTH, BTN_HEIGHT)) btn = wx.Button(self.m_panel, id=-1, label=friendly_name, size=(WIDTH, BTN_HEIGHT))
@ -230,16 +238,16 @@ class Cast(wx.Frame):
), ),
) )
self.m_sizer.Add(btn, wx.ALIGN_CENTER_VERTICAL) self.m_sizer.Add(btn, wx.ALIGN_CENTER_VERTICAL)
self.m_sizer.AddSpacer(SPACER_HEIGHT) self.m_panel.SetupScrolling()
self.m_panel.SetSizer(self.m_sizer) self.m_panel.SetSizer(self.m_sizer)
self.m_sizer.Fit(self) self.Fit()
self.m_panel.Layout() self.Layout()
def set_chromecast(self, event, chromecast, uri, provider_index): def set_chromecast(self, event, chromecast, uri, provider_index):
self.m_selected_chromecast = chromecast self.m_selected_chromecast = chromecast
self.show_player(event, uri, provider_index) self.show_player(event, uri, provider_index)
def cast(self, event, uri): def cast(self, _, uri):
mimetype = "video/mp4" mimetype = "video/mp4"
cast = self.m_selected_chromecast cast = self.m_selected_chromecast
cast.wait() cast.wait()

Loading…
Cancel
Save