Skip to content

Commit 624b93d

Browse files
[#1363] (Corrections) IMplementing fixes & style improvements recommended by @ferdnyc
NAmely, duplicate code from NextMarker and PreviousMarker popped to a method, to reduce duplicate code
1 parent da3cf6f commit 624b93d

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

src/windows/main_window.py

+41-44
Original file line numberDiff line numberDiff line change
@@ -1227,13 +1227,29 @@ def actionAddMarker_trigger(self, event):
12271227
marker.data = {"position": position, "icon": "blue.png"}
12281228
marker.save()
12291229

1230-
def actionPreviousMarker_trigger(self, event):
1231-
log.info("actionPreviousMarker_trigger")
12321230

1233-
# Calculate current position (in seconds)
1231+
def findAllMarkerPositions(self):
1232+
"""Build and return a list of all seekable locations for the currently-selected timeline elements"""
1233+
1234+
def getKeyframePositions(data, clip_start_time, clip_stop_time, fps_float):
1235+
""" Add all keyframes of a clip.data to all_marker_positions """
1236+
positions = []
1237+
for property in data :
1238+
try :
1239+
for point in data[property]["Points"] :
1240+
keyframe_time=(point["co"]["X"]-1)/fps_float - data["start"] + data["position"]
1241+
if keyframe_time > clip_start_time and keyframe_time < clip_stop_time :
1242+
positions.append(keyframe_time)
1243+
except TypeError:
1244+
log.info("%s : %s : not itterable", property, data[property])
1245+
pass
1246+
except KeyError:
1247+
log.info("%s : %s : has no points", property, data[property])
1248+
pass
1249+
return positions
1250+
12341251
fps = get_app().project.get("fps")
12351252
fps_float = float(fps["num"]) / float(fps["den"])
1236-
current_position = (self.preview_thread.current_frame - 1) / fps_float
12371253
all_marker_positions = []
12381254

12391255
# Get list of marker and important positions (like selected clip bounds)
@@ -1245,10 +1261,12 @@ def actionPreviousMarker_trigger(self, event):
12451261
# Get selected object
12461262
selected_clip = Clip.get(id=clip_id)
12471263
if selected_clip:
1248-
all_marker_positions.append(selected_clip.data["position"])
1249-
all_marker_positions.append(selected_clip.data["position"] + (selected_clip.data["end"] - selected_clip.data["start"]))
1250-
# add all keyframes. itterate on all properties of Data, look for each points
1251-
addKeyframesToMarkers(selected_clip.data)
1264+
clip_start_time=selected_clip.data["position"]
1265+
clip_stop_time=selected_clip.data["position"] + (selected_clip.data["end"] - selected_clip.data["start"])
1266+
all_marker_positions.append(clip_start_time)
1267+
all_marker_positions.append(clip_stop_time)
1268+
# add all keyframes
1269+
all_marker_positions.extend(getKeyframePositions(selected_clip.data, clip_start_time, clip_stop_time, fps_float))
12521270

12531271
# Loop through selected transitions (and add key positions)
12541272
for tran_id in self.selected_transitions:
@@ -1258,6 +1276,20 @@ def actionPreviousMarker_trigger(self, event):
12581276
all_marker_positions.append(selected_tran.data["position"])
12591277
all_marker_positions.append(selected_tran.data["position"] + (selected_tran.data["end"] - selected_tran.data["start"]))
12601278

1279+
# remove duplicates
1280+
all_marker_positions = list(set(all_marker_positions))
1281+
1282+
return all_marker_positions
1283+
1284+
def actionPreviousMarker_trigger(self, event):
1285+
log.info("actionPreviousMarker_trigger")
1286+
1287+
# Calculate current position (in seconds)
1288+
fps = get_app().project.get("fps")
1289+
fps_float = float(fps["num"]) / float(fps["den"])
1290+
current_position = (self.preview_thread.current_frame - 1) / fps_float
1291+
all_marker_positions = self.findAllMarkerPositions()
1292+
12611293
# Loop through all markers, and find the closest one to the left
12621294
closest_position = None
12631295
for marker_position in sorted(all_marker_positions):
@@ -1289,28 +1321,7 @@ def actionNextMarker_trigger(self, event):
12891321
fps = get_app().project.get("fps")
12901322
fps_float = float(fps["num"]) / float(fps["den"])
12911323
current_position = (self.preview_thread.current_frame - 1) / fps_float
1292-
all_marker_positions = []
1293-
1294-
# Get list of marker and important positions (like selected clip bounds)
1295-
for marker in Marker.filter():
1296-
all_marker_positions.append(marker.data["position"])
1297-
1298-
# Loop through selected clips (and add key positions)
1299-
for clip_id in self.selected_clips:
1300-
# Get selected object
1301-
selected_clip = Clip.get(id=clip_id)
1302-
if selected_clip:
1303-
all_marker_positions.append(selected_clip.data["position"])
1304-
all_marker_positions.append(selected_clip.data["position"] + (selected_clip.data["end"] - selected_clip.data["start"]))
1305-
# add all keyframes. itterate on all properties of Data, look for each points
1306-
addKeyframesToMarkers(selected_clip.data)
1307-
# Loop through selected transitions (and add key positions)
1308-
for tran_id in self.selected_transitions:
1309-
# Get selected object
1310-
selected_tran = Transition.get(id=tran_id)
1311-
if selected_tran:
1312-
all_marker_positions.append(selected_tran.data["position"])
1313-
all_marker_positions.append(selected_tran.data["position"] + (selected_tran.data["end"] - selected_tran.data["start"]))
1324+
all_marker_positions = self.findAllMarkerPositions()
13141325

13151326
# Loop through all markers, and find the closest one to the right
13161327
closest_position = None
@@ -1335,20 +1346,6 @@ def actionNextMarker_trigger(self, event):
13351346
get_app().window.refreshFrameSignal.emit()
13361347
get_app().window.propertyTableView.select_frame(frame_to_seek)
13371348

1338-
def addKeyframesToMarkers(self, data):
1339-
for property in data :
1340-
try :
1341-
for point in data[property]["Points"] :
1342-
keyframe=(point["co"]["X"]-1)/fps_float - data["start"] + data["position"]
1343-
if keyframe > start and keyframe < stop :
1344-
all_marker_positions.append(keyframe)
1345-
except TypeError:
1346-
log.info("%s : %s : not itterable", property, data[property])
1347-
pass
1348-
except KeyError:
1349-
log.info("%s : %s : has no points", property, data[property])
1350-
pass
1351-
13521349
def actionCenterOnPlayhead_trigger(self, event):
13531350
""" Center the timeline on the current playhead position """
13541351
self.timeline.centerOnPlayhead()

0 commit comments

Comments
 (0)