diff --git a/src/Channel/SVT/__init__.py b/src/Channel/SVT/__init__.py index 06c5010..195223d 100644 --- a/src/Channel/SVT/__init__.py +++ b/src/Channel/SVT/__init__.py @@ -83,7 +83,7 @@ class SVT(Channel): self.m_cache[key]['description'] = description self.m_cache[key]['published_parsed'] = published_parsed self.m_cache[key]['title'] = title - thumbnail = make_bitmap_from_url(thumbnail_link,wx.Size(720,300)) + thumbnail = make_bitmap_from_url(thumbnail_link,wx.Size(self.m_screen_width,150)) if resolved_link: item = Item(description, resolved_link, self.m_provider_name, published_parsed, diff --git a/src/Channel/YouTube/__init__.py b/src/Channel/YouTube/__init__.py index 1067c41..ab043d7 100644 --- a/src/Channel/YouTube/__init__.py +++ b/src/Channel/YouTube/__init__.py @@ -87,7 +87,7 @@ class YouTube(Channel): self.m_cache[key]['description'] = description self.m_cache[key]['published_parsed'] = published_parsed self.m_cache[key]['title'] = title - thumbnail = make_bitmap_from_url(thumbnail_link, wx.Size(720,300)) + thumbnail = make_bitmap_from_url(thumbnail_link, wx.Size(self.m_screen_width,150)) item = Item(description, resolved_link, self.m_provider_name, published_parsed, thumbnail, title) self.m_items.append(item) diff --git a/src/Channel/__init__.py b/src/Channel/__init__.py index 96d86e3..b548fb6 100644 --- a/src/Channel/__init__.py +++ b/src/Channel/__init__.py @@ -18,6 +18,7 @@ class Channel: self.m_name = name self.m_feed = feed self.m_items: Union[list[Item], None] = None + self.m_screen_width = 720/2 def get_logo_as_bitmap(self) -> wx.Bitmap: return self.m_logo diff --git a/src/Utils/__init__.py b/src/Utils/__init__.py index aa66e4b..f034a86 100644 --- a/src/Utils/__init__.py +++ b/src/Utils/__init__.py @@ -1,13 +1,15 @@ #!/usr/bin/env python3 import io from os import path +from posixpath import relpath import requests import wx from typing import Union, Callable -SIZE = wx.Size(200,135) +SIZE = wx.Size(100,68) MYPATH = path.dirname(path.abspath(__file__)) +SCREEN_WIDTH = 720 /2 def get_default_logo(providerid: str = 'default') -> wx.Bitmap: if providerid == 'SVT': @@ -33,7 +35,7 @@ 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_text = wx.Button(parent_pnl, wx.ID_ANY, text, style=wx.BORDER_NONE | wx.BU_AUTODRAW) - btn_text.SetMinSize(wx.Size(720 - SIZE.GetWidth(),SIZE.GetHeight())) + btn_text.SetMinSize(wx.Size(SCREEN_WIDTH - SIZE.GetWidth(),SIZE.GetHeight())) btn_text.SetToolTip(text) btn_sizer.Add(btn_text, 0, wx.BOTTOM | wx.RIGHT | wx.TOP | wx.EXPAND, 1) parent_pnl.Bind(wx.EVT_BUTTON, callback, btn_logo) @@ -47,40 +49,54 @@ def make_bitmap_from_url(logo_url: str, size: wx.Size = SIZE ) -> wx.Bitmap: content = res.content content_bytes = io.BytesIO(content) image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1) - image = image.Resize(size, (0,0)) + scale_factor = image.GetWidth() / SCREEN_WIDTH + size.SetWidth(SCREEN_WIDTH) + height = image.GetHeight() + size.SetHeight(height/scale_factor) + image.Rescale(size.GetWidth(), size.GetHeight() ) return wx.Bitmap(image) +def make_bitmap_from_file(path, size: wx.Size = SIZE) -> wx.Bitmap: + image = wx.Image(path, type=wx.BITMAP_TYPE_ANY, index=-1) + # scale_factor = image.GetWidth() / SCREEN_WIDTH + # size.SetWidth(SCREEN_WIDTH) + # height = image.GetHeight() + # size.SetHeight(height/scale_factor) + # image.Rescale(size.GetWidth(), size.GetHeight() ) + return wx.Bitmap(image) + def resolve_svt_channel(svt_id: str) -> dict: + channels = { "ch-barnkanalen": { "name": "Barnkanalen", - "thumbnail": wx.Bitmap('{}/assets/Barnkanalen.png'.format(MYPATH)) + "thumbnail": make_bitmap_from_file('{}/assets/Barnkanalen.png'.format(MYPATH)) }, "ch-svt1": { "name": "SVT 1", - "thumbnail": wx.Bitmap('{}/assets/SVT1.png'.format(MYPATH)) + "thumbnail": make_bitmap_from_file('{}/assets/SVT1.png'.format(MYPATH)) }, "ch-svt2": { "name": "SVT 2", - "thumbnail": wx.Bitmap('{}/assets/SVT2.png'.format(MYPATH)) + "thumbnail": make_bitmap_from_file('{}/assets/SVT2.png'.format(MYPATH)) }, "ch-svt24": { "name": "SVT 24", - "thumbnail": wx.Bitmap('{}/assets/SVT24.png'.format(MYPATH)) + "thumbnail": make_bitmap_from_file('{}/assets/SVT24.png'.format(MYPATH)) }, "kunskapskanalen": { "name": "Kunskapskanalen", - "thumbnail": wx.Bitmap('{}/assets/Kunskapskanalen.png'.format(MYPATH)) + "thumbnail": make_bitmap_from_file('{}/assets/Kunskapskanalen.png'.format(MYPATH)) }, "feed": { "name": "Senaste program", - "thumbnail": wx.Bitmap('{}/assets/SVT.png'.format(MYPATH)) + "thumbnail": make_bitmap_from_file('{}/assets/SVT.png'.format(MYPATH)) }, } diff --git a/src/Utils/assets/Barnkanalen.png b/src/Utils/assets/Barnkanalen.png index 676dc96..36d56ca 100644 Binary files a/src/Utils/assets/Barnkanalen.png and b/src/Utils/assets/Barnkanalen.png differ diff --git a/src/Utils/assets/Default.png b/src/Utils/assets/Default.png index 44a4c6f..5760060 100644 Binary files a/src/Utils/assets/Default.png and b/src/Utils/assets/Default.png differ diff --git a/src/Utils/assets/Kunskapskanalen.png b/src/Utils/assets/Kunskapskanalen.png index 0f89634..7f7b4d1 100644 Binary files a/src/Utils/assets/Kunskapskanalen.png and b/src/Utils/assets/Kunskapskanalen.png differ diff --git a/src/Utils/assets/SVT.png b/src/Utils/assets/SVT.png index ab6f49b..02d1301 100644 Binary files a/src/Utils/assets/SVT.png and b/src/Utils/assets/SVT.png differ diff --git a/src/Utils/assets/SVT1.png b/src/Utils/assets/SVT1.png index 87de532..a1fb04a 100644 Binary files a/src/Utils/assets/SVT1.png and b/src/Utils/assets/SVT1.png differ diff --git a/src/Utils/assets/SVT2.png b/src/Utils/assets/SVT2.png index ba68e1b..5123ad6 100644 Binary files a/src/Utils/assets/SVT2.png and b/src/Utils/assets/SVT2.png differ diff --git a/src/Utils/assets/SVT24.png b/src/Utils/assets/SVT24.png index 1931519..94929f2 100644 Binary files a/src/Utils/assets/SVT24.png and b/src/Utils/assets/SVT24.png differ diff --git a/src/Utils/assets/YouTube.png b/src/Utils/assets/YouTube.png index 49dfa6e..c45b460 100644 Binary files a/src/Utils/assets/YouTube.png and b/src/Utils/assets/YouTube.png differ diff --git a/src/main.py b/src/main.py index ae9a5c1..0935e47 100644 --- a/src/main.py +++ b/src/main.py @@ -156,7 +156,6 @@ class Cast(wx.Frame): self.m_sizer.Add(inner_sizer) self.m_sizer.AddSpacer(SPACER_HEIGHT) self.m_index = self.m_index + 1 - #self.m_sizer.AddStretchSpacer() self.m_panel.SetupScrolling() self.m_panel.SetSizer(self.m_sizer) self.m_sizer.Fit(self)