Skip to content

Commit ba2ca78

Browse files
committed
STY: Use enumerate, avoid Yoda conditions
Found by flake8-simplify
1 parent 685326f commit ba2ca78

File tree

7 files changed

+21
-47
lines changed

7 files changed

+21
-47
lines changed

src/classes/exporters/edl.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ def export_edl():
9292
f.write("FCM: NON-DROP FRAME\n\n")
9393

9494
# Loop through each track
95-
edit_index = 1
9695
export_position = 0.0
9796

9897
# Loop through clips on this track
99-
for clip in clips_on_track:
98+
for edit_index, clip in enumerate(clips_on_track, start=1):
10099
# Do we need a blank clip?
101100
if clip.data.get('position', 0.0) > export_position:
102101
# Blank clip (i.e. 00:00:00:00)
@@ -165,7 +164,5 @@ def export_edl():
165164
export_position = clip.data.get('position') + (clip.data.get('end') - clip.data.get('start'))
166165
f.write("\n")
167166

168-
edit_index += 1
169-
170167
# Update counters
171168
track_count -= 1

src/classes/info.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,8 @@
170170

171171
def website_language():
172172
"""Get the current website language code for URLs"""
173-
if CURRENT_LANGUAGE == "zh_CN":
174-
return "zh-hans/"
175-
elif CURRENT_LANGUAGE == "zh_TW":
176-
return "zh-hant/"
177-
elif CURRENT_LANGUAGE == "en_US":
178-
return ""
179-
else:
180-
return "%s/" % CURRENT_LANGUAGE.split("_")[0].lower()
173+
return {
174+
"zh_CN": "zh-hans/",
175+
"zh_TW": "zh-hant/",
176+
"en_US": ""}.get(CURRENT_LANGUAGE,
177+
"%s/" % CURRENT_LANGUAGE.split("_")[0].lower())

src/windows/export.py

+5-19
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,15 @@ def __init__(self):
227227
self.profile_names.sort()
228228

229229
# Loop through sorted profiles
230-
box_index = 0
231230
self.selected_profile_index = 0
232-
for profile_name in self.profile_names:
233-
231+
for box_index, profile_name in enumerate(self.profile_names):
234232
# Add to dropdown
235233
self.cboProfile.addItem(self.getProfileName(self.getProfilePath(profile_name)), self.getProfilePath(profile_name))
236234

237235
# Set default (if it matches the project)
238236
if get_app().project.get(['profile']) in profile_name:
239237
self.selected_profile_index = box_index
240238

241-
# increment item counter
242-
box_index += 1
243-
244-
245239
# ********* Simple Project Type **********
246240
# load the simple project type dropdown
247241
presets = []
@@ -259,14 +253,12 @@ def __init__(self):
259253
log.error("Failed to parse file '%s' as a preset: %s" % (preset_path, e))
260254

261255
# Exclude duplicates
262-
type_index = 0
263256
selected_type = 0
264257
presets = list(set(presets))
265-
for item in sorted(presets):
258+
for type_index, item in enumerate(sorted(presets)):
266259
self.cboSimpleProjectType.addItem(item, item)
267260
if item == _("All Formats"):
268261
selected_type = type_index
269-
type_index += 1
270262

271263
# Always select 'All Formats' option
272264
self.cboSimpleProjectType.setCurrentIndex(selected_type)
@@ -559,12 +551,10 @@ def cboSimpleTarget_index_changed(self, widget, index):
559551

560552
self.txtAudioCodec.setText(audio_codec_name)
561553

562-
layout_index = 0
563-
for layout in self.channel_layout_choices:
554+
for layout_index, layout in enumerate(self.channel_layout_choices):
564555
if layout == int(c[0].childNodes[0].data):
565556
self.cboChannelLayout.setCurrentIndex(layout_index)
566557
break
567-
layout_index += 1
568558

569559
# Free up DOM memory
570560
xmldoc.unlink()
@@ -606,17 +596,13 @@ def cboSimpleVideoProfile_index_changed(self, widget, index):
606596
def populateAllProfiles(self, selected_profile_path):
607597
"""Populate the full list of profiles"""
608598
# Look for matching profile in advanced options
609-
profile_index = 0
610-
for profile_name in self.profile_names:
599+
for profile_index, profile_name in enumerate(self.profile_names):
611600
# Check for matching profile
612601
if self.getProfilePath(profile_name) == selected_profile_path:
613602
# Matched!
614603
self.cboProfile.setCurrentIndex(profile_index)
615604
break
616605

617-
# increment index
618-
profile_index += 1
619-
620606
def cboSimpleQuality_index_changed(self, widget, index):
621607
selected_quality = widget.itemData(index)
622608
log.info(selected_quality)
@@ -797,7 +783,7 @@ def accept(self):
797783
"video_bitrate": int(self.convert_to_bytes(self.txtVideoBitRate.text())),
798784
"start_frame": self.txtStartFrame.value(),
799785
"end_frame": self.txtEndFrame.value(),
800-
"interlace": ((interlacedIndex == 1) or (interlacedIndex == 2)),
786+
"interlace": interlacedIndex in [1, 2],
801787
"topfirst": interlacedIndex == 1
802788
}
803789

src/windows/file_properties.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,23 @@ def __init__(self, file):
143143
self.txtOutput.setText(json.dumps(file.data, sort_keys=True, indent=2))
144144

145145
# Add channel layouts
146-
channel_layout_index = 0
147146
selected_channel_layout_index = 0
148147
current_channel_layout = 0
149148
if self.file.data["has_audio"]:
150149
current_channel_layout = int(self.file.data["channel_layout"])
151150
self.channel_layout_choices = []
152-
for layout in [(0, _("Unknown")),
153-
(openshot.LAYOUT_MONO, _("Mono (1 Channel)")),
154-
(openshot.LAYOUT_STEREO, _("Stereo (2 Channel)")),
155-
(openshot.LAYOUT_SURROUND, _("Surround (3 Channel)")),
156-
(openshot.LAYOUT_5POINT1, _("Surround (5.1 Channel)")),
157-
(openshot.LAYOUT_7POINT1, _("Surround (7.1 Channel)"))]:
151+
layouts = [(0, _("Unknown")),
152+
(openshot.LAYOUT_MONO, _("Mono (1 Channel)")),
153+
(openshot.LAYOUT_STEREO, _("Stereo (2 Channel)")),
154+
(openshot.LAYOUT_SURROUND, _("Surround (3 Channel)")),
155+
(openshot.LAYOUT_5POINT1, _("Surround (5.1 Channel)")),
156+
(openshot.LAYOUT_7POINT1, _("Surround (7.1 Channel)"))]
157+
for channel_layout_index, layout in enumerate(layouts):
158158
log.info(layout)
159159
self.channel_layout_choices.append(layout[0])
160160
self.cboChannelLayout.addItem(layout[1], layout[0])
161161
if current_channel_layout == layout[0]:
162162
selected_channel_layout_index = channel_layout_index
163-
channel_layout_index += 1
164163

165164
# Select matching channel layout
166165
self.cboChannelLayout.setCurrentIndex(selected_channel_layout_index)

src/windows/models/transition_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def filterAcceptsRow(self, sourceRow, sourceParent):
5858
trans_name = self.sourceModel().data(index) # transition name (i.e. Fade In)
5959

6060
# Return, if regExp match in displayed format.
61-
return "common" == group_name and self.filterRegExp().indexIn(trans_name) >= 0
61+
return group_name == "common" and self.filterRegExp().indexIn(trans_name) >= 0
6262

6363
# Continue running built-in parent filter logic
6464
return super(TransitionFilterProxyModel, self).filterAcceptsRow(sourceRow, sourceParent)

src/windows/profile.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,14 @@ def __init__(self):
9090
self.profile_names.sort()
9191

9292
# Loop through sorted profiles
93-
box_index = 0
94-
for profile_name in self.profile_names:
95-
93+
for box_index, profile_name in enumerate(self.profile_names):
9694
# Add to dropdown
9795
self.cboProfile.addItem(profile_name, self.profile_paths[profile_name])
9896

9997
# Set default (if it matches the project)
10098
if get_app().project.get(['profile']) in profile_name:
10199
self.initial_index = box_index
102100

103-
# increment item counter
104-
box_index += 1
105-
106101
# Connect signals
107102
self.cboProfile.currentIndexChanged.connect(self.dropdown_index_changed)
108103
self.cboProfile.activated.connect(self.dropdown_activated)

src/windows/title_editor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def get_ref_color(self, id):
522522
return self.get_ref_color(xlink_ref_id)
523523
elif ref_node.childNodes:
524524
for stop_node in ref_node.childNodes:
525-
if "stop" == stop_node.nodeName:
525+
if stop_node.nodeName == "stop":
526526
# get color from stop
527527
ar = stop_node.attributes["style"].value.split(";")
528528
sc = self.find_in_list(ar, "stop-color:")

0 commit comments

Comments
 (0)