Skip to content

Commit 27bf096

Browse files
committed
main_window: Code style (indentation, exceptions)
- 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
1 parent 1ec4d24 commit 27bf096

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

src/windows/main_window.py

+40-41
Original file line numberDiff line numberDiff line change
@@ -545,34 +545,34 @@ def open_project(self, file_path, clear_thumbnails=True):
545545
def clear_all_thumbnails(self):
546546
"""Clear all user thumbnails"""
547547
try:
548-
openshot_thumbnail_path = os.path.join(info.USER_PATH, "thumbnail")
549-
if os.path.exists(openshot_thumbnail_path):
550-
log.info("Clear all thumbnails: %s" % openshot_thumbnail_path)
551-
shutil.rmtree(openshot_thumbnail_path)
552-
os.mkdir(openshot_thumbnail_path)
548+
clear_path = os.path.join(info.USER_PATH, "thumbnail")
549+
if os.path.exists(clear_path):
550+
log.info("Clear all thumbnails: %s" % clear_path)
551+
shutil.rmtree(clear_path)
552+
os.mkdir(clear_path)
553553

554554
# Clear any blender animations
555-
openshot_blender_path = os.path.join(info.USER_PATH, "blender")
556-
if os.path.exists(openshot_blender_path):
557-
log.info("Clear all animations: %s" % openshot_blender_path)
558-
shutil.rmtree(openshot_blender_path)
559-
os.mkdir(openshot_blender_path)
555+
clear_path = os.path.join(info.USER_PATH, "blender")
556+
if os.path.exists(clear_path):
557+
log.info("Clear all animations: %s" % clear_path)
558+
shutil.rmtree(clear_path)
559+
os.mkdir(clear_path)
560560

561561
# Clear any title animations
562-
openshot_title_path = os.path.join(info.USER_PATH, "title")
563-
if os.path.exists(openshot_title_path):
564-
log.info("Clear all titles: %s" % openshot_title_path)
565-
shutil.rmtree(openshot_title_path)
566-
os.mkdir(openshot_title_path)
562+
clear_path = os.path.join(info.USER_PATH, "title")
563+
if os.path.exists(clear_path):
564+
log.info("Clear all titles: %s" % clear_path)
565+
shutil.rmtree(clear_path)
566+
os.mkdir(clear_path)
567567

568568
# Clear any backups
569569
if os.path.exists(info.BACKUP_FILE):
570570
log.info("Clear backup: %s" % info.BACKUP_FILE)
571571
# Remove backup file
572572
os.unlink(info.BACKUP_FILE)
573573

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

577577
def actionOpen_trigger(self, event):
578578
app = get_app()
@@ -1041,13 +1041,13 @@ def actionSaveFrame_trigger(self, event):
10411041
framePathTime = QDateTime()
10421042

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

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

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

12661266
# Seek to marker position (if any)
1267-
if closest_position != None:
1267+
if closest_position is not None:
12681268
# Seek
12691269
frame_to_seek = round(closest_position * fps_float) + 1
12701270
self.SeekSignal.emit(frame_to_seek)
@@ -1317,7 +1317,7 @@ def actionNextMarker_trigger(self, event):
13171317
closest_position = marker_position
13181318

13191319
# Seek to marker position (if any)
1320-
if closest_position != None:
1320+
if closest_position is not None:
13211321
# Seek
13221322
frame_to_seek = round(closest_position * fps_float) + 1
13231323
self.SeekSignal.emit(frame_to_seek)
@@ -1404,16 +1404,16 @@ def keyPressEvent(self, event):
14041404
ui_util.setup_icon(self, self.actionPlay, "actionPlay", "media-playback-pause")
14051405
self.actionPlay.setChecked(True)
14061406

1407-
elif key.matches(self.getShortcutByName("playToggle")) == QKeySequence.ExactMatch or \
1408-
key.matches(self.getShortcutByName("playToggle1")) == QKeySequence.ExactMatch or \
1409-
key.matches(self.getShortcutByName("playToggle2")) == QKeySequence.ExactMatch or \
1410-
key.matches(self.getShortcutByName("playToggle3")) == QKeySequence.ExactMatch:
1407+
elif (key.matches(self.getShortcutByName("playToggle")) == QKeySequence.ExactMatch or
1408+
key.matches(self.getShortcutByName("playToggle1")) == QKeySequence.ExactMatch or
1409+
key.matches(self.getShortcutByName("playToggle2")) == QKeySequence.ExactMatch or
1410+
key.matches(self.getShortcutByName("playToggle3")) == QKeySequence.ExactMatch):
14111411
# Toggle playbutton and show properties
14121412
self.actionPlay.trigger()
14131413
self.propertyTableView.select_frame(player.Position())
14141414

1415-
elif key.matches(self.getShortcutByName("deleteItem")) == QKeySequence.ExactMatch or \
1416-
key.matches(self.getShortcutByName("deleteItem1")) == QKeySequence.ExactMatch:
1415+
elif (key.matches(self.getShortcutByName("deleteItem")) == QKeySequence.ExactMatch or
1416+
key.matches(self.getShortcutByName("deleteItem1")) == QKeySequence.ExactMatch):
14171417
# Delete selected clip / transition
14181418
self.actionRemoveClip.trigger()
14191419
self.actionRemoveTransition.trigger()
@@ -2225,11 +2225,8 @@ def setup_toolbars(self):
22252225

22262226
# Add fixed spacer(s) (one for each "Other control" to keep playback controls centered)
22272227
ospacer1 = QWidget(self)
2228-
ospacer1.setMinimumSize(32, 1) # actionSaveFrame
2228+
ospacer1.setMinimumSize(32, 1) # actionSaveFrame
22292229
self.videoToolbar.addWidget(ospacer1)
2230-
#ospacer2 = QWidget(self)
2231-
#ospacer2.setMinimumSize(32, 1) # ???
2232-
#self.videoToolbar.addWidget(ospacer2)
22332230

22342231
# Add left spacer
22352232
spacer = QWidget(self)
@@ -2283,7 +2280,9 @@ def setup_toolbars(self):
22832280
self.sliderZoom.setInvertedControls(True)
22842281
self.sliderZoom.resize(100, 16)
22852282

2286-
self.zoomScaleLabel = QLabel( _("{} seconds").format(zoomToSeconds(self.sliderZoom.value())) )
2283+
self.zoomScaleLabel = QLabel(
2284+
_("{} seconds").format(zoomToSeconds(self.sliderZoom.value()))
2285+
)
22872286

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

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

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

2429-
except:
2428+
except Exception:
24302429
# Just ignore
24312430
self.has_launcher = False
24322431

@@ -2438,7 +2437,7 @@ def ExportFinished(self, path):
24382437
# Set progress on Unity launcher and hide progress bar
24392438
launcher.set_property("progress", 0.0)
24402439
launcher.set_property("progress_visible", False)
2441-
except:
2440+
except Exception:
24422441
pass
24432442

24442443
def transformTriggered(self, clip_id):
@@ -2596,9 +2595,9 @@ def __init__(self, mode=None):
25962595

25972596
# Set encoding method
25982597
if s.get("hw-decoder"):
2599-
openshot.Settings.Instance().HARDWARE_DECODER = int(str(s.get("hw-decoder")))
2598+
openshot.Settings.Instance().HARDWARE_DECODER = int(str(s.get("hw-decoder")))
26002599
else:
2601-
openshot.Settings.Instance().HARDWARE_DECODER = 0
2600+
openshot.Settings.Instance().HARDWARE_DECODER = 0
26022601

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

26212620
# Set audio playback settings
26222621
if s.get("playback-audio-device"):
2623-
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = str(s.get("playback-audio-device"))
2622+
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = str(s.get("playback-audio-device"))
26242623
else:
2625-
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = ""
2624+
openshot.Settings.Instance().PLAYBACK_AUDIO_DEVICE_NAME = ""
26262625

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

26362635
# Set use omp threads number environment variable
26372636
if s.get("omp_threads_number"):
2638-
openshot.Settings.Instance().OMP_THREADS = max(2,int(str(s.get("omp_threads_number"))))
2637+
openshot.Settings.Instance().OMP_THREADS = max(2, int(str(s.get("omp_threads_number"))))
26392638
else:
26402639
openshot.Settings.Instance().OMP_THREADS = 12
26412640

26422641
# Set use ffmpeg threads number environment variable
26432642
if s.get("ff_threads_number"):
2644-
openshot.Settings.Instance().FF_THREADS = max(1,int(str(s.get("ff_threads_number"))))
2643+
openshot.Settings.Instance().FF_THREADS = max(1, int(str(s.get("ff_threads_number"))))
26452644
else:
26462645
openshot.Settings.Instance().FF_THREADS = 8
26472646

0 commit comments

Comments
 (0)