From cba2be47d5bcd5637380f2f24c8ba6270eba8c87 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Sun, 19 Dec 2021 14:19:27 +0100 Subject: [PATCH] Add busy window --- ChannelProvider/SVT/__init__.py | 23 ++++++++++++----------- ChannelProvider/__init__.py | 3 +++ main.py | 8 ++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChannelProvider/SVT/__init__.py b/ChannelProvider/SVT/__init__.py index 288dbd0..d8f6e96 100644 --- a/ChannelProvider/SVT/__init__.py +++ b/ChannelProvider/SVT/__init__.py @@ -5,6 +5,7 @@ import io import json import os import pickle +import threading import ChannelProvider import feedparser @@ -24,15 +25,18 @@ class SVT(ChannelProvider.ChannelProvider): if os.path.exists(self.m_cachefile): with open(self.m_cachefile, 'rb') as cachehandle: self.m_cache = pickle.load(cachehandle) - self.m_items: list[Item] = self.parse_feed() + self.m_thr = threading.Thread(target=self.parse_feed, + args=(), + kwargs={}) + self.m_thr.start() - def refresh_items(self): - self.m_items: list[Item] = self.parse_feed() + def wait(self) -> bool: + return self.m_thr.is_alive() - def parse_feed(self) -> list[Item]: + def parse_feed(self) -> None: feed = feedparser.parse(self.get_feed()) entries = feed['entries'] - items: list[Item] = list() + self.m_items: list[Item] = list() for entry in entries: key = hashlib.sha256(entry['link'].encode('utf-8')).hexdigest() @@ -50,6 +54,7 @@ class SVT(ChannelProvider.ChannelProvider): for link in entry['links']: if str(link['type']).startswith('image/'): thumbnail_link = str(link['href']) + break page = requests.get(str(entry['link'])) soup = BeautifulSoup(page.text, 'html.parser') @@ -83,16 +88,12 @@ class SVT(ChannelProvider.ChannelProvider): self.m_cache[key]['published_parsed'] = published_parsed self.m_cache[key]['title'] = title - image = wx.Image(content_bytes, - type=wx.BITMAP_TYPE_ANY, - index=-1) + image = wx.Image(content_bytes, type=wx.BITMAP_TYPE_ANY, index=-1) thumbnail = wx.Bitmap(image) item = Item(description, resolved_link, self.m_provider_name, published_parsed, thumbnail, title) - items.append(item) + self.m_items.append(item) # write to cache file with open(self.m_cachefile, 'wb') as cachehandle: pickle.dump(self.m_cache, cachehandle) - - return items diff --git a/ChannelProvider/__init__.py b/ChannelProvider/__init__.py index 0744bb7..bd6413a 100644 --- a/ChannelProvider/__init__.py +++ b/ChannelProvider/__init__.py @@ -22,3 +22,6 @@ class ChannelProvider: def parse_feed(self) -> Union[list[Item], None]: pass + + def wait(self) -> bool: + return False diff --git a/main.py b/main.py index 7c43227..1d43876 100644 --- a/main.py +++ b/main.py @@ -45,6 +45,14 @@ class Cast(wx.Frame): self.m_sizer = wx.BoxSizer(wx.VERTICAL) for channel in self.m_channels: + if channel.wait(): + with wx.BusyInfo("Please wait, working..."): + index = 0 + while channel.wait(): + time.sleep(1) + wx.GetApp().Yield() + + for item in channel.get_items(): title = wx.StaticText(self.m_panel, -1) title.SetLabelMarkup("{}".format(item['title']))