Add busy window
This commit is contained in:
parent
5e35383636
commit
cba2be47d5
3 changed files with 23 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -22,3 +22,6 @@ class ChannelProvider:
|
|||
|
||||
def parse_feed(self) -> Union[list[Item], None]:
|
||||
pass
|
||||
|
||||
def wait(self) -> bool:
|
||||
return False
|
||||
|
|
8
main.py
8
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("<span weight='bold' >{}</span>".format(item['title']))
|
||||
|
|
Loading…
Add table
Reference in a new issue