Skip to content

Commit 41e6b58

Browse files
committed
Tutorial: Format code, eliminate one-use variables
1 parent 9a27269 commit 41e6b58

File tree

1 file changed

+71
-28
lines changed

1 file changed

+71
-28
lines changed

src/windows/views/tutorial.py

+71-28
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def paintEvent(self, event, *args):
6565
if self.arrow:
6666
arrow_height = 20
6767
path = QPainterPath()
68-
path.moveTo (0, 35)
69-
path.lineTo (31, 35 - arrow_height)
70-
path.lineTo (31, (35 - arrow_height) + (arrow_height * 2))
71-
path.lineTo (0, 35)
68+
path.moveTo(0, 35)
69+
path.lineTo(31, 35 - arrow_height)
70+
path.lineTo(31, (35 - arrow_height) + (arrow_height * 2))
71+
path.lineTo(0, 35)
7272
painter.fillPath(path, frameColor)
7373
painter.drawPath(path)
7474

@@ -102,7 +102,7 @@ def __init__(self, id, text, arrow, *args):
102102

103103
# Create vertical box
104104
vbox = QVBoxLayout()
105-
vbox.setContentsMargins(32,10,10,10)
105+
vbox.setContentsMargins(32, 10, 10, 10)
106106

107107
# Add label
108108
self.label = QLabel(self)
@@ -132,7 +132,7 @@ def __init__(self, id, text, arrow, *args):
132132

133133
# Add button box
134134
hbox = QHBoxLayout()
135-
hbox.setContentsMargins(20,10,0,0)
135+
hbox.setContentsMargins(20, 10, 0, 0)
136136

137137
# Create buttons
138138
self.btn_close_tips = QPushButton(self)
@@ -165,7 +165,7 @@ class TutorialManager(object):
165165
def process(self, parent_name=None):
166166
""" Process and show the first non-completed tutorial """
167167

168-
# Do nothing if a tutorial is already visible
168+
# If a tutorial is already visible, just update it
169169
if self.current_dialog:
170170
# XXX: Respond to possible dock floats/moves
171171
self.dock.raise_()
@@ -176,24 +176,19 @@ def process(self, parent_name=None):
176176
for tutorial_details in self.tutorial_objects:
177177
# Get details
178178
tutorial_id = tutorial_details["id"]
179-
tutorial_object_id = tutorial_details["object_id"]
180-
tutorial_text = tutorial_details["text"]
181-
tutorial_x_offset = tutorial_details["x"]
182-
tutorial_y_offset = tutorial_details["y"]
183-
turorial_arrow = tutorial_details["arrow"]
184179

185180
# Get QWidget
186-
tutorial_object = self.get_object(tutorial_object_id)
181+
tutorial_object = self.get_object(tutorial_details["object_id"])
187182

188183
# Skip completed tutorials (and invisible widgets)
189-
if tutorial_object.visibleRegion().isEmpty() or tutorial_id in self.tutorial_ids or not self.tutorial_enabled:
184+
if not self.tutorial_enabled or tutorial_id in self.tutorial_ids or tutorial_object.visibleRegion().isEmpty():
190185
continue
191186

192187
# Create tutorial
193188
self.position_widget = tutorial_object
194-
self.x_offset = tutorial_x_offset
195-
self.y_offset = tutorial_y_offset
196-
tutorial_dialog = TutorialDialog(tutorial_id, tutorial_text, turorial_arrow)
189+
self.x_offset = tutorial_details["x"]
190+
self.y_offset = tutorial_details["y"]
191+
tutorial_dialog = TutorialDialog(tutorial_id, tutorial_details["text"], tutorial_details["arrow"])
197192

198193
# Connect signals
199194
tutorial_dialog.btn_next_tip.clicked.connect(functools.partial(self.next_tip, tutorial_id))
@@ -284,7 +279,7 @@ def exit_manager(self):
284279
self.win.dockEffects.visibilityChanged.disconnect()
285280
self.win.dockProperties.visibilityChanged.disconnect()
286281
self.win.dockVideo.visibilityChanged.disconnect()
287-
except:
282+
except Exception:
288283
# Ignore errors from this
289284
pass
290285

@@ -326,18 +321,66 @@ def __init__(self, win):
326321
self.tutorial_ids = s.get("tutorial_ids").split(",")
327322

328323
# Add all possible tutorials
329-
self.tutorial_objects = [ {"id":"0", "x":400, "y":0, "object_id":"filesTreeView", "text":_("<b>Welcome!</b> OpenShot Video Editor is an award-winning, open-source video editing application! This tutorial will walk you through the basics.<br><br>Would you like to automatically send errors and metrics to help improve OpenShot?"), "arrow":False},
330-
{"id":"1", "x":20, "y":0, "object_id":"filesTreeView", "text":_("<b>Project Files:</b> Get started with your project by adding video, audio, and image files here. Drag and drop files from your file system."), "arrow":True},
331-
{"id":"2", "x":200, "y":-15, "object_id":"timeline", "text":_("<b>Timeline:</b> Arrange your clips on the timeline here. Overlap clips to create automatic transitions. Access lots of fun presets and options by right-clicking on clips."), "arrow":True},
332-
{"id":"3", "x":200, "y":100, "object_id":"dockVideoContents", "text":_("<b>Video Preview:</b> Watch your timeline video preview here. Use the buttons (play, rewind, fast-forward) to control the video playback."), "arrow":True},
333-
{"id":"4", "x":20, "y":-35, "object_id":"propertyTableView", "text":_("<b>Properties:</b> View and change advanced properties of clips and effects here. Right-clicking on clips is usually faster than manually changing properties."), "arrow":True},
334-
{"id":"5", "x":20, "y":10, "object_id":"transitionsTreeView", "text":_("<b>Transitions:</b> Create a gradual fade from one clip to another. Drag and drop a transition onto the timeline and position it on top of a clip (usually at the beginning or ending)."), "arrow":True},
335-
{"id":"6", "x":20, "y":20, "object_id":"effectsTreeView", "text":_("<b>Effects:</b> Adjust brightness, contrast, saturation, and add exciting special effects. Drag and drop an effect onto the timeline and position it on top of a clip (or track)"), "arrow":True},
336-
{"id":"7", "x":-265, "y":-22, "object_id":"export_button", "text":_("<b>Export Video:</b> When you are ready to create your finished video, click this button to export your timeline as a single video file."), "arrow":True}
337-
]
324+
self.tutorial_objects = [
325+
{"id": "0",
326+
"x": 400,
327+
"y": 0,
328+
"object_id": "filesTreeView",
329+
"text": _("<b>Welcome!</b> OpenShot Video Editor is an award-winning, open-source video editing application! This tutorial will walk you through the basics.<br><br>Would you like to automatically send errors and metrics to help improve OpenShot?"),
330+
"arrow": False
331+
},
332+
{"id": "1",
333+
"x": 20,
334+
"y": 0,
335+
"object_id": "filesTreeView",
336+
"text": _("<b>Project Files:</b> Get started with your project by adding video, audio, and image files here. Drag and drop files from your file system."),
337+
"arrow": True
338+
},
339+
{"id": "2",
340+
"x": 200,
341+
"y": -15,
342+
"object_id": "timeline",
343+
"text": _("<b>Timeline:</b> Arrange your clips on the timeline here. Overlap clips to create automatic transitions. Access lots of fun presets and options by right-clicking on clips."),
344+
"arrow": True
345+
},
346+
{"id": "3",
347+
"x": 200,
348+
"y": 100,
349+
"object_id": "dockVideoContents",
350+
"text": _("<b>Video Preview:</b> Watch your timeline video preview here. Use the buttons (play, rewind, fast-forward) to control the video playback."),
351+
"arrow": True},
352+
{"id": "4",
353+
"x": 20,
354+
"y": -35,
355+
"object_id": "propertyTableView",
356+
"text": _("<b>Properties:</b> View and change advanced properties of clips and effects here. Right-clicking on clips is usually faster than manually changing properties."),
357+
"arrow": True
358+
},
359+
{"id": "5",
360+
"x": 20,
361+
"y": 10,
362+
"object_id": "transitionsTreeView",
363+
"text": _("<b>Transitions:</b> Create a gradual fade from one clip to another. Drag and drop a transition onto the timeline and position it on top of a clip (usually at the beginning or ending)."),
364+
"arrow": True
365+
},
366+
{"id": "6",
367+
"x": 20,
368+
"y": 20,
369+
"object_id": "effectsTreeView",
370+
"text": _("<b>Effects:</b> Adjust brightness, contrast, saturation, and add exciting special effects. Drag and drop an effect onto the timeline and position it on top of a clip (or track)"),
371+
"arrow": True
372+
},
373+
{"id": "7",
374+
"x": -265,
375+
"y": -22,
376+
"object_id": "export_button",
377+
"text": _("<b>Export Video:</b> When you are ready to create your finished video, click this button to export your timeline as a single video file."),
378+
"arrow": True
379+
}
380+
]
338381

339382
# Configure tutorial frame
340-
self.dock.setTitleBarWidget(QWidget()) # Prevents window decoration
383+
self.dock.setTitleBarWidget(QWidget()) # Prevents window decoration
341384
self.dock.setAttribute(Qt.WA_NoSystemBackground, True)
342385
self.dock.setAttribute(Qt.WA_TranslucentBackground, True)
343386
self.dock.setWindowFlags(Qt.FramelessWindowHint)

0 commit comments

Comments
 (0)