Skip to content

Commit

Permalink
Simplify code by combining 'or' statements
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Oct 12, 2020
1 parent a17a730 commit 2042227
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/windows/add_to_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ def accept(self):
position = max(start_position, new_clip["position"] - fade_length)
new_clip["position"] = position

if fade_value == 'Fade In' or fade_value == 'Fade In & Out':
if fade_value in ['Fade In', 'Fade In & Out']:
start = openshot.Point(round(start_time * fps_float) + 1, 0.0, openshot.BEZIER)
start_object = json.loads(start.Json())
end = openshot.Point(min(round((start_time + fade_length) * fps_float) + 1, round(end_time * fps_float) + 1), 1.0, openshot.BEZIER)
end_object = json.loads(end.Json())
new_clip['alpha']["Points"].append(start_object)
new_clip['alpha']["Points"].append(end_object)

if fade_value == 'Fade Out' or fade_value == 'Fade In & Out':
if fade_value in ['Fade Out', 'Fade In & Out']:
start = openshot.Point(max(round((end_time * fps_float) + 1) - (round(fade_length * fps_float) + 1), round(start_time * fps_float) + 1), 1.0, openshot.BEZIER)
start_object = json.loads(start.Json())
end = openshot.Point(round(end_time * fps_float) + 1, 0.0, openshot.BEZIER)
Expand Down
5 changes: 2 additions & 3 deletions src/windows/views/blender_listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,8 @@ def Render(self):

_ = get_app()._tr

if not self.version:
if not self.blender_version_check():
return
if not self.version and not self.blender_version_check():
return

self.command_output = ""
self.current_frame = 0
Expand Down
8 changes: 2 additions & 6 deletions src/windows/views/timeline_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ def get_html(self):
def keyPressEvent(self, event):
""" Keypress callback for timeline """
key_value = event.key()
if (key_value == Qt.Key_Shift or key_value == Qt.Key_Control):

if key_value in [Qt.Key_Shift, Qt.Key_Control]:
# Only pass a few keystrokes to the webview (CTRL and SHIFT)
return QWebEngineView.keyPressEvent(self, event)

else:
# Ignore most keypresses
event.ignore()
Expand Down Expand Up @@ -212,11 +210,9 @@ def get_html(self):
def keyPressEvent(self, event):
""" Keypress callback for timeline """
key_value = event.key()
if (key_value == Qt.Key_Shift or key_value == Qt.Key_Control):

if key_value in [Qt.Key_Shift, Qt.Key_Control]:
# Only pass a few keystrokes to the webview (CTRL and SHIFT)
return QWebView.keyPressEvent(self, event)

else:
# Ignore most keypresses
event.ignore()
Expand Down
18 changes: 9 additions & 9 deletions src/windows/views/timeline_webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,11 @@ def Layout_Triggered(self, action, clip_ids):
clip.data["location_x"] = {"Points": [p_object]}
clip.data["location_y"] = {"Points": [p_object]}

if action == MENU_LAYOUT_CENTER or \
action == MENU_LAYOUT_TOP_LEFT or \
action == MENU_LAYOUT_TOP_RIGHT or \
action == MENU_LAYOUT_BOTTOM_LEFT or \
action == MENU_LAYOUT_BOTTOM_RIGHT:
if action in [MENU_LAYOUT_CENTER,
MENU_LAYOUT_TOP_LEFT,
MENU_LAYOUT_TOP_RIGHT,
MENU_LAYOUT_BOTTOM_LEFT,
MENU_LAYOUT_BOTTOM_RIGHT]:
# Reset scale mode
clip.data["scale"] = openshot.SCALE_FIT
clip.data["gravity"] = new_gravity
Expand Down Expand Up @@ -1437,7 +1437,7 @@ def Copy_Triggered(self, action, clip_ids, tran_ids):

self.copy_clipboard[clip_id] = {}

if action == MENU_COPY_CLIP or action == MENU_COPY_ALL:
if action in [MENU_COPY_CLIP, MENU_COPY_ALL]:
self.copy_clipboard[clip_id] = clip.data
elif action == MENU_COPY_KEYFRAMES_ALL:
self.copy_clipboard[clip_id]['alpha'] = clip.data['alpha']
Expand Down Expand Up @@ -1480,7 +1480,7 @@ def Copy_Triggered(self, action, clip_ids, tran_ids):

self.copy_transition_clipboard[tran_id] = {}

if action == MENU_COPY_TRANSITION or action == MENU_COPY_ALL:
if action in [MENU_COPY_TRANSITION, MENU_COPY_ALL]:
self.copy_transition_clipboard[tran_id] = tran.data
elif action == MENU_COPY_KEYFRAMES_ALL:
self.copy_transition_clipboard[tran_id]['brightness'] = tran.data['brightness']
Expand Down Expand Up @@ -1891,7 +1891,7 @@ def Slice_Triggered(self, action, clip_ids, trans_ids, playhead_position=0):
# Determine if waveform needs to be redrawn
has_audio_data = clip_id in self.waveform_cache

if action == MENU_SLICE_KEEP_LEFT or action == MENU_SLICE_KEEP_BOTH:
if action in [MENU_SLICE_KEEP_LEFT, MENU_SLICE_KEEP_BOTH]:
# Get details of original clip
position_of_clip = float(clip.data["position"])
start_of_clip = float(clip.data["start"])
Expand Down Expand Up @@ -1954,7 +1954,7 @@ def Slice_Triggered(self, action, clip_ids, trans_ids, playhead_position=0):
# Invalid transition, skip to next item
continue

if action == MENU_SLICE_KEEP_LEFT or action == MENU_SLICE_KEEP_BOTH:
if action in [MENU_SLICE_KEEP_LEFT, MENU_SLICE_KEEP_BOTH]:
# Get details of original transition
position_of_tran = float(trans.data["position"])

Expand Down

0 comments on commit 2042227

Please sign in to comment.