fullscreen works

This commit is contained in:
Jonas Weinz 2020-10-23 20:48:43 +02:00
parent 64f86677bd
commit b20ea9f3ec
2 changed files with 60 additions and 14 deletions

View File

@ -3,7 +3,7 @@ import gi
from gtk_mediathek_player.tools import new_button_with_icon, new_radio_button_with_icon from gtk_mediathek_player.tools import new_button_with_icon, new_radio_button_with_icon
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gio from gi.repository import Gtk, GLib
from . import player_widget from . import player_widget
from . import search_widget from . import search_widget
@ -30,23 +30,40 @@ class MainApp(Gtk.Window):
self._main_stack.show_all() self._main_stack.show_all()
self.set_active_pane("search")
self._main_container.add(self._main_stack) self._main_container.add(self._main_stack)
self._headerbar = self._create_headerbar(True) self._headerbar = self._create_headerbar(True)
self._create_fullscreen_bar()
#self._main_container.add_overlay(self._create_fullscreen_bar()) #self._main_container.add_overlay(self._create_fullscreen_bar())
self._main_container.add_overlay(self._revealer)
self.add(self._main_container) self.add(self._main_container)
self.connect('motion-notify-event', self.on_mouse_move) self.connect('motion-notify-event', self.on_mouse_move)
self._seconds_after_mouse_move = 0
self.set_active_pane("search")
GLib.timeout_add_seconds(1, self.update)
def on_mouse_move(self, _, __): def on_mouse_move(self, _, __):
self._player_widget.show_controls() self._player_widget.show_controls()
self._seconds_after_mouse_move = 0
if self._fullscreen:
self._revealer.set_reveal_child(True)
def update(self):
if self._seconds_after_mouse_move > 1:
self._revealer.set_reveal_child(False)
self._seconds_after_mouse_move += 1
self._player_widget.update_controls()
return True
def on_search(self, _ = None): def on_search(self, _ = None):
if self.get_active_pane() == "player": if self.get_active_pane() == "player":
@ -68,27 +85,31 @@ class MainApp(Gtk.Window):
fullscreen = tools.new_button_with_icon("view-fullscreen") fullscreen = tools.new_button_with_icon("view-fullscreen")
fullscreen.connect("clicked", self.toggle_fullscreen)
headerbar.pack_end(fullscreen) headerbar.pack_end(fullscreen)
if main_bar: if main_bar:
self._create_context_switch() self._create_context_switch()
self._fullscreen_button = fullscreen
headerbar.pack_start(self._search_radio) headerbar.pack_start(self._search_radio)
headerbar.set_show_close_button(True) headerbar.set_show_close_button(True)
headerbar.props.title = "Main Window" headerbar.props.title = "Main Window"
self.set_titlebar(headerbar) self.set_titlebar(headerbar)
return headerbar return headerbar
def _create_fullscreen_bar(self): def _create_fullscreen_bar(self):
self._revealer = Gtk.Revealer() self._revealer = Gtk.Revealer()
self._revealer.add(self._create_headerbar(False)) self._revealer.add(self._create_headerbar(False))
self.set_valign(Gtk.Align.START) self._revealer.set_valign(Gtk.Align.START)
self._revealer.set_vexpand(False)
self._revealer.set_transition_type(Gtk.RevealerTransitionType.SLIDE_DOWN)
return self._revealer return self._revealer
@ -105,6 +126,11 @@ class MainApp(Gtk.Window):
def set_active_pane(self, name: str): def set_active_pane(self, name: str):
self._main_stack.set_visible_child_name(name) self._main_stack.set_visible_child_name(name)
if name != "player":
self._fullscreen_button.set_sensitive(False)
else:
self._fullscreen_button.set_sensitive(True)
def get_active_pane(self): def get_active_pane(self):
return self._main_stack.get_visible_child_name() return self._main_stack.get_visible_child_name()
@ -117,4 +143,26 @@ class MainApp(Gtk.Window):
self._player_widget.play_from_uri(uri) self._player_widget.play_from_uri(uri)
self._player_widget.play() self._player_widget.play()
def go_fullscreen(self):
if self._fullscreen:
return
self._fullscreen = True
self.fullscreen()
self._revealer.set_reveal_child(True)
def go_unfullscreen(self):
if not self._fullscreen:
return
self._fullscreen = False
self.unfullscreen()
self._revealer.set_reveal_child(False)
def toggle_fullscreen(self,_ = None):
if self._fullscreen:
self.go_unfullscreen()
else:
self.go_fullscreen()

View File

@ -30,8 +30,6 @@ class PlayerWidget(Gtk.Overlay):
self._seconds_after_mouse_move = 0 self._seconds_after_mouse_move = 0
GLib.timeout_add_seconds(1, self.update_controls)
self._slider.connect("value-changed", self._on_user_slider_change) self._slider.connect("value-changed", self._on_user_slider_change)
def update_controls(self): def update_controls(self):