[pitivi] Fix pylint protected-access



commit 0ac189e9a7da3b804951d19a7674003b3c748957
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Oct 29 17:23:01 2019 +0100

    Fix pylint protected-access

 pitivi/dialogs/prefs.py         |  6 ++---
 pitivi/project.py               |  2 +-
 pitivi/timeline/elements.py     |  5 ++--
 pitivi/timeline/timeline.py     | 53 +++++++++++++++++------------------------
 pitivi/utils/loggable.py        |  3 ++-
 pitivi/utils/validate.py        |  1 +
 pre-commit.hook                 |  1 -
 tests/common.py                 |  5 ++--
 tests/test_medialibrary.py      |  2 +-
 tests/test_preset.py            |  3 ++-
 tests/test_project.py           |  2 ++
 tests/test_timeline_timeline.py | 18 +++++++-------
 tests/test_undo.py              |  1 +
 tests/test_undo_timeline.py     |  6 +++--
 14 files changed, 55 insertions(+), 53 deletions(-)
---
diff --git a/pitivi/dialogs/prefs.py b/pitivi/dialogs/prefs.py
index 3b285719..bfd5b4e9 100644
--- a/pitivi/dialogs/prefs.py
+++ b/pitivi/dialogs/prefs.py
@@ -127,7 +127,7 @@ class PreferencesDialog(Loggable):
     @classmethod
     def remove_section(cls, section):
         if cls._instance is not None:
-            cls._instance._remove_page(section)
+            cls._instance.remove_page(section)
         try:
             del cls.section_names[section]
             del cls.prefs[section]
@@ -157,7 +157,7 @@ class PreferencesDialog(Loggable):
             cls.prefs[section] = {}
         cls.prefs[section][attrname] = (label, description, widget_class, args)
         if cls._instance is not None:
-            cls._instance._remove_page(section)
+            cls._instance.remove_page(section)
             cls._instance.add_settings_page(section)
 
     @classmethod
@@ -213,7 +213,7 @@ class PreferencesDialog(Loggable):
             raise Exception("%s is not a valid section id" % section)
         self.stack.add_titled(widget, section, self.section_names[section])
 
-    def _remove_page(self, section):
+    def remove_page(self, section):
         if section in self.section_names:
             widget = self.stack.get_child_by_name(section)
             if widget is not None:
diff --git a/pitivi/project.py b/pitivi/project.py
index c079c891..8a995dfc 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -524,7 +524,7 @@ class ProjectManager(GObject.Object, Loggable):
         project.author = pwd.getpwuid(os.getuid()).pw_gecos.split(",")[0]
 
         project.createTimeline()
-        project._ensureTracks()
+        project._ensureTracks()  # pylint: disable=protected-access
         project.update_restriction_caps()
         self.current_project = project
         self.emit("new-project-created", project)
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index a58491c1..aaefa9fa 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -283,6 +283,7 @@ class KeyframeCurve(FigureCanvas, Loggable):
             offsets = self._keyframes.get_offsets()
             offset = offsets[keyframe_index][0]
 
+            # pylint: disable=protected-access
             if event.guiEvent.type == Gdk.EventType._2BUTTON_PRESS:
                 index = result[1]['ind'][0]
                 # pylint: disable=consider-using-in
@@ -1266,7 +1267,7 @@ class Clip(Gtk.EventBox, Zoomable, Loggable):
             return False
 
         mode = SELECT
-        if self.timeline.get_parent()._controlMask:
+        if self.timeline.get_parent().control_mask:
             if not self.get_state_flags() & Gtk.StateFlags.SELECTED:
                 mode = SELECT_ADD
             else:
@@ -1307,7 +1308,7 @@ class Clip(Gtk.EventBox, Zoomable, Loggable):
     def _event_cb(self, element, event):
         if (event.type == Gdk.EventType.ENTER_NOTIFY and
                 event.mode == Gdk.CrossingMode.NORMAL and
-                not self.timeline._scrubbing):
+                not self.timeline.scrubbing):
             set_children_state_recurse(self, Gtk.StateFlags.PRELIGHT)
             for handle in self.handles:
                 handle.enlarge()
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index e18ab092..9c8cbb54 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -179,8 +179,8 @@ class Marquee(Gtk.Box, Loggable):
         Returns:
             List[GES.Clip]: The clips under the marquee.
         """
-        start_layer = self._timeline._get_layer_at(self.start_y)[0]
-        end_layer = self._timeline._get_layer_at(self.end_y)[0]
+        start_layer = self._timeline.get_layer_at(self.start_y)[0]
+        end_layer = self._timeline.get_layer_at(self.end_y)[0]
         start_pos = max(0, self._timeline.pixelToNs(self.start_x))
         end_pos = max(0, self._timeline.pixelToNs(self.end_x))
 
@@ -358,7 +358,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         self._separator_accepting_drop = False
         self._separator_accepting_drop_id = 0
         self.__last_position = 0
-        self._scrubbing = False
+        self.scrubbing = False
         self._scrolling = False
         # The parameters for the delayed scroll to be performed after
         # the layers box is allocated a size.
@@ -726,8 +726,8 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                 else:
                     self.layout.marquee.set_start_position(event)
 
-        self._scrubbing = res and button == 3
-        if self._scrubbing:
+        self.scrubbing = res and button == 3
+        if self.scrubbing:
             self._seek(event)
             clip = self._getParentOfType(event_widget, Clip)
             if clip:
@@ -751,7 +751,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         elif res and button == 1:
             self._selectUnderMarquee()
 
-        self._scrubbing = False
+        self.scrubbing = False
 
         self._scrolling = False
 
@@ -766,7 +766,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                         self._seek(event)
 
             # Allowing group clips selection by shift+clicking anywhere on the timeline.
-            if self.get_parent()._shiftMask:
+            if self.get_parent().shift_mask:
                 last_clicked_layer = self.last_clicked_layer
                 if not last_clicked_layer:
                     clicked_layer, click_pos = self.get_clicked_layer_and_pos(event)
@@ -777,7 +777,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                     clips = self.get_clips_in_between(
                         last_clicked_layer, cur_clicked_layer, last_click_pos, cur_click_pos)
                     self.selection.setSelection(clips, SELECT)
-            elif not self.get_parent()._controlMask:
+            elif not self.get_parent().control_mask:
                 clicked_layer, click_pos = self.get_clicked_layer_and_pos(event)
                 self.set_selection_meta_info(clicked_layer, click_pos, SELECT)
 
@@ -798,7 +798,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         """Gets layer and position in the timeline where user clicked."""
         event_widget = Gtk.get_event_widget(event)
         x, y = event_widget.translate_coordinates(self.layout.layers_vbox, event.x, event.y)
-        clicked_layer = self._get_layer_at(y)[0]
+        clicked_layer = self.get_layer_at(y)[0]
         click_pos = max(0, self.pixelToNs(x))
         return clicked_layer, click_pos
 
@@ -859,7 +859,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         elif self.__moving_layer:
             event_widget = Gtk.get_event_widget(event)
             unused_x, y = event_widget.translate_coordinates(self, event.x, event.y)
-            layer, unused_on_sep = self._get_layer_at(
+            layer, unused_on_sep = self.get_layer_at(
                 y, prefer_ges_layer=self.__moving_layer,
                 past_middle_when_adjacent=True)
             if layer != self.__moving_layer:
@@ -867,7 +867,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                 self.moveLayer(self.__moving_layer, priority)
         elif self.layout.marquee.start_x:
             self.layout.marquee.move(event)
-        elif self._scrubbing:
+        elif self.scrubbing:
             self._seek(event)
         elif self._scrolling:
             self.__scroll(event)
@@ -939,7 +939,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
             else:
                 clip_duration = asset.get_duration()
 
-            ges_layer, unused_on_sep = self._get_layer_at(y)
+            ges_layer, unused_on_sep = self.get_layer_at(y)
             if not placement:
                 placement = self.pixelToNs(x)
             placement = max(0, placement)
@@ -1228,15 +1228,15 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
         parent = self.get_parent()
         autoripple_active = self.app.settings.timelineAutoRipple and in_devel()
-        if parent._shiftMask or autoripple_active:
+        if parent.shift_mask or autoripple_active:
             return GES.EditMode.EDIT_RIPPLE
-        if is_handle and parent._controlMask:
+        if is_handle and parent.control_mask:
             return GES.EditMode.EDIT_ROLL
         elif is_handle:
             return GES.EditMode.EDIT_TRIM
         return GES.EditMode.EDIT_NORMAL
 
-    def _get_layer_at(self, y, prefer_ges_layer=None, past_middle_when_adjacent=False):
+    def get_layer_at(self, y, prefer_ges_layer=None, past_middle_when_adjacent=False):
         ges_layers = self.ges_timeline.get_layers()
         if y < SEPARATOR_HEIGHT:
             # The cursor is at the top, above the first layer.
@@ -1333,7 +1333,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
             position = self.pixelToNs(x - self.__drag_start_x)
 
         self._setSeparatorsPrelight(False)
-        res = self._get_layer_at(y, prefer_ges_layer=self._on_layer)
+        res = self.get_layer_at(y, prefer_ges_layer=self._on_layer)
         self._on_layer, self.__on_separators = res
         if (mode != GES.EditMode.EDIT_NORMAL or
                 self.dragging_group.props.height > 1):
@@ -1413,8 +1413,8 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
 
         self.app = app
         self._settings = self.app.settings
-        self._shiftMask = False
-        self._controlMask = False
+        self.shift_mask = False
+        self.control_mask = False
 
         self._project = None
         self.ges_timeline = None
@@ -1530,15 +1530,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         """Connects to the project's timeline and pipeline."""
         if self._project:
             self._project.disconnect_by_func(self._rendering_settings_changed_cb)
-            try:
-                self.timeline._pipeline.disconnect_by_func(
-                    self.timeline.positionCb)
-            except AttributeError:
-                pass
-            except TypeError:
-                pass  # We were not connected no problem
-
-            self.timeline._pipeline = None
             self.markers.markers_container = None
 
         self._project = project
@@ -2058,15 +2049,15 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         # This is used both for changing the selection modes and for affecting
         # the seek keyboard shortcuts further below
         if event.keyval == Gdk.KEY_Shift_L:
-            self._shiftMask = True
+            self.shift_mask = True
         elif event.keyval == Gdk.KEY_Control_L:
-            self._controlMask = True
+            self.control_mask = True
 
     def do_key_release_event(self, event):
         if event.keyval == Gdk.KEY_Shift_L:
-            self._shiftMask = False
+            self.shift_mask = False
         elif event.keyval == Gdk.KEY_Control_L:
-            self._controlMask = False
+            self.control_mask = False
 
     def _seek_backward_one_second_cb(self, unused_action, unused_parameter):
         self._project.pipeline.seekRelative(0 - Gst.SECOND)
diff --git a/pitivi/utils/loggable.py b/pitivi/utils/loggable.py
index e384347e..f1a1a095 100644
--- a/pitivi/utils/loggable.py
+++ b/pitivi/utils/loggable.py
@@ -398,7 +398,7 @@ def getFileLine(where=-1):
         lineno = co.co_firstlineno
         name = co.co_name
     else:
-        stackFrame = sys._getframe()
+        stackFrame = sys._getframe()  # pylint: disable=protected-access
         while stackFrame:
             co = stackFrame.f_code
             if not co.co_filename.endswith('loggable.py'):
@@ -548,6 +548,7 @@ def safeprintf(file, format, *args):
         if e.errno == errno.EPIPE:
             # if our output is closed, exit; e.g. when logging over an
             # ssh connection and the ssh connection is closed
+            # pylint: disable=protected-access
             os._exit(os.EX_OSERR)
         # otherwise ignore it, there's nothing you can do
 
diff --git a/pitivi/utils/validate.py b/pitivi/utils/validate.py
index d8957eb8..8e0ed7af 100644
--- a/pitivi/utils/validate.py
+++ b/pitivi/utils/validate.py
@@ -16,6 +16,7 @@
 # License along with this program; if not, write to the
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
+# pylint: disable=protected-access
 import locale
 import subprocess
 from unittest import mock
diff --git a/pre-commit.hook b/pre-commit.hook
index 2433f536..81db31dd 100755
--- a/pre-commit.hook
+++ b/pre-commit.hook
@@ -14,7 +14,6 @@ export PYTHONPATH=$TOPLEVEL/pitivi/coptimizations/.libs:$PYTHONPATH
 PYLINT_IGNORED_FILES="
 bin/pitivi.in
 pitivi/autoaligner.py
-pitivi/dialogs/prefs.py
 pitivi/editorperspective.py
 pitivi/effects.py
 pitivi/mediafilespreviewer.py
diff --git a/tests/common.py b/tests/common.py
index 13620a29..ff9bc0d2 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -17,6 +17,7 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 """Useful objects for testing."""
+# pylint: disable=protected-access
 import contextlib
 import gc
 import locale
@@ -281,8 +282,8 @@ class TestCase(unittest.TestCase, Loggable):
             ges_clip.ui.timeline._button_press_event_cb(None, event)
             with mock.patch.object(ges_clip.ui, "translate_coordinates") as translate_coordinates:
                 translate_coordinates.return_value = (0, 0)
-                with mock.patch.object(ges_clip.ui.timeline, "_get_layer_at") as _get_layer_at:
-                    _get_layer_at.return_value = ges_clip.props.layer, None
+                with mock.patch.object(ges_clip.ui.timeline, "get_layer_at") as get_layer_at:
+                    get_layer_at.return_value = ges_clip.props.layer, None
                     ges_clip.ui._button_release_event_cb(None, event)
                     ges_clip.ui.timeline._button_release_event_cb(None, event)
 
diff --git a/tests/test_medialibrary.py b/tests/test_medialibrary.py
index 932f2d4e..bfcf8673 100644
--- a/tests/test_medialibrary.py
+++ b/tests/test_medialibrary.py
@@ -17,7 +17,7 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 """Tests for the pitivi.medialibrary module."""
-# pylint: disable=attribute-defined-outside-init
+# pylint: disable=attribute-defined-outside-init,protected-access
 import os
 import tempfile
 from unittest import mock
diff --git a/tests/test_preset.py b/tests/test_preset.py
index 4782a6a3..40e1b464 100644
--- a/tests/test_preset.py
+++ b/tests/test_preset.py
@@ -17,7 +17,8 @@
 # License along with this program; if not, write to the
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
-# TODO: add a specific testcase for audio, video, render presets
+"""Tests for the pitivi.preset module."""
+# pylint: disable=protected-access
 import os.path
 import shutil
 import tempfile
diff --git a/tests/test_project.py b/tests/test_project.py
index b985365b..3ee668f3 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -17,6 +17,8 @@
 # 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 pitivi.project module."""
+# pylint: disable=protected-access
 import collections
 import os
 import tempfile
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index 6927b924..01329483 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -16,6 +16,8 @@
 # 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 pitivi.timeline.timeline module."""
+# pylint: disable=protected-access
 from unittest import mock
 
 from gi.repository import Gdk
@@ -109,7 +111,7 @@ class TestLayers(BaseTestTimeline):
         s = SEPARATOR_HEIGHT
 
         def assertLayerAt(ges_layer, y):
-            result = timeline._get_layer_at(
+            result = timeline.get_layer_at(
                 int(y),
                 prefer_ges_layer=preferred_ges_layer,
                 past_middle_when_adjacent=past_middle_when_adjacent)
@@ -490,8 +492,8 @@ class TestGrouping(BaseTestTimeline):
             event.get_state.return_value = Gdk.ModifierType.BUTTON1_MASK
             with mock.patch.object(clip1.ui, "translate_coordinates") as translate_coordinates:
                 translate_coordinates.return_value = (40, 0)
-                with mock.patch.object(timeline, "_get_layer_at") as _get_layer_at:
-                    _get_layer_at.return_value = layer1, timeline._separators[1]
+                with mock.patch.object(timeline, "get_layer_at") as get_layer_at:
+                    get_layer_at.return_value = layer1, timeline._separators[1]
                     timeline._motion_notify_event_cb(None, event)
             self.assertTrue(timeline.got_dragged)
 
@@ -601,8 +603,8 @@ class TestEditing(BaseTestTimeline):
             event.get_state.return_value = Gdk.ModifierType.BUTTON1_MASK
             with mock.patch.object(clip.ui.rightHandle, "translate_coordinates") as translate_coordinates:
                 translate_coordinates.return_value = (0, 0)
-                with mock.patch.object(timeline, "_get_layer_at") as _get_layer_at:
-                    _get_layer_at.return_value = layer, timeline._separators[1]
+                with mock.patch.object(timeline, "get_layer_at") as get_layer_at:
+                    get_layer_at.return_value = layer, timeline._separators[1]
                     timeline._motion_notify_event_cb(None, event)
             self.assertTrue(timeline.got_dragged)
 
@@ -654,7 +656,7 @@ class TestShiftSelection(BaseTestTimeline):
             # Simulate click on first and shift+click on second clip.
             timeline.get_clicked_layer_and_pos.return_value = (ges_layer, 0.5 * Gst.SECOND)
             timeline._button_release_event_cb(None, event)
-            timeline.get_parent()._shiftMask = True
+            timeline.get_parent().shift_mask = True
             timeline.get_clicked_layer_and_pos.return_value = (ges_layer, 1.5 * Gst.SECOND)
             timeline._button_release_event_cb(None, event)
             self.__check_selected([ges_clip1, ges_clip2], [])
@@ -676,7 +678,7 @@ class TestShiftSelection(BaseTestTimeline):
 
         event = mock.Mock()
         event.get_button.return_value = (True, 1)
-        timeline.get_parent()._shiftMask = True
+        timeline.get_parent().shift_mask = True
         timeline._seek = mock.Mock()
         timeline._seek.return_value = True
         timeline.get_clicked_layer_and_pos = mock.Mock()
@@ -741,7 +743,7 @@ class TestShiftSelection(BaseTestTimeline):
 
         event = mock.Mock()
         event.get_button.return_value = (True, 1)
-        timeline.get_parent()._shiftMask = True
+        timeline.get_parent().shift_mask = True
         timeline._seek = mock.Mock()
         timeline._seek.return_value = True
         timeline.get_clicked_layer_and_pos = mock.Mock()
diff --git a/tests/test_undo.py b/tests/test_undo.py
index 8ca1ea03..5e4311b2 100644
--- a/tests/test_undo.py
+++ b/tests/test_undo.py
@@ -17,6 +17,7 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 """Tests for the pitivi.undo.undo module."""
+# pylint: disable=protected-access
 from unittest import mock
 
 from gi.repository import GES
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index 785b60bf..793d8638 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -17,6 +17,8 @@
 # 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 pitivi.undo.timeline module."""
+# pylint: disable=protected-access
 from unittest import mock
 
 from gi.repository import Gdk
@@ -296,8 +298,8 @@ class TestLayerObserver(BaseTestUndoTimeline):
 
             with mock.patch.object(layer1.control_ui, "translate_coordinates") as translate_coordinates:
                 translate_coordinates.return_value = (0, 0)
-                with mock.patch.object(timeline_ui, "_get_layer_at") as _get_layer_at:
-                    _get_layer_at.return_value = layer3, None
+                with mock.patch.object(timeline_ui, "get_layer_at") as get_layer_at:
+                    get_layer_at.return_value = layer3, None
                     timeline_ui._motion_notify_event_cb(None, event=event)
 
             timeline_ui._button_release_event_cb(None, event=event)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]