From 1a97232327bd6dff3d10b6c18ed461c55580de5e Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 28 Dec 2021 17:47:49 +0100 Subject: [PATCH] Fix consistent back buttons Now you can go all the way back, from any where via backbuttons. --- main.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 561193f..851ff20 100644 --- a/main.py +++ b/main.py @@ -45,7 +45,8 @@ class Cast(wx.Frame): channels=[YouTube.YouTube('UCu6mSoMNzHQiBIOCkHUa2Aw')]) ] self.m_selected_channel = None - self.show_splash(None) + self.m_selected_provider_index = None + self.show_provider_list(None) def get_chromecasts(self) -> None: """ @@ -55,7 +56,7 @@ class Cast(wx.Frame): """ self.m_chromecasts, self.m_browser = pychromecast.get_chromecasts() - def show_splash(self, _) -> None: + def show_provider_list(self, _) -> None: self.m_sizer.Clear(delete_windows=True) self.m_sizer = wx.BoxSizer(wx.VERTICAL) provider_index = 0 @@ -75,9 +76,14 @@ class Cast(wx.Frame): self.m_panel.Layout() def show_channel_list(self, _, provider_index) -> None: + self.m_selected_provider_index = provider_index + self.m_selected_provider = self.m_providers[provider_index] self.m_sizer.Clear(delete_windows=True) self.m_sizer = wx.BoxSizer(wx.VERTICAL) - self.m_selected_provider = self.m_providers[provider_index] + backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(480, 40)) + backbtn.Bind(wx.EVT_BUTTON, lambda event: self.show_provider_list(event)) + self.m_sizer.Add(backbtn, wx.ALIGN_CENTER_VERTICAL) + self.m_sizer.AddSpacer(10) channel_index = 0 for channel in self.m_selected_provider.get_channels(): bitmap = channel.get_logo_as_bitmap() @@ -113,7 +119,7 @@ class Cast(wx.Frame): wx.GetApp().Yield() backbtn = wx.Button(self.m_panel, -1, label="Go back", size=(480, 40)) - backbtn.Bind(wx.EVT_BUTTON, lambda event: self.show_splash(event)) + backbtn.Bind(wx.EVT_BUTTON, lambda event: self.show_channel_list(event, self.m_selected_provider_index)) self.m_sizer.Add(backbtn, wx.ALIGN_CENTER_VERTICAL) self.m_sizer.AddSpacer(10) for item in channel.get_items(): @@ -171,7 +177,8 @@ class Cast(wx.Frame): chromecast_button = wx.Button(self.m_panel, -1, "Cast") chromecast_button.Bind( wx.EVT_BUTTON, - lambda event, muri=uri: self.select_chromecast(event, muri)) + lambda event, muri=uri, index=provider_index: self. + select_chromecast(event, muri, index)) self.m_sizer.Add(chromecast_button, (2, 2)) if self.m_selected_chromecast: @@ -191,7 +198,7 @@ class Cast(wx.Frame): self.m_panel.Layout() self.m_panel.ScrollChildIntoView(self.m_control) - def select_chromecast(self, _, uri): + def select_chromecast(self, _, uri, provider_index): self.m_sizer.Clear(delete_windows=True) self.m_sizer = wx.BoxSizer(wx.VERTICAL) @@ -202,16 +209,16 @@ class Cast(wx.Frame): label=friendly_name, size=(480, 40)) btn.Bind(wx.EVT_BUTTON, - lambda event, chromecast=cast, muri=uri: self. - set_chromecast(event, chromecast, muri)) + lambda event, chromecast=cast, muri=uri, index=provider_index: self. + set_chromecast(event, chromecast, muri, index)) self.m_sizer.Add(btn, wx.ALIGN_CENTER_VERTICAL) self.m_panel.SetSizer(self.m_sizer) self.m_sizer.Fit(self) self.m_panel.Layout() - def set_chromecast(self, event, chromecast, uri): + def set_chromecast(self, event, chromecast, uri, provider_index): self.m_selected_chromecast = chromecast - self.show_player(event, uri) + self.show_player(event, uri, provider_index) def cast(self, event, uri): mimetype = 'video/mp4'