mirror of
https://github.com/OpenShot/openshot-qt.git
synced 2026-06-08 22:18:12 -07:00
STY: Simplify the code
I used my tool flake8-simplify (version 0.4.1) to find those. I didn't use contextlib.suppress.
This commit is contained in:
@@ -11,11 +11,10 @@ for root, dirs, files in os.walk(os.path.join(PATH, 'build', 'OpenShot Video Edi
|
||||
file_path = os.path.join(root, basename)
|
||||
|
||||
output = str(subprocess.Popen(["oTool", "-L", file_path], stdout=subprocess.PIPE).communicate()[0])
|
||||
if not "is not an object file" in output:
|
||||
if "is not an object file" not in output:
|
||||
dependency_path = output.replace('\\n','').split('\\t')[1].split(' ')[0]
|
||||
dependency_version = output.replace('\\n','').split('\\t')[1].split(' (')[1].replace(')','')
|
||||
|
||||
if "@executable_path" not in dependency_path:
|
||||
if not dependency_path in unique_dependencies.keys():
|
||||
unique_dependencies[dependency_path] = file_path
|
||||
print("%s => %s (%s)" % (basename, dependency_path, dependency_version))
|
||||
if "@executable_path" not in dependency_path and dependency_path not in unique_dependencies.keys():
|
||||
unique_dependencies[dependency_path] = file_path
|
||||
print("%s => %s (%s)" % (basename, dependency_path, dependency_version))
|
||||
|
||||
@@ -58,7 +58,7 @@ ROOT = os.geteuid() == 0
|
||||
# For Debian packaging it could be a fakeroot so reset flag to prevent execution of
|
||||
# system update services for Mime and Desktop registrations.
|
||||
# The debian/openshot.postinst script must do those.
|
||||
if not os.getenv("FAKEROOTKEY") == None:
|
||||
if os.getenv("FAKEROOTKEY") is not None:
|
||||
log.info("NOTICE: Detected execution in a FakeRoot so disabling calls to system update services.")
|
||||
ROOT = False
|
||||
|
||||
|
||||
@@ -29,7 +29,17 @@ def is_image(file):
|
||||
"""Check a File object if the file extension is a known image format"""
|
||||
path = file["path"].lower()
|
||||
|
||||
if path.endswith((".jpg", ".jpeg", ".png", ".bmp", ".svg", ".thm", ".gif", ".bmp", ".pgm", ".tif", ".tiff")):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
img_file_extensions = (
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".png",
|
||||
".bmp",
|
||||
".svg",
|
||||
".thm",
|
||||
".gif",
|
||||
".bmp",
|
||||
".pgm",
|
||||
".tif",
|
||||
".tiff",
|
||||
)
|
||||
return path.endswith(img_file_extensions)
|
||||
|
||||
@@ -77,10 +77,8 @@ class LoggerLibOpenShot(Thread):
|
||||
|
||||
# Receive all debug message sent from libopenshot (if any)
|
||||
socks = dict(poller.poll(1000))
|
||||
if socks:
|
||||
if socks.get(socket) == zmq.POLLIN:
|
||||
msg = socket.recv(zmq.NOBLOCK)
|
||||
if socks and socks.get(socket) == zmq.POLLIN:
|
||||
msg = socket.recv(zmq.NOBLOCK)
|
||||
|
||||
# Log the message (if any)
|
||||
if msg:
|
||||
log.info(msg.strip().decode('UTF-8'))
|
||||
|
||||
@@ -113,16 +113,17 @@ class QueryObject:
|
||||
match = True
|
||||
for key, value in kwargs.items():
|
||||
|
||||
# Equals
|
||||
if key in child and not child[key] == value:
|
||||
if key in child and child[key] != value:
|
||||
match = False
|
||||
break
|
||||
|
||||
# Intersection Position
|
||||
if key == "intersect":
|
||||
if (child.get("position", 0) > value or
|
||||
child.get("position", 0) + (child.get("end", 0) - child.get("start", 0)) < value):
|
||||
match = False
|
||||
if key == "intersect" and (
|
||||
child.get("position", 0) > value
|
||||
or child.get("position", 0) + (child.get("end", 0) - child.get("start", 0)) < value
|
||||
):
|
||||
match = False
|
||||
|
||||
|
||||
# Add matched record
|
||||
if match:
|
||||
@@ -341,7 +342,7 @@ class Effect(QueryObject):
|
||||
# Loop through all kwargs (and look for matches)
|
||||
match = True
|
||||
for key, value in kwargs.items():
|
||||
if key in child and not child[key] == value:
|
||||
if key in child and child[key] != value:
|
||||
match = False
|
||||
break
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ def load_theme():
|
||||
s = settings.get_settings()
|
||||
|
||||
# If theme not reported by OS
|
||||
if QIcon.themeName() == '' and not s.get("theme") == "No Theme":
|
||||
if QIcon.themeName() == '' and s.get("theme") != "No Theme":
|
||||
|
||||
# Address known Ubuntu bug of not reporting configured theme name, use default ubuntu theme
|
||||
if os.getenv('DESKTOP_SESSION') == 'ubuntu':
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
import sys, os
|
||||
# Import parent folder (so it can find other imports)
|
||||
PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
if not PATH in sys.path:
|
||||
if PATH not in sys.path:
|
||||
sys.path.append(PATH)
|
||||
|
||||
import random
|
||||
|
||||
@@ -114,7 +114,7 @@ class MainWindow(QMainWindow, updates.UpdateWatcher):
|
||||
self.tutorial_manager.hide_dialog()
|
||||
|
||||
# Prompt user to save (if needed)
|
||||
if app.project.needs_save() and not self.mode == "unittest":
|
||||
if app.project.needs_save() and self.mode != "unittest":
|
||||
log.info('Prompt user to save project')
|
||||
# Translate object
|
||||
_ = app._tr
|
||||
@@ -751,10 +751,7 @@ class MainWindow(QMainWindow, updates.UpdateWatcher):
|
||||
_("Would you like to import %s as an image sequence?") % filename,
|
||||
QMessageBox.No | QMessageBox.Yes
|
||||
)
|
||||
if ret == QMessageBox.Yes:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return ret == QMessageBox.Yes
|
||||
|
||||
def actionAdd_to_Timeline_trigger(self, event):
|
||||
# Loop through selected files
|
||||
@@ -2663,7 +2660,7 @@ class MainWindow(QMainWindow, updates.UpdateWatcher):
|
||||
get_current_Version()
|
||||
|
||||
# Connect signals
|
||||
if not self.mode == "unittest":
|
||||
if self.mode != "unittest":
|
||||
self.RecoverBackup.connect(self.recover_backup)
|
||||
|
||||
# Initialize and start the thumbnail HTTP server
|
||||
@@ -2860,7 +2857,7 @@ class MainWindow(QMainWindow, updates.UpdateWatcher):
|
||||
self.OpenProjectSignal.connect(self.open_project)
|
||||
|
||||
# Show window
|
||||
if not self.mode == "unittest":
|
||||
if self.mode != "unittest":
|
||||
self.show()
|
||||
else:
|
||||
log.info('Hiding UI for unittests')
|
||||
|
||||
@@ -149,7 +149,7 @@ class BlenderModel():
|
||||
row.append(col)
|
||||
|
||||
# Append ROW to MODEL (if does not already exist in model)
|
||||
if not path in self.model_paths:
|
||||
if path not in self.model_paths:
|
||||
self.model.appendRow(row)
|
||||
self.model_paths[path] = path
|
||||
|
||||
|
||||
@@ -66,9 +66,14 @@ class ChangelogModel():
|
||||
author_str = commit.get("author", "")
|
||||
subject_str = commit.get("subject", "")
|
||||
|
||||
if filter:
|
||||
if not (filter.lower() in hash_str.lower() or filter.lower() in date_str.lower() or filter.lower() in author_str.lower() or filter.lower() in subject_str.lower()):
|
||||
continue
|
||||
if filter and not (
|
||||
filter.lower() in hash_str.lower()
|
||||
or filter.lower() in date_str.lower()
|
||||
or filter.lower() in author_str.lower()
|
||||
or filter.lower() in subject_str.lower()
|
||||
):
|
||||
continue
|
||||
|
||||
|
||||
row = []
|
||||
|
||||
|
||||
@@ -84,9 +84,13 @@ class CreditsModel():
|
||||
if "icons" in person.keys():
|
||||
icons = person["icons"]
|
||||
|
||||
if filter:
|
||||
if not (filter.lower() in name.lower() or filter.lower() in email.lower() or filter.lower() in website.lower()):
|
||||
continue
|
||||
if filter and not (
|
||||
filter.lower() in name.lower()
|
||||
or filter.lower() in email.lower()
|
||||
or filter.lower() in website.lower()
|
||||
):
|
||||
continue
|
||||
|
||||
if len(name) < 2:
|
||||
# Skip blank names
|
||||
continue
|
||||
|
||||
@@ -107,10 +107,13 @@ class EffectsModel(QObject):
|
||||
category = "Video"
|
||||
|
||||
# Filter out effect (if needed)
|
||||
if win.effectsFilter.text() != "":
|
||||
if (not win.effectsFilter.text().lower() in self.app._tr(title).lower()
|
||||
and not win.effectsFilter.text().lower() in self.app._tr(description).lower()):
|
||||
continue
|
||||
if (
|
||||
win.effectsFilter.text() != ""
|
||||
and win.effectsFilter.text().lower() not in self.app._tr(title).lower()
|
||||
and win.effectsFilter.text().lower() not in self.app._tr(description).lower()
|
||||
):
|
||||
continue
|
||||
|
||||
|
||||
# Check for thumbnail path (in build-in cache)
|
||||
thumb_path = os.path.join(info.IMAGES_PATH, "cache", icon_name)
|
||||
|
||||
@@ -69,15 +69,12 @@ class FileFilterProxyModel(QSortFilterProxyModel):
|
||||
index = self.sourceModel().index(sourceRow, 2, sourceParent)
|
||||
tags = self.sourceModel().data(index) # tags (i.e. intro, custom, etc...)
|
||||
|
||||
if get_app().window.actionFilesShowVideo.isChecked():
|
||||
if not media_type == "video":
|
||||
return False
|
||||
elif get_app().window.actionFilesShowAudio.isChecked():
|
||||
if not media_type == "audio":
|
||||
return False
|
||||
elif get_app().window.actionFilesShowImage.isChecked():
|
||||
if not media_type == "image":
|
||||
return False
|
||||
if get_app().window.actionFilesShowVideo.isChecked() and media_type != "video":
|
||||
return False
|
||||
elif get_app().window.actionFilesShowAudio.isChecked() and media_type != "audio":
|
||||
return False
|
||||
elif get_app().window.actionFilesShowImage.isChecked() and media_type != "image":
|
||||
return False
|
||||
|
||||
# Match against regex pattern
|
||||
return self.filterRegExp().indexIn(file_name) >= 0 or self.filterRegExp().indexIn(tags) >= 0
|
||||
|
||||
@@ -219,57 +219,55 @@ class PropertiesModel(updates.UpdateInterface):
|
||||
# Get effect object
|
||||
c = Effect.get(id=clip_id)
|
||||
|
||||
if c:
|
||||
# Update clip attribute
|
||||
if property_key in c.data:
|
||||
log.info("remove keyframe: %s" % c.data)
|
||||
if c and property_key in c.data: # Update clip attribute
|
||||
log.info("remove keyframe: %s" % c.data)
|
||||
|
||||
# Determine type of keyframe (normal or color)
|
||||
keyframe_list = []
|
||||
if property_type == "color":
|
||||
keyframe_list = [c.data[property_key]["red"], c.data[property_key]["blue"], c.data[property_key]["green"]]
|
||||
else:
|
||||
keyframe_list = [c.data[property_key]]
|
||||
# Determine type of keyframe (normal or color)
|
||||
keyframe_list = []
|
||||
if property_type == "color":
|
||||
keyframe_list = [c.data[property_key]["red"], c.data[property_key]["blue"], c.data[property_key]["green"]]
|
||||
else:
|
||||
keyframe_list = [c.data[property_key]]
|
||||
|
||||
# Loop through each keyframe (red, blue, and green)
|
||||
for keyframe in keyframe_list:
|
||||
# Loop through each keyframe (red, blue, and green)
|
||||
for keyframe in keyframe_list:
|
||||
|
||||
# Keyframe
|
||||
# Loop through points, find a matching points on this frame
|
||||
closest_point = None
|
||||
point_to_delete = None
|
||||
for point in keyframe["Points"]:
|
||||
if point["co"]["X"] == self.frame_number:
|
||||
# Found point, Update value
|
||||
clip_updated = True
|
||||
point_to_delete = point
|
||||
break
|
||||
if point["co"]["X"] == closest_point_x:
|
||||
closest_point = point
|
||||
|
||||
# If no point found, use closest point x
|
||||
if not point_to_delete:
|
||||
point_to_delete = closest_point
|
||||
|
||||
# Delete point (if needed)
|
||||
if point_to_delete:
|
||||
# Keyframe
|
||||
# Loop through points, find a matching points on this frame
|
||||
closest_point = None
|
||||
point_to_delete = None
|
||||
for point in keyframe["Points"]:
|
||||
if point["co"]["X"] == self.frame_number:
|
||||
# Found point, Update value
|
||||
clip_updated = True
|
||||
log.info("Found point to delete at X=%s" % point_to_delete["co"]["X"])
|
||||
keyframe["Points"].remove(point_to_delete)
|
||||
point_to_delete = point
|
||||
break
|
||||
if point["co"]["X"] == closest_point_x:
|
||||
closest_point = point
|
||||
|
||||
# Reduce # of clip properties we are saving (performance boost)
|
||||
c.data = {property_key: c.data[property_key]}
|
||||
# If no point found, use closest point x
|
||||
if not point_to_delete:
|
||||
point_to_delete = closest_point
|
||||
|
||||
# Save changes
|
||||
if clip_updated:
|
||||
# Save
|
||||
c.save()
|
||||
# Delete point (if needed)
|
||||
if point_to_delete:
|
||||
clip_updated = True
|
||||
log.info("Found point to delete at X=%s" % point_to_delete["co"]["X"])
|
||||
keyframe["Points"].remove(point_to_delete)
|
||||
|
||||
# Update the preview
|
||||
get_app().window.refreshFrameSignal.emit()
|
||||
# Reduce # of clip properties we are saving (performance boost)
|
||||
c.data = {property_key: c.data[property_key]}
|
||||
|
||||
# Clear selection
|
||||
self.parent.clearSelection()
|
||||
# Save changes
|
||||
if clip_updated:
|
||||
# Save
|
||||
c.save()
|
||||
|
||||
# Update the preview
|
||||
get_app().window.refreshFrameSignal.emit()
|
||||
|
||||
# Clear selection
|
||||
self.parent.clearSelection()
|
||||
|
||||
def color_update(self, item, new_color, interpolation=-1, interpolation_details=[]):
|
||||
"""Insert/Update a color keyframe for the selected row"""
|
||||
|
||||
@@ -140,9 +140,9 @@ class Preferences(QDialog):
|
||||
if sort_category:
|
||||
self.category_sort[category] = sort_category
|
||||
|
||||
if not setting_type == "hidden":
|
||||
if setting_type != "hidden":
|
||||
# Load setting
|
||||
if not category in self.category_names:
|
||||
if category not in self.category_names:
|
||||
self.category_names[category] = []
|
||||
|
||||
# Create scrollarea
|
||||
|
||||
@@ -69,7 +69,7 @@ class PreviewParent(QObject):
|
||||
_ = get_app()._tr
|
||||
|
||||
# Only JUCE audio errors bubble up here now
|
||||
if not get_app().window.mode == "unittest":
|
||||
if get_app().window.mode != "unittest":
|
||||
QMessageBox.warning(self.parent, _("Audio Error"), _("Please fix the following error and restart OpenShot\n%s") % error)
|
||||
|
||||
@pyqtSlot(object, object)
|
||||
|
||||
@@ -681,12 +681,11 @@ class VideoWidget(QWidget, updates.UpdateInterface):
|
||||
"""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
|
||||
# Is this the same clip_id already being transformed?
|
||||
if self and self.transforming_clip and not clip_id:
|
||||
# Clear transform
|
||||
self.transforming_clip = None
|
||||
need_refresh = True
|
||||
|
||||
# Get new clip for transform
|
||||
if clip_id:
|
||||
|
||||
@@ -183,7 +183,7 @@ class EmojisListView(QListView):
|
||||
# Off by one, due to 'show all' choice above
|
||||
dropdown_index = index + 1
|
||||
|
||||
if not self.win.mode == "unittest":
|
||||
if self.win.mode != "unittest":
|
||||
self.win.emojiFilterGroup.currentIndexChanged.connect(self.group_changed)
|
||||
self.win.emojiFilterGroup.setCurrentIndex(dropdown_index)
|
||||
|
||||
|
||||
@@ -213,10 +213,9 @@ class PropertiesTableView(QTableView):
|
||||
# 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
|
||||
if c and property_key in c.data:
|
||||
# Grab the original data for this item/property
|
||||
self.original_data = c.data
|
||||
|
||||
# For numeric values, apply percentage within parameter's allowable range
|
||||
if property_type in ["float", "int"] and property_name != "Track":
|
||||
|
||||
@@ -434,16 +434,17 @@ class TimelineWebView(TimelineMixin, updates.UpdateInterface):
|
||||
clipboard_tran_ids = [k for k, v in self.copy_transition_clipboard.items() if v.get('id')]
|
||||
|
||||
# Paste Menu (if entire clips or transitions are copied)
|
||||
if self.copy_clipboard or self.copy_transition_clipboard:
|
||||
if len(clipboard_clip_ids) + len(clipboard_tran_ids) > 0:
|
||||
menu = QMenu(self)
|
||||
Paste_Clip = menu.addAction(_("Paste"))
|
||||
Paste_Clip.setShortcut(QKeySequence(self.window.getShortcutByName("pasteAll")))
|
||||
Paste_Clip.triggered.connect(
|
||||
partial(self.Paste_Triggered, MENU_PASTE, float(position), int(layer_id), [], [])
|
||||
)
|
||||
if (self.copy_clipboard or self.copy_transition_clipboard) and (
|
||||
len(clipboard_clip_ids) + len(clipboard_tran_ids) > 0
|
||||
):
|
||||
menu = QMenu(self)
|
||||
Paste_Clip = menu.addAction(_("Paste"))
|
||||
Paste_Clip.setShortcut(QKeySequence(self.window.getShortcutByName("pasteAll")))
|
||||
Paste_Clip.triggered.connect(
|
||||
partial(self.Paste_Triggered, MENU_PASTE, float(position), int(layer_id), [], [])
|
||||
)
|
||||
|
||||
return menu.popup(QCursor.pos())
|
||||
return menu.popup(QCursor.pos())
|
||||
|
||||
@pyqtSlot(str)
|
||||
def ShowClipMenu(self, clip_id=None):
|
||||
@@ -1401,7 +1402,11 @@ class TimelineWebView(TimelineMixin, updates.UpdateInterface):
|
||||
"""Add a Point to a Keyframe dict. Always remove existing points,
|
||||
if any collisions are found"""
|
||||
# Get all points that don't match new point coordinate
|
||||
cleaned_points = [point for point in keyframe["Points"] if not point.get("co", {}).get("X") == new_point.get("co", {}).get("X")]
|
||||
cleaned_points = [
|
||||
point
|
||||
for point in keyframe["Points"]
|
||||
if point.get("co", {}).get("X") != new_point.get("co", {}).get("X")
|
||||
]
|
||||
cleaned_points.append(new_point)
|
||||
|
||||
# Replace points with new list
|
||||
@@ -2367,13 +2372,12 @@ class TimelineWebView(TimelineMixin, updates.UpdateInterface):
|
||||
clip.data["reader"]["video_length"] = self.round_to_multiple(
|
||||
float(clip.data["reader"]["video_length"]) / speed_factor, even_multiple)
|
||||
|
||||
if action == MENU_TIME_NONE:
|
||||
if action == MENU_TIME_NONE and "original_data" in clip.data.keys():
|
||||
# Reset original end & duration (if available)
|
||||
if "original_data" in clip.data.keys():
|
||||
clip.data["end"] = clip.data["original_data"]["end"]
|
||||
clip.data["duration"] = clip.data["original_data"]["duration"]
|
||||
clip.data["reader"]["video_length"] = clip.data["original_data"]["video_length"]
|
||||
clip.data.pop("original_data")
|
||||
clip.data["end"] = clip.data["original_data"]["end"]
|
||||
clip.data["duration"] = clip.data["original_data"]["duration"]
|
||||
clip.data["reader"]["video_length"] = clip.data["original_data"]["video_length"]
|
||||
clip.data.pop("original_data")
|
||||
|
||||
# Save changes
|
||||
self.update_clip_data(clip.data, only_basic_props=False, ignore_reader=True)
|
||||
|
||||
Reference in New Issue
Block a user