[pitivi] tests: Check shortcuts groups
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] tests: Check shortcuts groups
- Date: Sun, 17 Jul 2016 21:31:20 +0000 (UTC)
commit bc23d89eb418b7544443c23f5b4c637867b0e8f4
Author: Jakub Brindza <jakub brindza gmail com>
Date: Thu Jul 7 17:23:17 2016 +0100
tests: Check shortcuts groups
Should have been part of ae41568fc74261d15aad9251db9b8ace03bc8a02
Differential Revision: https://phabricator.freedesktop.org/D1158
pitivi/application.py | 6 +++-
pitivi/clipproperties.py | 1 -
pitivi/mainwindow.py | 3 +-
pitivi/medialibrary.py | 1 -
pitivi/shortcuts.py | 11 +++-----
pitivi/timeline/timeline.py | 1 -
tests/meson.build | 1 +
tests/test_shortcuts.py | 57 +++++++++++++++++++++++++++++++++++++++++++
8 files changed, 67 insertions(+), 14 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index ee23b42..a089ac8 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -157,7 +157,8 @@ class Pitivi(Gtk.Application, Loggable):
self.undo_action = Gio.SimpleAction.new("undo", None)
self.undo_action.connect("activate", self._undoCb)
self.add_action(self.undo_action)
- self.shortcuts.add("app.undo", ["<Control>z"], _("Undo the most recent action"))
+ self.shortcuts.add("app.undo", ["<Control>z"],
+ _("Undo the most recent action"))
self.redo_action = Gio.SimpleAction.new("redo", None)
self.redo_action.connect("activate", self._redoCb)
@@ -173,7 +174,8 @@ class Pitivi(Gtk.Application, Loggable):
self.show_shortcuts_action = Gio.SimpleAction.new("shortcuts_window", None)
self.show_shortcuts_action.connect("activate", self._show_shortcuts_cb)
self.add_action(self.show_shortcuts_action)
- self.shortcuts.add("app.shortcuts_window", ["<Control>F1", "<Control>question"],
+ self.shortcuts.add("app.shortcuts_window",
+ ["<Control>F1", "<Control>question"],
_("Show the Shortcuts Window"))
def do_activate(self):
diff --git a/pitivi/clipproperties.py b/pitivi/clipproperties.py
index 4cbd8ac..cb10d02 100644
--- a/pitivi/clipproperties.py
+++ b/pitivi/clipproperties.py
@@ -31,7 +31,6 @@ from pitivi.effects import AUDIO_EFFECT
from pitivi.effects import EffectsPropertiesManager
from pitivi.effects import HIDDEN_EFFECTS
from pitivi.effects import VIDEO_EFFECT
-from pitivi.shortcuts import ShortcutsWindow
from pitivi.undo.timeline import CommitTimelineFinalizingAction
from pitivi.utils.loggable import Loggable
from pitivi.utils.ui import disable_scroll
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index e8c5d4f..2f3d0f0 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -43,7 +43,6 @@ from pitivi.mediafilespreviewer import PreviewWidget
from pitivi.medialibrary import MediaLibraryWidget
from pitivi.project import ProjectSettingsDialog
from pitivi.settings import GlobalSettings
-from pitivi.shortcuts import ShortcutsWindow
from pitivi.tabsmanager import BaseTabs
from pitivi.timeline.timeline import TimelineContainer
from pitivi.titleeditor import TitleEditor
@@ -441,9 +440,9 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
self.save_action = Gio.SimpleAction.new("save", None)
self.save_action.connect("activate", self._saveProjectCb)
self.add_action(self.save_action)
- self.save_button.set_action_name("win.save")
self.app.shortcuts.add("win.save", ["<Control>s"],
_("Save the current project"))
+ self.save_button.set_action_name("win.save")
self.new_project_action = Gio.SimpleAction.new("new-project", None)
self.new_project_action.connect("activate", self._newProjectMenuCb)
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index a070ef1..197bd88 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -45,7 +45,6 @@ from pitivi.dialogs.clipmediaprops import ClipMediaPropsDialog
from pitivi.dialogs.filelisterrordialog import FileListErrorDialog
from pitivi.mediafilespreviewer import PreviewWidget
from pitivi.settings import GlobalSettings
-from pitivi.shortcuts import ShortcutsWindow
from pitivi.timeline.previewers import getThumbnailCache
from pitivi.utils.loggable import Loggable
from pitivi.utils.misc import disconnectAllByFunc
diff --git a/pitivi/shortcuts.py b/pitivi/shortcuts.py
index 2c125b8..1f1bc24 100644
--- a/pitivi/shortcuts.py
+++ b/pitivi/shortcuts.py
@@ -23,7 +23,7 @@ from pitivi.utils.misc import show_user_manual
class ShortcutsManager:
- """Manager class storing the shortcuts from all across the app"""
+ """Manager storing the shortcuts from all across the app."""
def __init__(self, app):
self.app = app
@@ -68,9 +68,6 @@ class ShortcutsWindow(Gtk.ShortcutsWindow):
def __init__(self, app):
Gtk.ShortcutsWindow.__init__(self)
self.app = app
- self.group_titles = self.app.shortcuts.group_titles
- self.group_actions = self.app.shortcuts.group_actions
- self.groups = self.app.shortcuts.groups
self.set_transient_for(self.app.gui)
self.set_modal(True)
self.populate()
@@ -79,10 +76,10 @@ class ShortcutsWindow(Gtk.ShortcutsWindow):
"""Gathers the accelerators and populates the window."""
section = Gtk.ShortcutsSection()
section.show()
- for group_id in self.groups:
- group = Gtk.ShortcutsGroup(title=self.group_titles[group_id])
+ for group_id in self.app.shortcuts.groups:
+ group = Gtk.ShortcutsGroup(title=self.app.shortcuts.group_titles[group_id])
group.show()
- for action, title in self.group_actions[group_id]:
+ for action, title in self.app.shortcuts.group_actions[group_id]:
accelerators = " ".join(self.app.get_accels_for_action(action))
short = Gtk.ShortcutsShortcut(title=title, accelerator=accelerators)
short.show()
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 87bf8dd..ee99766 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -31,7 +31,6 @@ from pitivi.autoaligner import AutoAligner
from pitivi.configure import get_ui_dir
from pitivi.dialogs.prefs import PreferencesDialog
from pitivi.settings import GlobalSettings
-from pitivi.shortcuts import ShortcutsWindow
from pitivi.timeline.elements import Clip
from pitivi.timeline.elements import TransitionClip
from pitivi.timeline.elements import TrimHandle
diff --git a/tests/meson.build b/tests/meson.build
index 6788144..c3a2484 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -16,6 +16,7 @@ tests = [
['Test presets', 'test_preset.py'],
['Test the previewer', 'test_previewers.py'],
['Test the project', 'test_project.py'],
+ ['Test the keyboard shortcuts', 'test_shortcuts.py'],
['Test system integration', 'test_system.py'],
['Test graphical timeline elements', 'test_timeline_elements.py'],
['Test graphical layers', 'test_timeline_layer.py'],
diff --git a/tests/test_shortcuts.py b/tests/test_shortcuts.py
new file mode 100644
index 0000000..3f90caa
--- /dev/null
+++ b/tests/test_shortcuts.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+# Pitivi video editor
+# Copyright (c) 2016, Jakub Brindza <jakub brindza 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.
+"""Test the keyboard shortcuts."""
+from unittest import mock
+from unittest import TestCase
+
+from pitivi.shortcuts import ShortcutsManager
+
+
+class TestShortcutsManager(TestCase):
+ """Tests for the ShortcutsManager."""
+
+ def test_groups(self):
+ """Checks the group in which the shortcut ends up."""
+ app = mock.MagicMock()
+ manager = ShortcutsManager(app)
+
+ # Test register_group method
+ manager.register_group("alpha_group", "The very first test group")
+ self.assertListEqual(manager.groups, ["alpha_group"])
+ manager.register_group("beta_group", "Another test group")
+ self.assertListEqual(manager.groups, ["alpha_group", "beta_group"])
+
+ # Test grouping using the stripping away group name from action name
+ manager.add("alpha_group.first", ["<Control>A"], "First action")
+ self.assertIn(("alpha_group.first", "First action"),
+ manager.group_actions["alpha_group"])
+ manager.add("alpha_group.second", ["<Control>B"], "Second action")
+ self.assertIn(("alpha_group.second", "Second action"),
+ manager.group_actions["alpha_group"])
+ manager.add("beta_group.first", ["<Control>C"], "First beta action")
+ self.assertIn(("beta_group.first", "First beta action"),
+ manager.group_actions["beta_group"])
+
+ # Test grouping using the group optional argument
+ # if group parameter is set, the action prefix can be anything,
+ # it should be disregarded in favour of the group value.
+ manager.add("anything.third_action", ["<Control>D"], "Third action",
+ group="beta_group")
+ self.assertIn(("anything.third_action", "Third action"),
+ manager.group_actions["beta_group"])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]