Import_3ds: Improved distance cue node setup
[blender-addons.git] / power_sequencer / operators / markers_set_preview_in_between.py
blob0baf9e0207170d8b2d10b29ed842d94b1351d453
1 # SPDX-FileCopyrightText: 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
3 # SPDX-License-Identifier: GPL-3.0-or-later
5 import bpy
7 from .utils.functions import find_neighboring_markers
8 from .utils.doc import doc_name, doc_idname, doc_brief, doc_description
11 class POWER_SEQUENCER_OT_set_preview_between_markers(bpy.types.Operator):
12 """
13 Set the timeline's preview range using the 2 markers closest to the time cursor
14 """
16 doc = {
17 "name": doc_name(__qualname__),
18 "demo": "",
19 "description": doc_description(__doc__),
20 "shortcuts": [],
21 "keymap": "Sequencer",
23 bl_idname = doc_idname(__qualname__)
24 bl_label = doc["name"]
25 bl_description = doc_brief(doc["description"])
26 bl_options = {"REGISTER", "UNDO"}
28 @classmethod
29 def poll(cls, context):
30 return context.scene.sequence_editor
32 def invoke(self, context, event):
33 if not context.scene.timeline_markers:
34 self.report({"ERROR_INVALID_INPUT"}, "There are no markers. Operation cancelled.")
35 return {"CANCELLED"}
37 frame = context.scene.frame_current
38 previous_marker, next_marker = find_neighboring_markers(context, frame)
40 if not (previous_marker and next_marker):
41 self.report({"ERROR_INVALID_INPUT"}, "There are no markers. Operation cancelled.")
42 return {"CANCELLED"}
44 frame_start = previous_marker.frame if previous_marker else 0
45 if next_marker:
46 frame_end = next_marker.frame
47 else:
48 from operator import attrgetter
50 frame_end = max(
51 context.scene.sequence_editor.sequences, key=attrgetter("frame_final_end")
52 ).frame_final_end
54 from .utils.functions import set_preview_range
56 set_preview_range(context, frame_start, frame_end)
57 return {"FINISHED"}