-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtutorial.py
More file actions
144 lines (115 loc) · 4.59 KB
/
tutorial.py
File metadata and controls
144 lines (115 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
Copyright (c) Contributors to the Open 3D Engine Project.
For complete copyright and license terms please see the LICENSE at the root of this distribution.
SPDX-License-Identifier: Apache-2.0 OR MIT
"""
import json
import os
# Class that describes a step in the tutorial
class TutorialStep:
def __init__(self, title, content, highlight_pattern=None,
highlight_parent=None, highlight_index=0):
self.title = title
self.content = content
# The highlight pattern is a widget/item that will be highlighted
# for this particular step (can be None)
# This pattern will be passed to `pyside_utils`
# to find the widget/item. See its documentation for supported patterns
# If a named parent is specified, the first child of the specified type
# is returned
# An optional index can be specified to select a child to highlight
self.highlight_pattern = highlight_pattern
self.highlight_parent = highlight_parent
self.highlight_index = highlight_index
self.prev_step = None
self.next_step = None
# Method that will be called when the step starts
# A step class can override this method if they need
# to setup any special handling/listeners
def on_step_start(self):
# Automated testing scripts go here
pass
# Method that will be called after a step has ended
# A step class can override this method if they need
# to perform any cleanup or other tasks
def on_step_end(self):
pass
# Method that will be called if the user selects to 'Autoplay' tutorial
# Provide editor script functionality to perform the actions for the step
# Use time.sleep() judiciously so the step text can be read by user
def automate(self):
pass
def get_title(self):
return self.title
def get_content(self):
return self.content
def get_highlight_pattern(self):
return self.highlight_pattern
def get_highlight_parent(self):
return self.highlight_parent
def get_highlight_index(self):
return self.highlight_index
# Top-level entry point for describing a tutorial which is a series of steps
class Tutorial:
def __init__(self):
self.steps = []
self.title = ""
# Set True if each step has an automate() method
self.has_automation = False
# This flag is set then the user chooses "Autoplay Tutorial"
self.autoplay = False
@classmethod
def create_from_json_file(cls, file_path):
# If the specified file path isn't an absolute path,
# try to resolve it locally
if not os.path.isabs(file_path):
local_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(local_dir, file_path)
# Read the json data in from the json file
f = open(file_path)
data = json.load(f)
# Create the new tutorial
new_tutorial = cls()
new_tutorial.title = data["title"]
# Add the tutorial steps
steps = data["steps"]
for step in steps:
title = step["title"]
content = step["content"]
highlight_pattern = step.get("highlight_pattern", None)
highlight_parent = step.get("highlight_parent", None)
highlight_index = step.get("highlight_index", None)
new_step = TutorialStep(title, content, highlight_pattern, highlight_parent, highlight_index)
new_tutorial.add_step(new_step)
return new_tutorial
# Method that will be called when the tutorial starts
# A tutorial class can override this method if they need
# to setup any special handling/listeners
def on_tutorial_start(self):
pass
# Method that will be called after a tutorial has ended
# A tutorial class can override this method if they need
# to perform any cleanup or other tasks
def on_tutorial_end(self):
pass
def get_title(self):
return self.title
def get_has_automation(self):
return self.has_automation
def get_autoplay(self):
return self.autoplay
def set_autoplay(self, value):
self.autoplay = value
def add_step(self, step):
# Set the step references for the current last step on the list
if self.steps:
last_step = self.steps[-1]
last_step.next_step = step
step.prev_step = last_step
self.steps.append(step)
def get_first_step(self):
if self.steps:
return self.steps[0]
return None
def get_steps(self):
return self.steps