[pitivi] mainwindow: Fix widgets shrinking when small screen
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] mainwindow: Fix widgets shrinking when small screen
- Date: Sat, 5 Oct 2019 05:14:28 +0000 (UTC)
commit 01b12c4d5662a1d23bbe13c82fd6b8f2674f54b2
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Tue Sep 24 16:55:30 2019 +0200
mainwindow: Fix widgets shrinking when small screen
pitivi/editorperspective.py | 5 +++++
pitivi/mainwindow.py | 23 ++++++++++++-----------
pitivi/perspective.py | 5 ++++-
tests/test_mainwindow.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/editorperspective.py b/pitivi/editorperspective.py
index be353e5f..ab49e9ca 100644
--- a/pitivi/editorperspective.py
+++ b/pitivi/editorperspective.py
@@ -104,6 +104,11 @@ class EditorPerspective(Perspective, Loggable):
self.app.gui.connect("focus-in-event", self.__focus_in_event_cb)
self.app.gui.connect("destroy", self._destroyedCb)
+ def activate_compact_mode(self):
+ """Shrinks widgets to suit better a small screen."""
+ self.medialibrary.activateCompactMode()
+ self.viewer.activateCompactMode()
+
def refresh(self):
"""Refreshes the perspective."""
self.focusTimeline()
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 6ec847a7..62599bbe 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -111,7 +111,6 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
self.log("Setting up the perspectives.")
self.set_icon_name("pitivi")
- self.__check_screen_constraints()
self.__set_keyboard_shortcuts()
self.greeter.setup_ui()
@@ -133,6 +132,8 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
self.app.settings.mainWindowY,
width, height)
+ self.check_screen_constraints()
+
self.connect("configure-event", self.__configure_cb)
self.connect("delete-event", self.__delete_cb)
@@ -140,11 +141,16 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
self.resize(width, height)
self.move(x, y)
- def __check_screen_constraints(self):
- """Measures the approximate minimum size required by the main window.
+ def check_screen_constraints(self):
+ """Shrinks some widgets to fit better on smaller screen resolutions."""
+ if self._small_screen():
+ self.greeter.activate_compact_mode()
+ self.editor.activate_compact_mode()
+ min_size, _ = self.get_preferred_size()
+ self.info("Minimum UI size has been reduced to %sx%s",
+ min_size.width, min_size.height)
- Shrinks some widgets to fit better on smaller screen resolutions.
- """
+ def _small_screen(self):
# This code works, but keep in mind get_preferred_size's output
# is only an approximation. As of 2015, GTK still does not have
# a way, even with client-side decorations, to tell us the exact
@@ -154,12 +160,7 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
screen_height = self.get_screen().get_height()
self.debug("Minimum UI size is %sx%s", min_size.width, min_size.height)
self.debug("Screen size is %sx%s", screen_width, screen_height)
- if min_size.width >= 0.9 * screen_width:
- self.medialibrary.activateCompactMode()
- self.viewer.activateCompactMode()
- min_size, _ = self.get_preferred_size()
- self.info("Minimum UI size has been reduced to %sx%s",
- min_size.width, min_size.height)
+ return min_size.width >= 0.9 * screen_width
def __set_keyboard_shortcuts(self):
self.app.shortcuts.register_group("win", _("Project"), position=20)
diff --git a/pitivi/perspective.py b/pitivi/perspective.py
index 4496a1df..0c1bf91b 100644
--- a/pitivi/perspective.py
+++ b/pitivi/perspective.py
@@ -19,7 +19,7 @@
"""Interface for different perspectives."""
-class Perspective(object):
+class Perspective():
"""Interface for different perspectives."""
def __init__(self):
@@ -34,6 +34,9 @@ class Perspective(object):
"""
raise NotImplementedError()
+ def activate_compact_mode(self):
+ """Shrinks widgets to suit better a small screen."""
+
def refresh(self):
"""Refreshes the perspective while activating it."""
raise NotImplementedError()
diff --git a/tests/test_mainwindow.py b/tests/test_mainwindow.py
new file mode 100644
index 00000000..e64077dd
--- /dev/null
+++ b/tests/test_mainwindow.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+# Pitivi video editor
+# Copyright (c) 2019, Alex Băluț <alexandru balut gmail com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+"""Tests for the mainwindow module."""
+# pylint: disable=no-self-use,protected-access
+from unittest import mock
+
+from pitivi.application import Pitivi
+from pitivi.mainwindow import MainWindow
+from tests import common
+
+
+class MainWindowTest(common.TestCase):
+ """Tests for the MainWindow class."""
+
+ def test_create(self):
+ """Exercise creating the main window."""
+ app = Pitivi()
+ app._setup()
+ app.create_main_window()
+
+ def test_create_small(self):
+ """Exercise creating the main window when the screen is small."""
+ with mock.patch.object(MainWindow, "_small_screen") as small_screen:
+ small_screen.return_value = True
+ with mock.patch.object(MainWindow, "get_preferred_size") as get:
+ get.return_value = mock.Mock(), None
+ app = Pitivi()
+ app._setup()
+ app.create_main_window()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]