Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def transformTriggered(self, clip_id):
"""Handle the transform signal when it's emitted"""
need_refresh = False
# Disable Transform UI
if self and self.transforming_clip:
# Is this the same clip_id already being transformed?
if not clip_id:
# Clear transform
self.transforming_clip = None
need_refresh = True
# Get new clip for transform
if clip_id:
self.transforming_clip = Clip.get(id=clip_id)
if self.transforming_clip:
self.transforming_clip_object = None
clips = get_app().window.timeline_sync.timeline.Clips()
for clip in clips:
if clip.Id() == self.transforming_clip.id:
self.transforming_clip_object = clip
need_refresh = True
break
# Update the preview and reselct current frame in properties
if need_refresh:
get_app().window.refreshFrameSignal.emit()
get_app().window.propertyTableView.select_frame(get_app().window.preview_thread.player.Position())
item_id, item_type = self.selected_item.data()
# Bail if readonly
if readonly:
return
# Get the original data of this item (prior to any updates, for the undo/redo system)
if not self.original_data:
# Ignore undo/redo history temporarily (to avoid a huge pile of undo/redo history)
get_app().updates.ignore_history = True
# Find this clip
c = None
if item_type == "clip":
# Get clip object
c = Clip.get(id=item_id)
elif item_type == "transition":
# Get transition object
c = Transition.get(id=item_id)
elif item_type == "effect":
# Get effect object
c = Effect.get(id=item_id)
if c:
if property_key in c.data:
# Grab the original data for this item/property
self.original_data = c.data
# Calculate percentage value
if property_type in ["float", "int"] and property_name != "Track":
min_max_range = float(property_max) - float(property_min)
log.info("actionPreviousMarker_trigger")
# Calculate current position (in seconds)
fps = get_app().project.get(["fps"])
fps_float = float(fps["num"]) / float(fps["den"])
current_position = (self.preview_thread.current_frame - 1) / fps_float
all_marker_positions = []
# Get list of marker and important positions (like selected clip bounds)
for marker in Marker.filter():
all_marker_positions.append(marker.data["position"])
# Loop through selected clips (and add key positions)
for clip_id in self.selected_clips:
# Get selected object
selected_clip = Clip.get(id=clip_id)
if selected_clip:
all_marker_positions.append(selected_clip.data["position"])
all_marker_positions.append(selected_clip.data["position"] + (selected_clip.data["end"] - selected_clip.data["start"]))
# Loop through selected transitions (and add key positions)
for tran_id in self.selected_transitions:
# Get selected object
selected_tran = Transition.get(id=tran_id)
if selected_tran:
all_marker_positions.append(selected_tran.data["position"])
all_marker_positions.append(selected_tran.data["position"] + (selected_tran.data["end"] - selected_tran.data["start"]))
# Loop through all markers, and find the closest one to the left
closest_position = None
for marker_position in sorted(all_marker_positions):
# Is marker smaller than position?
def Volume_Triggered(self, action, clip_ids, position="Entire Clip"):
"""Callback for volume context menus"""
log.info(action)
prop_name = "volume"
# Get FPS from project
fps = get_app().project.get(["fps"])
fps_float = float(fps["num"]) / float(fps["den"])
# Loop through each selected clip
for clip_id in clip_ids:
# Get existing clip object
clip = Clip.get(id=clip_id)
if not clip:
# Invalid clip, skip to next item
continue
start_of_clip = round(float(clip.data["start"]) * fps_float) + 1
end_of_clip = round(float(clip.data["end"]) * fps_float) + 1
# Determine the beginning and ending of this animation
# ["Start of Clip", "End of Clip", "Entire Clip"]
start_animation = start_of_clip
end_animation = end_of_clip
if position == "Start of Clip" and action in [MENU_VOLUME_FADE_IN_FAST, MENU_VOLUME_FADE_OUT_FAST]:
start_animation = start_of_clip
end_animation = min(start_of_clip + (1.0 * fps_float), end_of_clip)
elif position == "Start of Clip" and action in [MENU_VOLUME_FADE_IN_SLOW, MENU_VOLUME_FADE_OUT_SLOW]:
start_animation = start_of_clip
# Determine what was changed
property = self.model.item(item.row(), 0).data()
property_type = property[1]["type"]
closest_point_x = property[1]["closest_point_x"]
previous_point_x = property[1]["previous_point_x"]
property_key = property[0]
clip_id, item_type = item.data()
if property_type == "color":
# Find this clip
c = None
clip_updated = False
if item_type == "clip":
# Get clip object
c = Clip.get(id=clip_id)
elif item_type == "transition":
# Get transition object
c = Transition.get(id=clip_id)
elif item_type == "effect":
# Get effect object
c = Effect.get(id=clip_id)
if c:
# Update clip attribute
if property_key in c.data:
log.info("color update: %s" % c.data)
# Loop through each keyframe (red, blue, and green)
for color, new_value in [("red", new_color.red()), ("blue", new_color.blue()), ("green", new_color.green())]:
# Keyframe
def refreshTriggered(self):
"""Signal to refresh viewport (i.e. a property might have changed that effects the preview)"""
# Update reference to clip
if self and self.transforming_clip:
self.transforming_clip = Clip.get(id=self.transforming_clip.id)
def Align_Triggered(self, action, clip_ids, tran_ids):
"""Callback for alignment context menus"""
log.info(action)
prop_name = "position"
left_edge = -1.0
right_edge = -1.0
# Loop through each selected clip (find furthest left and right edge)
for clip_id in clip_ids:
# Get existing clip object
clip = Clip.get(id=clip_id)
if not clip:
# Invalid clip, skip to next item
continue
position = float(clip.data["position"])
start_of_clip = float(clip.data["start"])
end_of_clip = float(clip.data["end"])
if position < left_edge or left_edge == -1.0:
left_edge = position
if position + (end_of_clip - start_of_clip) > right_edge or right_edge == -1.0:
right_edge = position + (end_of_clip - start_of_clip)
# Loop through each selected transition (find furthest left and right edge)
for tran_id in tran_ids:
# Get existing transition object
def update_clip_data(self, clip_json):
""" Create an updateAction and send it to the update manager """
# read clip json
if not isinstance(clip_json, dict):
clip_data = json.loads(clip_json)
else:
clip_data = clip_json
# Search for matching clip in project data (if any)
existing_clip = Clip.get(id=clip_data["id"])
if not existing_clip:
# Create a new clip (if not exists)
existing_clip = Clip()
existing_clip.data = clip_data
existing_clip.save()
log.info(self.preview_thread.current_frame)
# Calculate current position (in seconds)
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
current_position = (self.preview_thread.current_frame - 1) / fps_float
all_marker_positions = []
# Get list of marker and important positions (like selected clip bounds)
for marker in Marker.filter():
all_marker_positions.append(marker.data["position"])
# Loop through selected clips (and add key positions)
for clip_id in self.selected_clips:
# Get selected object
selected_clip = Clip.get(id=clip_id)
if selected_clip:
all_marker_positions.append(selected_clip.data["position"])
all_marker_positions.append(selected_clip.data["position"] + (selected_clip.data["end"] - selected_clip.data["start"]))
# Loop through selected transitions (and add key positions)
for tran_id in self.selected_transitions:
# Get selected object
selected_tran = Transition.get(id=tran_id)
if selected_tran:
all_marker_positions.append(selected_tran.data["position"])
all_marker_positions.append(selected_tran.data["position"] + (selected_tran.data["end"] - selected_tran.data["start"]))
# Loop through all markers, and find the closest one to the right
closest_position = None
for marker_position in sorted(all_marker_positions):
# Is marker smaller than position?