Skip to content

Commit

Permalink
main_window: Code style (indentation, exceptions)
Browse files Browse the repository at this point in the history
- clear_all_thumbnails was changed to track the path being cleared, and
  to properly log that path and the error when an exception is raised,
  instead of always reporting the error for info.THUMBNAIL_PATH
  • Loading branch information
ferdnyc committed Jan 10, 2020
1 parent 1ec4d24 commit 27bf096
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions src/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,34 +545,34 @@ def open_project(self, file_path, clear_thumbnails=True):
def clear_all_thumbnails(self):
"""Clear all user thumbnails"""
try:
openshot_thumbnail_path = os.path.join(info.USER_PATH, "thumbnail")
if os.path.exists(openshot_thumbnail_path):
log.info("Clear all thumbnails: %s" % openshot_thumbnail_path)
shutil.rmtree(openshot_thumbnail_path)
os.mkdir(openshot_thumbnail_path)
clear_path = os.path.join(info.USER_PATH, "thumbnail")
if os.path.exists(clear_path):
log.info("Clear all thumbnails: %s" % clear_path)
shutil.rmtree(clear_path)
os.mkdir(clear_path)

# Clear any blender animations
openshot_blender_path = os.path.join(info.USER_PATH, "blender")
if os.path.exists(openshot_blender_path):
log.info("Clear all animations: %s" % openshot_blender_path)
shutil.rmtree(openshot_blender_path)
os.mkdir(openshot_blender_path)
clear_path = os.path.join(info.USER_PATH, "blender")
if os.path.exists(clear_path):
log.info("Clear all animations: %s" % clear_path)
shutil.rmtree(clear_path)
os.mkdir(clear_path)

# Clear any title animations
openshot_title_path = os.path.join(info.USER_PATH, "title")
if os.path.exists(openshot_title_path):
log.info("Clear all titles: %s" % openshot_title_path)
shutil.rmtree(openshot_title_path)
os.mkdir(openshot_title_path)
clear_path = os.path.join(info.USER_PATH, "title")
if os.path.exists(clear_path):
log.info("Clear all titles: %s" % clear_path)
shutil.rmtree(clear_path)
os.mkdir(clear_path)

# Clear any backups
if os.path.exists(info.BACKUP_FILE):
log.info("Clear backup: %s" % info.BACKUP_FILE)
# Remove backup file
os.unlink(info.BACKUP_FILE)

except:
log.info("Failed to clear thumbnails: %s" % info.THUMBNAIL_PATH)
except Exception as ex:
log.info("Failed to clear {}: {}".format(clear_path, ex))

def actionOpen_trigger(self, event):
app = get_app()
Expand Down Expand Up @@ -1041,13 +1041,13 @@ def actionSaveFrame_trigger(self, event):
framePathTime = QDateTime()

# Get and Save the frame (return is void, so we cannot check for success/fail here - must use file modification timestamp)
openshot.Timeline.GetFrame(self.timeline_sync.timeline,self.preview_thread.current_frame).Save(framePath, 1.0)
openshot.Timeline.GetFrame(self.timeline_sync.timeline, self.preview_thread.current_frame).Save(framePath, 1.0)

# Show message to user
if os.path.exists(framePath) and (QFileInfo(framePath).lastModified() > framePathTime):
self.statusBar.showMessage(_("Saved Frame to %s" % framePath), 5000)
else:
self.statusBar.showMessage( _("Failed to save image to %s" % framePath), 5000)
self.statusBar.showMessage(_("Failed to save image to %s" % framePath), 5000)

# Reset the MaxSize to match the preview and reset the preview cache
viewport_rect = self.videoPreview.centeredViewport(self.videoPreview.width(), self.videoPreview.height())
Expand Down Expand Up @@ -1264,7 +1264,7 @@ def actionPreviousMarker_trigger(self, event):
closest_position = marker_position

# Seek to marker position (if any)
if closest_position != None:
if closest_position is not None:
# Seek
frame_to_seek = round(closest_position * fps_float) + 1
self.SeekSignal.emit(frame_to_seek)
Expand Down Expand Up @@ -1317,7 +1317,7 @@ def actionNextMarker_trigger(self, event):
closest_position = marker_position

# Seek to marker position (if any)
if closest_position != None:
if closest_position is not None:
# Seek
frame_to_seek = round(closest_position * fps_float) + 1
self.SeekSignal.emit(frame_to_seek)
Expand Down Expand Up @@ -1404,16 +1404,16 @@ def keyPressEvent(self, event):
ui_util.setup_icon(self, self.actionPlay, "actionPlay", "media-playback-pause")
self.actionPlay.setChecked(True)

elif key.matches(self.getShortcutByName("playToggle")) == QKeySequence.ExactMatch or \
key.matches(self.getShortcutByName("playToggle1")) == QKeySequence.ExactMatch or \
key.matches(self.getShortcutByName("playToggle2")) == QKeySequence.ExactMatch or \
key.matches(self.getShortcutByName("playToggle3")) == QKeySequence.ExactMatch:
elif (key.matches(self.getShortcutByName("playToggle")) == QKeySequence.ExactMatch or
key.matches(self.getShortcutByName("playToggle1")) == QKeySequence.ExactMatch or
key.matches(self.getShortcutByName("playToggle2")) == QKeySequence.ExactMatch or
key.matches(self.getShortcutByName("playToggle3")) == QKeySequence.ExactMatch):
# Toggle playbutton and show properties
self.actionPlay.trigger()
self.propertyTableView.select_frame(player.Position())

elif key.matches(self.getShortcutByName("deleteItem")) == QKeySequence.ExactMatch or \
key.matches(self.getShortcutByName("deleteItem1")) == QKeySequence.ExactMatch:
elif (key.matches(self.getShortcutByName("deleteItem")) == QKeySequence.ExactMatch or
key.matches(self.getShortcutByName("deleteItem1")) == QKeySequence.ExactMatch):
# Delete selected clip / transition
self.actionRemoveClip.trigger()
self.actionRemoveTransition.trigger()
Expand Down Expand Up @@ -2225,11 +2225,8 @@ def setup_toolbars(self):

# Add fixed spacer(s) (one for each "Other control" to keep playback controls centered)
ospacer1 = QWidget(self)
ospacer1.setMinimumSize(32, 1) # actionSaveFrame
ospacer1.setMinimumSize(32, 1) # actionSaveFrame
self.videoToolbar.addWidget(ospacer1)
#ospacer2 = QWidget(self)
#ospacer2.setMinimumSize(32, 1) # ???
#self.videoToolbar.addWidget(ospacer2)

# Add left spacer
spacer = QWidget(self)
Expand Down Expand Up @@ -2283,7 +2280,9 @@ def setup_toolbars(self):
self.sliderZoom.setInvertedControls(True)
self.sliderZoom.resize(100, 16)

self.zoomScaleLabel = QLabel( _("{} seconds").format(zoomToSeconds(self.sliderZoom.value())) )
self.zoomScaleLabel = QLabel(
_("{} seconds").format(zoomToSeconds(self.sliderZoom.value()))
)

# add zoom widgets
self.timelineToolbar.addAction(self.actionTimelineZoomIn)
Expand Down Expand Up @@ -2386,7 +2385,7 @@ def InitCacheSettings(self):
log.info("cache-limit-mb: %s" % s.get("cache-limit-mb"))

# Get MB limit of cache (and convert to bytes)
cache_limit = s.get("cache-limit-mb") * 1024 * 1024 # Convert MB to Bytes
cache_limit = s.get("cache-limit-mb") * 1024 * 1024 # Convert MB to Bytes

# Clear old cache
new_cache_object = None
Expand Down Expand Up @@ -2426,7 +2425,7 @@ def FrameExported(self, title_message, start_frame, end_frame, current_frame):
launcher.set_property("progress", current_frame / (end_frame - start_frame))
launcher.set_property("progress_visible", True)

except:
except Exception:
# Just ignore
self.has_launcher = False

Expand All @@ -2438,7 +2437,7 @@ def ExportFinished(self, path):
# Set progress on Unity launcher and hide progress bar
launcher.set_property("progress", 0.0)
launcher.set_property("progress_visible", False)
except:
except Exception:
pass

def transformTriggered(self, clip_id):
Expand Down Expand Up @@ -2596,9 +2595,9 @@ def __init__(self, mode=None):

# Set encoding method
if s.get("hw-decoder"):
openshot.Settings.Instance().HARDWARE_DECODER = int(str(s.get("hw-decoder")))
openshot.Settings.Instance().HARDWARE_DECODER = int(str(s.get("hw-decoder")))
else:
openshot.Settings.Instance().HARDWARE_DECODER = 0
openshot.Settings.Instance().HARDWARE_DECODER = 0

# Set graphics card for decoding
if s.get("graca_number_de"):
Expand All @@ -2620,9 +2619,9 @@ def __init__(self, mode=None):

# Set audio playback settings
if s.get("playback-audio-device"):
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = str(s.get("playback-audio-device"))
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = str(s.get("playback-audio-device"))
else:
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = ""
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = ""

# Set OMP thread enabled flag (for stability)
if s.get("omp_threads_enabled"):
Expand All @@ -2635,13 +2634,13 @@ def __init__(self, mode=None):

# Set use omp threads number environment variable
if s.get("omp_threads_number"):
openshot.Settings.Instance().OMP_THREADS = max(2,int(str(s.get("omp_threads_number"))))
openshot.Settings.Instance().OMP_THREADS = max(2, int(str(s.get("omp_threads_number"))))
else:
openshot.Settings.Instance().OMP_THREADS = 12

# Set use ffmpeg threads number environment variable
if s.get("ff_threads_number"):
openshot.Settings.Instance().FF_THREADS = max(1,int(str(s.get("ff_threads_number"))))
openshot.Settings.Instance().FF_THREADS = max(1, int(str(s.get("ff_threads_number"))))
else:
openshot.Settings.Instance().FF_THREADS = 8

Expand Down

0 comments on commit 27bf096

Please sign in to comment.