Skip to content

Commit af857fb

Browse files
committed
improved tutorial docs
1 parent 6171030 commit af857fb

File tree

3 files changed

+182
-3
lines changed

3 files changed

+182
-3
lines changed
+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# -*- coding: utf-8 -*-
2-
"""Tutorials for straditize"""
2+
"""Tutorials for straditize
3+
4+
The :mod:`~straditize.widgets.tutorial.beginner` tutorial serves as a first
5+
look into the software. The
6+
:mod:`~straditize.widgets.tutorial.hoya_del_castillo` tutorial on the other
7+
hand is a true pollen diagram with more than 20 taxa. Both tutorials can be
8+
started from the GUI through the :guilabel:`Tutorial` button.
9+
10+
**Disclaimer**
11+
12+
Copyright (C) 2018-2019 Philipp S. Sommer
13+
14+
This program is free software: you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation, either version 3 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program. If not, see <https://www.gnu.org/licenses/>.
26+
"""
327
from straditize.widgets.tutorial.beginner import Tutorial
428
from straditize.widgets.tutorial.hoya_del_castillo import (
529
HoyaDelCastilloTutorial)

straditize/widgets/tutorial/beginner.py

+138-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
# -*- coding: utf-8 -*-
22
"""The tutorial of straditize
33
4-
This module contains a guided tour through straditize"""
4+
This module contains a guided tour to get started with straditize
5+
6+
**Disclaimer**
7+
8+
Copyright (C) 2018-2019 Philipp S. Sommer
9+
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
"""
523
import os.path as osp
624
import shutil
725
import glob
@@ -16,6 +34,11 @@
1634

1735

1836
class TutorialDocs(UrlHelp, DockMixin):
37+
"""A documentation viewer for the tutorial docs
38+
39+
This viewer is accessible through the :attr:`Tutorial.tutorial_docs`
40+
attribute and shows the :attr:`~TutorialPage.src_file` for the
41+
tutorial :attr:`~Tutorial.pages`"""
1942

2043
dock_position = QtCore.Qt.RightDockWidgetArea
2144

@@ -54,6 +77,16 @@ class TutorialNavigation(QtWidgets.QWidget):
5477
current_step = 0
5578

5679
def __init__(self, nsteps, validate, *args, **kwargs):
80+
"""
81+
Parameters
82+
----------
83+
nsteps: int
84+
The total number of steps in the :class:`Tutorial`
85+
validate: callable
86+
A callable that takes the :attr:`current_step` as an argument and
87+
returns a :class:`bool` whether the current step is valid and
88+
finished, or not
89+
"""
5790
super().__init__(*args, **kwargs)
5891
self.enabled = True
5992
self.nsteps = nsteps
@@ -108,13 +141,20 @@ def __init__(self, nsteps, validate, *args, **kwargs):
108141
self.btn_info.clicked.connect(self.show_info)
109142

110143
def setEnabled(self, enable):
144+
"""Enable or disable the navigation buttons
145+
146+
Parameters
147+
----------
148+
enable: bool
149+
Whether to enable or disable the buttons"""
111150
for w in [self.btn_prev, self.btn_next, self.btn_skip, self.btn_info]:
112151
w.setEnabled(enable)
113152
if enable:
114153
self.maybe_enable_widgets()
115154
self.enabled = enable
116155

117156
def maybe_enable_widgets(self):
157+
"""Enable the buttons based on the :attr:`current_step`"""
118158
i = self.current_step
119159
if i == 0:
120160
self.btn_next.setEnabled(True)
@@ -131,12 +171,20 @@ def maybe_enable_widgets(self):
131171
self.btn_prev.setEnabled(i > 0)
132172

133173
def show_info(self):
174+
"""Trigger the :attr:`step_changed` signal with the current step"""
134175
self.step_changed.emit(self.current_step, self.current_step)
135176

136177
def display_hint(self):
178+
"""Trigger the :attr:`hint_requested` signal with the current step"""
137179
self.hint_requested.emit(self.current_step)
138180

139181
def set_current_step(self, i):
182+
"""Change the :attr:`current_step`
183+
184+
Parameters
185+
----------
186+
i: int
187+
The :attr:`current_step` to switch to"""
140188
self.current_step = i
141189
self.progress_bar.setValue(i)
142190
self.btn_next.setText('Next')
@@ -152,6 +200,7 @@ def set_current_step(self, i):
152200
self.maybe_enable_widgets()
153201

154202
def goto_next_step(self):
203+
"""Increase the :attr:`current_step` by one"""
155204
if self.validate(self.current_step):
156205
if self.current_step <= self.nsteps:
157206
self.set_current_step(self.current_step + 1)
@@ -161,11 +210,14 @@ def goto_next_step(self):
161210
self.set_current_step(self.current_step)
162211

163212
def goto_prev_step(self):
213+
"""Decrease the :attr:`current_step` by one"""
164214
if self.current_step > 0:
165215
self.set_current_step(self.current_step - 1)
166216
self.step_changed.emit(self.current_step + 1, self.current_step)
167217

168218
def skip(self):
219+
"""Skip the :attr:`current_step` and emit the :attr:`skipped` signal
220+
"""
169221
self.skipped.emit(self.current_step)
170222
self.goto_next_step()
171223

@@ -176,17 +228,29 @@ class TutorialPage(object):
176228
Subclasses show implement the :meth:`show_hint` method and the
177229
:meth:`is_finished` property"""
178230

231+
#: The source directory for the docs
179232
src_dir = osp.join(osp.dirname(__file__), 'beginner')
180233

234+
#: The basename of the stratigraphic diagram image for this tutorial
181235
src_base = 'beginner-tutorial.png'
182236

237+
#: The complete path to the of the stratigraphic diagram image for this
238+
#: tutorial
183239
src_file = osp.join(src_dir, src_base)
184240

185241
#: str. The tooltip that has been shown. This attribute is mainly for
186242
#: testing purposes
187243
_last_tooltip_shown = None
188244

189245
def __init__(self, filename, tutorial):
246+
"""
247+
Parameters
248+
----------
249+
filename: str
250+
The basename (without ending) of the RST file corresponding to this
251+
tutorial page
252+
tutorial: Tutorial
253+
The tutorial instance"""
190254
self.filename = filename
191255
self.tutorial = tutorial
192256
self.straditizer_widgets = self.tutorial.straditizer_widgets
@@ -229,6 +293,8 @@ def lock_viewer(self, lock):
229293
pass
230294

231295
def show(self):
296+
"""Show the page and browse the :attr:`filename` in the tutorial docs
297+
"""
232298
try:
233299
self.lock_viewer(False)
234300
self.tutorial.tutorial_docs.browse(self.filename)
@@ -309,14 +375,27 @@ class Tutorial(StraditizerControlBase, TutorialPage):
309375

310376
@property
311377
def current_page(self):
378+
"""The current page of the tutorial (corresponding to the
379+
:attr:`TutorialNavigation.current_step`)"""
312380
return self.pages[self.navigation.current_step]
313381

314382
@property
315383
def load_image_step(self):
384+
"""The number of the page that loads the diagram image (i.e. the index
385+
of the :class:`LoadImage` instance in the :attr:`pages` attribute"""
316386
return next(
317387
(i for i, p in enumerate(self.pages) if isinstance(p, LoadImage)),
318388
1)
319389

390+
#: A list of the :class:`TutorialPages` for this tutorial
391+
pages = []
392+
393+
#: A :class:`TutorialDocs` to display the RST-files of the tutorial
394+
tutorial_docs = None
395+
396+
#: A :class:`TutorialNavigation` to navigate through the tutorial
397+
navigation = None
398+
320399
def __init__(self, straditizer_widgets):
321400
from psyplot_gui.main import mainwindow
322401
self.init_straditizercontrol(straditizer_widgets)
@@ -374,6 +453,8 @@ def show(self):
374453
self.tutorial_docs.show_rst(rst, name, files=files)
375454

376455
def setup_tutorial_pages(self):
456+
"""Setup the :attr:`pages` attribute and initialize the tutorial pages
457+
"""
377458
self.pages = [
378459
self,
379460
ControlIntro('beginner-tutorial-control', self),
@@ -402,6 +483,12 @@ def refresh(self):
402483
self.navigation.set_current_step(self.load_image_step)
403484

404485
def _get_tutorial_stradi(self):
486+
"""Get the straditizer for this tutorial
487+
488+
Returns
489+
-------
490+
straditize.straditizer.Straditizer
491+
The straditizer for this tutorial or None if it is closed"""
405492
src_file = self.src_base
406493
get_attr = self.straditizer_widgets.get_attr
407494
for stradi in self.straditizer_widgets._straditizers:
@@ -424,15 +511,50 @@ def close(self):
424511
del self.pages
425512

426513
def goto_page(self, old, new):
514+
"""Go to another page
515+
516+
Parameters
517+
----------
518+
old: int
519+
The index of the old page in the :attr:`pages` attribute that is
520+
subject to be deactivated (see :meth:`TutorialPage.deactivate`)
521+
new: int
522+
The index of the new page in the :attr:`pages` attribute that is
523+
subject to be activated (see :meth:`TutorialPage.activate`)
524+
525+
See Also
526+
--------
527+
TutorialPage.activate
528+
TutorialPage.deactivate"""
427529
self.pages[old].deactivate()
428530
page = self.pages[new]
429531
page.show()
430532
page.activate()
431533

432534
def skip_page(self, i):
535+
"""Skip a tutorial page
536+
537+
Parameters
538+
----------
539+
i: int
540+
The index of the page in the :attr:`pages` attribute
541+
542+
See Also
543+
--------
544+
TutorialPage.skip"""
433545
self.pages[i].skip()
434546

435547
def display_hint(self, i):
548+
"""Display the hint for a tutorial page
549+
550+
Parameters
551+
----------
552+
i: int
553+
The index of the page in the :attr:`pages` attribute
554+
555+
See Also
556+
--------
557+
TutorialPage.hint"""
436558
stradi = self._get_tutorial_stradi()
437559
if stradi is None and i > self.load_image_step:
438560
self.navigation.set_current_step(self.load_image_step)
@@ -444,6 +566,20 @@ def display_hint(self, i):
444566
self.pages[i].hint()
445567

446568
def validate_page(self, i, silent=False):
569+
"""Validate a tutorial page
570+
571+
Parameters
572+
----------
573+
i: int
574+
The index of the page in the :attr:`pages` attribute
575+
silent: bool
576+
If True, and the page is not yet finished (see
577+
:attr:`TutorialPage.is_finished`), the hint is displayed
578+
579+
Returns
580+
-------
581+
bool
582+
True, if the page :attr:`~TutorialPage.is_finished`"""
447583
ret = self.pages[i].is_finished
448584
if not silent and not ret:
449585
self.navigation.display_hint()
@@ -773,6 +909,7 @@ class ColumnNames(TutorialPage):
773909

774910
select_names_button_clicked = False
775911

912+
#: The column names in the diagram
776913
column_names = [
777914
'Pinus', 'Juniperus', 'Quercus ilex-type', 'Chenopodiaceae']
778915

straditize/widgets/tutorial/hoya_del_castillo.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
# -*- coding: utf-8 -*-
22
"""The tutorial of straditize
33
4-
This module contains a guided tour through straditize"""
4+
This module contains an advanced guided tour through straditize
5+
6+
**Disclaimer**
7+
8+
Copyright (C) 2018-2019 Philipp S. Sommer
9+
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
"""
523
import os.path as osp
624
import numpy as np
725
from PyQt5 import QtWidgets

0 commit comments

Comments
 (0)