Commit d91c1283 authored by Harish Fulara's avatar Harish Fulara Committed by Alexandru Băluț

viewer: Show resize status

parent 7f5a6085
......@@ -43,10 +43,10 @@ from pitivi.transitions import TransitionsListWidget
from pitivi.utils.loggable import Loggable
from pitivi.utils.misc import path_from_uri
from pitivi.utils.ui import beautify_time_delta
from pitivi.utils.ui import EDITOR_PERSPECTIVE_CSS
from pitivi.utils.ui import info_name
from pitivi.utils.ui import PADDING
from pitivi.utils.ui import SPACING
from pitivi.utils.ui import TIMELINE_CSS
from pitivi.viewer.viewer import ViewerContainer
......@@ -110,7 +110,7 @@ class EditorPerspective(Perspective, Loggable):
def __setup_css(self):
css_provider = Gtk.CssProvider()
css_provider.load_from_data(TIMELINE_CSS.encode('UTF-8'))
css_provider.load_from_data(EDITOR_PERSPECTIVE_CSS.encode("UTF-8"))
screen = Gdk.Screen.get_default()
style_context = self.app.gui.get_style_context()
style_context.add_provider_for_screen(screen, css_provider,
......
......@@ -157,7 +157,13 @@ GREETER_PERSPECTIVE_CSS = """
}
"""
TIMELINE_CSS = """
EDITOR_PERSPECTIVE_CSS = """
#resize_status {
font-size: 200%%;
background-color: black;
opacity: 0.8;
}
.AudioBackground {
background-color: #496c21;
}
......
......@@ -19,6 +19,7 @@
import numpy
from gi.repository import Gdk
from gi.repository import GES
from gi.repository import GLib
from gi.repository import Gtk
from pitivi.utils.loggable import Loggable
......@@ -50,6 +51,19 @@ class OverlayStack(Gtk.Overlay, Loggable):
self.add(sink_widget)
self.connect("size-allocate", self.__on_size_allocate)
# Whether to show the percent of the size relative to the project size.
# It is set to false initially because the viewer gets resized
# while the project is loading and we don't want to show the percent
# in this case.
self.__show_resize_status = False
# ID of resizing timeout callback, so it can be delayed.
self.__resizing_id = 0
self.revealer = Gtk.Revealer(transition_type=Gtk.RevealerTransitionType.CROSSFADE)
self.resize_status = Gtk.Label(name="resize_status")
self.revealer.add(self.resize_status)
self.add_overlay(self.revealer)
sink_widget.connect("size-allocate", self.__sink_widget_size_allocate_cb)
def __on_size_allocate(self, widget, rectangle):
self.window_size = numpy.array([rectangle.width,
rectangle.height])
......@@ -169,3 +183,29 @@ class OverlayStack(Gtk.Overlay, Loggable):
def get_normalized_cursor_position(self, cursor_position):
return cursor_position / self.window_size
def enable_resize_status(self, enabled):
self.__show_resize_status = enabled
def __sink_widget_size_allocate_cb(self, unused_widget, allocation):
if not self.__show_resize_status:
return
if not self.revealer.get_reveal_child():
self.revealer.set_transition_duration(10)
self.revealer.set_reveal_child(True)
video_width = self.app.project_manager.current_project.videowidth
percent = int(allocation.width / video_width * 100)
self.resize_status.set_text("{}%".format(percent))
# Add timeout function to hide the resize percent.
if self.__resizing_id:
GLib.source_remove(self.__resizing_id)
self.__resizing_id = GLib.timeout_add(1000, self.__resizing_timeout_cb, None)
def __resizing_timeout_cb(self, unused_data):
self.__resizing_id = 0
self.revealer.set_transition_duration(500)
self.revealer.set_reveal_child(False)
return False
......@@ -21,6 +21,7 @@ from time import time
from gi.repository import Gdk
from gi.repository import GES
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gst
from gi.repository import Gtk
......@@ -148,6 +149,10 @@ class ViewerContainer(Gtk.Box, Loggable):
self.setDisplayAspectRatio(self.app.project_manager.current_project.getDAR())
self.target.show_all()
# Wait for 1s to make sure that the viewer has completely realized
# and then we can mark the resize status as showable.
GLib.timeout_add(1000, self.__viewer_realization_done_cb, None)
def _disconnectFromPipeline(self):
if self.pipeline is None:
# silently return, there's nothing to disconnect from
......@@ -402,6 +407,7 @@ class ViewerContainer(Gtk.Box, Loggable):
self.docked = False
self.settings.viewerDocked = False
self.overlay_stack.enable_resize_status(False)
self.remove(self.buttons_container)
position = None
if self.pipeline:
......@@ -431,6 +437,10 @@ class ViewerContainer(Gtk.Box, Loggable):
self.pipeline.pause()
self.pipeline.simple_seek(position)
def __viewer_realization_done_cb(self, unused_data):
self.overlay_stack.enable_resize_status(True)
return False
def dock(self):
if self.docked:
self.warning("The viewer is already docked")
......@@ -438,6 +448,7 @@ class ViewerContainer(Gtk.Box, Loggable):
self.docked = True
self.settings.viewerDocked = True
self.overlay_stack.enable_resize_status(False)
position = None
if self.pipeline:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment